• 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 Question about performance?

mRefaat

Marketing and Coding
Joined
Jan 18, 2014
Messages
854
Solutions
3
Reaction score
141
Location
Egypt
Hello

I am trying to make my scripts more cleaner and use less cpu.
So,
I want to ask if i am going to check some players to teleport them after an event.
Getting them by using storages and check the whole online list or getting them by checking a specific area x,y,z?

Which is better?
Also any ideas what script problems can take too much cpu?
 
Hello again,

i used table but i have a problem when someone die or leave, i get the player not found problem.
so how to delete a player from the table when he dies?
The way that table is setup, you can't use table.remove, since it would re-number the table.

Only way to remove it would be table[creature:getId()] = nil, which would effectively remove it, as far as most scripts are concerned.. and Lua would eventually do garbage collection on it to free up the ram.
 
Lua:
local table = ...
for cid in pairs(table) do
    local creature = Creature(cid)
    if creature then
        -- creature is valid, do something with it
    else
        -- creature is offline or just this cid got thrown away
        table[cid] = nil
    end
end
 
The way that table is setup, you can't use table.remove, since it would re-number the table.

Only way to remove it would be table[creature:getId()] = nil, which would effectively remove it, as far as most scripts are concerned.. and Lua would eventually do garbage collection on it to free up the ram.
thanks :)
Lua:
local table = ...
for cid in pairs(table) do
    local creature = Creature(cid)
    if creature then
        -- creature is valid, do something with it
    else
        -- creature is offline or just this cid got thrown away
        table[cid] = nil
    end
end
thanks :)
 
Back
Top