SA-MP Forums Archive
problem with 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: problem with switch (/showthread.php?tid=147990)



problem with switch - Jonni8 - 15.05.2010

Hey, another day another problem :P

ehm now i have a problem with the swith-command:
Код:
zcmd(kaufe, playerid, params[])
{
	new pWaffe;
	if (!sscanf(params, "s", pWaffe)) 
	{
		switch (pWaffe)
		{
			case pWaffe = "deagle":
			{
				gAmmo[playerid] + 20;
				GivePlayerMoney(playerid, -300);
				SendClientMessage(playerid, GREEN, "Du hast dir eine Desert Eagle gekauft");
				GivePlayerWeapon(playerid, 24, gAmmo[playerid]);
				return 1;
			}
			default:
			{
				SendClientMessage(playerid, RED, "Die Waffe existiert nicht.");
				return 1;
			}
		}
	}
	else if (GetPlayerMoney(playerid) < 300)
	{
		SendClientMessage(playerid, RED, "Du hast nicht genug Geld.");
	}	
	else 
	{
		SendClientMessage(playerid, RED, "Anwendung: /kaufe deagle");
	}
	return 1;
}
i posted a topic before called "trouble with ammo-array" and i've still problems with that too. (i changed my method to zcmd since last topic.)

BTW so i just want to decide which weapon was chosen and give the player the weapon. there is only the desert eagle yet.


Re: problem with switch - juice.j - 15.05.2010

Problem is - unlike in languages as PHP - PAWN doesn't support comparing strings in switch-case, so you might wanna go for if-clauses using strcmp instead.


Re: problem with switch - Jonni8 - 15.05.2010

Okay, thanks.
i didnt know that.
i thought its easier....


Re: problem with switch - juice.j - 15.05.2010

Leider nicht... PAWN halt.


Re: problem with switch - Zh3r0 - 15.05.2010

Quote:
Originally Posted by juice.j
Leider nicht... PAWN halt.
Talk English nab...
If you see a script made in german variables and texts doesn't give you right to talk in other languages than English...


Re: problem with switch - juice.j - 15.05.2010

Watch it internet police is active!

You know how much crap I give about that?


Re: problem with switch - Jonni8 - 15.05.2010

Please could u give a suggestion for the code? :S
i dont know how i do this, because if i do it like i think, you have to script an own if-else construction for each weapon.

BTW im only a "newbie" i think and its my first script, so sorry if its a simple solution and i didnt know.


Re: problem with switch - juice.j - 15.05.2010

Just add me on MSN, I ll give you a short explanation in German...

...but to bug PlayON a little:

Add mich im MSN, ich erklдrs dir da.


Re: problem with switch - Zh3r0 - 15.05.2010

Quote:
Originally Posted by juice.j
Just add me on MSN, I ll give you a short explanation in German...

...but to bug PlayON a little:

Add mich im MSN, ich erklдrs dir da.
I don't coz you pwn3d yourself by translating it actually..


Re: problem with switch - juice.j - 15.05.2010

I didn't translate anything, but threw in a line in German. Please don't talk nerdy internet language