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

TFS 1.X+ [tfs 1.3] dont have function onCast

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,210
Solutions
35
Reaction score
206
In tfs 0.4 I used the function:
Code:
<event type="cast" name="master heal" event="script" value="master heal.lua"/>
to make a summon heal a "master" every X seconds.
But in tfs 1.3 dont have this function, ill need to use onThink?
But couldn't the onThink function weigh in the game as it runs every second?
 
Solution
I always ask because I already had a server with 140 players online and cpu up to 120% (monsters stop walking, mana stops healing, life stops healing).
and I believe it's bad scripts made in lua.
so I have been trying to avoid functions onThink, onHealthChange, and others.
but you claim that if the script is well done, none of these functions will cause cpu usage problem right?
The biggest problem in performance is caused by getSpectators, which nobody has bothered to optimize yet (other than people who are here only to moneygrab and not help the community :D).
There are ways you can destroy performance in Lua, if you have no clue what you're doing and have no idea how to optimize scripts. But for the most part (especially...
In tfs 0.4 I used the function:
Code:
<event type="cast" name="master heal" event="script" value="master heal.lua"/>
to make a summon heal a "master" every X seconds.
But in tfs 1.3 dont have this function, ill need to use onThink?
But couldn't the onThink function weigh in the game as it runs every second?
I'm serious when I tell you that you almost never have to worry about performance in Lua, a single script to execute something at an interval takes nanoseconds of time, maybe even smaller.
LUA:
local masterHeal = CreatureEvent("Master Heal")

function masterHeal.onThink(creature, interval)
    local master = creature:getMaster()
    if master then
        master:addHealth(math.random(1, 100))
    end
    return true
end

masterHeal:register()

Register in monster like so:
XML:
<script>
     <event name="Master Heal"/>
</script>
 
I'm serious when I tell you that you almost never have to worry about performance in Lua, a single script to execute something at an interval takes nanoseconds of time, maybe even smaller.
I always ask because I already had a server with 140 players online and cpu up to 120% (monsters stop walking, mana stops healing, life stops healing).
and I believe it's bad scripts made in lua.
so I have been trying to avoid functions onThink, onHealthChange, and others.
but you claim that if the script is well done, none of these functions will cause cpu usage problem right?
 
I always ask because I already had a server with 140 players online and cpu up to 120% (monsters stop walking, mana stops healing, life stops healing).
and I believe it's bad scripts made in lua.
so I have been trying to avoid functions onThink, onHealthChange, and others.
but you claim that if the script is well done, none of these functions will cause cpu usage problem right?
The biggest problem in performance is caused by getSpectators, which nobody has bothered to optimize yet (other than people who are here only to moneygrab and not help the community :D).
There are ways you can destroy performance in Lua, if you have no clue what you're doing and have no idea how to optimize scripts. But for the most part (especially something like this), the event will have next to no hit on performance.
If you want to test, you can benchmark functions using something like this:
LUA:
do
    local units = {
        ['seconds'] = 1,
        ['milliseconds'] = 1000,
        ['microseconds'] = 1000000,
        ['nanoseconds'] = 1000000000
    }
    function benchmark(unit, decPlaces, f, ...)
        local multiplier = units[unit]
        local now = os.clock()
        f(...)
        print(string.format('Time elapsed: %.'.. decPlaces ..'f %s', (os.clock() - now) * multiplier, unit))
    end
end

Example:
LUA:
function test(n)
    local t = {}
    for i = 1, n do
        t[i] = i
    end
end

benchmark('microseconds', 2, test, 10000) -- Time elapsed: 1153.00 microseconds

If you want to test something like this onThink event for example, you can wrap the entire function body in an anonymous function and pass it to the benchmark function like so:
LUA:
local masterHeal = CreatureEvent("Master Heal")

function masterHeal.onThink(creature, interval)
    benchmark('microseconds', 2, function(creature, interval)
        local master = creature:getMaster()
        if master then
            master:addHealth(math.random(1, 100))
        end
    end, creature, interval)
    return true
end

masterHeal:register()
 
Solution
The biggest problem in performance is caused by getSpectators, which nobody has bothered to optimize yet (other than people who are here only to moneygrab and not help the community :D).
There are ways you can destroy performance in Lua, if you have no clue what you're doing and have no idea how to optimize scripts. But for the most part (especially something like this), the event will have next to no hit on performance.
If you want to test, you can benchmark functions using something like this:
I know who you are talking about xD.
I will test this function, thank you for the clarification!
 
Back
Top