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

getCreatureStorage returning NIL

Way20

Well-Known Member
Joined
Sep 29, 2014
Messages
205
Solutions
3
Reaction score
79
On my server when the player doens't have the storage, instead of returning -1 its returning nil, so if I use
Code:
math.max(0, getCreatureStorage(cid, storage))
I got this error.

Code:
bad argument #3 to 'max' (number expected, got nil)

I think that is source related, can anyone give me a hint to where I should look?
 
Last edited:
i guess this function could solve it but
Lua:
function getStore(cid,storage)
  return getCreatureStorage(cid,storage) or -1
end

else i guess check luascript.cpp or creature.cpp
 
i guess this function could solve it but
Lua:
function getStore(cid,storage)
  return getCreatureStorage(cid,storage) or -1
end

else i guess check luascript.cpp or creature.cpp

I already made a function similar but I wanna fix it through source editing. And I already looked in luascript and creature.cpp.

Luascript.cpp
Code:
int32_t LuaInterface::luaGetCreatureStorage(lua_State* L)
{
    //getCreatureStorage(cid, key)
    std::string key = popString(L);
    ScriptEnviroment* env = getEnv();
    if(Creature* creature = env->getCreatureByUID(popNumber(L)))
    {
        std::string strValue;
        if(!creature->getStorage(key, strValue))
        {
            lua_pushnumber(L, -1);
            lua_pushnil(L);
            return 2;
        }

        int32_t intValue = atoi(strValue.c_str());
        if(intValue || strValue == "0")
            lua_pushnumber(L, intValue);
        else
            lua_pushstring(L, strValue.c_str());
    }
    else
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
    }

    return 1;
}

Creature.cpp
Code:
bool Creature::getStorage(const std::string& key, std::string& value) const
{
    StorageMap::const_iterator it = storageMap.find(key);
    if(it != storageMap.end())
    {
        value = it->second;
        return true;
    }

    value = "-1";
    return false;
}

It seens fine to me, I don't know what else I can do. :(
 
Code:
int32_t LuaInterface::luaGetCreatureStorage(lua_State* L)
{
    //getCreatureStorage(cid, key)
    uint32_t key = popNumber(L);
    ScriptEnviroment* env = getEnv();
    if(Creature* creature = env->getCreatureByUID(popNumber(L)))
    {
        std::string strValue;
        if(creature->getStorage(key, strValue))
        {
            int32_t intValue = atoi(strValue.c_str());
            if(intValue || strValue == "0")
                lua_pushnumber(L, intValue);
            else
                lua_pushstring(L, strValue.c_str());
        }
        else
            lua_pushnumber(L, -1);
    }
    else
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
    }

    return 1;
}
 
Back
Top