ON
spell

Pull/Push Spells

Por Oneshot, 03 de jan. de 2013 em Globalevents e Spells

8
5.9k
OneshotO
03 de janeiro de 2013 às 20:17

Nome: Pull/Push Spells

Autor: Oneshot

Tipo: Magia

 


 

Já vi vários pedidos de magias que puxem ou empurrem monstros e jogadores, então resolvi fazer essas duas magias.

 


 

Pull Spell

 

local function doPullCreature(target, cid)
   if target > 0 then
    if not isNpc(target) then
	    local position = getThingPosition(cid)
	    local fromPosition = getThingPosition(target)
	    local x = ((fromPosition.x - position.x) < 0 and 1 or ((fromPosition.x - position.x) == 0 and 0 or -1))
	    local y = ((fromPosition.y - position.y) < 0 and 1 or ((fromPosition.y - position.y) == 0 and 0 or -1))
	    local toPosition = {x = fromPosition.x + x, y = fromPosition.y + y, z = fromPosition.z}
	    if doTileQueryAdd(target, toPosition) == 1 and getTileInfo(toPosition).house == false then
		    doTeleportThing(target, toPosition, true)
	    end
    end
   end
end
local spell = {}
spell.config = {
   [3] = {
    damageType = 1,
    areaEffect = 2,
    area = {
	    {0, 0, 1, 1, 1, 0, 0},
	    {0, 1, 1, 1, 1, 1, 0},
	    {1, 1, 1, 1, 1, 1, 1},
	    {1, 1, 1, 3, 1, 1, 1},
	    {1, 1, 1, 1, 1, 1, 1},
	    {0, 1, 1, 1, 1, 1, 0},
	    {0, 0, 1, 1, 1, 0, 0}
    }	   
   },
   [2] = {
    damageType = 1,
    areaEffect = 2,
    area = {
	    {0, 0, 0, 0, 0, 0, 0},
	    {0, 0, 1, 1, 1, 0, 0},
	    {0, 1, 1, 1, 1, 1, 0},
	    {0, 1, 1, 3, 1, 1, 0},
	    {0, 1, 1, 1, 1, 1, 0},
	    {0, 0, 1, 1, 1, 0, 0},
	    {0, 0, 0, 0, 0, 0, 0}
    }	   
   },
   [1] = {
    damageType = 1,
    areaEffect = 2,
    area = {
	    {0, 0, 0, 0, 0, 0, 0},
	    {0, 0, 0, 0, 0, 0, 0},
	    {0, 0, 1, 1, 1, 0, 0},
	    {0, 0, 1, 3, 1, 0, 0},
	    {0, 0, 1, 1, 1, 0, 0},
	    {0, 0, 0, 0, 0, 0, 0},
	    {0, 0, 0, 0, 0, 0, 0}
    }	   
   }
}

spell.combats = {}
for _, config in ipairs(spell.config) do
   local combat = createCombatObject()
   setCombatParam(combat, COMBAT_PARAM_TYPE, config.damageType)
   setCombatParam(combat, COMBAT_PARAM_EFFECT, config.areaEffect)
   function onTargetCreature(cid, target)
    doPullCreature(target, cid)
   end
   setCombatCallback(combat, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
   setCombatArea(combat, createCombatArea(config.area))
   table.insert(spell.combats, combat)
end
function onCastSpell(cid, var)
   for n = 1, #spell.combats do
    addEvent(doCombat, (n * 150) - 150, cid, spell.combats[n], var)
   end
   return true
end

 

Push Spell

 

local function doPushCreature(target, cid)
   if target > 0 then
    if not isNpc(target) then
	    local position = getThingPosition(cid)
	    local fromPosition = getThingPosition(target)
	    local x = ((fromPosition.x - position.x) < 0 and -1 or ((fromPosition.x - position.x) == 0 and 0 or 1))
	    local y = ((fromPosition.y - position.y) < 0 and -1 or ((fromPosition.y - position.y) == 0 and 0 or 1))
	    local toPosition = {x = fromPosition.x + x, y = fromPosition.y + y, z = fromPosition.z}
	    if doTileQueryAdd(target, toPosition) == 1 and getTileInfo(toPosition).house == false then
		    doTeleportThing(target, toPosition, true)
	    end
    end
   end
end
local spell = {}
spell.config = {
   [3] = {
    damageType = 1,
    areaEffect = 2,
    area = {
	    {0, 0, 1, 1, 1, 0, 0},
	    {0, 1, 1, 1, 1, 1, 0},
	    {1, 1, 1, 1, 1, 1, 1},
	    {1, 1, 1, 3, 1, 1, 1},
	    {1, 1, 1, 1, 1, 1, 1},
	    {0, 1, 1, 1, 1, 1, 0},
	    {0, 0, 1, 1, 1, 0, 0}
    }	   
   },
   [2] = {
    damageType = 1,
    areaEffect = 2,
    area = {
	    {0, 0, 0, 0, 0, 0, 0},
	    {0, 0, 1, 1, 1, 0, 0},
	    {0, 1, 1, 1, 1, 1, 0},
	    {0, 1, 1, 3, 1, 1, 0},
	    {0, 1, 1, 1, 1, 1, 0},
	    {0, 0, 1, 1, 1, 0, 0},
	    {0, 0, 0, 0, 0, 0, 0}
    }	   
   },
   [1] = {
    damageType = 1,
    areaEffect = 2,
    area = {
	    {0, 0, 0, 0, 0, 0, 0},
	    {0, 0, 0, 0, 0, 0, 0},
	    {0, 0, 1, 1, 1, 0, 0},
	    {0, 0, 1, 3, 1, 0, 0},
	    {0, 0, 1, 1, 1, 0, 0},
	    {0, 0, 0, 0, 0, 0, 0},
	    {0, 0, 0, 0, 0, 0, 0}
    }	   
   }
}

spell.combats = {}
for _, config in ipairs(spell.config) do
   local combat = createCombatObject()
   setCombatParam(combat, COMBAT_PARAM_TYPE, config.damageType)
   setCombatParam(combat, COMBAT_PARAM_EFFECT, config.areaEffect)
   function onTargetCreature(cid, target)
    doPushCreature(target, cid)
   end
   setCombatCallback(combat, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
   setCombatArea(combat, createCombatArea(config.area))
   table.insert(spell.combats, combat)
end
function onCastSpell(cid, var)
   for n = 1, #spell.combats do
    addEvent(doCombat, (n * 150) - 150, cid, spell.combats[n], var)
   end
   return true
end

 


 

Abraços.

Editado Janeiro 3 por Oneshot

rohfagundesR
04 de janeiro de 2013 às 10:34

legal eu gostei

só queria saber caso eu queira

colocar dano

e mudar o efeito q sai

vc explica?

OneshotO
04 de janeiro de 2013 às 11:16

Mude todos os números dessas linhas:

 

areaEffect = 2

 

 

E para dar dano

 

Adicione essa linha:

 

setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -1, 0, -1, 0)

 

Embaixo dessa:

 

 

setCombatParam(combat, COMBAT_PARAM_EFFECT, config.areaEffect)

rohfagundesR
04 de janeiro de 2013 às 12:08

vlw =D

 

e outra coisa

se eu quiser q essa spell saia em volta do meu player em vez do monstro selecionado tem como?

OneshotO
04 de janeiro de 2013 às 12:10

Eu coloquei para sair em volta do jogador.

 

Provavelmente, você tem isso isso do spells.xml, ou algo parecido.

 

casterTargetOrDirection="1"

 

É só retirar.

Editado Janeiro 4 por Oneshot

rohfagundesR
05 de janeiro de 2013 às 22:33

noobei =X

 

vlw ai a spell ta otima =D

 

--------

 

edit:

 

cara

vc pode me falar o q eu posso mudar nessa spell

pra ela empurrar só pra onde eu estiver virado

 

tipo empurrar reto

e n diagonal

tem como?

Editado Janeiro 5 por rohfagundes

OneshotO
05 de janeiro de 2013 às 22:43

Eu desenvolvi um "algoritmo" para decidir as posições de empurrar e puxar das magias, que comparam a posição do jogador para com a posição do alvo.

Já do jeito que você quer, eu teria que fazer um novo algoritmo, não com base na comparação de posições, mas sim na direção do olhar do jogador, uma vez que:

 

HKJJ6.jpg

 

E no momento estou com preguiça de refazer minha magia que já me agrada como está.

 

Abração.

Editado Janeiro 5 por Oneshot

8 anos depois...
11 de fevereiro de 2021 às 18:26

Tem como atualizar para TFS 1.3?

 

Coloquei no servidor aqui e o efeito sai, porém não puxa o monstro e da erro na distro:

 

Citar

Lua Script Error: [Spell Interface]
data/spells/scripts/support/pull.lua:onCastSpell
LuaScriptInterface::luaAddEvent(). Argument #3 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        data/spells/scripts/support/pull.lua:72: in function <data/spells/scripts/support/pull.lua:70>

Lua Script Error: [Spell Interface]
data/spells/scripts/support/pull.lua:onCastSpell
LuaScriptInterface::luaAddEvent(). Argument #3 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        data/spells/scripts/support/pull.lua:72: in function <data/spells/scripts/support/pull.lua:70>

Lua Script Error: [Spell Interface]
data/spells/scripts/support/pull.lua:onCastSpell
LuaScriptInterface::luaAddEvent(). Argument #3 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        data/spells/scripts/support/pull.lua:72: in function <data/spells/scripts/support/pull.lua:70>

Lua Script Error: [Spell Interface]
in callback: data/spells/scripts/support/pull.lua:onTargetCreature
(Unknown scriptfile)
data/spells/scripts/support/pull.lua:2: attempt to compare number with userdata

Lua Script Error: [Spell Interface]
in callback: data/spells/scripts/support/pull.lua:onTargetCreature
(Unknown scriptfile)
data/spells/scripts/support/pull.lua:2: attempt to compare number with userdata

Lua Script Error: [Spell Interface]
data/spells/scripts/support/pull.lua:onCastSpell
LuaScriptInterface::luaAddEvent(). Argument #3 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        data/spells/scripts/support/pull.lua:72: in function <data/spells/scripts/support/pull.lua:70>

Lua Script Error: [Spell Interface]
data/spells/scripts/support/pull.lua:onCastSpell
LuaScriptInterface::luaAddEvent(). Argument #3 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        data/spells/scripts/support/pull.lua:72: in function <data/spells/scripts/support/pull.lua:70>

Lua Script Error: [Spell Interface]
data/spells/scripts/support/pull.lua:onCastSpell
LuaScriptInterface::luaAddEvent(). Argument #3 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        data/spells/scripts/support/pull.lua:72: in function <data/spells/scripts/support/pull.lua:70>

Lua Script Error: [Spell Interface]
in callback: data/spells/scripts/support/pull.lua:onTargetCreature
(Unknown scriptfile)
data/spells/scripts/support/pull.lua:2: attempt to compare number with userdata

Lua Script Error: [Spell Interface]
in callback: data/spells/scripts/support/pull.lua:onTargetCreature
(Unknown scriptfile)
data/spells/scripts/support/pull.lua:2: attempt to compare number with userdata