• 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!

registerCreatureEvents(cid)

hodleo

Formerly cbrm -Crypto enthusiast, Retired scripter
Staff member
Global Moderator
Joined
Jan 6, 2009
Messages
6,598
Solutions
3
Reaction score
955
Location
Caribbean Sea
Well, you might have noticed that the function 'registerCreatureEvents' needs to be repeated each time an event is registered in login.lua
And if you use more creaturevents, you'll need to have more lines.

Lua:
registerCreatureEvent(cid, "Mail")
registerCreatureEvent(cid, "GuildMotd")

registerCreatureEvent(cid, "Idle")
if(config.useFragHandler) then
registerCreatureEvent(cid, "SkullCheck")
end

registerCreatureEvent(cid, "ReportBug")
registerCreatureEvent(cid, "AdvanceSave")

then with an easy custom function, you can reduce that to this:
Lua:
function registerEvents(cid)
    _event = {"Mail", "GuildMotd", "Idle", "SkullCheck", "ReportBug", "AdvanceSave"}    
for i = 1, # _event do registerCreatureEvent(cid, _event[i]) end end
(SkullCheck is in the list supposing that you are using fraghandler)

that way the login.lua looks shorter and cleaner.
 
Code:
local t = {"Mail", "GuildMotd", "Idle", "SkullCheck", "ReportBug", "AdvanceSave"}    
for _, v in ipairs(t) do registerCreatureEvent(cid, v) end
:_D:D i'm being a fag
 
if you want to do it as you wrote it why not just put it in login.lua without making a function?

Like this:
Code:
local _event = {"Mail", "GuildMotd", "Idle", "SkullCheck", "ReportBug", "AdvanceSave"}    
for i = 1, # _event do
registerCreatureEvent(cid, _event[i]) 
end

if you want a function do it like that:
Code:
function registerEvents(cid,events)
for i = 1, #events do 
registerCreatureEvent(cid, events[i]) 
end 
end
 
because i want <.<
 
Functions should be set up so you can change everything by changing the variables, but in your function you can't do that..
So in that case you don't need a function.
 
Back
Top