How to return to Gamemode 0, after it goes through all the modes? - 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: How to return to Gamemode 0, after it goes through all the modes? (
/showthread.php?tid=353058)
How to return to Gamemode 0, after it goes through all the modes? -
rangerxxll - 22.06.2012
Hello, I'm currently developing a Mini-game type server. There's currently 6 modes. When the server starts up, it goes through mode 0-5 and then it keeps repeating 5 over and over, after every cycle. After gamemode 5, I want it to restart and go back to mode 0.
I hope you understand what I'm trying to do, here's some of my code.
pawn Код:
forward ChangeMode();
public ChangeMode()
{
if(CurrentGamemode == 0)
{
ServerMinutes = 0;
ServerSeconds = 10;
}
if(CurrentGamemode == 1)
{
ServerMinutes = 0;
ServerSeconds = 10;
}
if(CurrentGamemode == 2)
{
ServerMinutes = 0;
ServerSeconds = 10;
}
if(CurrentGamemode == 3)
{
ServerMinutes = 0;
ServerSeconds = 10;
}
if(CurrentGamemode == 4)
{
ServerMinutes = 0;
ServerSeconds = 10;
}
if(CurrentGamemode == 5)
{
ServerMinutes = 0;
ServerSeconds = 10;
}
else
{
CurrentGamemode++;
}
Thanks for your help.
Re: How to return to Gamemode 0, after it goes through all the modes? -
[MM]RoXoR[FS] - 22.06.2012
pawn Код:
if(CurrentGamemode == 5)
{
ServerMinutes = 0;
ServerSeconds = 10;
CurrentGamemode = 0;
}
Re: How to return to Gamemode 0, after it goes through all the modes? -
ReneG - 22.06.2012
One minor thing you could do to optimize your code is use a
switch statement.
Example with your code.
pawn Код:
switch(CurrentGamemode)
{
// If Current Gamemode is equal to the value after "case" then it runs that code
// So on and so forth.
case 0:
{
ServerMinutes = 0;
ServerSeconds = 10;
CurrentGamemode++; // adds one for the next time you call ChangeMode or w/e
}
case 1:
{
ServerMinutes = 0;
ServerSeconds = 10;
CurrentGamemode++;
}
case 2:
{
ServerMinutes = 0;
ServerSeconds = 10;
CurrentGamemode++;
}
case 3:
{
ServerMinutes = 0;
ServerSeconds = 10;
CurrentGamemode++;
}
case 4:
{
ServerMinutes = 0;
ServerSeconds = 10;
CurrentGamemode++;
}
case 5:
{
ServerMinutes = 0;
ServerSeconds = 10;
// if we've reached the final mode
// we reset it to zero.
CurrentGamemode = 0;
}
}
Much more powerful than the if structure, and easier to read. I recommend you to look at that link. It tells you every thing about switch statements.
Re: How to return to Gamemode 0, after it goes through all the modes? -
rangerxxll - 22.06.2012
Thanks a ton. I'll look into switches. Appreciate the help.