• 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
811
Solutions
3
Reaction score
122
Location
Egypt
GitHub
MohamedRefaat
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?
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,809
Solutions
432
Reaction score
3,945
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.
 

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,553
Solutions
119
Reaction score
1,861
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
 
OP
OP
mRefaat

mRefaat

Marketing and Coding
Joined
Jan 18, 2014
Messages
811
Solutions
3
Reaction score
122
Location
Egypt
GitHub
MohamedRefaat
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 :)
 
Top