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

C++ getPlayerItemCont -> `getPlayerItemCount' (a nil value)

legadoss

New Member
Joined
Jun 1, 2014
Messages
142
Reaction score
4
hello, someone can a little help?

NPC:
Lua:
if getPlayerItemCount(cid, 2160) >= 1 then

c++
action.cpp
C++:
#ifdef ITEM_COUNT
int ActionScript::luaActionGetPlayerItemCount(lua_State *L) //By Black Boss nigger
{
    //getPlayerItemCount(uid,itemid)
    int itemid = (int)internalGetNumber(L);
    unsigned int cid = (unsigned int)internalGetNumber(L);
 
    ActionScript *action = getActionScript(L);
 
    const KnownThing* tmp = action->GetPlayerByUID(cid);
    if(tmp)
    {
        Player *player = (Player*)(tmp->thing);
        return player->getItemX(itemid);
    }
    else
    {
        lua_pushnumber(L, -1);
        std::cout << "luaGetPlayerItemCount: player not found" << std::endl;
        return 1;
    }
 
    lua_pushnumber(L, 0);
    return 1;
}
#endif

action.h
C++:
#ifdef ITEM_COUNT
       static int32_t luaActionGetPlayerItemCount(lua_State *L);
#endif //ITEM_COUNT

npc.cpp
C++:
#ifdef ITEM_COUNT
       lua_register(luaState, "getPlayerItemCount", NpcScript::luaPlayerGetCount); //? By BlackBoss
#endif

#ifdef ITEM_COUNT
int32_t NpcScript::luaPlayerGetCount(lua_State* L)
{
  int id = (int)lua_tonumber(L, -2);
  unsigned long item_id = (unsigned long)lua_tonumber(L, -1);
  lua_pop(L, 2);
 
  Npc* mynpc = getNpc(L);
  Creature* creature = mynpc->game->getCreatureByID(id);
  Player* player = creature? dynamic_cast<Player*>(creature) : NULL;
 
  if (player && player->getItemX(item_id) > 0)
    lua_pushnumber(L, player->getItemX(item_id));
  else
    lua_pushnumber(L, -1);
 
  return 1;
}
#endif

npc.h
C++:
#ifdef ITEM_COUNT
       static int32_t luaPlayerGetCount(lua_State *L); //black boss nigger beach
#endif

player.h
C++:
#ifdef ITEM_COUNT
       unsigned long getItemX(int);
#endif

player.cpp
C++:
#ifdef ITEM_COUNT
unsigned long Player::getItemX(int itemid)
{
  unsigned long itemcount = 0;
  std::list<const Container*> blackbossbicz;
  ContainerList::const_iterator contgetitems;
  for(int i=0; i< 11; i++)
    {
      if(items[i])
        {
          if(Container *tmpcontainer = dynamic_cast<Container*>(items[i]))
            {
              blackbossbicz.push_back(tmpcontainer);
            }
          else
            {
                if(items[i]->getID() == itemid)
              itemcount += 1;
            }
        }
    }
 
  while(blackbossbicz.size() > 0)
    {
      const Container *container = blackbossbicz.front();
      blackbossbicz.pop_front();
      for(contgetitems = container->getItems(); contgetitems != container->getEnd(); ++contgetitems)
        {
            if((*contgetitems)->getID() == itemid)
          itemcount += 1;
          Container *container = dynamic_cast<Container*>(*contgetitems);
          if(container)
            {
              blackbossbicz.push_back(container);
            }
        }
    }
  return itemcount;
}
#endif
 
Back
Top