• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua getSpectators function

Dubler

PHP, LUA, C++
Joined
Aug 3, 2009
Messages
268
Reaction score
11
Location
Poland
HI
maby somebody can tell me how to use getSpectators function on 2x1 and 2x2 positions?
 
Center: 0
Fields checked: x

With range x (2), y (2):
x x x x x
x x x x x
x x 0 x x
x x x x x
x x x x x

Range x (2), y(1)
x x x x x
x x 0 x x
x x x x x

Range x (1), y (1)
x x x
x 0 x
x x x
 
something like this perhaps? (Not tested)
PHP:
function getSpectatorsWithoutCenter(pos1, pos2)
   local i = 1
   local table = {}
   for xx=pos1.x,pos2.x,1 do
      for yy=pos1.y,pos2.y,1 do
         for zz=pos1.z, pos2.z, 1 do
            local checkPos = {x = xx, y = yy, z = zz, stackpos = 253} --I think 253 is the correct stackpos for creatures,not 100% sure
            local thing = getThingFromPos(checkPos)
            if isPlayer(thing) then
               table[i] = thing
               i = i + 1
            end
         end
      end
   end
   return table
end
 
I would do in with: for _, pid in pairs(getPlayersOnline()) do
and then if getThingPos(pid).x >= YOUR_X and getThingPos(pid).x <= YOUR_X_END etc. (do that for y and z too)
because Scarlet Ayleid's will only get TOP creature (for stacks, and I dont like that)
 
I thought of that, but if a server has tons of players online, it would make the script very slow
Its a bad side effect, but the fastest way to do it..

@TC
Just use the already existing getSpectators function, its the fastest lol
If you want to make an odd shape, use multiple getSpectators :P
 
Back
Top