Lua Teleport scroll tfs 1.2

Discussion in 'Support' started by Vitich, Apr 20, 2017 at 9:42 PM.

  1. Vitich

    Vitich Member

    Joined:
    Nov 28, 2012
    Messages:
    237
    Likes Received:
    11
    Best Answers:
    0
    Hi to all.

    I want modify this script, because when someone is trying to kill someone he use tp and back to temple without die.

    Code (Text):
    1.  
    2. savePos = {}
    3.  
    4. local function sendEffects(pos, eff, pid)
    5.     if savePos[pid] then
    6.         local player = Player(pid)
    7.         if isPlayer(player) then
    8.             pos:sendMagicEffect(eff, player)
    9.             addEvent(sendEffects, 400, pos, eff, pid)
    10.         end
    11.     end
    12. end
    13.  
    14. function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    15.     local pid   = player:getId()
    16.     if not player:isPzLocked() then
    17.         if not savePos[pid] then
    18.             savePos[pid] = {player:getPosition()}
    19.             player:teleportTo(player:getTown():getTemplePosition())
    20.             local pos = player:getPosition()
    21.             local randpos = Position(pos.x+math.random(2), pos.y+math.random(2), pos.z)
    22.             savePos[pid] = {savePos[pid][1], randpos}
    23.             local cache  = savePos[pid]
    24.             sendEffects(cache[2], 12, pid)
    25.             sendEffects(cache[1], 35, pid)
    26.             local item = Item(Tile(randpos):getGround().uid)
    27.             item:setActionId(3006)
    28.             addEvent(function()
    29.                         if item:getActionId(3006) then
    30.                             item:removeAttribute('aid')
    31.                             savePos[pid] = nil
    32.                         end
    33.                     end, 30000)
    34.         else
    35.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You must enter your teleport first before you use this again.')
    36.         end
    37.     else
    38.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You may not use this while you are in battle.')
    39.     end
    40.     return true
    41. end
    I want to change that when you got battle, you can't use tp.

    Code (Text):
    1. if not player:isPzLocked() then
    I tried a lot of conditions but not working...
     
  2. Best Answer:
    Post #10 by Lay, Apr 21, 2017 at 9:40 AM
  3. Aled

    Aled Active Member

    Joined:
    Mar 30, 2017
    Messages:
    129
    Likes Received:
    71
    Best Answers:
    6
    put this
    Code (Lua):
    1.     if player:isPzLocked() then
    2.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You may not use this while you are in battle.')
    3.         return false
    4.     end
    directly below
    Code (Lua):
    1. function onUse(player, item, fromPosition, target, toPosition, isHotkey)
     
  4. Vitich

    Vitich Member

    Joined:
    Nov 28, 2012
    Messages:
    237
    Likes Received:
    11
    Best Answers:
    0
    This is not the problem with pz.
    I want that u can't use it while battle(from monsters) like when you need logout and u can't cuz of battle
     
  5. Xeraphus

    Xeraphus Premium User Premium User

    Joined:
    Feb 14, 2015
    Messages:
    2,348
    Likes Received:
    925
    Best Answers:
    100
    if player:getCondition(CONDITION_INFIGHT) then
     
    boro boro likes this.
  6. Aled

    Aled Active Member

    Joined:
    Mar 30, 2017
    Messages:
    129
    Likes Received:
    71
    Best Answers:
    6
    Yeah do that ^
    Code (Lua):
    1. if player:getCondition(CONDITION_INFIGHT) then
    2.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You may not use this while you are in battle.')
    3.         return false
    4.     end
    That's what I thought I had :p
     
  7. Vitich

    Vitich Member

    Joined:
    Nov 28, 2012
    Messages:
    237
    Likes Received:
    11
    Best Answers:
    0
    Still not working
     
  8. Aled

    Aled Active Member

    Joined:
    Mar 30, 2017
    Messages:
    129
    Likes Received:
    71
    Best Answers:
    6
    Code (Lua):
    1. savePos = {}
    2. local function sendEffects(pos, eff, pid)
    3.     if savePos[pid] then
    4.         local player = Player(pid)
    5.         if isPlayer(player) then
    6.             pos:sendMagicEffect(eff, player)
    7.             addEvent(sendEffects, 400, pos, eff, pid)
    8.         end
    9.     end
    10. end
    11. function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    12.     local pid   = player:getId()
    13.     if player:getCondition(CONDITION_INFIGHT) then
    14.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You may not use this while you are in battle.')
    15.         return true
    16.     end
    17.     if not player:isPzLocked() then
    18.         if not savePos[pid] then
    19.             savePos[pid] = {player:getPosition()}
    20.             player:teleportTo(player:getTown():getTemplePosition())
    21.             local pos = player:getPosition()
    22.             local randpos = Position(pos.x+math.random(2), pos.y+math.random(2), pos.z)
    23.             savePos[pid] = {savePos[pid][1], randpos}
    24.             local cache  = savePos[pid]
    25.             sendEffects(cache[2], 12, pid)
    26.             sendEffects(cache[1], 35, pid)
    27.             local item = Item(Tile(randpos):getGround().uid)
    28.             item:setActionId(3006)
    29.             addEvent(function()
    30.                         if item:getActionId(3006) then
    31.                             item:removeAttribute('aid')
    32.                             savePos[pid] = nil
    33.                         end
    34.                     end, 30000)
    35.         else
    36.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You must enter your teleport first before you use this again.')
    37.         end
    38.     else
    39.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You may not use this while you are in battle.')
    40.     end
    41.     return true
    42. end
     
  9. Vitich

    Vitich Member

    Joined:
    Nov 28, 2012
    Messages:
    237
    Likes Received:
    11
    Best Answers:
    0
    I can still use with battle :/
     
  10. Aled

    Aled Active Member

    Joined:
    Mar 30, 2017
    Messages:
    129
    Likes Received:
    71
    Best Answers:
    6
    I do not know why =/
    Let me rewrite it
    What is in your actions.xml?
    Try this anyway:
    Code (Lua):
    1. savePos = {}
    2. local function sendEffects(pos, eff, pid)
    3.     if savePos[pid] then
    4.         local player = Player(pid)
    5.         if isPlayer(player) then
    6.             pos:sendMagicEffect(eff, player)
    7.             addEvent(sendEffects, 400, pos, eff, pid)
    8.         end
    9.     end
    10. end
    11. function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    12.     local pid   = player:getId()
    13.     if not player:getCondition(CONDITION_INFIGHT) then
    14.         if not savePos[pid] then
    15.             savePos[pid] = {player:getPosition()}
    16.             player:teleportTo(player:getTown():getTemplePosition())
    17.             local pos = player:getPosition()
    18.             local randpos = Position(pos.x+math.random(2), pos.y+math.random(2), pos.z)
    19.             savePos[pid] = {savePos[pid][1], randpos}
    20.             local cache  = savePos[pid]
    21.             sendEffects(cache[2], 12, pid)
    22.             sendEffects(cache[1], 35, pid)
    23.             local item = Item(Tile(randpos):getGround().uid)
    24.             item:setActionId(3006)
    25.             addEvent(function()
    26.                 if item:getActionId(3006) then
    27.                     item:removeAttribute('aid')
    28.                     savePos[pid] = nil
    29.                 end
    30.             end, 30*1000)
    31.         else
    32.             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You must enter your teleport first before you use this again.')
    33.         end
    34.     else
    35.         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You may not use this while you are in battle.')
    36.     end
    37.     return true
    38. end
     
    Vitich likes this.
  11. Lay

    Lay Member

    Joined:
    Dec 7, 2012
    Messages:
    41
    Likes Received:
    11
    Best Answers:
    5
    Best Answer
    Code (Lua):
    1.         if not player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
     
  12. Aled

    Aled Active Member

    Joined:
    Mar 30, 2017
    Messages:
    129
    Likes Received:
    71
    Best Answers:
    6
    GitHub says CONDITIONID is optional
    Though who knows, might work
     
  13. Vitich

    Vitich Member

    Joined:
    Nov 28, 2012
    Messages:
    237
    Likes Received:
    11
    Best Answers:
    0
    Not working :/ can use with battle.

    Code (Text):
    1. <action itemid="1953" script="tpscroll.lua"/>
     
  14. Vitich

    Vitich Member

    Joined:
    Nov 28, 2012
    Messages:
    237
    Likes Received:
    11
    Best Answers:
    0
    Working now!

    Thank you guys both :)
     

Share This Page

Loading...