TFS 1.X+ getPosByDir

Discussion in 'Support' started by Decodde, Oct 11, 2018.

  1. Decodde

    Decodde New Member

    Joined:
    Oct 8, 2018
    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Code (Text):
    1. local config = {
    2. velocidade = 350, -- intervalo entre os giros (quanto menor, mais rapido)
    3. hits = 24, -- quantos hits vai dar
    4. msg = "Frozen Orb", -- msg ao soltar a spell
    5. key = 13871, -- storage que sera utilizado pro cooldown
    6. cooldown = 3, -- tempo em segundos de cooldown entre um uso da spell e outro.
    7. effect1 = 36, -- efeito de distancia que vai ficar rodando
    8. effect2 = 56, -- efeito no sqm do item
    9. effect3 = 37, -- efeito ao castar a spell
    10. effect4 = 43 -- efeito ao acertar a roda no player
    11. }
    12. --[[Note que a velocidade multiplicada pelo numero de hits deve dar algo proximo de 8550 pra que a magia nao fique ruim ou um efeito acabe antes do outro.
    13. Nos valores que eu utilizei eles dao 8400, oque ja eh considerado perto pois temos 200 milisegundos iniciais,
    14. 8550 eh o tempo que o item sera removido e coincide com o tempo de duracao do efeito 56 (config.effect2)]]
    15.  
    16. local combat = createCombatObject()
    17. setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
    18. setCombatParam(combat, COMBAT_PARAM_EFFECT, 255)
    19. setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -1, -10, -1, -20, 5, 5, 1.4, 2.1)
    20. function onTargetCreature(cid, target)
    21.    doSendMagicEffect(getCreaturePosition(target), config.effect4)
    22. end
    23. setCombatCallback(combat, 4, "onTargetCreature")
    24.  
    25. local arr = {
    26. {1, 1, 1},
    27. {1, 3, 1}, -- area que vai acertar a spell enquanto estiver rodando
    28. {1, 1, 1},
    29. }
    30.  
    31. local area = createCombatArea(arr)
    32. setCombatArea(combat, area)
    33.  
    34. function initEffect(position)
    35.     for i = 0, 3 do
    36.    
    37.         local pos = {x = position.x, y = position.y, z = position.z}
    38.         local dir = Creature(cid):getDirection(pos, i)
    39.         doSendDistanceShoot(position, dir, config.effect1)
    40.     end
    41. addEvent(doSendMagicEffect, 300, position, config.effect2)
    42. return true
    43. end
    44.  
    45. function middleEffect(cid, param, position, lim, count)
    46. n = count or 0
    47.     if isCreature(cid) and n < lim then
    48.         for i = 0, 3 do
    49.             local pos = {x = position.x, y = position.y, z = position.z}
    50.             local pos2 = {x = position.x, y = position.y, z = position.z}
    51.             local dir = Creature(cid):getDirection(pos, i)
    52.             local dir2 = Creature(cid):getDirection(pos2, i + 1 <= 3 and i + 1 or 0)
    53.             doSendDistanceShoot(dir, dir2, config.effect1)
    54.         end
    55.         doCombat(cid, combat, param)
    56.         addEvent(middleEffect, config.velocidade, cid, param, position, lim, n + 1)
    57.     end
    58. return true
    59. end
    60.  
    61. function endEffect(position)
    62.     for i = 0, 3 do
    63.         local pos = {x = position.x, y = position.y, z = position.z}
    64.         local dir = Creature(cid):getDirection(pos, i)
    65.         doSendDistanceShoot(dir, position, config.effect1)
    66.     end
    67.     local item = getTileItemById(position, 2180)
    68.     if item.uid > 0 then
    69.         doRemoveItem(item.uid)
    70.     end
    71. return true
    72. end
    73.  
    74. function onCastSpell(cid, var)
    75. local player = Player(cid)
    76. if player:getStorageValue(cid, config.key) - os.time() <= 0 then
    77.     player:setStorageValue(cid, config.key, os.time() + config.cooldown)
    78.     local position = getCreaturePosition(cid)
    79.     doCreatureSay(cid, config.msg, 20)
    80.     local orb = doCreateItem(2180, 1, position)
    81.     addEvent(endEffect, 8.55 * 1000, position)
    82.     doSendMagicEffect(position, config.effect3)
    83.     initEffect(position)
    84.     addEvent(middleEffect, 200, cid, var, position, config.hits)
    85. else
    86.     doPlayerSendCancel(cid, "You're exhausted.")
    87.     return false
    88. end
    89.  
    90. return true
    91. end
    Im trying convert this spell to tfs 1.3, but i stuck in that line

    It was:
    local dir = getPosByDir(pos, i)

    I tried
    local dir = Creature(cid):getDirection(pos, i)

    :rolleyes:

    How would it be in tfs 1.x?

    e.png
     
  2. Mr Trala

    Mr Trala Active Member

    Joined:
    Aug 26, 2014
    Messages:
    126
    Likes Received:
    55
    Best Answers:
    6
    Code (Lua):
    1. local config = {
    2. velocidade = 350, -- intervalo entre os giros (quanto menor, mais rapido)
    3. hits = 24, -- quantos hits vai dar
    4. msg = "Frozen Orb", -- msg ao soltar a spell
    5. key = 13871, -- storage que sera utilizado pro cooldown
    6. cooldown = 3, -- tempo em segundos de cooldown entre um uso da spell e outro.
    7. effect1 = 36, -- efeito de distancia que vai ficar rodando
    8. effect2 = 56, -- efeito no sqm do item
    9. effect3 = 37, -- efeito ao castar a spell
    10. effect4 = 43 -- efeito ao acertar a roda no player
    11. }
    12. --[[Note que a velocidade multiplicada pelo numero de hits deve dar algo proximo de 8550 pra que a magia nao fique ruim ou um efeito acabe antes do outro.
    13. Nos valores que eu utilizei eles dao 8400, oque ja eh considerado perto pois temos 200 milisegundos iniciais,
    14. 8550 eh o tempo que o item sera removido e coincide com o tempo de duracao do efeito 56 (config.effect2)]]
    15.  
    16. local function getPosByDir(position, direction, size)
    17.     local n = size or 1
    18.     if(direction == NORTH) then
    19.         position.y = position.y - n
    20.     elseif(direction == SOUTH) then
    21.         position.y = position.y + n
    22.     elseif(direction == WEST) then
    23.         position.x = position.x - n
    24.     elseif(direction == EAST) then
    25.         position.x = position.x + n
    26.     elseif(direction == NORTHWEST) then
    27.         position.y = position.y - n
    28.         position.x = position.x - n
    29.     elseif(direction == NORTHEAST) then
    30.         position.y = position.y - n
    31.         position.x = position.x + n
    32.     elseif(direction == SOUTHWEST) then
    33.         position.y = position.y + n
    34.         position.x = position.x - n
    35.     elseif(direction == SOUTHEAST) then
    36.         position.y = position.y + n
    37.         position.x = position.x + n
    38.     end
    39.  
    40.     return position
    41. end
    42.  
    43. local combat = createCombatObject()
    44. setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
    45. setCombatParam(combat, COMBAT_PARAM_EFFECT, 255)
    46. setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, -1, -10, -1, -20, 5, 5, 1.4, 2.1)
    47. function onTargetCreature(cid, target)
    48.    doSendMagicEffect(getCreaturePosition(target), config.effect4)
    49. end
    50. setCombatCallback(combat, 4, "onTargetCreature")
    51.  
    52. local arr = {
    53. {1, 1, 1},
    54. {1, 3, 1}, -- area que vai acertar a spell enquanto estiver rodando
    55. {1, 1, 1},
    56. }
    57.  
    58. local area = createCombatArea(arr)
    59. setCombatArea(combat, area)
    60.  
    61. function initEffect(position)
    62.     for i = 0, 3 do
    63.    
    64.         local pos = {x = position.x, y = position.y, z = position.z}
    65.         local dir = getPosByDir(pos, i)
    66.         doSendDistanceShoot(position, dir, config.effect1)
    67.     end
    68. addEvent(doSendMagicEffect, 300, position, config.effect2)
    69. return true
    70. end
    71.  
    72. function middleEffect(cid, param, position, lim, count)
    73. n = count or 0
    74.     if isCreature(cid) and n < lim then
    75.         for i = 0, 3 do
    76.             local pos = {x = position.x, y = position.y, z = position.z}
    77.             local pos2 = {x = position.x, y = position.y, z = position.z}
    78.             local dir = getPosByDir(pos, i)
    79.             local dir2 = getPosByDir(pos, i + 1 <= 3 and i + 1 or 0)
    80.             doSendDistanceShoot(dir, dir2, config.effect1)
    81.         end
    82.         doCombat(cid, combat, param)
    83.         addEvent(middleEffect, config.velocidade, cid, param, position, lim, n + 1)
    84.     end
    85. return true
    86. end
    87.  
    88. function endEffect(position)
    89.     for i = 0, 3 do
    90.         local pos = {x = position.x, y = position.y, z = position.z}
    91.         local dir = getPosByDir(pos, i)
    92.         doSendDistanceShoot(dir, position, config.effect1)
    93.     end
    94.     local item = getTileItemById(position, 2180)
    95.     if item.uid > 0 then
    96.         doRemoveItem(item.uid)
    97.     end
    98. return true
    99. end
    100.  
    101. function onCastSpell(cid, var)
    102. local player = Player(cid)
    103. if player:getStorageValue(cid, config.key) - os.time() <= 0 then
    104.     player:setStorageValue(cid, config.key, os.time() + config.cooldown)
    105.     local position = player:getPosition()
    106.     doCreatureSay(cid, config.msg, 20)
    107.     local orb = Game.createItem(2180, position)
    108.     addEvent(endEffect, 8.55 * 1000, position)
    109.     doSendMagicEffect(position, config.effect3)
    110.     initEffect(position)
    111.     addEvent(middleEffect, 200, cid, var, position, config.hits)
    112. else
    113.     doPlayerSendCancel(cid, "You're exhausted.")
    114.     return false
    115. end
    116.  
    117. return true
    118. end
    You will need to redo those addEvents tho, I can't confidently say that they are safe in a live server.
     
  3. Night Wolf

    Night Wolf I don't bite.

    Joined:
    Feb 10, 2008
    Messages:
    99
    Likes Received:
    54
    Best Answers:
    2
    If you still need help on this adaptation please feel free to send me a PM.
     

Share This Page

Loading...