LucasFerraz
Systems Analyst
Code:
Name: Collision System of Spells
Author: Ramza (Ricardo Ianelli)
Tested: TFS 0.3.6PL1
[video=youtube;uTvin2sLwu8]http://www.youtube.com/watch?feature=player_embedded&v=uTvin2sLwu8#at=28[/video]
From the viewpoint of the player:
The player uses a spell, exori frigo. At the same time, the enemy uses a exori vis for example. Spells fly and collide in the air.
From the viewpoint of the scripter:
All spells before being casted, save a storage value, and check if enemy have the same storage. If yes , instead of sending the magic, the effects sends to a calculated position between two points, and an effect of collision.
How to install
colisionLIB.lua
Lua:
function checkColision(cid) -- Function by Ramza (Ricardo Ianelli)
if getCreatureTarget(cid) ~= 0 then
setPlayerStorageValue(cid, 9001, 'casting')
local ppos, enemy = getCreaturePosition(cid), getCreatureTarget(cid)
local epos = getCreaturePosition(enemy)
if getPlayerStorageValue(enemy, 9001) == 'casting' and getCreatureTarget(enemy) == cid then
setPlayerStorageValue(enemy, 9001, 'colision')
setPlayerStorageValue(cid, 9001, 'colision')
if ppos.x > epos.x and ppos.y > epos.y then
cpos = {x = ppos.x - ((ppos.x - epos.x) / 2), y = ppos.y - ((ppos.y - epos.y) / 2), z = ppos.z}
elseif ppos.x > epos.x and ppos.y < epos.y then
cpos = {x = ppos.x - ((ppos.x - epos.x) / 2), y = epos.y - ((epos.y - ppos.y) / 2), z = ppos.z}
elseif ppos.x < epos.x and ppos.y < epos.y then
cpos = {x = epos.x - ((epos.x - ppos.x) / 2), y = epos.y - ((epos.y - ppos.y) / 2), z = ppos.z}
elseif ppos.x < epos.x and ppos.y > epos.y then
cpos = {x = epos.x - ((epos.x - ppos.x) / 2), y = ppos.y - ((ppos.y - epos.y) / 2), z = ppos.z}
end
doSendDistanceShoot(ppos, cpos, CONST_ANI_ENERGY)
doSendDistanceShoot(epos, cpos, CONST_ANI_ENERGYBALL)
local value = math.random(1, 3)
doSendMagicEffect(cpos, 27+value)
return true
else
return false
end
end
end
Let's take a classic spell to example, this case exori vis.
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_ENERGYAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -1, -10, -1, -20, 5, 5, 1.4, 2.1)
function onCastSpell(cid, var)
return doCombat(cid, combat, var)
end
You must change to this:
Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_ENERGYAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -1, -10, -1, -20, 5, 5, 1.4, 2.1)
local function spell(cid, var)
if getPlayerStorageValue(cid, 9001) ~= 'colision' then
doCreatureSay(cid, 'Strike!', TALKTYPE_ORANGE_1)
return doCombat(cid, combat, var)
end
end
function onCastSpell(cid, var)
checkColision(cid)
doCreatureSay(cid, 'Energy...', TALKTYPE_ORANGE_1)
addEvent(spell, 2000, cid, var)
end