17.06.2018, 21:44
You can do a few tricks to detect when there are 10 players in the server:
1. Create a timer
2. Use OnPlayerConnect and a variable
Once you've detected using one of the methods, you actually need to make a function, name it whatever you want but be sure that you need to name it properly that it makes sense and is properly named, for example, I'd name it: InitiateChaos.
Under that, you can actually run a foreach (y_iterate) loop and use random or Iter_Random to help me with it. For example:
1. Create a timer
PHP код:
new gChaosTimer;
public OnGameModeInit() {
gChaosTimer = SetTimer("OnTenPlayers", 2000, true);
return 1;
}
forward OnTenPlayers();
public OnTenPlayers() {
if (Iter_Count(Player) == 10) {
InitiateChaos();
}
KillTimer(gChaosTimer);
return 1;
}
Once you've detected using one of the methods, you actually need to make a function, name it whatever you want but be sure that you need to name it properly that it makes sense and is properly named, for example, I'd name it: InitiateChaos.
Under that, you can actually run a foreach (y_iterate) loop and use random or Iter_Random to help me with it. For example:
PHP код:
InitiateChaos() {
// When there are 10 players in the server - I want 7 cops and 3 criminals
new Criminals_Selected = 0; // Make a new variable and set it's value to 0 (the default value of a variable is 0 by default, I just like to define it like this for no reason)
foreach (new i : Player) { // Alternative loop would be to use GetPlayerPoolSize function
if (Criminals_Selected == 3) { // Maximum number of criminals are selected? Set the player team to cops!
// Set their team to Cops
}
else { // Not enough criminals selected?
new Team = random(2); // Randomize their team!! random (2) will return either 0 or 1
if (Team) { // if random is 1
// set their team to cops
}
else {
// set their team to criminals
Criminals_Selected += 1; // Increase the value of Criminals_Selected variable to keep a track of how many Criminals are selected
}
}
}
return 1;
}