local config = {
itemId = 1234, --item id
storage = 1234, --storage value to store the timestamp
duration = 24, --duration(hours)
teleportActionId = 1234, --teleport action id
teleportPosition = Position(500, 500, 7) --position to teleport to if successful (leave teleport co-ordinates blank in RME)
}
local entryItem = Action()
function entryItem.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local now = os.time()
local expiryTime = player:getStorageValue(config.storage)
if now < expiryTime then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You already have entry to the city.")
return true
end
player:setStorageValue(config.storage, now + (config.duration * 60 * 60))
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You now have access to the city for the next 24 hours.")
item:remove(1)
return true
end
entryItem:id(config.itemId)
entryItem:register()
local entryTeleport = MoveEvent()
function entryTeleport.onStepIn(player, item, position, fromPosition)
if not player:isPlayer() then
return false
end
local now = os.time()
local expiryTime = player:getStorageValue(config.storage)
if now > expiryTime then
player:teleportTo(fromPosition)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You don't have access to the city.")
return true
end
player:teleportTo(config.teleportPosition)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have been teleported to the city.")
return true
end
entryTeleport:aid(config.teleportActionId)
entryTeleport:register()