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

[fixed] Getting players positions

Doggynub

LUA / C++
Joined
Sep 28, 2008
Messages
2,541
Reaction score
186
so i made this thing
LUA:
     local players = {}

              for v = frompos.x , topos.x do
                    for k = frompos.y , topos.y do
                       local position = {x=v,y=k,z=7}
	                   local pid = getTopCreature(position).uid
		          
		                   if(pid ~= 0 and isPlayer(pid)) then
                                table.insert(players, pid)
                           end
                    end
              end

But i want it to insert players if there is more than one player on same sqm , i know i have used getTopCreature, but i have tryed to use other and it didnt get any players.
 
Last edited:
Totally dunno wether it works.
LUA:
local players = {}
for v = frompos.x , topos.x do
	for k = frompos.y , topos.y do
		for i = 1, 255 do
			position = {x = v, y = k, z = 7, stackpos = i}
			pid = getThingfromPos(position).uid
			if(pid ~= nil and isPlayer(pid)) then
				table.insert(players, pid)
			end
		end
	end
end
 
I think this will duplicate the insert for each player found.

But this works thanks it needed a little edit :)
LUA:
		local players = {}
for v = frompos.x , topos.x do
	for k = frompos.y , topos.y do
		for i = 1, 200 do
			position = {x = v, y = k, z = 7, stackpos = i}
			local pid = getThingfromPos(position).uid
			if(pid ~= nil and isPlayer(pid)) then
				table.insert(players, pid)
			end
		end
	end
end
 
Last edited:
Just check it, and then we'll see. :D And btw dont use locals if you're going to use them once and don't store them, becouse it uses more ram, and with f.e. 3 loops it'll use much more.

@EDIT

Yea, I forgot about 255 stackpos, it would duplicate. But now it shouldnt.
 
Last edited:
LUA:
	local players = {}
	for v = frompos.x , topos.x do
		for k = frompos.y , topos.y do
			for i = 1, 252 do
				local pid = getThingfromPos({x = v, y = k, z = 7, stackpos = i}).uid
				if pid > 0 then
					if isPlayer(pid) then
						table.insert(players, pid)
					end
				else
					break
				end
			end
		end
	end
? ;/
 
@up

And you have made how many loops??


Edit : didnt notice the break & btw as i said if you made 252 it will duplicate the inserting of same player.
 
Back
Top