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

function getPlayersInArea

amoeba13

New Member
Joined
Jan 7, 2011
Messages
10
Reaction score
2
Hello guys, today I made a very useful function and decided to post it here. It's name is getPlayersInArea, what it does? It gets the players in an area...

@@EDIT - Sorry guys, when I first posted it, there was an error. Now its fixed.

Code:
function getPlayersInArea(fromPos, toPos) -- function by amoeba13
playersInArea = {}
for x = fromPos.x, toPos.x do
for y = fromPos.y, toPos.y do
for z = fromPos.z, toPos.z do
totalArea = {x=x, y=y, z=z}
playerz = getTopCreature(totalArea)
ifisPlayer(playerz.uid) then
table.insert(playersInArea, playerz.uid)
end
end
end
end
return playersInArea
end

How to use it? Here is an example:

Code:
function onSay(cid, words, param, channel)
local area = getPlayersInArea({x = 153, y = 50, z = 7}, {x = 156, y = 53, z = 7})if area then
for i = 1, (#area) do
doTeleportThing(area[i], {x = 160, y = 51, z = 7}, false)end
end
returntrue
end

Hope u enjoy it.
 
Last edited:
I quote what Mark told me a while ago:
  • Always use getSpectators for that task. getSpectators is highly optimized for that task and getTopCreature will miss creatures that are standing in a stack (as the function name says top creature)
 
According to Gesior: http://otland.net/threads/getplayerguild.169480/#post-1639339
getSpectators kills CPU and getPlayersOnline is better. But imo it all depends on how many people are in the server or how many players/npcs are in a certain area. Also, with today's hardware both of those functions wouldn't cause much of a trouble really...
Well, gesior is talking mby about 0.3. Since Mark is telling about 1.0, and i would follow Mark advice since he is the developer of tfs 1.0.
 
I actually made this for 0.3.6 because this is the version I use... Anyway, would it be better if I used getThingFromPos?
 
I actually made this for 0.3.6 because this is the version I use... Anyway, would it be better if I used getThingFromPos?
getThingFromPos is a real resource waster unless you're doing small operations since it looks for EVERYTHING in each tile (items, npcs, players). Follow what Cyko said since I'm a kinda outdated and idk what has changed in the past year.
 
Back
Top