SA-MP Forums Archive
switch failure? or am i stupid? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: switch failure? or am i stupid? (/showthread.php?tid=187674)



switch failure? or am i stupid? - -Rebel Son- - 04.11.2010

Код:
forward switcher(playerid);
public switcher(playerid)
{
new
	a = 2;
switch (a)
{
	case 1:
	{
	Mode[playerid] = 1;
	SendClientMessage(playerid, COLOR_GREY, "MODE 1 MAC10");
	GivePlayerWeapon(playerid, 32,500);
	print("MODE SWITCHED to 1");
	}
	case 2:
	{
	Mode[playerid] = 2;
	SendClientMessage(playerid, COLOR_GREY, "MODE 1 SNIPER?");
	GivePlayerWeapon(playerid, 36,500);
	print("MODE SWITCHED to 2");
	}
	}
}
i want this switch to move back and forth, from 1 to 2, and so far it goes to two. and keeps reseting to number 2, i havnt scripted in a logn time, so... idea? broken? or am i an idiot?


Re: switch failure? or am i stupid? - Crayon - 04.11.2010

possibly need return 1;


Re: switch failure? or am i stupid? - -Rebel Son- - 04.11.2010

Tryed that, didnt work.


Re: switch failure? or am i stupid? - Crayon - 04.11.2010

I wouldn't know then, sorry man. I'm quite new to scripting still. Sorry!


Re: switch failure? or am i stupid? - -Rebel Son- - 04.11.2010

hey no problem, atleast you tryed. :P


Re: switch failure? or am i stupid? - Miguel - 04.11.2010

What are you trying to do?

Your code will always do this:
pawn Код:
Mode[playerid] = 2;
SendClientMessage(playerid, COLOR_GREY, "MODE 1 SNIPER?");
GivePlayerWeapon(playerid, 36,500);
print("MODE SWITCHED to 2");
Because "a" is always 2.


Re: switch failure? or am i stupid? - -Rebel Son- - 04.11.2010

im trying to switch them back and forth on a timer.


Re: switch failure? or am i stupid? - Crayon - 04.11.2010

I guess you need to label them "a" and 1 and 2.


Re: switch failure? or am i stupid? - -Rebel Son- - 04.11.2010

still not following


Re: switch failure? or am i stupid? - Crayon - 04.11.2010

I'm not sure how to do this, but what Miguel is trying to say, it is only choosing 2 because you placed (a = 2). If you replaced that 2 with a 1, it will only repeat mode 1. So if you try getting a to be both 1 and 2 or some crap, it'll do both.

I dont know if this is right, maybe I'm just blabbering


Re: switch failure? or am i stupid? - -Rebel Son- - 04.11.2010

Crayon, i think your a genious, holdon a second.


Re: switch failure? or am i stupid? - -Rebel Son- - 04.11.2010

Well, still cant get them to switch, but i got case 1 definded as a = 1. and case 2 as b = 2

how can i get these to rotate?


Re: switch failure? or am i stupid? - pen_theGun - 04.11.2010

pawn Код:
forward switcher(playerid);
public switcher(playerid)
{
    switch (Mode[playerid])
    {
        case 1:
            {
                Mode[playerid] = 2;
                SendClientMessage(playerid, COLOR_GREY, "MODE 1 MAC10");
                GivePlayerWeapon(playerid, 32,500);
                print("MODE SWITCHED to 1");
            }
        case 2:
            {
                Mode[playerid] = 1;
                SendClientMessage(playerid, COLOR_GREY, "MODE 1 SNIPER?");
                GivePlayerWeapon(playerid, 36,500);
                print("MODE SWITCHED to 2");
            }
        default: Mode[playerid] = 1;
    }
    return 1;
}



Re: switch failure? or am i stupid? - -Rebel Son- - 04.11.2010

You sir, i love you. i apriciate i <3