• 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 addEvent with metatable

951357

New Member
Joined
Nov 27, 2008
Messages
30
Reaction score
0
Location
Brazil
Code:
addEvent(function(player, param)
    player:test(param) 
end, 1000, player, param)

function Player.test(self, param)
   ...
end

Is there a better way to use addEvent? Something like addEvent(player:test, 1000, param).
 
Code:
addEvent(Player.test, 1000, player, param)
It's usually better to pass the id and make a new Player instance in case the player disconnects before the event runs.
 
This is the best way:
Code:
addEvent(function(cid, param)
    local player = Player(cid)
    if not player then
        return
    end

    player:test(param)
end, 1000, player:getId(), param)
 
Code:
addEvent(Player.test, 1000, player, param)
It's usually better to pass the id and make a new Player instance in case the player disconnects before the event runs.
That's true, thanks!

This is the best way:
Code:
addEvent(function(cid, param)
    local player = Player(cid)
    if not player then
        return
    end

    player:test(param)
end, 1000, player:getId(), param)
Thank you!
 
Back
Top