15.09.2015, 21:49
Just like this:
PHP Code:
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);
}