• 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!

lua_pop(L, 2) and lua_pushnumber()

legadoss

New Member
Joined
Jun 1, 2014
Messages
142
Reaction score
4
Hello, can someone explain what mean lua_pop?

there i have example code:

C++:
int32_t NpcScript::luaGetItemCount(lua_State* L){
    int item_count= (int)lua_tonumber(L, -1);
    uint32_t item_id = (uint32_t)lua_tonumber(L, -2);
    int32_t id = (int32_t)lua_tonumber(L, -3);
    lua_pop(L, 3);

    Npc* mynpc = getNpc(L);
    Creature* creature = mynpc->game->getCreatureByID(id);
    Player* player = creature? dynamic_cast<Player*>(creature) : NULL;

    if (player && player->getItem(item_id, item_count)){
        return 1;
    }else{
        return 0;
    }
}

i trying learn and make function to getitemcount but no have idea how lua_pop works


how i can achieve it?

getitemcount(item_id) > 0){
how to check if >0 == item count?
}


C++:
if (player && player->getItem(item_id, count)){
   
}

look like in lua:

if getitemcount(2160, 10)

    but how i can acheive it?
   
    if getitemcount(2160) > 10
 
Last edited:
I am not sure what version you are using to help you.

The aspect of a function in good condition would be this:
Code:
int32_t NpcScript::luaGetItemCount(lua_State* L)
{
    int item_count= (int)lua_tonumber(L, -1);
    uint32_t item_id = (uint32_t)lua_tonumber(L, -2);
    int32_t id = (int32_t)lua_tonumber(L, -3);
    lua_pop(L, 3);
    Npc* mynpc = getNpc(L);
    Creature* creature = mynpc->game->getCreatureByID(id);
    Player* player = creature ? dynamic_cast<Player*>(creature) : NULL;
    if (player && player->__getItemTypeCount(itemId, -1) >= item_count)
    {
        lua_pushboolean(L, true)
        return 1;
    }
    lua_pushboolean(L, false)
    return 1;
}

Remember to push the result to lua stack.

per example:
Code:
if getitemcount(cid, 2160, 100) then
 print("You have 100 crystal coins.")
end
 
I am not sure what version you are using to help you.

The aspect of a function in good condition would be this:
Code:
int32_t NpcScript::luaGetItemCount(lua_State* L)
{
    int item_count= (int)lua_tonumber(L, -1);
    uint32_t item_id = (uint32_t)lua_tonumber(L, -2);
    int32_t id = (int32_t)lua_tonumber(L, -3);
    lua_pop(L, 3);
    Npc* mynpc = getNpc(L);
    Creature* creature = mynpc->game->getCreatureByID(id);
    Player* player = creature ? dynamic_cast<Player*>(creature) : NULL;
    if (player && player->__getItemTypeCount(itemId, -1) >= item_count)
    {
        lua_pushboolean(L, true)
        return 1;
    }
    lua_pushboolean(L, false)
    return 1;
}

Remember to push the result to lua stack.

per example:
Code:
if getitemcount(cid, 2160, 100) then
print("You have 100 crystal coins.")
end
i use kentana 3.0 there no _getItemTypeCount() function
 

Similar threads

Back
Top