• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ [TFS 1.4.1] 1098 NPC's again...

Itutorial

Legendary OT User
Joined
Dec 23, 2014
Messages
2,334
Solutions
68
Reaction score
1,012
Tried a few different things with no luck.

show1.pngshow2.png
C++:
int NpcScriptInterface::luaNpcOpenShopWindow(lua_State* L)
{
    // npc:openShopWindow(cid, items, buyCallback, sellCallback)
    if (!isTable(L, 3)) {
        reportErrorFunc(L, "item list is not a table.");
        pushBoolean(L, false);
        return 1;
    }

    Player* player = getPlayer(L, 2);
    if (!player) {
        reportErrorFunc(L, getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND));
        pushBoolean(L, false);
        return 1;
    }

    Npc* npc = getUserdata<Npc>(L, 1);
    if (!npc) {
        reportErrorFunc(L, 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;
}

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid)         end
function onCreatureSay(cid, type, msg)      npcHandler:onCreatureSay(cid, type, msg)    end
function onThink()                          npcHandler:onThink()                        end

local voices = { {text = "Be safe, bring tools whenever you are exploring!"} }
npcHandler:addModule(VoiceModule:new(voices))

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

keywordHandler:addKeyword({'stuff'}, StdModule.say, {npcHandler = npcHandler, text = 'Just ask me for a {trade} to see my offers.'})
keywordHandler:addAliasKeyword({'wares'})
keywordHandler:addAliasKeyword({'offer'})

shopModule:addBuyableItem({'rope'}, 2120, 15, 'rope') -- Ive tried adding 1 after the 15 on all didnt help
shopModule:addBuyableItem({'shovel'}, 2554, 20, 'shovel')
shopModule:addBuyableItem({'bag'}, 1987, 5, 'bag')
shopModule:addBuyableItem({'backpack'}, 1988, 20, 'backpack')
shopModule:addBuyableItem({'fishing rod'}, 2580, 30, 'fishing rod')
shopModule:addBuyableItem({'flintstone'}, 13943, 2, 'flintstone')
shopModule:addBuyableItem({'pickaxe'}, 2553, 10, 'pickaxe')
shopModule:addBuyableItem({'hatchet'}, 2559, 20, 'hatchet')
shopModule:addBuyableItem({'skinning knife'}, 13828, 15, 'skinning knife')
 
Last edited:
Solution
I guess its the sellprice or something? I figured it had to do with subtype because it was -1. The error didn't make any sense. ty
 
Back
Top