Mode Changes Automatically in Sequence
#1

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

Aynone?
Reply
#3

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.
Reply
#4

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;
}
Reply
#5

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

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

@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.
Reply
#8

Код:
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;
}
Reply
#9

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

Thanks @goldspy98, FIXED.
Thanks inno for replying.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)