PROBLEM 1
PROBLEM 2
You cannot use same callback function for 2 combats. It's removed from Lua, when you call
It blocks possibility to add same callback to multiple
SOLUTION
Function that accepts
Add this in
Now you can use it in loop:
(
combat:setCallback
binds event function to combat
by name (string) ex. "onGetFormulaValues"
, not by function ex. onGetFormulaValues
:
Lua:
function onGetFormulaValues(x, y, z)
return 0
end
combat = Combat()
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
PROBLEM 2
You cannot use same callback function for 2 combats. It's removed from Lua, when you call
setCallbackFunction
ex.:
Lua:
function onGetFormulaValues(x, y, z)
return 0
end
combat1 = Combat()
combat1:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
-- NOW function onGetFormulaValues is not defined, it was removed from Lua by setCallback
combat2 = Combat()
-- THIS will throw error: "[Warning - CallBack::loadCallBack] Event onGetFormulaValues not found."
combat2:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
It blocks possibility to add same callback to multiple
combat
s in loop (ex. in spell with multiple delayed effects with addEvent):
Lua:
function onGetFormulaValues(x, y, z)
return 0
end
local combats = {}
combats[1] = Combat()
combats[1]:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_ENERGYAREA)
combats[2] = Combat()
combats[2]:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_BLOCKHIT)
combats[3] = Combat()
combats[3]:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
for i = 1, 3 do
-- THIS will throw error after first loop
combat[i]:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
end
SOLUTION
Function that accepts
function
as parameter (not string with function name), copies it and binds to combat
.Add this in
data/lib/lib.lua
:
Lua:
function Combat.setCallbackFunction(self, event, callback)
temporaryGlobalCallbackFunction = loadstring(string.dump(callback))
self:setCallback(event, "temporaryGlobalCallbackFunction")
end
(
setCallbackFunction
in place of setCallback
and function onGetFormulaValues
in place of function name (string) "onGetFormulaValues"
)
Lua:
(...) -- as in code above
for i = 1, 3 do
combat[i]:setCallbackFunction(CALLBACK_PARAM_SKILLVALUE, onGetFormulaValues)
end
Last edited: