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

Fix/Patch onEquip/onDeEquip, properly handled at Login/Logout

Evil Hero

Legacy Member
TFS Developer
Joined
Dec 12, 2007
Messages
1,246
Solutions
26
Reaction score
713
Location
Germany
Greetings,

The following code will fix the problem that you have an onDeEquip when you logout.
For those who used a static code like this (example)
Code:
function onEquip(cid, item, slot)
    setCreatureMaxHealth(cid, getCreatureMaxHealth(cid) + 100)
    return true
end

function onDeEquip(cid, item, slot)
    setCreatureMaxHealth(cid, getCreatureMaxHealth(cid) - 100)
    return true
end
that if you reloged, the ammount would have been added again, without removing it first (so the player can add everytime he relogs the 100 more max health)
example:
Code:
Player has 800hp
relog..
Player has 900hp
another relog...
Player has 1000hp
and so on...

Then this is the solution for your problem:

0.2.x Version!
search for:
Code:
void Player::eek:nCreatureDisappear(const Creature* creature, uint32_t stackpos, bool isLogout)
goto:
Code:
if(isLogout)
{
    loginPosition = getPosition();
    lastLogout = time(NULL);
}
add this afterwards:
Code:
//Evil Hero, handling DeEquip if the Player logout or die.
Item* item;
for(int32_t slot = SLOT_FIRST; slot < SLOT_LAST; ++slot)
{
    if((item = getInventoryItem((slots_t)slot)))
    {
        g_moveEvents->onPlayerDeEquip(this, item, (slots_t)slot, false);
    }
}

compile and you're done.

0.3.x Version! (I'm not sure if 0.4 has this bug aswell)
search for:
Code:
void Player::eek:nCreatureDisappear(const Creature* creature, bool isLogout)
goto:
Code:
if(isLogout)
{
    loginPosition = getPosition();
    lastLogout = time(NULL);
}
add this afterwards:
Code:
//Evil Hero, handling DeEquip if the Player logout or die.
Item* item = NULL;
for(int32_t slot = SLOT_FIRST; slot < SLOT_LAST; ++slot)
{
    if(!(item = getInventoryItem((slots_t)slot)))
        continue;

    g_moveEvents->onPlayerDeEquip(this, item, (slots_t)slot, false);
}

rebuild and you're done.



kind regards, Evil Hero.
 
Last edited:
nice thing, simple and effective

maybe you have also some idea how to call onEquip/onDeEquip from luascript?(I mean, if I script one of that events skills etc are not added/removed)
 
nice thing, simple and effective

maybe you have also some idea how to call onEquip/onDeEquip from luascript?(I mean, if I script one of that events skills etc are not added/removed)

I'm currently working on something like that, as I'm having the same issue as you do :p


kind regards, Evil Hero.
 
I managed only to crash serv, also code in source looks for me like it should work but who knows, it was just fast research
 
was playin with 0.3.6 probably, or maybe 0.4a1(the released one)? I'm not sure, it was looong time ago
 
@Evil Hero, I was thinking about implementing this instead of my current solution (reversing all item effects onLogin script), but I fear player get double stats in a crash. That would happen with your implementation, right?
 
@Evil Hero, I was thinking about implementing this instead of my current solution (reversing all item effects onLogin script), but I fear player get double stats in a crash. That would happen with your implementation, right?
Hmm the only case I could think of where this might happen is if you manipulate the max hp straight through db on equip/deequip (dunno why would anyone do this) but incase of a normal crash nothing should actually happen because the player is not saved if the server crashes, so the stats are set to 0 and once you login again it should work fine.

If you still have doubts feel free to let me know in which way it would be abuseable or possible to behave in a bad way as I can't really think of a certain scenario right now
 
Back
Top