Ir para conteúdo
  • 0

Problema Com Teleporte Para Random X,y A Partir Do Target.


razurator

Pergunta

No momento essa magia teleporta para a posição do inimigo, mas se o inimigo esta parado ele acaba por empurra-lo.

Eu queria que ele se teleporte para uma posição randômica de (x,y) a partir do enemypos. (enemypos+n) ou seja, do lado, atras na frente ou até diagonal do inimigo se houver espaço.

 

local distanceCombat = createCombatObject()
setCombatParam(distanceCombat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(distanceCombat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SPEAR)
function getSpellDamage(cid, lv)
			damage_min = lv * 2
			damage_max = lv * 1
			if(damage_max < damage_min) then
							local tmp = damage_max
			  damage_max = damage_min
			  damage_min = tmp
			end
			return -damage_min, -damage_max
end
setCombatCallback(distanceCombat, CALLBACK_PARAM_SKILLVALUE, "getSpellDamage")
function onCastSpell(cid, var)
local player = getCreaturePosition(cid)
local target = getCreatureTarget(cid)
local enemypos = getCreaturePosition(target)
if target == isMonster or isCreature then
doTeleportThing(cid, enemypos)
doSendMagicEffect(player, 61)
doCombat(cid, distanceCombat, var)
return 1
else
doPlayerSendCancel(cid, "You need a taget.")
end
end

Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 0
local distanceCombat = createCombatObject()
setCombatParam(distanceCombat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(distanceCombat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SPEAR)

function getSpellDamage(cid, lv)
   damage_min = lv * 2
   damage_max = lv * 1
   if(damage_max < damage_min) then
    local tmp = damage_max
       damage_max = damage_min
       damage_min = tmp
   end
   return -damage_min, -damage_max
end
setCombatCallback(distanceCombat, CALLBACK_PARAM_SKILLVALUE, "getSpellDamage")

function onCastSpell(cid, var)
local target = getCreatureTarget(cid)
local enemypos = getCreaturePosition(target)
   if isMonster(target) or isCreature(target) then
       if verificaPos(cid, enemypos, var) == false then
           doPlayerSendCancel(cid, "Position not valid.")
           return false
       else
           return true
       end
   else
       doPlayerSendCancel(cid, "You need a taget.")
       return false
   end
end

function verificaPos(cid, enemypos, var)
local positions = {}
local player = getCreaturePosition(cid)
for i=-1, 1 do
   for j=-1, 1 do
       local position = {x=enemypos.x+i,y=enemypos.y+j,z=enemypos.z}
       if isWalkable(position) then
           positions[#positions+1] = position        
       end
   end
end
if #positions > 0 then
   doTeleportThing(cid, positions[math.random(1,#positions)])
   doSendMagicEffect(player, 61)
   return doCombat(cid, distanceCombat, var)
else
   return false
end
end

function isWalkable(pos, creature, pz, proj) -- nord
   if getTileThingByPos({x = pos.x, y = pos.y, z = pos.z, stackpos = 0}).itemid == 0 then return false end
   local creature = getTopCreature(pos)
   if creature.type > 0 then    return false end
   if getTilePzInfo(pos) and not pz then return false end
   local n = not proj and 3 or 2
   for i = 0, 255 do
       pos.stackpos = i
       local tile = getTileThingByPos(pos)
       if tile.itemid ~= 0 and not isCreature(tile.uid) then
           if hasProperty(tile.uid, n) or hasProperty(tile.uid, 7) then
               return false
           end
       end
   end
return true
end

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...