function countPlayers(fromPosition, toPosition)
local count = 0
for _, pid in ipairs(getPlayersOnline()) do
if isInRange(getCreaturePosition(pid), fromPosition, toPosition) then
count = (count + 1)
end
end
return count
end
function onSay(cid, words, param, channel)
local area1 = countPlayers({x = 1, y = 1, z = 7}, {x = 3, y = 3, z = 7})
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Players in area 1: "..area1..".")
return true
end
what if players are stacked?? iterate thru getPlayersOnline() and check with isInRange(position, fromPosition, toPosition)Try
Code:function countPlayers(fromPos, toPos) local count = 0 for x=fromPos.x,toPos.x do for y=fromPos.y,toPos.y do for z=fromPos.z,toPos.z do local v = getTopCreature({x=x, y=y, z=z}).uid if isPlayer(v) then count = (count + 1) end end end end return count end function onSay(cid, words, param, channel) local area1 = countPlayers({x = 1, y = 1, z = 7}, {x = 3, y = 3, z = 7}) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Players in area 1: "..area1..".") return true end