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

Lua getSpectatorts

GOD Fito

Member
Joined
Oct 3, 2008
Messages
97
Solutions
1
Reaction score
9
Script Below: How to check if there are 2 or more players on screen using getSpectators and getCreaturePosition(cid) as center.
 
Last edited:
Code:
#players
will return how many elements in your table
Code:
function onThrow(cid, item, fromPosition, toPosition)
   local item = {2160}
   local players = getSpectators(getCreaturePosition(cid), 3, 3, false) -- using posCreature as center
   if #players == 1 then
     --do something
   else
     return false
   end
return true
end
 
@SpiderOT ?
#players will return the creatores from spectators too...

just do after
if isPlayer(pid) and isInArray(item, item.itemid) then

a new variable that counts
for example
pleyer = pleyer + 1


then you can use that to check how many players there is with if check

or u could also
check if its not a player
u remove it from the table with table.remove

and then you can use #players as spiderot said

script would be like this for example:
Code:
function onThrow(cid, item, fromPosition, toPosition)

   local item = {2160}
   local pleyers = 0
   local players = getSpectators(getCreaturePosition(cid), 3, 3, false) -- using posCreature as center
   if players ~= nil then
      for _, pid in pairs(players) do
            if isPlayer(pid) and isInArray(item, item.itemid) then
                  pleyers = pleyers + 1
                  return false
           end
      end
   end
   if pleyers >= 2 then
   end

return true
end

nvm dis... i forgot u can make it check only players with true in getspectators =_=
 
Last edited:
@Ahilphino You're right it will check all creatures
the true/false is for multi floor
@GOD Fito
it's safe to use my script if there won't be any creatures other than players else you should use Ahilphino 's script
 
Back
Top