• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Teleport scroll tfs 1.2

Vitich

Member
Joined
Nov 28, 2012
Messages
266
Reaction score
11
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:
savePos = {}

local function sendEffects(pos, eff, pid)
    if savePos[pid] then
        local player = Player(pid)
        if isPlayer(player) then
            pos:sendMagicEffect(eff, player)
            addEvent(sendEffects, 400, pos, eff, pid)
        end
    end
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local pid   = player:getId()
    if not player:isPzLocked() then
        if not savePos[pid] then
            savePos[pid] = {player:getPosition()}
            player:teleportTo(player:getTown():getTemplePosition())
            local pos = player:getPosition()
            local randpos = Position(pos.x+math.random(2), pos.y+math.random(2), pos.z)
            savePos[pid] = {savePos[pid][1], randpos}
            local cache  = savePos[pid]
            sendEffects(cache[2], 12, pid)
            sendEffects(cache[1], 35, pid)
            local item = Item(Tile(randpos):getGround().uid)
            item:setActionId(3006)
            addEvent(function()
                        if item:getActionId(3006) then
                            item:removeAttribute('aid')
                            savePos[pid] = nil
                        end
                    end, 30000)
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You must enter your teleport first before you use this again.')
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You may not use this while you are in battle.')
    end
    return true
end

I want to change that when you got battle, you can't use tp.

Code:
if not player:isPzLocked() then

I tried a lot of conditions but not working...
 
put this
Lua:
    if player:isPzLocked() then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You may not use this while you are in battle.')
        return false
    end
directly below
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
 
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
 
if player:getCondition(CONDITION_INFIGHT) then

Yeah do that ^
Lua:
if player:getCondition(CONDITION_INFIGHT) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You may not use this while you are in battle.')
        return false
    end
That's what I thought I had :p
 
Lua:
savePos = {}
local function sendEffects(pos, eff, pid)
    if savePos[pid] then
        local player = Player(pid)
        if isPlayer(player) then
            pos:sendMagicEffect(eff, player)
            addEvent(sendEffects, 400, pos, eff, pid)
        end
    end
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local pid   = player:getId()
    if player:getCondition(CONDITION_INFIGHT) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You may not use this while you are in battle.')
        return true
    end
    if not player:isPzLocked() then
        if not savePos[pid] then
            savePos[pid] = {player:getPosition()}
            player:teleportTo(player:getTown():getTemplePosition())
            local pos = player:getPosition()
            local randpos = Position(pos.x+math.random(2), pos.y+math.random(2), pos.z)
            savePos[pid] = {savePos[pid][1], randpos}
            local cache  = savePos[pid]
            sendEffects(cache[2], 12, pid)
            sendEffects(cache[1], 35, pid)
            local item = Item(Tile(randpos):getGround().uid)
            item:setActionId(3006)
            addEvent(function()
                        if item:getActionId(3006) then
                            item:removeAttribute('aid')
                            savePos[pid] = nil
                        end
                    end, 30000)
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You must enter your teleport first before you use this again.')
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You may not use this while you are in battle.')
    end
    return true
end
 
I do not know why =/
Let me rewrite it
What is in your actions.xml?
Try this anyway:
Lua:
savePos = {}
local function sendEffects(pos, eff, pid)
    if savePos[pid] then
        local player = Player(pid)
        if isPlayer(player) then
            pos:sendMagicEffect(eff, player)
            addEvent(sendEffects, 400, pos, eff, pid)
        end
    end
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local pid   = player:getId()
    if not player:getCondition(CONDITION_INFIGHT) then
        if not savePos[pid] then
            savePos[pid] = {player:getPosition()}
            player:teleportTo(player:getTown():getTemplePosition())
            local pos = player:getPosition()
            local randpos = Position(pos.x+math.random(2), pos.y+math.random(2), pos.z)
            savePos[pid] = {savePos[pid][1], randpos}
            local cache  = savePos[pid]
            sendEffects(cache[2], 12, pid)
            sendEffects(cache[1], 35, pid)
            local item = Item(Tile(randpos):getGround().uid)
            item:setActionId(3006)
            addEvent(function()
                if item:getActionId(3006) then
                    item:removeAttribute('aid')
                    savePos[pid] = nil
                end
            end, 30*1000)
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You must enter your teleport first before you use this again.')
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You may not use this while you are in battle.')
    end
    return true
end
 
Lua:
        if not player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
###### getCondition(conditionType[, conditionId = CONDITIONID_COMBAT[, subId = 0]]) > **Description:** N/A > **Parameters:**
  • _conditionType_ - _No description_
  • _conditionId_ - _(optional, default: CONDITIONID_COMBAT)_
  • _subId_ - _(optional, default: 0)_
> **Returns:** N/A > **Example:** ```Lua local creature = Creature(...) creature:getCondition(CONDITION_POISON, CONDITIONID_COMBAT, 0) ``` > **Added in version:** 1.0
GitHub says CONDITIONID is optional
Though who knows, might work
 
I do not know why =/
Let me rewrite it
What is in your actions.xml?
Try this anyway:
Lua:
savePos = {}
local function sendEffects(pos, eff, pid)
    if savePos[pid] then
        local player = Player(pid)
        if isPlayer(player) then
            pos:sendMagicEffect(eff, player)
            addEvent(sendEffects, 400, pos, eff, pid)
        end
    end
end
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local pid   = player:getId()
    if not player:getCondition(CONDITION_INFIGHT) then
        if not savePos[pid] then
            savePos[pid] = {player:getPosition()}
            player:teleportTo(player:getTown():getTemplePosition())
            local pos = player:getPosition()
            local randpos = Position(pos.x+math.random(2), pos.y+math.random(2), pos.z)
            savePos[pid] = {savePos[pid][1], randpos}
            local cache  = savePos[pid]
            sendEffects(cache[2], 12, pid)
            sendEffects(cache[1], 35, pid)
            local item = Item(Tile(randpos):getGround().uid)
            item:setActionId(3006)
            addEvent(function()
                if item:getActionId(3006) then
                    item:removeAttribute('aid')
                    savePos[pid] = nil
                end
            end, 30*1000)
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You must enter your teleport first before you use this again.')
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, 'You may not use this while you are in battle.')
    end
    return true
end

Not working :/ can use with battle.

Code:
<action itemid="1953" script="tpscroll.lua"/>
 
Back
Top