• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Player Winner in Event.

lSenturion2

Active Member
Joined
Oct 2, 2019
Messages
124
Reaction score
29
Hello my friends, I wanted to ask you a huge favor, if someone has a script for when there is only one player in a specific area, only this player is teleported to a position.

Example: I won the event "The last man standing" and when I was the only player in that area, I teleported to a position where the rewards will be.

Thanks a lot !

PD: It doesn't matter if it's Globalevent, Action, Movement ... I just want if there is 1 player in the area, it is teleported.
 
Solution
Lua:
local area = {{x = 100, y = 100, z = 7}, {x = 105, y = 105, z = 7}} -- from, to

local playersInArea = {}
local pos
for _, pid in ipairs(getPlayersOnline()) do
    pos = getThingPosition(pid)
    if pos.x >= area[1].x and pos.y >= area[1].y and pos.z >= area[1].z and pos.x <= area[2].x and pos.y <= area[2].y and pos.z <= area[2].z then
        table.insert(playersInArea, pid)
    end
end

if #playersInArea == 1 then
    doTeleportThing(playersInArea[1], {x = 200, y = 200, z = 7}) -- teleport location
end
Untested, but should work.

Put this wherever you need it.

Lua:
local area = {Position(100, 100, 7), Position(105, 105, 7)} -- from, to

local playersInArea = {}
for _, targetPlayer in ipairs(Game.getPlayers()) do
	if targetPlayer:getPosition():isInRange(area[1], area[2])
		table.insert(playersInArea, targetPlayer:getId())
	end
end

if #playersInArea == 1 then
	local player = Player(playersInArea[1])
	player:teleportTo(Position(200, 200, 7)) -- teleport location
end
 
Lua:
local area = {{x = 100, y = 100, z = 7}, {x = 105, y = 105, z = 7}} -- from, to

local playersInArea = {}
local pos
for _, pid in ipairs(getPlayersOnline()) do
    pos = getThingPosition(pid)
    if pos.x >= area[1].x and pos.y >= area[1].y and pos.z >= area[1].z and pos.x <= area[2].x and pos.y <= area[2].y and pos.z <= area[2].z then
        table.insert(playersInArea, pid)
    end
end

if #playersInArea == 1 then
    doTeleportThing(playersInArea[1], {x = 200, y = 200, z = 7}) -- teleport location
end
 
Solution
Back
Top