mattch
New Member
- Joined
- Jun 15, 2013
- Messages
- 13
- Solutions
- 1
- Reaction score
- 3
Hello.
I'm trying to make a function that send the item to the player depot, even if he are not online.
Thats the function that i created. Its only working if the player is online.
I want to know whats wrong and what i have to do to make it work.
I'm trying to make a function that send the item to the player depot, even if he are not online.
Thats the function that i created. Its only working if the player is online.
C++:
int LuaScriptInterface::luaSendPlayerDepotItem(lua_State* L)
{
//sendPlayerDepotItem(guid, item[, depotId = 0])
uint32_t guid = getNumber<uint32_t>(L, 1);
Item* item = getScriptEnv()->getItemByUID(getNumber<uint32_t>(L, 2));
if (!item) {
lua_pushnil(L);
return 1;
}
uint32_t depotId = getNumber<uint32_t>(L, 3, 0);
Player* player = g_game.getPlayerByGUID(guid);
if (!player) {
Player tmpPlayer(nullptr);
if(!IOLoginData::loadPlayerById(&tmpPlayer, guid)) {
lua_pushnil(L);
return 1;
}
DepotChest* depotChest = (&tmpPlayer)->getDepotChest(depotId, true);
pushBoolean(L, g_game.internalAddItem(depotChest, item) == RETURNVALUE_NOERROR);
IOLoginData::savePlayer(&tmpPlayer);
} else {
DepotChest* depotChest = player->getDepotChest(depotId, true);
pushBoolean(L, g_game.internalAddItem(depotChest, item) == RETURNVALUE_NOERROR);
}
return 1;
}
I want to know whats wrong and what i have to do to make it work.