Match scripting help - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Match scripting help (
/showthread.php?tid=655291)
Match scripting help -
AndrewBones - 17.06.2018
So I'm new to scripting and I want to script something that would, for example:
The server has 10 players.
3 random players get picked to be criminals, 7 get to be cops and spawn in random places around the town.
Southclaws tried helping me but what he said seems out of my league so.
Southclaws - Today at 12:22 AM
if you use y_iterate, you can simply create an iterator then iterate through it and use Iter_Random to select one, then remove it with Iter_SafeRemove
you end up with two iterators, one for one team and one for another
if you're not using iterators, it will require a bit more code
So how do I actually put this in practice?
Re: Match scripting help -
Logic_ - 17.06.2018
You can do a few tricks to detect when there are 10 players in the server:
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;
}
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:
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;
}