• 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] [0.3.7 / 0.4 / 0.3.6] Multiple onEquip bug.

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,756
Solutions
578
Reaction score
5,305
Does your server have the Multiple onEquip bug?
OKU2tSV.png

You want to put a fancy script into your server but your onEquip function is executing 2,3,4,5, even 6 times?
Have you asked your buddy what to do, to fix the issue?
You try using storage values, or your os.time to compensate?
You've tried checking the uniquid of each item, or the itemid, before equipping the item?
You've tried checking the position of these items?
You've realized that each of these options have a flaw? The same flaw?

Well look no further! maybe..

Here is the default function almost all of us are using.
It's the "hey this has been working since 2008, so let's continue using it" copy-paste script from god who knows where
Lua:
function onEquip(cid, item, slot)
    -- script here
    return callFunction(cid, item.uid, slot, boolean)
end

If you use this function, your in the same boat as I was.
Well, I am here to fix your issue.

Start using this.
Lua:
function onEquip(cid, item, slot, boolean)
    if boolean == false then
        -- script here
    end
    return callFunction(cid, item.uid, slot, boolean)
end

For whatever reason we've all forgotten about boolean and his accomplishments, but never fear..
He's been hiding in the shadows, waiting for his return..
Now is his time to shine!

Jokes aside,

When you equip your item, boolean returns true, multiple times until it's checked through everything your source wants to check, then will return false the final time and equip your item.

You can test it yourself using these two quick examples.
Lua:
function onEquip(cid, item, slot, boolean)
    print(boolean)
    print("Script working.")
    return callFunction(cid, item.uid, slot, boolean)
end
Lua:
function onEquip(cid, item, slot, boolean)
    print(boolean)
    if boolean == false then
        print("Script working.")
    end
    return callFunction(cid, item.uid, slot, boolean)
end
Using above code will get you these results in console, when equipping your armor.
Code:
true
Script working.
true
Script working.
false
Script working.
Code:
true
true
false
Script working.



I haven't found any issue while using this method, and we have nearly 400 items in our server using some form of onEquip function.

Hope I helped someone with this unusual problem that has been plaguing us all for.. 8-9 years?

Cheers,

Xikini
 
sorry reopen this post, but i was with this bug on tsf 0.3.6, and in my server i dnt have this "callfunction" or the "boolean" to call in the function, but i finde one way to solve this:

In movement.cpp, replace this funtion:

uint32_t MoveEvent::fireEquip(Player* player, Item* item, slots_t slot, bool boolean)
{
if(isScripted())
return executeEquip(player, item, slot);

return equipFunction(this, player, item, slot, boolean);
}

With this:

uint32_t MoveEvent::fireEquip(Player* player, Item* item, slots_t slot, bool boolean)
{
if(isScripted())
{
if (boolean == 1)
{
return executeEquip(player, item, slot);
}
else
{
return 0;
}
}
else
{
return equipFunction(this, player, item, slot, boolean);
}
}

It solved my onequip/ondeequip bug, this function now is trigered only one time in all my scripts...

"Srry the inglish"
 
Its funny... I just discovered this issue today, I admit I am starting to use custom scripts on my Movements folder, definitely will try your fixes :)

Cheers and happy holidays~
 
Back
Top