Itutorial
Legendary OT User
- Joined
- Dec 23, 2014
- Messages
- 2,461
- Solutions
- 68
- Reaction score
- 1,123
So, I am trying to figure out how to make it so npcs can send a trade window that requires items instead of gold to buy... I know I need to edit this function
I am just not sure how.
Code:
int NpcScriptInterface::luaNpcOpenCustomShopWindow(lua_State* L)
{
// npc:openShopWindow(cid, items, buyCallback, sellCallback)
if (!isTable(L, 3)) {
reportErrorFunc("item list is not a table.");
pushBoolean(L, false);
return 1;
}
Player* player = getPlayer(L, 2);
if (!player) {
reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
pushBoolean(L, false);
return 1;
}
Npc* npc = getUserdata<Npc>(L, 1);
if (!npc) {
reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}
int32_t sellCallback = -1;
if (LuaScriptInterface::isFunction(L, 5)) {
sellCallback = luaL_ref(L, LUA_REGISTRYINDEX);
}
int32_t buyCallback = -1;
if (LuaScriptInterface::isFunction(L, 4)) {
buyCallback = luaL_ref(L, LUA_REGISTRYINDEX);
}
std::list<ShopInfo> items;
lua_pushnil(L);
while (lua_next(L, 3) != 0) {
const auto tableIndex = lua_gettop(L);
ShopInfo item;
item.itemId = getField<uint32_t>(L, tableIndex, "id");
item.subType = getField<int32_t>(L, tableIndex, "subType");
if (item.subType == 0) {
item.subType = getField<int32_t>(L, tableIndex, "subtype");
lua_pop(L, 1);
}
item.buyPrice = getField<uint32_t>(L, tableIndex, "buy");
item.sellPrice = getField<uint32_t>(L, tableIndex, "sell");
item.realName = getFieldString(L, tableIndex, "name");
items.push_back(item);
lua_pop(L, 6);
}
lua_pop(L, 1);
player->closeShopWindow(false);
npc->addShopPlayer(player);
player->setShopOwner(npc, buyCallback, sellCallback);
player->openShopWindow(npc, items);
pushBoolean(L, true);
return 1;
}
I am just not sure how.