• 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++ New Function

_Aion_

Nothing Else
Joined
Jan 19, 2010
Messages
400
Solutions
4
Reaction score
10
Location
Jequie,Bahia,Brazil
Someone can help me?
i'm trying make an new function setCreatureHealth, this function are for set Health not MaxHealth.

i made this based on setCreatureMaxHealth, but no wokrs :(

Code:
int32_t LuaInterface::luaSetCreatureHealth(lua_State* L)//Health
    uint64_t health = (uint64_t)popNumber(L);

    ScriptEnviroment* env = getEnv();
    if (Creature* creature = env->getCreatureByUID(popNumber(L)))
    {
        creature->changeHealth(health);
        lua_pushboolean(L, true);
    }
    else
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
    }

    return 1;
}
and
Code:
int32_t LuaInterface::luaSetCreatureHealth(lua_State* L)//Health
{
    //setCreatureHealth(cid, health)
    uint64_t health = popNumber(L);
    ScriptEnviroment* env = getEnv();
    if (Player* player = env->getPlayerByUID(popNumber(L)))
    {
        player->setCreatureHealth(health);
        //lua_pushnumber(L, creature->getHealth());
        lua_pushboolean(L, true);
    }
    else
    {
        errorEx(getError(LUA_ERROR_PLAYER_NOT_FOUND));
        lua_pushboolean(L, false);
    }
    return 1;
}
both no works.

Someone good in C++ can help?
 
Solution
Isn't doCreatureAddHealth enough?

You can write this function in lua:

Tell me if it worked.

No, it's not doCreatureAddHealth
I'll explain a little.
In my server, I unlocked the limit of health and mana, works fine ...
But now, I'm making a new buff, in which I add a quantity of life for a certain amount of time and I do not want to use setCreatureMaxHealth because health does not disappear even after the buff is gone.
The way I thought of solving this is to create a function for set health instead of maxhealth.

PS: everything is in int64

EDIT: Fixed, i made by other way.
Isn't doCreatureAddHealth enough?

You can write this function in lua:
Code:
function setCreatureHealth(cid, newHealth)
    local health = getCreatureHealth(cid)
    if(health > newHealth) then
        doCreatureAddHealth(cid, -(health - newHealth))
    elseif(newHealth > health) then
        doCreatureAddHealth(cid, newHealth - health)
    end
  
    return true
end

Tell me if it worked.
 
Isn't doCreatureAddHealth enough?

You can write this function in lua:

Tell me if it worked.

No, it's not doCreatureAddHealth
I'll explain a little.
In my server, I unlocked the limit of health and mana, works fine ...
But now, I'm making a new buff, in which I add a quantity of life for a certain amount of time and I do not want to use setCreatureMaxHealth because health does not disappear even after the buff is gone.
The way I thought of solving this is to create a function for set health instead of maxhealth.

PS: everything is in int64

EDIT: Fixed, i made by other way.
 
Last edited:
Solution

Similar threads

Back
Top