SA-MP Forums Archive
Mode Changes Automatically in Sequence - 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: Mode Changes Automatically in Sequence (/showthread.php?tid=584367)



Mode Changes Automatically in Sequence - SpikY_ - 04.08.2015

Hi, I'm little bit confuse that how can i make these code to change the gamemode in Sequence. It changes randomly at this moment.
I want it to be like First mode should be Gamemode 1 and gamemode 2 and gamemode 3 and at last gamemode 4.

Here are the codes:
Код:
forward switchmode();
forward StopChangemodeTimer();

static
    changemodetimer,
    currentmode
;

enum smode
{
    Mode[50],
    Time
}

static const ModeInfo[][smode] =
{
    {"Gamemode 1",          300000},
    {"Gamemode 2",          300000},
    {"Gamemode 3",          300000},
    {"Gamemode 4",          300000}
};

public OnGameModeInit()
{
    new
        randmode = random( sizeof (ModeInfo) );

    currentmode = randmode;
    changemodetimer = SetTimer("switchmode", ModeInfo[currentmode][Time], false);

    return 1;
}

public OnGameModeExit()
{
    KillTimer(changemodetimer);
    currentmode = 0;

	return 1;
}

public StopChangemodeTimer()
{
	KillTimer(changemodetimer);
	return 1;
}

public switchmode()
{
    new
        modestring[50],
        randmode = random( sizeof (ModeInfo) )
    ;


    format(modestring, sizeof(modestring), "The Next mode will be %s!", ModeInfo[currentmode][Mode]);
    SendClientMessageToAll(0x32CD32FF, modestring);
    format(modestring,sizeof(modestring), "changemode %s", ModeInfo[currentmode][Mode]);
    SendRconCommand(modestring);

    currentmode = randmode;
    changemodetimer = SetTimer("switchmode", ModeInfo[currentmode][Time], false);

    return 1;
}
Regards,
- SpikY_


Re: Mode Changes Automatically in Sequence - SpikY_ - 04.08.2015

Aynone?


Re: Mode Changes Automatically in Sequence - Krokett - 04.08.2015

Well you would need to increment the variable currentmode, instead of it being assigned randomly.

Instead of this in switchmode()
PHP код:
randmode randomsizeof (ModeInfo) ) 
Something like this in switchmode()
PHP код:
if(randmode sizeof(ModeInfo)) {
   
randmode++;
}
else {
   
randmode 0;

Make sure randmode is a global variable.


Re: Mode Changes Automatically in Sequence - SpikY_ - 04.08.2015

It should be like this?

Код:
public switchmode()
{
    new
        modestring[50]
    ;

if(randmode < sizeof(ModeInfo)) {
   randmode++;
}
else {
   randmode = 0;
}

    format(modestring, sizeof(modestring), "The Next mode will be %s!", ModeInfo[currentmode][Mode]);
    SendClientMessageToAll(0x32CD32FF, modestring);
    format(modestring,sizeof(modestring), "changemode %s", ModeInfo[currentmode][Mode]);
    SendRconCommand(modestring);

    currentmode = randmode;
    changemodetimer = SetTimer("switchmode", ModeInfo[currentmode][Time], false);

    return 1;
}



Re: Mode Changes Automatically in Sequence - Crayder - 04.08.2015

If you're going to load multiple gamemodes in sequence, why not just do it from the server.cfg? It has multiple gamemode support just for this.

But if you want the names and stuff, yea keep it like you have it above.


Re: Mode Changes Automatically in Sequence - SpikY_ - 04.08.2015

Quote:
Originally Posted by Crayder
Посмотреть сообщение
If you're going to load multiple gamemodes in sequence, why not just do it from the server.cfg? It has multiple gamemode support just for this.

But if you want the names and stuff, yea keep it like you have it above.
Yes i know, but i want to use those stuffs like timer of changing the mode.

Can you please tell me that I have put those codes in the script are correct? ( the codes given by @Krokett Above )


Re: Mode Changes Automatically in Sequence - SpikY_ - 04.08.2015

@Krokett, I use your codes something like this :

Код:
public switchmode()
{
    new
        modestring[50],
        randmode
    ;

    if(randmode < sizeof(ModeInfo))
	{
    randmode++;
    }
    else
	{
    randmode = 0;
    }

    format(modestring, sizeof(modestring), "The Next mode will be %s!", ModeInfo[currentmode][Mode]);
    SendClientMessageToAll(0x32CD32FF, modestring);
    format(modestring,sizeof(modestring), "changemode %s", ModeInfo[currentmode][Mode]);
    SendRconCommand(modestring);

    currentmode = randmode;
    changemodetimer = SetTimer("switchmode", ModeInfo[currentmode][Time], false);

    return 1;
}
and it still changes the mode randomly.


Re: Mode Changes Automatically in Sequence - goldspy98 - 04.08.2015

Код:
random( sizeof (ModeInfo) );
You can't use "random" if you want it to run in sequence.

Make sure you run this as a Filterscripts otherwise it will not work as expected. (Check the comments in the code for more info)

Код:
#include <a_samp>

new changemodetimer, currentmode = 0;

enum smode
{
    Mode[50],
    Time
}

stock const ModeInfo[][smode] =
{
    {"Gamemode 1", 300000}, //Make sure this ("Gamemode 1") is the first one in your server otherwise the sequence will be mixed
    {"Gamemode 2", 300000},
    {"Gamemode 3", 300000},
    {"Gamemode 4", 300000}
};

public OnGameModeInit()
{
    changemodetimer = SetTimer("switchmode", ModeInfo[currentmode][Time], false); //This timer will be started everytime a new Gamemode is loaded
	
    return 1;
}

public OnGameModeExit()
{
    KillTimer(changemodetimer); //This will prevent errors if you manually change the Gamemode
	
	return 1;
}

forward switchmode();
public switchmode()
{
	new modestring[50];
	
	//This works like a loop, so when it reach the last Gamemode it will change to the first again
	if(currentmode < sizeof(ModeInfo))
		++currentmode;
	else
		currentmode = 0;
	
	format(modestring, sizeof(modestring), "The Next mode will be %s!", ModeInfo[currentmode][Mode]);
    SendClientMessageToAll(0x32CD32FF, modestring);
    
	format(modestring,sizeof(modestring), "changemode %s", ModeInfo[currentmode][Mode]);
    SendRconCommand(modestring);
	
    return 1;
}



Re: Mode Changes Automatically in Sequence - Inn0cent - 04.08.2015

What about name it like Mission1, 2, 3 and in mission 1 end load mission 2 ezi? if random is disabled.


Re: Mode Changes Automatically in Sequence - SpikY_ - 04.08.2015

Thanks @goldspy98, FIXED.
Thanks inno for replying.