Dzsozi (h03) Posted December 6, 2014 Share Posted December 6, 2014 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
#DRAGON!FIRE Posted December 6, 2014 Share Posted December 6, 2014 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
Dzsozi (h03) Posted December 6, 2014 Author Share Posted December 6, 2014 Thank you, but I have one more problem. How could I count which city has more players in it? Link to comment
Castillo Posted December 6, 2014 Share Posted December 6, 2014 You could store all the players and their cities in a table, then sort it with table.sort. Link to comment
Bssol Posted December 6, 2014 Share Posted December 6, 2014 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
Dzsozi (h03) Posted December 7, 2014 Author Share Posted December 7, 2014 Thank you, works, this is what I was looking for! Thanks! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now