• 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!

Check players in range

klekSu

Stroke my ego.
Joined
Nov 4, 2008
Messages
1,285
Reaction score
18
Hello,

How to check if 5 players are in range fromPos = {x = 1111, y = 1005, z = 7} toPos = {x = 1115, y = 1012, z = 7}?

I'd like to make a script that look like this

Lua:
if < 5 players are in range fromPos = {x = 1111, y = 1005, z = 7} toPos = {x = 1115, y = 1012, z = 7} then
doBroadcastMessage
elseif < 5 players are in range fromPos = {x = 1105, y = 1005, z = 7} toPos = {x = 1109, y = 1011, z = 7} then
doBroadcastMessage
else
doTeleportThing

Anyone?
 
Lua:
	local players={}
	for _,cid in ipairs(getPlayersOnline()) do
		  if isInRange(getThingPos(cid),fromPosition,toPosition) then
				table.insert(players,cid)
		  end
	end
	 
	if #players >= 5 then
		doBroadcastMessage("There was more or equal to 5("..#players..") found in this place.")   --- #players return number of players found
			for _,pid in ipairs(players) do
				doTeleportThing(pid,place,false)   --- This will teleport all players found in that area to this pos
				doSendMagicEffect(getThingPos(cid),10)
			end
	elseif #players > 0 and < 5 then
		doBroadcastMessage("There was less than 5 players found in this place ("..#players..")")
	elseif #players < 1 then
		doBroadcastMEssage("There was no players found in this place.")
	end

Hope you got somthng
 
Last edited:
humm , ye i know you willl put them here obviously
Code:
if isInRange(getThingPos(cid),fromPosition,toPosition) the

it is third or fourth line in script i think
 
Yeah but I can put there only one range, and I need to check two places, the first range must have 5 players, and the second aswell, else it will broadcast that there are not enough numbers of players.
 
then add new table
local players2 ={}
and a else after the first range to check the second range
Lua:
if isInRange(place,from,to) then
table.insert(players,cid)
elseif isInRange(cid,from,to)
table.inster(players2,cid)
end
and #players || #players2 ---> get the number of players fround in each team

Code:
for _,pid in ipairs(players) do -- pid will return each player found in first place
 doTeleport(pid)
end
for _,pid in ipairs(players2) do   -- pid here will return every player found in second place)
doTeleport(pid)
end
just fast info :p
 
It doesn't work like this. When two players are standing in from/toRedPos and one player in from/toBluePos it teleports only the player from from/toBluePos.

Lua:
local red={}
local blue={}
for _, cid in ipairs(getPlayersOnline()) do

	if isInRange(getThingPos(cid), t.fromRedPos, t.toRedPos) then
		table.insert(red, cid)
	elseif isInRange(getThingPos(cid), t.fromBluePos, t.toBluePos) then
		table.insert(blue, cid)
	end

	if #red < 1 then
		doBroadcastMessage("It could not happen because there was less than 1 players on red carpet.")
	elseif #blue < 1 then
		doBroadcastMessage("It could not happen because there was less than 1 players on blue carpet.")
	else
		doBroadcastMessage("It has started!")
		if isInRange(getThingPos(cid), t.fromRedPos, t.toRedPos) then
			setPlayerStorageValue(cid, t.redStorage, 1)
			doTeleportThing(cid, t.redPos, true)
		elseif isInRange(getThingPos(cid), t.fromBluePos, t.toBluePos) then
			setPlayerStorageValue(cid, t.blueStorage, 1)
			doTeleportThing(cid, t.bluePos, true)
		end
	end
end
return true
end

It also broadcasts 3 times the same broadcast because there are 3 players online. It should broadcast only once
 
Lua:
local red={}
local blue={}
for _, cid in ipairs(getPlayersOnline()) do
 
	if isInRange(getThingPos(cid), t.fromRedPos, t.toRedPos) then
		table.insert(red, cid)
	elseif isInRange(getThingPos(cid), t.fromBluePos, t.toBluePos) then
		table.insert(blue, cid)
	end
end
	if #red < 1 then
		doBroadcastMessage("It could not happen because there was less than 1 players on red carpet.")
	elseif #blue < 1 then
		doBroadcastMessage("It could not happen because there was less than 1 players on blue carpet.")
	else
		doBroadcastMessage("It has started!")
		for _,pid in ipairs(red) do
				setPlayerStorageValue(pid, t.redStorage, 1)
				doTeleportThing(pid, t.redPos, true)
		end
		for _,pid in ipairs(blue) do
				setPlayerStorageValue(pid, t.blueStorage, 1)
				doTeleportThing(pid, t.bluePos, true)
		end
	end

return true
end
 
Back
Top