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

Lua onPrepareDeath problem...help please

kird

New Member
Joined
Jul 3, 2010
Messages
78
Reaction score
1
Well i took this script from mock's post and modified it a bit. It's a script so the players gets teleported to the temple if its health goes to 0. (yes, like in pvp arena script)
Everything goes fine but i just cant modify the players health after it "dies".

It stands on the temple with 0 health and nither the spells or the functions (doAddCreatureHealth) works.

Seems like you cant modify the health variable anymore once your health goes under 0.
what's wrong?

Code:
local templePos = {x = 1011, y = 1008, z = 6}

function onPrepareDeath(cid,aa) -- Script by mock the bear

	doPlayerAddHealth(cid,getCreatureMaxHealth(cid))
	doCreatureAddMana(cid,getCreatureMaxMana(cid))
	doTeleportThing(cid,getTownTemplePosition(getPlayerTown(cid)))
        return false
end
It's 0.3.6pl1

Thanx in advance
Kird~
 
Last edited:
well it's in sources, test with

doCreatureAddHealth(cid, getCreatureMaxHealth, true)

it worked for me once
PHP:
//doCreatureAddHealth(cid, health[, hitEffect[, hitColor[, force]]])
    lua_register(m_luaState, "doCreatureAddHealth", LuaScriptInterface::luaDoCreatureAddHealth);

PHP:
int32_t LuaScriptInterface::luaDoCreatureAddHealth(lua_State* L)
{
    //doCreatureAddHealth(uid, health[, hitEffect[, hitColor[, force]]])
    int32_t params = lua_gettop(L);
    bool force = false;
    if(params > 4)
        force = popNumber(L);

    TextColor_t hitColor = TEXTCOLOR_UNKNOWN;
    if(params > 3)
        hitColor = (TextColor_t)popNumber(L);

    MagicEffect_t hitEffect = MAGIC_EFFECT_UNKNOWN;
    if(params > 2)
        hitEffect = (MagicEffect_t)popNumber(L);

    int32_t healthChange = popNumber(L);
    ScriptEnviroment* env = getEnv();
    if(Creature* creature = env->getCreatureByUID(popNumber(L)))
    {
        if(healthChange) //do not post with 0 value
            g_game.combatChangeHealth(healthChange < 1 ? COMBAT_UNDEFINEDDAMAGE : COMBAT_HEALING,
                NULL, creature, healthChange, hitEffect, hitColor, force);

        lua_pushboolean(L, true);
    }
    else
    {
        errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));
        lua_pushboolean(L, false);
    }

    return 1;
}
 
Same error, i told you, is not about the script
Anyway this is what happends everytime

http://www.tibiapic.com/image.php?v=sGLS32T4TTTT


Any error in the server window? The fact that you're not teleported indicates that the script stops before it can execute the temple teleportation.

Also, have you tried putting the addHealth function below the doTeleport function?
 
Ye the script stops on addCreatureHealth, but there's no error on the console.
I noticed, that the server keeps looping over this script as the health is 0, but its normal i guess
 
Then try changing the script so that only the doTeleport function exists, and then below it add an addEvent function, which on execute (about 500 milliseconds after the teleport) heals the players HP/Mana.

This should separate the addHealth from onPrepareDeath, and cause the player to have full HP/Mana almost instantly when appearing in the temple.
 
try something like this.

LUA:
function onStatsChange(cid, attacker, type, combat, value)
local v,m,t = {x=1,y=1,z=1},'You got teleported because of having too less health.',{health=getCreatureMaxHealth(cid),mana=getCreatureMaxMana(cid)} -- health = how much hp is added, mana = how much mana is added.
	if isPlayer(cid) then
		if getCreatureHealth(cid) <= 20 then
			doTeleportThing(cid,v)
			doSendMagicEffect(v)
			doPlayerSendTextMessage(cid,27,m)
			doCreatureAddHealth(cid,t.health)
			doCreatureAddMana(cid,t.mana)
		end
	end
	return true
end
 
try something like this.

LUA:
function onStatsChange(cid, attacker, type, combat, value)
local v,m,t = {x=1,y=1,z=1},'You got teleported because of having too less health.',{health=getCreatureMaxHealth(cid),mana=getCreatureMaxMana(cid)} -- health = how much hp is added, mana = how much mana is added.
	if isPlayer(cid) then
		if getCreatureHealth(cid) <= 20 then
			doTeleportThing(cid,v)
			doSendMagicEffect(v)
			doPlayerSendTextMessage(cid,27,m)
			doCreatureAddHealth(cid,t.health)
			doCreatureAddMana(cid,t.mana)
		end
	end
	return true
end

It's the one im useing, and works, but as i said before im not happy about this, i'd like to solve the onPrepareDeath issue, as it might be a bug on the official sources


Then try changing the script so that only the doTeleport function exists, and then below it add an addEvent function, which on execute (about 500 milliseconds after the teleport) heals the players HP/Mana.

This should separate the addHealth from onPrepareDeath, and cause the player to have full HP/Mana almost instantly when appearing in the temple.

Working on that...
 
Back
Top