SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 15/09/2015, 09:25 PM   #1
Face9000
Banned
 
Join Date: Jan 2010
Location: Pigland
Posts: 3,351
Reputation: 190
Default Info about random gmx

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?
Face9000 is offline   Reply With Quote
Old 15/09/2015, 09:49 PM   #2
Kaliber
High-roller
 
Kaliber's Avatar
 
Join Date: Jun 2012
Location: Localhost
Posts: 1,092
Reputation: 156
Default AW: Info about random gmx

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

__________________
Kaliber is offline   Reply With Quote
Old 15/09/2015, 09:54 PM   #3
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,067
Reputation: 2660
Default Re: Info about random gmx

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); 
__________________
Vince is offline   Reply With Quote
Old 15/09/2015, 10:05 PM   #4
[KHK]Khalid
Gangsta
 
[KHK]Khalid's Avatar
 
Join Date: Jan 2012
Location: Alexandria, Egypt
Posts: 854
Reputation: 136
Default Re: Info about random gmx

Posts above beat me to it.
[KHK]Khalid is offline   Reply With Quote
Old 16/09/2015, 11:04 AM   #5
Face9000
Banned
 
Join Date: Jan 2010
Location: Pigland
Posts: 3,351
Reputation: 190
Default Re: Info about random gmx

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?
Face9000 is offline   Reply With Quote
Old 17/09/2015, 10:28 PM   #6
Face9000
Banned
 
Join Date: Jan 2010
Location: Pigland
Posts: 3,351
Reputation: 190
Default Re: Info about random gmx

Bump.
Face9000 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] Random Aspects - Using numargs(), getarg(...) and random(...) to make random systems dynamic and easier! SickAttack Tutorials 7 10/05/2015 10:39 AM
How to make a random that chooses each random selection once Mennims Scripting Help 6 17/09/2013 06:56 AM
[Include] rInfoBox - Cool looking textdraw Info boxes ! Show info to players in one line! RajatPawar Includes 39 24/07/2013 01:33 PM
[Include] Insanity Random Lists(generate a random number from your list) CyNiC Includes 10 23/07/2011 01:45 PM


All times are GMT. The time now is 10:09 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.