- Joined
- Feb 14, 2015
- Messages
- 5,643
- Solutions
- 559
- Reaction score
- 3,949
Description
Teleports player to default town position, creates a teleport near the player (that only the player can see).
The player has 30 seconds to enter the teleport to get back to their previous position.
Teleports player to default town position, creates a teleport near the player (that only the player can see).
The player has 30 seconds to enter the teleport to get back to their previous position.
If you don't understand from the screenshots, here is a video
actions.xml
XML:
<action itemid="1953" script="tp scroll.lua"/>
actions/scripts/tp scroll.lua
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: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(3), 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
movements.xml
XML:
<movevent event="StepIn" actionid="3006" script="tpscroll.lua"/>
movements/scripts/tpscroll.lua
Lua:
function onStepIn(creature, item, position, fromPosition)
local pid = creature:getId()
local pos = savePos[pid]
if pos and pos[2] then
creature:teleportTo(pos[1])
pos[2]:sendMagicEffect(CONST_ME_STUN)
pos[1]:sendMagicEffect(CONST_ME_STUN)
item:removeAttribute('aid')
savePos[pid] = nil
end
return true
end
creaturescripts.xml
XML:
<event type="logout" name="Script Logut" script="Script Logout.lua"/>
creaturescripts/scripts/Script Logout.lua
Lua:
function onLogout(player)
local pid = player:getId()
if savePos[pid] then
Item(Tile(savePos[pid][2]):getGround().uid):removeAttribute('aid')
savePos[pid] = nil
end
return true
end
Last edited by a moderator: