@Sir Sezago
Asked me about spell that attack like 'exori vis' (front of player or distance if creature attacked), but if item 'x' in hand, it should be 'wave' (front of player, no matter if creature attacked).
After.. 53 days I found time to write it.
It wasn't easy, so I decided to release it and show how to handle 'var' in spells to customize target of spell.
spells.xml (casterTargetOrDirection="1" range="3"):
attack/mis strike.lua:
Item in right hand:
Replace 'var' (which containts target of spell) with position 'in front of player' and cast 'wave'.
Item in left hand:
Just cast spell like exori vis, if player has target it will attack target, if not then it will attack in front of him.
No item:
No attack, but you can change it.
IMPORTANT thing to understand how it works is 'var' in spells. In this variable is information about target of spell. It may contain 3 types of value:
- number = CID of target creature/player (selected on battle window)
- position = position of target creature/player OR position in front of casting player if it's wave spell
- string = name of target player (for spells like 'exura sio "gesior')
To display it's value (in console) or modify, you must use one of functions:
To change some LUA variable into 'variant' you must use one functions:
and then you can pass 'var' to 'doCombat' as 3rd parameter.
Asked me about spell that attack like 'exori vis' (front of player or distance if creature attacked), but if item 'x' in hand, it should be 'wave' (front of player, no matter if creature attacked).
After.. 53 days I found time to write it.
It wasn't easy, so I decided to release it and show how to handle 'var' in spells to customize target of spell.
spells.xml (casterTargetOrDirection="1" range="3"):
PHP:
<instant name="Mis Strike" words="exori mis" lvl="12" mana="20" prem="0" range="3" casterTargetOrDirection="1" blockwalls="1" exhaustion="500" needlearn="0" event="script" value="attack/mis strike.lua">
</instant>
attack/mis strike.lua:
PHP:
local combatStrike = createCombatObject()
setCombatParam(combatStrike, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatParam(combatStrike, COMBAT_PARAM_EFFECT, CONST_ME_ENERGYAREA)
setCombatParam(combatStrike, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
setCombatFormula(combatStrike, COMBAT_FORMULA_LEVELMAGIC, -1, -10, -1, -20, 5, 5, 3.4, 5.1)
local combatWave = createCombatObject()
setCombatParam(combatWave, COMBAT_PARAM_TYPE, COMBAT_HOLYDAMAGE)
setCombatParam(combatWave, COMBAT_PARAM_EFFECT, CONST_ME_HOLYDAMAGE)
setCombatParam(combatWave, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_HOLY)
setAttackFormula(combatWave, COMBAT_FORMULA_LEVELMAGIC, 3, 3, 19, 24)
setCombatArea(combatWave, createCombatArea(AREA_SQUAREWAVE5))
local items = {12609, 7424}
function onCastSpell(cid, var)
for i, itemid in pairs(items) do
if getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid then
-- if in right hand
-- replace 'var' (which contains TARGET!) with position in front of player
local targetPosition = getCreatureLookPosition(cid) -- position if front of player
local newVar = positionToVariant(targetPosition)
return doCombat(cid, combatWave, newVar)
elseif getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid then
-- if in left hand
-- do normal 'exori vis' attack, just pass 'var'
return doCombat(cid, combatStrike, var)
end
end
-- HERE YOU CAN PLACE 'WHAT TO DO WHEN NO ITEM'
-- I set it to 'nothing'
return false
end
Replace 'var' (which containts target of spell) with position 'in front of player' and cast 'wave'.
Item in left hand:
Just cast spell like exori vis, if player has target it will attack target, if not then it will attack in front of him.
No item:
No attack, but you can change it.
IMPORTANT thing to understand how it works is 'var' in spells. In this variable is information about target of spell. It may contain 3 types of value:
- number = CID of target creature/player (selected on battle window)
- position = position of target creature/player OR position in front of casting player if it's wave spell
- string = name of target player (for spells like 'exura sio "gesior')
To display it's value (in console) or modify, you must use one of functions:
PHP:
number = variantToNumber(var) // returns 0, if not set
string = variantToString(var) // returns empty string, if not set
position = luaVariantToPosition(var) // returns {x=0, y=0, z=0, stackpos=0}, if not set
PHP:
var = numberToVariant(number)
var = stringToVariant(string)
var = positionToVariant(pos)
var = targetPositionToVariant(pos)
Last edited by a moderator: