r1731 (Efficiency in LUA)
Posted: Wed Sep 12, 2012 11:58 pm
Since diatanato posts his changelog in Russian, and there are some people who are new to LUA and/or new to the project but don't know how to read C++ source about, let me translate what he's asking you to do:
replaced with:
There's already a lot of stuff handled in the source code, and C++ is MUCH faster than parsed LUA scripts. If you use target:hasStatusEffect(), then you will get a boolean (true/false) returned. But if you use target:getStatusEffect(), you'll get an object (I believe in this case a number), which you must compare to nil/null to get your boolean. For efficiency's sake, use the already coded functions instead of trying to handle it yourself in the LUA script.
replaced with:
If you simply call delStatusEffect(), it will return true if the target had the effect and it was able to delete said effect. It's an unnecessary extra step to check first.
replaced with:
DECLARE YOUR VARIABLES AS LOCAL IF YOU DON'T NEED THEM ELSEWHERE! This cannot be stressed enough. Local vars have a sizable performance improvement.
replaced with:
If you call a function more than once, put it's result in a LOCAL variable. Every time you call the function, the server has to look that function up, slowing everything down. For instance, if you need to check a player's neck slot, we would not use target/caster:getEquipID(9) every place we wanted to check. Instead we would do this:
(I'm not commanding/asking you to use sNeck for neck. You may name the variable whatever you wish, but please make the name intuitive.)
The last part of dia's changes is just that you do not need to call updateEnmity for a spell. That is already handled by the C++ code.
Code: Select all
if(target:getStatusEffect(EFFECT_ACCURACY_DOWN) ~= nil) or (caster:getStatusEffect(EFFECT_ACCURACY_BOOST) ~=nil) then
Code: Select all
if(target:hasStatusEffect(EFFECT_ACCURACY_DOWN) or caster:hasStatusEffect(EFFECT_ACCURACY_BOOST)) then
Code: Select all
if(target:getStatusEffect(EFFECT_BLINDNESS) ~= nil) then
target:delStatusEffect(EFFECT_BLINDNESS);
Code: Select all
if (target:delStatusEffect(EFFECT_BLINDNESS)) then
Code: Select all
dINT = (caster:getStat(MOD_INT) - target:getStat(MOD_INT));
Code: Select all
local dINT = (caster:getStat(MOD_INT) - target:getStat(MOD_INT));
Code: Select all
if(target:getStatusEffect(EFFECT_BLINDNESS) ~= nil) then
if((target:getStatusEffect(EFFECT_BLINDNESS)):getPower() < power) then
Code: Select all
local blindness = target:getStatusEffect(EFFECT_BLINDNESS);
if(blindness ~= nil) then
if(blindness:getPower() < power) then
Code: Select all
local sNeck = target:getEquipID(9);
if (sNeck == whatever) then
The last part of dia's changes is just that you do not need to call updateEnmity for a spell. That is already handled by the C++ code.