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

Solved movevent output x3

Dercas

Well-Known Member
Joined
Nov 15, 2008
Messages
158
Solutions
1
Reaction score
64
Hi all,

I need help a bit. So, I got onEquip script and the script works fine but... it returns the message 3 times instead of sending it once. The script is pretty easy and im sure it's not the fault of the script. Why?
function onEquip(player, item, slot)
local test = "test"
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, test)
return true
end
That's the code i put there for testing. The result after equipping the item once:
1717533153220.png

I've found some old threads regarding this:
onEquip executes two times, when we equip item. [$5] · Issue #278 · otland/forgottenserver (https://github.com/otland/forgottenserver/issues/278)
Lua - TFS 1.0 Movement loops 3 times (https://otland.net/threads/tfs-1-0-movement-loops-3-times.209686)

But any solutions / fixes are not really helping in my case.
I'm using TFS 1.4.2, 10.98
I just realised that I'm using a new slot, i mean, new eq slot:
1717533531529.png
& not sure if it matters or not. Others had the same issue without using a new slot in the eq so i guess it doesn't ?

Any help/tips will be much appreciated.
 
Solution
I don't know which server version you are using, but they added a variable to make it easier called "isCheck", that can be used as an additional param in the onEquip and onDeEquip events like so


Lua:
function onEquip(player, item, slot, isCheck)
    if not isCheck then
        --- successfully equipped
    end
    return true
end
Post automatically merged:

They added it at the end of december 2017, it looks like it was in 1.3 onward.
Any help/tips will be much appreciated.
There is some Lua code to block onEquip from executing more than once - you got to test it with items that change ID on equip (ex. life ring) and items that do not (ex. BoH):
and as author stated 2-3x execution is not a mistake, if it was intentionally..

I would say that there should be 2 functions tryToEquip and onEquip, but as long as OTSes exist it was always just 1 function onEquip. It executes when you try to equip item (return false blocks item movement) and after item is equipped and in some cases - ex. when item change ID on equip - it executes 3rd time.
 
There is some Lua code to block onEquip from executing more than once - you got to test it with items that change ID on equip (ex. life ring) and items that do not (ex. BoH):
and as author stated 2-3x execution is not a mistake, if it was intentionally..

I would say that there should be 2 functions tryToEquip and onEquip, but as long as OTSes exist it was always just 1 function onEquip. It executes when you try to equip item (return false blocks item movement) and after item is equipped and in some cases - ex. when item change ID on equip - it executes 3rd time.
Hi Gesior,

Thank you for your response!
I did try this:
function onEquip(player, item, slot)
local slots = player:getSlotItem(slot)
if slots.itemid ~= item.itemid then
return true
end

local test = "test"
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, test)
return true
end

and that's the result:

1717535359603.png

with no error in the console

I'll try to debug and see what it brings but I've already tried earlier today to put this code before my script and no success :(

//edit
Apparently the above script returned a nil value (weird the console didn't shout errors). This:
function onEquip(player, item, slot)
local slots = player:getSlotItem(slot)
if not slots or slots.itemid ~= item.itemid then
return true
end

local test = "test"
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, test)
return true
end

Worked. The message appeared only once. YAY!
I haven't tested items that change ID on equip yet but it def. works for items that are havin the same ID after equip.

Thank you Gesior! You've sent what I've already seen and tried but your response pushed me to try again so :D thank you
Need further testing but this may be it.
 
Last edited:
Worked. The message appeared only once. YAY!
Make sure it also appears when you login into game (relog). It's onEquip event that makes items 'work' after login.
It should work, but you have to test all scenarios.

Mark my answer as 'solution', so thread will be 'resolved' on OTLand.
 
I don't know which server version you are using, but they added a variable to make it easier called "isCheck", that can be used as an additional param in the onEquip and onDeEquip events like so


Lua:
function onEquip(player, item, slot, isCheck)
    if not isCheck then
        --- successfully equipped
    end
    return true
end
Post automatically merged:

They added it at the end of december 2017, it looks like it was in 1.3 onward.
 
Solution
I don't know which server version you are using, but they added a variable to make it easier called "isCheck", that can be used as an additional param in the onEquip and onDeEquip events like so


Lua:
function onEquip(player, item, slot, isCheck)
    if not isCheck then
        --- successfully equipped
    end
    return true
end
Post automatically merged:

They added it at the end of december 2017, it looks like it was in 1.3 onward.

It's 1.4.2 & this works too, thank you! I'm gonna use 'isCheck' as this is much nicer than the previous solution
 
Back
Top