• 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?
 
You should save them to lua table by id to later recreate userdata and get them by id, that's the best performance option.
 
You should save them to lua table by id to later recreate userdata and get them by id, that's the best performance option.
Thanks for your answer.
Can you explain with a small example to understand how it should be?
Post automatically merged:

generally speaking: addEvent and onThink
Thanks for your answer.
But some scripts needed to use one of them, what should be alternatives?
 
Last edited:
first we need to know what are these scripts doing :p
For example for addEvent: adding it into a script (event or something) to end the event, send warning about time left, ending that event or removing a monster after its spawn after some hours.

onThink examples: Making effects? Running an event every x hours?

Suggest better solutions?
 
For example for addEvent: adding it into a script (event or something) to end the event, send warning about time left, ending that event or removing a monster after its spawn after some hours.

onThink examples: Making effects? Running an event every x hours?

Suggest a better solutions?

if you are using it like that is ok, the problem is using then actively, like rainbown outfits, displaying special effect on players, etc. if you use they as you said there is no problem
 
if you are using it like that is ok, the problem is using then actively, like rainbown outfits, displaying special effect on players, etc. if you use they as you said there is no problem
Well, I understood from that I shouldn’t use them to make things too fast?
 
exactly, the faster and continuously you execute a task, the more resources you demand
Thanks for information, i am trying to learn more about that to improve my scripts.

What about using onThink (creature event) to check an item equipped by a player? The same rule applies on that?
 
It was a general question about onThink in creature event, and for the item as Evil Puncker said i can use onEquip or like you said onInvertoryUpdate.
So using onThink in general in creature event is bad.

Thanks for information @Infernum @Evil Puncker
It depends, sometimes you need to do stuff in onThink, but for this case you can definitely do it better, even by utilizing onMoveItem event
 
Lua:
local table = {}

-- store
local creature = ...
table[creature:getId()] = true

-- iterate stored
for cid in pairs(table) do
    print(cid) -- prints creature id
    local creature = Creature(cid)
    if creature then
        -- do something
    end
end
 
Lua:
local table = {}

-- store
local creature = ...
table[creature:getId()] = true

-- iterate stored
for cid in pairs(table) do
    print(cid) -- prints creature id
    local creature = Creature(cid)
    if creature then
        -- do something
    end
end
Thanks for that
 
Lua:
local table = {}

-- store
local creature = ...
table[creature:getId()] = true

-- iterate stored
for cid in pairs(table) do
    print(cid) -- prints creature id
    local creature = Creature(cid)
    if creature then
        -- do something
    end
end
Hello again,

i used table but i have a problem when someone die or logout, i get the player not found problem.
so how to delete a player from the table when he dies?
 
Back
Top