• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua addEvent(callback, time, ...)

What you're doing is fine, just remember that defining playersaround inside the for loop means playersaround will only have that value in that scope, that is the variable will be defined only in the loop, you might want to change that.
 
solved, thanks

btw can anyone help me using addEvent for this?

Code:
playersaround[k]:say("C-Point", TALKTYPE_MONSTER_SAY, false, playersaround[k], tps[i].pos)

I tried:

Code:
addEvent(playersaround[k]:say, 100, "C-Point", TALKTYPE_MONSTER_SAY, false, playersaround[k], tps[i].pos)

but it doesnt work
 
Do you get an error?
Code:
// creature:say(text, type[, ghost = false[, target = nullptr[, position]]])

Try writing a new function and then call that function through addEvent like say
Code:
function creatureSpeak(creature, text, type_, pos)
    if creature:isPlayer() then
        creature:say(text, type_, false, creature, pos)
    end
end


addEvent(creatureSpeak, 100, playersaround[k], "C-Point", TALKTYPE_MONSTER_SAY, tps[i].pos)
 
Last edited:
It's not safe to pass a userdata value to addEvent. If the object linked to that userdata, in this case the creature, doesn't exist any more, ex. player logged out, when the event callback is fired, the server will crash.
Best practice is to pass the creature id to addEvent and construct it again from the id.

Building on @Codex NG's example:
Code:
function creatureSpeak(cid, text, type_, pos)
    local creature = Creature(cid)
    if creature and creature:isPlayer() then
        creature:say(text, type_, false, creature, pos)
    end
end

addEvent(creatureSpeak, 100, playersaround[k]:getId(), "C-Point", TALKTYPE_MONSTER_SAY, tps[i].pos)
 
Back
Top