pasiak12
Well-Known Member
- Joined
- Jun 7, 2009
- Messages
- 261
- Solutions
- 13
- Reaction score
- 71
Hi!
I would like to reduce my lua code. There are a lot of repeated functions but with another variables. I'd like to use there some table initialization like in c++, but in LUA.
Example spell:
For example in C++ language the solution for declaring all the combats would be like this:
PSEUDOCODE:
And another question:
I tried to set formula values once for all combats because the damage is the same for every tick, but the
worked only for 1 combat (1 combat did damage and the rest didnt)
I would like to reduce my lua code. There are a lot of repeated functions but with another variables. I'd like to use there some table initialization like in c++, but in LUA.
Example spell:
Code:
local combat1 = Combat()
combat1:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat1:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat1:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat1:setParameter(COMBAT_PARAM_USECHARGES, true)
combat1:setArea(createCombatArea(AREA_g1))
local combat2 = Combat()
combat2:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat2:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat2:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat2:setParameter(COMBAT_PARAM_USECHARGES, true)
combat2:setArea(createCombatArea(AREA_g2))
local combat3 = Combat()
combat3:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat3:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat3:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat3:setParameter(COMBAT_PARAM_USECHARGES, true)
combat3:setArea(createCombatArea(AREA_g3))
local combat4 = Combat()
combat4:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat4:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat4:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat4:setParameter(COMBAT_PARAM_USECHARGES, true)
combat4:setArea(createCombatArea(AREA_g4))
local combat5 = Combat()
combat5:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat5:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat5:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat5:setParameter(COMBAT_PARAM_USECHARGES, true)
combat5:setArea(createCombatArea(AREA_g5))
local combat6 = Combat()
combat6:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat6:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat6:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat6:setParameter(COMBAT_PARAM_USECHARGES, true)
combat6:setArea(createCombatArea(AREA_g6))
local combat7 = Combat()
combat7:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat7:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat7:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat7:setParameter(COMBAT_PARAM_USECHARGES, true)
combat7:setArea(createCombatArea(AREA_g7))
local combat8 = Combat()
combat8:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat8:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat8:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat8:setParameter(COMBAT_PARAM_USECHARGES, true)
combat8:setArea(createCombatArea(AREA_g8))
function onGetFormulaValues1(player, skill, attack, factor)
local min = 10
local max = 20
return -min, -max
end
function onGetFormulaValues2(player, skill, attack, factor)
local min = 10
local max = 20
return -min, -max
end
function onGetFormulaValues3(player, skill, attack, factor)
local min = 10
local max = 20
return -min, -max
end
function onGetFormulaValues4(player, skill, attack, factor)
local min = 10
local max = 20
return -min, -max
end
function onGetFormulaValues5(player, skill, attack, factor)
local min = 10
local max = 20
return -min, -max
end
function onGetFormulaValues6(player, skill, attack, factor)
local min = 10
local max = 20
return -min, -max
end
function onGetFormulaValues7(player, skill, attack, factor)
local min = 10
local max = 20
return -min, -max
end
function onGetFormulaValues8(player, skill, attack, factor)
local min = 10
local max = 20
return -min, -max
end
combat1:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues1")
combat2:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues2")
combat3:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues3")
combat4:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues4")
combat5:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues5")
combat6:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues6")
combat7:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues7")
combat8:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues8")
function onCastSpell(creature, variant)
mana20 = creature:getMaxMana() * 20/100
if creature:getMana() >= mana20 then
creature:addMana(- mana20 )
else
creature:getPlayer():sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Not enough mana points")
return
end
local i =0;
local mul = 100;
addEvent(doCombat, i*mul, creature.uid, combat1, variant)
i=i+1
addEvent(doCombat, i*mul, creature.uid, combat2, variant)
i=i+1
addEvent(doCombat, i*mul, creature.uid, combat3, variant)
i=i+1
addEvent(doCombat, i*mul, creature.uid, combat4, variant)
i=i+1
addEvent(doCombat, i*mul, creature.uid, combat5, variant)
i=i+1
addEvent(doCombat, i*mul, creature.uid, combat6, variant)
i=i+1
addEvent(doCombat, i*mul, creature.uid, combat7, variant)
i=i+1
addEvent(doCombat, i*mul, creature.uid, combat8, variant)
return
end
For example in C++ language the solution for declaring all the combats would be like this:
PSEUDOCODE:
Code:
local combat[8];
local AREA[8] = {AREA_g1, AREA_g2, AREA_g3, AREA_g4, AREA_g5, AREA_g6, AREA_g7, AREA_g8}
for(int i =0; i<0; i++)
{
combat[i]:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat[i]:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat[i]:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat[i]:setParameter(COMBAT_PARAM_USECHARGES, true)
combat[i]:setArea(createCombatArea(AREA[i])
}
And another question:
I tried to set formula values once for all combats because the damage is the same for every tick, but the
Code:
function onGetFormulaValues(player, skill, attack, factor)
local min = 10
local max = 20
return -min, -max
end
combat1:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
combat2:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
combat3:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
combat4:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
combat5:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
combat6:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
combat7:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
combat8:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
worked only for 1 combat (1 combat did damage and the rest didnt)