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

Player location check.

Torrix

New Member
Joined
Mar 28, 2012
Messages
1
Reaction score
0
Is it possible to check if a player exists at specific location, in relation to your character? For example, I would be player x:

0 0 0 0 0
0 0 0 0 0
0 0 x 0 0
0 0 0 0 0
0 0 0 0 0

In this area, I want to check if any of those zeroes around me is actually a player.
 
LUA:
function getCreaturesInRange(position, radiusx, radiusy, showMonsters, showPlayers, showSummons)
	local creaturesList = {}
	for x = -radiusx, radiusx do
		for y = -radiusy, radiusy do
			if not (x == 0 and y == 0) then
				local creature = getTopCreature({x = position.x+x, y = position.y+y, z = position.z})
				if (creature.type == 1 and showPlayers) or (creature.type == 2 and showMonsters and (not showSummons or (showSummons and getCreatureMaster(creature.uid) == (creature.uid)))) then
					table.insert(creaturesList, creature.uid)
				end
			end
		end
	end

	local creature = getTopCreature(position)
	if (creature.type == 1 and showPlayers) or (creature.type == 2 and showMonsters and (not showSummons or (showSummons and getCreatureMaster(creature.uid) == (creature.uid)))) then
		if not(table.find(creaturesList, creature.uid)) then
			table.insert(creaturesList, creature.uid)
		end
	end
    return creaturesList
end

Add this in your libs/050-functions.lua or just put it as local function in your script :)

usage ex:
LUA:
function onUse(cid)
	if(#getCreaturesInRange(position, radiusx, radiusy, showMonsters, showPlayers, showSummons) > 1) then -- Checks if there is more than 1 player/monster/summon in position
		print("Yes")
	end
	return true
end
 
Last edited:
Back
Top