• 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 TFS 1.0 Movement loops 3 times

Giddran

Techical Artist
Joined
Sep 8, 2007
Messages
70
Reaction score
25
Location
Sweden
Anyone know why the text message get called 3 times when i equip and item with the following code?

<movevent event="Equip" itemid="2136" slot="necklace" function="onEquipItem" script="setitems/wand.lua"/>
<movevent event="DeEquip" itemid="2136" slot="necklace" function="onDeEquipItem" script="setitems/wand.lua"/>

function onEquip(cid, item, slot)

doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "hey")

return true
end
 
I'm still laughing when i read that.
Anyone know why the text message get called 3 times when i equip and item with the following code?
[...]
u script execult 3 times because it is bad write, there is no condition made what you expect, if there is no control with your script.
[ HERE IS HOW YOU DO IT ] it is just a exemple ^^
PHP:
function onEquip(cid, item, slot)

    local playerVoc = getPlayerVocation(cid)
    if playerVoc ~= 1 then
        local msg = " only Sorcerer can equipt it. "
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg)
        return false
    end

    local slots = getPlayerSlotItem(cid, slot )
    if slots.itemid ~= item.itemid then
        return true
    end
  
    print ("_________________")
    print ("hello from function onEquip.")
  
return true
end
The magic is here, usualy put is after function onEquip(cid, item, slot)
but if you script have some condtion that negate its use like the exemple
thoses condition shall be write before.
PHP:
    local slots = getPlayerSlotItem(cid, slot )
    if slots.itemid ~= item.itemid then
        return true
    end
 
I dont see how that would change anything if the onequip still gets registered several times. Adding control values is easy but that is not really the answer i was looking for :)

Ninja however stilled my desires.
 
I dont see how that would change anything if the onequip still gets registered several times. Adding control values is easy but that is not really the answer i was looking for :)

Ninja however stilled my desires.
and no it is getting registered only one TIME. u dont even tryed it.
That just show us, that u didnt even read my post. this is the anwser u were looking. read this time carefully.
when u ll equip something, the server make 2 test before equip! [...] when
PHP:
getPlayerSlotItem(cid, slot )
will return [" we havent equiped it yet "]
to avoid the test and only run your script when the equipement is equiped!

use that code before ur script,
and it isnt using any storagevalue as people usualy does ( the easy way u call? )
PHP:
function onEquip(cid, item, slot)
    local slots = getPlayerSlotItem(cid, slot )
    if slots.itemid ~= item.itemid then
        return true
    end

   doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "hey")

return true
end
output : hey
1time
 
Back
Top