SA-MP Forums Archive
Info about random gmx - 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: Info about random gmx (/showthread.php?tid=589142)



Info about random gmx - Face9000 - 15.09.2015

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?


AW: Info about random gmx - Kaliber - 15.09.2015

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 {
        
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);




Re: Info about random gmx - Vince - 15.09.2015

Create an array with the filenames and randomly pick one. Pick again if it is the same. Assuming that a filterscript will handle this, something like this should work.
PHP Code:
// 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(rconCommandsizeof(rconCommand), "changemode %s.amx"FILE_NAMES[gCurrentIndex]);
SendRconCommand(rconCommand); 



Re: Info about random gmx - [KHK]Khalid - 15.09.2015

Posts above beat me to it.


Re: Info about random gmx - Face9000 - 16.09.2015

Thanks everybody.

@Vince: Where i have to place that code? In all the 5 gamemodes or just in a normal filterscript so i can call remotely using CallRemoteFunction in every gamemode?


Re: Info about random gmx - Face9000 - 17.09.2015

Bump.