• 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 Helmet addEvent [1.4.2]

lexus21

Active Member
Joined
Dec 14, 2022
Messages
88
Reaction score
25
Hi, I'm trying to create a helmet with an event. When equipped, it should execute the script every second, but it doesn't - it executes once when equipped.


Lua:
function onEquip(player, item, slot)
     addEvent(function()
             print("working")
         end, 1000, cid)
end

I also tried another option: (draft)
in this code, equipping this helmet triggered an event and removing the helmet stopped the event, but the change (swapping helmets) duplicated the events and e.g. I swapped helmets 3 times and the event triggered 3 times

Lua:
function onEquip(player, slot, item)
        startScript(player)
end

function startScript(player)
        eve = addEvent(startScript, 1000, player:getId())
        print("working")
end

function onDeEquip(player, item, slot)
        if eve then
            stopEvent(eve)
            eve = nil
        end

end

What is a good way to start an event after equipping the helmet and end the event after taking the helmet off? (so that swap does not duplicate events)
 
Last edited:
Back
Top