SA-MP Forums Archive
How to "switch" - 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 "switch" (/showthread.php?tid=405660)



How to "switch" - micol - 07.01.2013

Hello guys, I have some problem.
I know the code bellow i can write in switch, but i don't know how...

Код:
new string[128], Nick[MAX_PLAYER_NAME];
	GetPlayerName(playerid, Nick, sizeof(Nick));
	if(Player[playerid][pAdminLevel] == 3)
	{
		format(string, sizeof(string), "(Junior Admin ID:%d): %s",playerid, text);
		SendPlayerMessageToAll(playerid, string);
	}
	if(Player[playerid][pAdminLevel] == 4)
	{
		format(string, sizeof(string), "(Admin ID:%d): %s",playerid, text);
		SendPlayerMessageToAll(playerid, string);
	}
	if(Player[playerid][pAdminLevel] == 5)
	{
	    format(string,sizeof(string), "(Head Admin ID:%d): %s", playerid, text);
	    SendPlayerMessageToAll(playerid, string);
	}
	else
	{
		format(string, sizeof(string), "(ID:%d): %s", playerid, text);
	 	SendPlayerMessageToAll(playerid, string);
	}
Greetings, micol.


Re: How to "switch" - gtakillerIV - 07.01.2013

pawn Код:
new string[128], Nick[MAX_PLAYER_NAME];
    GetPlayerName(playerid, Nick, sizeof(Nick));
    switch(Player[playerid][pAdminLevel])
    {
        case 3: //If Player[playerid][pAdminLevel] equals to 3.
        {
            format(string, sizeof(string), "(Junior Admin ID:%d): %s",playerid, text);
            SendPlayerMessageToAll(playerid, string);
        }
        case 4: //If Player[playerid][pAdminLevel] equals to 4.
        {
            format(string, sizeof(string), "(Admin ID:%d): %s",playerid, text);
            SendPlayerMessageToAll(playerid, string);
        }
        case 5: //If Player[playerid][pAdminLevel] equals to 5.
        {
            format(string,sizeof(string), "(Head Admin ID:%d): %s", playerid, text);
            SendPlayerMessageToAll(playerid, string);
        }
        default: //If all of the cases above are false.
        {
            format(string, sizeof(string), "(ID:%d): %s", playerid, text);
            SendPlayerMessageToAll(playerid, string);
        }
    }
http://wiki.amxmodx.org/Pawn_Tutorial#Switch_Statements


Re: How to "switch" - AndreT - 07.01.2013

Just a tip if you're going to send the message in all cases: move SendPlayerMessageToAll from the switch parts to the end of the switch statement. Should make your code smaller!


Re: How to "switch" - micol - 07.01.2013

Thanks for all sugestions.

Greetings, micol.


@EDIT

And if we're almost at the end can you show me how this code will be look in switch? : D

Код:
if(arena1[playerid] == true)
	{
	    new arena2 = random(sizeof(arenaspawn));
	    SetPlayerPos(playerid, arenaspawn[arena2][0], arenaspawn[arena2][1], arenaspawn[arena2][2]);
	    ResetPlayerWeapons(playerid);
	    GivePlayerWeapon(playerid, 38,999999);
	}
	if(arenade1[playerid] == true)
	{
 		new arenade2 = random(sizeof(arenadespawn));
	    SetPlayerPos(playerid, arenadespawn[arenade2][0], arenadespawn[arenade2][1], arenadespawn[arenade2][2]);
	    ResetPlayerWeapons(playerid);
	    GivePlayerWeapon(playerid, 24,200);
	}
	if(arenaso1[playerid] == true)
	{
	    new arenaso2 = random(sizeof(arenasospawn));
	    SetPlayerPos(playerid, arenasospawn[arenaso2][0], arenasospawn[arenaso2][1], arenasospawn[arenaso2][2]);
	    ResetPlayerWeapons(playerid);
	    GivePlayerWeapon(playerid, 26,300);
	}
Greeting, micol.


Re: How to "switch" - gtakillerIV - 08.01.2013

Why not give it a try by yourself?


Re: How to "switch" - micol - 09.01.2013

My try:

pawn Код:
switch(arena1[playerid])
{
    case 1:
    {
        new arena2 = random(sizeof(arenaspawn));
        SetPlayerPos(playerid, arenaspawn[arena2][0], arenaspawn[arena2][1], arenaspawn[arena2][2]);
        ResetPlayerWeapons(playerid);
        GivePlayerWeapon(playerid, 38,999999);
    }
}
switch(arenade1[playerid])
{
    case 1:
    {
        new arenade2 = random(sizeof(arenadespawn));
        SetPlayerPos(playerid, arenadespawn[arenade2][0], arenadespawn[arenade2][1], arenadespawn[arenade2][2]);
        ResetPlayerWeapons(playerid);
        GivePlayerWeapon(playerid, 24,200);
    }
}
switch(arenaso1[playerid])
{
    case 1:
    {
        new arenaso2 = random(sizeof(arenasospawn));
        SetPlayerPos(playerid, arenasospawn[arenaso2][0], arenasospawn[arenaso2][1], arenasospawn[arenaso2][2]);
        ResetPlayerWeapons(playerid);
        GivePlayerWeapon(playerid, 26,300);
    }
}
I know this can be smaller, but how ?(Just another question)


Greetings, micol.