creature/global script onThink vs creaturescript onLogin addEvent?
If I am not mistaken, onLogin queries stuff once, and data is being passed to an event timeout, which can have exacly 1 second interval. No need to query for online list as onLogin already passes player object as param, no need to re-query for the player as it can be passed along the event.
Fetch entire online list and loop through it every 1 second, or fetch player on login and use an interval.
A few drawbacks with addEvent interval, you must recheck that cid is a player and stop the event in-case he logs out.
Also not sure how the garbage collector works when it comes to events calling themselves. Potential memmory hog?
Code:
function specialRegen(player)
if player:getId() != nil then -- Player still online check
-- todo: code
AddEvent(specialRegen, 1000, player) -- Recall this function in 1 second.
end
end
function onLogin(player)
AddEvent(specialRegen, 1000, player)
end
This code looks WAY more sane than fetching online list, loop through and fetch player by name every 1 second.