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

TFS 1.X+ OnEquip Lua Function

Ovnyx

Member
Joined
Jul 25, 2017
Messages
163
Solutions
2
Reaction score
7
good night, i was playing a lil with the onDeEquipItem DeEquipItem functions, i was trying to just get the description of the equiped item, i was using this simple script :
Code:
function onEquip(player, item, slot)
    print(item:getDescription())
end

and this for the item in movements:
<movevent event="Equip" itemid="2433" slot="hand" value ="script.lua"/>
but it is not working, i tried like this too with no success:
<movevent event="Equip" itemid="2433" slot="hand" script ="script.lua"/>

can any one please show me the correct way to use this function?
thanks in advice! :)
 
Solution
You have no return value set for it, you either have tu return false (not be able to equip) or return true (able to equip it) in order for it to work correctly.
Code:
function onEquip(player, item, slot)
    print(item:getDescription())
    return true
end
good night, i was playing a lil with the onDeEquipItem DeEquipItem functions, i was trying to just get the description of the equiped item, i was using this simple script :
Code:
function onEquip(player, item, slot)
    print(item:getDescription())
end

and this for the item in movements:
<movevent event="Equip" itemid="2433" slot="hand" value ="script.lua"/>
but it is not working, i tried like this too with no success:
<movevent event="Equip" itemid="2433" slot="hand" script ="script.lua"/>

can any one please show me the correct way to use this function?
thanks in advice! :)
XML:
<movevent event="DeEquip " itemid="2433" slot="hand" function="onDeEquipItem" />
 
Code:
<movevent event="Equip" itemid="2433" slot="hand" function="onEquipItem" script ="script.lua"/>
like this worked, but it executed what the script do (print), but now imcant equip that item in no hand D;
 
Your functions must include:
Lua:
return true
Otherwise, you're not going to be able to equip it.
 
You have no return value set for it, you either have tu return false (not be able to equip) or return true (able to equip it) in order for it to work correctly.
Code:
function onEquip(player, item, slot)
    print(item:getDescription())
    return true
end
 
Solution
Code:
<movevent event="Equip" itemid="2433" slot="hand" function="onEquipItem" script ="script.lua"/>
like this worked, but it executed what the script do (print), but now imcant equip that item in no hand D;
aa you have to change this
XML:
<movevent event="Equip" itemid="2433" slot="hand" function="onEquipItem" script ="script.lua"/>
to
XML:
<movevent event="DeEquip " itemid="2433" slot="hand" function="onDeEquipItem" script ="script.lua"/>
not tested but should work, you just forget to change the event from
XML:
"Equip"
to
XML:
"DeEquip"
to dequip the items
 
You have no return value set for it, you either have tu return false (not be able to equip) or return true (able to equip it) in order for it to work correctly.
Code:
function onEquip(player, item, slot)
    print(item:getDescription())
    return true
end
:O! that was the problem thank you!!!
so return statement always need to be at the end? true or false but they must be there ?
 
:O! that was the problem thank you!!!
so return statement always need to be at the end? true or false but they must be there ?
not every event needs a return value but you are always safe to go with putting a return true at the end, unless in this example ofc if you wouldn't want the player to be able to equip the item, then you'd return false.
Edit: You can take this for better reference otland/forgottenserver (https://github.com/otland/forgottenserver/wiki/Script-Interface)
 
Back
Top