15.09.2015, 21:25
Assuming i have 5 minigames (each game in gamemodes folder), how i can create a random gmx command that selects RANDOMLY this 5 minigames except the one played before restart?
new last;
//OnGameModeInit
last = LoadLastRestart();
//The function:
stock GetRandomRestart() //returns the id of the minigame to restart
{
new x;
do {
x = random(5); //The 5 is the max minigames
}
while(x==last);
SaveNewRestart(x);
return x;
}
stock SaveNewRestart(x) {
new File:f=fopen("restart.txt",io_write),tmp[4];
return valstr(tmp,x),fwrite(f,tmp),fclose(f);
}
stock LoadLastRestart()
{
if(!fexist("restart.txt")) return -1;
new File:f=fopen("restart.txt",io_read),tmp[4];
return fread(f,tmp),fclose(f),strval(tmp);
}
// global
static gCurrentIndex = -1;
// local stuff in function that handles the change
static const FILE_NAMES[][] = {
"file1",
"file2",
"file3"
};
new randomIndex;
do
{
randomIndex = random(sizeof(FILE_NAMES));
}
while(randomIndex == gCurrentIndex);
gCurrentIndex = randomIndex;
new rconCommand[16 + sizeof(FILE_NAMES[])];
format(rconCommand, sizeof(rconCommand), "changemode %s.amx", FILE_NAMES[gCurrentIndex]);
SendRconCommand(rconCommand);