• 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 Function "onEquip" launches twice, how to fix that?

Krewniak

New Member
Joined
Mar 21, 2013
Messages
11
Reaction score
1
Good morning.

I faced problem like in a thread title. Anyone can help me?

Code:
function onEquip(cid, item, slot)
    print("Picked item: " .. getItemName(item.uid))
    return true
end

Gives in logs:
Picked item: "item name"
Picked item: "item name"

I did the same function for deEquip, and was printed only once.
Dropped item: "item name"

Server version:
The Forgotten Server, version 0.3.5 (Crying Damson)
 
For temporary fix, you can use this script (see for more solutions https://github.com/otland/forgottenserver/issues/278)
Code:
local config = {storage = 10000}


function onEquip(cid, item, slot)
local player = Player(cid)

local value = math.max(player:getStorage(config.storage), 0)
if value % 2 > 0 then
return true
end

-- Paste your code here
-- print(1)

player:setStorage(value + 1)
return true
end


@edit: Sorry for mistake. It is solution for forgottenserver 1.0.
 
Thank You both for help.

I did something like:

Code:
function onEquip(cid, item, slot)
    if getPlayerSlotItem(cid, slot).itemid <= 0 then -- Thanks this it goes only once inside.
        print("Hurray only once!")
        return true
    else
        return true
    end
end

function onDeEquip(cid, item, slot)
    print("Hurray!")
    return true
end
 
Back
Top