function onThink(interval, lastExecution, thinkInterval)
local config = {
storage = 11111,
room_from = {x = 45421, y = 52254, z = 48746},
room_to = {x = 45421, y = 52254, z = 48746},
text = "You will be teleported within 10 seconds if you won't leave the protection zone!",
text_after_tp = "You have been teleported out of protection zone",
time_in_seconds = 10, -- notice that player will be teleported (he stays 10 seconds, receive info about it)
time_in_seconds_2 = 10, -- additional time when player will be teleported (he stayed 10 seconds, he received message but he is still in PZ, another check for 10 seconds to tp him)
position_where_player_will_be_teleported = {x = 45421, y = 52254, z = 48746}
}
local players = {}
for x = config.room_from.x, config.room_to.x do
for y = config.room_from.y, config.room_to.y do
for z = config.room_from.z, config.room_to.z do
local pos = {x=x, y=y, z=z,stackpos = 253}
local thing = getThingfromPos(pos)
if thing.itemid > 0 then
if isPlayer(thing.uid) == TRUE then
table.insert(players, thing.uid)
end
end
end
end
end
for _, kid in ipairs(getPlayersOnline()) do
if not isInArray(kid, players) then
setPlayerStorageValue(kid, config.storage, 0)
end
end
for _, pid in ipairs(players) do
if getPlayerStorageValue(pid, config.storage) == -1 then
setPlayerStorageValue(pid, config.storage, 0)
end
if getTilePzInfo(getPlayerPosition(pid)) == TRUE then
setPlayerStorageValue(pid, config.storage, getPlayerStorageValue(pid, config.storage)+1)
if getPlayerStorageValue(pid, config.storage) == config.time_in_seconds then
doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE , config.text)
addEvent(function(pid)
if getPlayerStorageValue(pid, config.storage) == (config.time_in_seconds + config.time_in_seconds_2) then
doTeleportThing(pid, config.position_where_player_will_be_teleported, false)
doSendMagicEffect(getPlayerPosition(pid), CONST_ME_TELEPORT)
doPlayerSendTextMessage(pid, MESSAGE_EVENT_ADVANCE , config.text_after_tp)
end
setPlayerStorageValue(pid, config.storage, 0)
end, config.time_in_seconds_2 * 1000)
end
end
end
return true
end