Info about random gmx
#1

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?
Reply
#2

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

Reply
#3

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); 
Reply
#4

Posts above beat me to it.
Reply
#5

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?
Reply
#6

Bump.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)