コード例 #1
0
// is armory already worn
int Script::getArmory(lua_State* L){
	short tx = (short)luaL_checknumber(L, 1);
	short ty = (short)luaL_checknumber(L, 2);
  string weapon = string(luaL_checkstring(L, 3));
  Inventory* inv = dynamic_cast<Creature*>(wrld.getObject(Vector2D(tx,ty)))->getInventory();
  Item it = inv->getArmory(weapon);
  if (it.isValid())
    lua_pushnumber(L, it.getId());
  else
    lua_pushnumber(L, -1);
  return 1;
}
コード例 #2
0
// use weapon
short Script::useWeapon(Vector2D source, Vector2D target){ 
  Inventory* inv = dynamic_cast<Creature*>(wrld.getObject(source))->getInventory();
  Item it = inv->getArmory("right hand");
  short index = it.getId();
  weapon_ = it.getName();
  lua_getglobal(L, "use_weapon");
  lua_pushnumber(L, source.x);
  lua_pushnumber(L, source.y);
  lua_pushnumber(L, target.x);
  lua_pushnumber(L, target.y);
  lua_pushnumber(L, index);
  if (lua_pcall(L, 5, 1, 0) != 0){
    cerr << lua_tostring(L, -1);
  }
  short attack = (short)luaL_checknumber(L, -1);
  lua_pop(L, 1);
  return attack;
}