local useInProtectionZone = false
local useWithoutPzLocked = false
local useWithoutConditionFight = false
local successMessage = 'You have teleported to your house.'
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local okayTeleport = successMessage
if useInProtectionZone and not Tile.hasFlag(Creature.getTile(player), TILESTATE_PROTECTIONZONE) then
okayTeleport = 'Sorry, this parchment used in protection zone only.'
end
if useWithoutPzLocked and Player.isPzLocked(player) then
okayTeleport = 'Sorry, this parchment used without PZ.'
end
if useWithoutConditionFight and Creature.getCondition(player, CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
okayTeleport = 'Sorry, this parchment used without fight condition.'
end
if okayTeleport == successMessage then
if Player.getHouse(player) then
local doorPosition = House.getExitPosition(Player.getHouse(player))
Position.sendMagicEffect(Creature.getPosition(player), CONST_ME_POFF)
Creature.teleportTo(player, doorPosition, false)
Position.sendMagicEffect(doorPosition, CONST_ME_TELEPORT)
Item.remove(item, 1)
Player.sendTextMessage(player, MESSAGE_STATUS_CONSOLE_BLUE, okayTeleport)
else
okayTeleport = 'You not have a house.'
Player.sendCancelMessage(player, okayTeleport)
Position.sendMagicEffect(Creature.getPosition(player), CONST_ME_POFF)
end
else
Player.sendCancelMessage(player, okayTeleport)
Position.sendMagicEffect(Creature.getPosition(player), CONST_ME_POFF)
end
return true
end