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

[Request] Checking the number of players in area.

GarQet

Own3d!
Joined
Feb 10, 2009
Messages
1,381
Solutions
14
Reaction score
81
Hello OTlanders,
I have a small problem with my script, it is that I don't know how I can retrieve the number of players that are in the area. Depending on the outcome (number of players on area) script to continue executing commands.
I've tried to write this script, here it's:
actions/scripts/test.lua
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local table = {}
	if(table.empty(getSpectators({x=146,y=1322,z=7}, 37, 50)) and table.empty(getSpectators({x=146,y=1322,z=6}, 37, 50)) and table.empty(getSpectators({x=146,y=1322,z=5}, 37, 50))) then
		doPlayerSendCancel(cid, "Sorry not possible, because someone is actually doing this mission.")
	else
		doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
		doTeleportThing(cid, {x=128,y=1351,z=7})
		return true
	end
end
lib/050-function.lua
Code:
table.empty = function (t)
return next(t) == nil
end

Errors:
attempt to call field 'empty' (a nil value)

This should work, but it doesn't work.
Has anyone any idea how to do that work properly?

Regards, GarQet.
//Sorry for my English.
 
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	for z = 7, 5, -1 do
		for x = 109, 183 do
			for y = 1272, 1372 do
				local v = getTopCreature({x=x, y=y, z=z}).uid
				if v ~= 0 and isPlayer(v) then
					return doPlayerSendCancel(cid, 'Sorry not possible, because someone is actually doing this mission.')
				end
			end
		end
	end
	doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
	doTeleportThing(cid, {x=128,y=1351,z=7})
	return true
end
 
LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	for z = 7, 5, -1 do
		for x = 109, 183 do
			for y = 1272, 1372 do
				local v = getTopCreature({x=x, y=y, z=z}).uid
				if v ~= 0 and isPlayer(v) then
					return doPlayerSendCancel(cid, 'Sorry not possible, because someone is actually doing this mission.')
				end
			end
		end
	end
	doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
	doTeleportThing(cid, {x=128,y=1351,z=7})
	return true
end

Thanks a lot, rep+
 
Back
Top