Jump to content

Get players in cities


Dzsozi (h03)

Recommended Posts

Hello community!

I'm making a mission, and I want to get the count of the players in the cities. Because I want to spawn the mission to the city that has more players, for exmaple if there's 10 players on the server, 8 of 10 are in LS and 2 of 10 are in LV then the mission would spawn to a specified position inside LS. Hope you understand me!

So my question is: How could I get this number?

I think I should use these functions:

  
getZoneName 
getElementsByType ( "player" ) 
getElementPosition 
  

But I don't know how to get the players count in the cities. I would appreciate it if someone could help me, thanks in advance!

Link to comment

getPlayersInZone = function ( ZoneName ) 
 local Players = {  }; 
 if ( ZoneName and type ( ZoneName ) == "string" ) then 
   for _,p in ipairs ( getElementsByType ( "player" ) ) do 
     local x, y, z = getElementPosition ( p ) 
     local Zname = getZoneName ( x, y, z, true ) 
     if ( Zname == ZoneName ) then 
       table.insert ( Players, p ) 
    end 
   end 
  end 
 return Players 
end   

local Count = #getPlayersInZone ( "test" ) 
Link to comment
function getPlayersInZone ( ZoneName ) 
    local Players = {  }; 
    if ( ZoneName ) and ( type(ZoneName) == "string" ) then 
        for _,p in ipairs ( getElementsByType ( "player" ) ) do 
            local x, y, z = getElementPosition ( p ) 
            local Zname = getZoneName ( x, y, z, true ) 
            if ( Zname == ZoneName ) then 
                table.insert ( Players, p ) 
            end 
        end 
    end 
    return Players 
end 
  
function getLargestCityInPopulation ( ) 
    local LS = #getPlayersInZone ( "Los Santos" ) 
    local SF = #getPlayersInZone ( "San Fierro" ) 
    local LV = #getPlayersInZone ( "Las Venturas" ) 
     
    local city = "Los Santos"   -- This is the default city, you can change it to any city. 
    if ( LS > SF ) and ( LS > LV ) then 
        city = "Los Santos" 
    elseif ( SF > LS ) and ( SF > LV ) then 
        city = "San Fierro" 
    elseif ( LV > LS ) and ( LV > SF ) then 
        city = "Las Venturas" 
    end 
    return city 
end 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...