• 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 onThink Technical Question

Ascuas Funkeln

Rakkedo Game
Joined
Apr 14, 2013
Messages
549
Solutions
32
Reaction score
304
Location
Poland
GitHub
AscuasFunkeln
Hello,
I have question about onThink in technical side. For example i have script contains 300 lines.
150 lines have information about 150 storages.
150 lines send msg of this storage values.
And the question is...
Better is making one 300 line script or divide it to multiple scripts? In which way this will work better and make less impact in performance?
 
The question is, what do you even need it for, most of the time you can avoid using onThink, if you're more specific then we can give you better answers

Also also, don't judge the script by the number of lines.
"Evil hero: The question is, what do you even need it for" - No this is not thread question :)
This is not the point of question...

I ask about performance, what is better for server -> one script with 300 lines or 10 scritps with 30 lines...
 
it's all subjective on the code itself, performance is not equal to line/script count
Yeah, that why i just need little information about this example:
150 lines have information about 150 storages.
150 lines send msg of this storage values.

In this case what is better, one script with 300 lines or 10 scritps with 30 lines.

The point is, i just need knowledge for future, that better is pack more information in one script or divide information for multiple scritps.
 
the difference will be literally nothing, you shouldnt need 150 lines to send messages if u have info about the 150 storages already predefined either way, just use a loop in 1 event
 
If you dofile them the difference is none, in fact, you will end up with less performant code if you divide it - but it's not a valid reason not to, because the difference is marginal.

I believe there are other ways to improve it, you can try posting it and we can point out the flaws because if you are going through 150 lines to set 150 predefined storages, there is still a high celling :D
This is the part, in future i want send more information! So if you guys forcing to help with improve it(instead of the subject), im open for suggestion :)

Lua:
function onThink(player, opcode, buffer, interval)
    local Physical = (Player(player):getProtectionPhysical())
    local Magic = (Player(player):getProtectionMagic())
    local Earth = (Player(player):getProtectionEarth())
    local Fire = (Player(player):getProtectionFire())
    local Anatomy = (Player(player):getProtectionAnatomy())
    local Wind = (Player(player):getProtectionWind())
    local Ice = (Player(player):getProtectionIce())
    local Holy = (Player(player):getProtectionHoly())
    local Death = (Player(player):getProtectionDeath())
    player:sendExtendedOpcode(103, Physical)
    player:sendExtendedOpcode(104, Magic)
    player:sendExtendedOpcode(105, Earth)
    player:sendExtendedOpcode(106, Fire)
    player:sendExtendedOpcode(107, Anatomy)
    player:sendExtendedOpcode(110, Wind)
    player:sendExtendedOpcode(111, Ice)
    player:sendExtendedOpcode(112, Holy)
    player:sendExtendedOpcode(113, Death)
    
    if Game.getStorageValue(125549) == nil then
player:sendExtendedOpcode(201, 0)
elseif Game.getStorageValue(125549) >= os.time() then
player:sendExtendedOpcode(201, (Game.getStorageValue(125549, os.time() + 10) -  os.time()))
elseif Game.getStorageValue(125549) <= os.time() then
player:sendExtendedOpcode(201, 0)
end
if Game.getStorageValue(111122) == 1 then
broadcastMessage("Recovered!", MESSAGE_STATUS_WARNING)
player:sendExtendedOpcode(60, 8)
Game.setStorageValue(111122, 0)
end
return
end
 
Why would you want to send something every second, when in fact probably 90% of it doesn't even change meanwhile, that's exactly what I meant with "try to avoid onThink" which you should clearly do here.
I get that you want to have it synced but it would be better to introduce some event which checks if protection has been changed and then send the info once every change.
This will definitely be a bottleneck at some point once you have more players online at the same time
 
You can make this 10x shorter and better.
First of all Player(player): is useless. Just use player.
Second, if you are using ExtendedOpcode then don't send 10 at a time for no reason.

If you are trying to update protection stats on the client then do it when protection value changes.
 
You can make this 10x shorter and better.
First of all Player(player): is useless. Just use player.
Second, if you are using ExtendedOpcode then don't send 10 at a time for no reason.

If you are trying to update protection stats on the client then do it when protection value changes.
local Physical = (Player(player):getProtectionPhysical()) - Working
local Physical = (player:getProtectionPhysical()) - Not Working
:)

When enemy debuff you protection then how to call it?
Ofc i think about this, i have alot things that improve all character stats, and i thinking how to made it. And made onThink for check is easier than put in every spell, item using, item equip, condition change etc. Extendedopcode.
This is my point of this thread, how big problem is using onThink for it.
 
And made onThink for check is easier than put in every spell, item using, item equip, condition change etc. Extendedopcode.
That is false. You probably have a function that update the value, you go inside that function, and tell it to send it to client as soon as it update the value.

Realtime checking all the stats that can be updated in a player even if they aren't is really troublesome. Imagine if code for all skills, armor, health and mana and armor and everything was made like that. Hahaah just imagine checking the entire server all the time instead of updating stuff when it's updated.
 
That is false. You probably have a function that update the value, you go inside that function, and tell it to send it to client as soon as it update the value.

Realtime checking all the stats that can be updated in a player even if they aren't is really troublesome. Imagine if code for all skills, armor, health and mana and armor and everything was made like that. Hahaah just imagine checking the entire server all the time instead of updating stuff when it's updated.
Can u throw light?
How i can send all storage values, protections and other when player equip item? Not creating script for each id, something like "player equip anything then"
 
Back
Top