• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Function not working correctly

Erexo

Kage
Premium User
Joined
Mar 27, 2010
Messages
743
Solutions
5
Reaction score
200
Location
Pr0land
GitHub
Erexo
Hello guys,
there is a few items on my OTS that increase your max HP and MP value, but when you wear any of that items, fuction getCreatureMax[Health/Mana] return your current maxHP (with those items).
Can someone fix[?] that? It must return your maxHP/MP value without any buffs.

Mine function in cpp, using tfs 0.3.6
Code:
int32_t LuaScriptInterface::luaGetCreatureMaxHealth(lua_State* L)
{
    //getCreatureMaxHealth(cid)
    ScriptEnviroment* env = getEnv();
    if(Creature* creature = env->getCreatureByUID(popNumber(L)))
        lua_pushnumber(L, creature->getMaxHealth());
    else
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
    }
    return 1;
}

Please, help :)
 
Code:
int32_t LuaInterface::luaGetCreatureMaxHealth(lua_State* L)
{
//getCreatureMaxHealth(cid[, ignoreModifiers = false])
bool ignoreModifiers = false;
if(lua_gettop(L) > 1)
ignoreModifiers = popBoolean(L);

ScriptEnviroment* env = getEnv();
if(Creature* creature = env->getCreatureByUID(popNumber(L)))
lua_pushnumber(L, creature->getPlayer() && ignoreModifiers ? creature->healthMax : creature->getMaxHealth());
else
{
errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
lua_pushboolean(L, false);
}

return 1;
}

real hp
Code:
getCreatureMaxHealth(cid, true)
with buffs
Code:
getCreatureMaxHealth(cid)
getCreatureMaxHealth(cid, false)
 
Back
Top