liqeen
Active Member
LUA:
local config = {
level = 50,
maxTimes = 1,
timeToWait = {1, 'day'},
maxPlayers = 1,
room = {fromPos = Position(1064, 1064, 7), toPos = Position(1069, 1069, 7)},
newPos = Position(1066, 1066, 7),
stone = {id = 1304, pos = Position(1059, 1065, 7)},
timeToKick = {0.3, 'min'},
kickPos = Position(1060, 1070, 7),
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if player:hasExhaustion(84309) then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You can use again at " .. os.date("%d %B %Y %X", player:getStorageValue(84309))..".")
return true
end
if player:getStorageValue(84310) == config.maxTimes then
player:setStorageValue(84310, -1)
end
if #getPlayersInArea(config.room.fromPos, config.room.toPos) >= config.maxPlayers then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Wait for the team to leave the room.')
player:getPosition():sendMagicEffect(CONST_ME_POFF)
return true
end
if player:getLevel() < config.level then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "You need at least level " .. config.level .. " to go.")
player:getPosition():sendMagicEffect(CONST_ME_POFF
)
return true
end
local max_times = player:getStorageValue(84310) > 0 and player:getStorageValue(84310) or 0
if (max_times + 1) == config.maxTimes then
player:setStorageValue(84309, mathtime(config.timeToWait) + os.time())
end
local stone = Tile(config.stone.pos):getItemById(config.stone.id)
if stone then
stone:getPosition():sendMagicEffect(CONST_ME_POFF)
stone:remove()
end
player:teleportTo(config.newPos)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:setStorageValue(84310, math.max(0, max_times) + 1)
addEvent(kickFromArea, mathtime(config.timeToKick) * 1000, player.uid)
return true
end
function getPlayersInArea(fromPos, toPos)
local players, playerss = {}, Game.getPlayers()
for i = 1, #playerss do
local player = playerss[i]
if isInRange(player:getPosition(), fromPos, toPos) then
table.insert(players, player)
end
end
return players
end
function mathtime(table) -- by dwarfer
local unit = {"sec", "min", "hour", "day"}
for i, v in pairs(unit) do
if v == table[2] then
return table[1]*(60^(v == unit[4] and 2 or i-1))*(v == unit[4] and 24 or 1)
end
end
return error("Bad declaration in mathtime function.")
end
function kickFromArea(cid)
local stone = Tile(config.stone.pos):getItemById(config.stone.id)
if not stone then
Game.createItem(config.stone.id, 1, config.stone.pos)
end
local player = Player(cid)
if player and isInRange(player:getPosition(), config.room.fromPos, config.room.toPos) then
player:teleportTo(config.kickPos)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end
end
The problem is with value maxTimes, it does not work.. Player still can use the stone no matter how much times he already used him.: s Can someone make it work?
Im using this also
Player.setExhaustion, Player.getExhaustion [TFS 1.0] (https://otland.net/threads/player-setexhaustion-player-getexhaustion-tfs-1-0.224233/)
Last edited by a moderator: