help. - 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: help. (
/showthread.php?tid=630022)
help. -
AndreaSanchez - 07.03.2017
PHP код:
new gun = GetPlayerWeapon(playerid);
* * * * if(gun == 4 || gun == 9 || gun == 26 || gun == 34 || gun == 35 || gun == 36 || gun == 37 || gun == 38 || gun == 39)
* * {
* * * * new plname[MAX_PLAYER_NAME];
* * * * new string[128];
* * * * if(Player[playerid][pAdmin] <= 1)
* * * * {
* * * * * * GetPlayerName(playerid, plname, sizeof(plname));
* * * * * * format(string, sizeof(string), "{00FF00}[ÀÍÒÈ×ÈÒ]{FFFFFF}: {FF0000}%s {FFFFFF}áûë êèêíóò. Ïðè÷èíà: ÷èò íà îðóæèå!", plname);
* * * * * * SendAdminMessage(COLOR_LIGHTRED, string);
* * * * * * DelGun(playerid);
* * * * * * Kick(playerid);
* * * * }
* * }
Hello, please help. ((336) : error 003: declaration of a local variable must appear in a compound block) - new gun = GetPlayerWeapon(playerid); Stars should not be. In the code they are not.
Re: help. -
Toroi - 07.03.2017
Let the stars be whatever they want to be.
Don't use the variable, do it like this:
PHP код:
if(GetPlayerWeapon(playerid) == 4 || GetPlayerWeapon(playerid) == 9 || ..)
Re: help. -
AndreaSanchez - 07.03.2017
Quote:
Originally Posted by Troydere
Let the stars be whatever they want to be.
Don't use the variable, do it like this:
PHP код:
if(GetPlayerWeapon(playerid) == 4 || GetPlayerWeapon(playerid) == 9 || ..)
|
Does not work.
Re: help. -
Toroi - 07.03.2017
How come? Does it give you error?
Re: help. -
Stinged - 07.03.2017
Quote:
Originally Posted by Troydere
Let the stars be whatever they want to be.
Don't use the variable, do it like this:
PHP код:
if(GetPlayerWeapon(playerid) == 4 || GetPlayerWeapon(playerid) == 9 || ..)
|
Actually no. Using a variable is much better.
You're calling GetPlayerWeapon(playerid) multiple times, while with a variable you only call it once.
What's even better is using
switch.
Post a couple of lines above the code you posted here.
Re: help. -
Toroi - 07.03.2017
Quote:
Originally Posted by Stinged
Actually no. Using a variable is much better.
You're calling GetPlayerWeapon(playerid) multiple times, while with a variable you only call it once.
What's even better is using switch.
Post a couple of lines above the code you posted here.
|
I made an extensive search through my entire post, but I could not find the part where I tell the guy that using a variable was not good. Perhaps can you point it for me?
OP, waiting for your answer to see what's wrong with your code.
Re: help. -
Stinged - 08.03.2017
Quote:
Originally Posted by Troydere
I made an extensive search through my entire post, but I could not find the part where I tell the guy that using a variable was not good. Perhaps can you point it for me?
OP, waiting for your answer to see what's wrong with your code.
|
Quote:
Originally Posted by Troydere
Don't use the variable, do it like this:
|
You're saying that he shouldn't use a variable to store the weapon id, he should instead call GetPlayerWeapon multiple times.
Re: help. -
Toroi - 08.03.2017
Quote:
Originally Posted by Stinged
You're saying that he shouldn't use a variable to store the weapon id, he should instead call GetPlayerWeapon multiple times.
|
http://www.wikihow.com/Solve-a-Problem
Re: help. -
SyS - 02.04.2017
Quote:
Originally Posted by Troydere
Let the stars be whatever they want to be.
Don't use the variable, do it like this:
PHP код:
if(GetPlayerWeapon(playerid) == 4 || GetPlayerWeapon(playerid) == 9 || ..)
|
Dont do it. Why to provide multiple overhead for getting same value? you can save some memory and performance by store and use method.
Re: help. -
GhostHacker9 - 02.04.2017
Quote:
Originally Posted by Troydere
Let the stars be whatever they want to be.
Don't use the variable, do it like this:
PHP код:
if(GetPlayerWeapon(playerid) == 4 || GetPlayerWeapon(playerid) == 9 || ..)
|
You complains a lot about having this type of declaration
But you suggest the most inefficient way to script. How moronic is that?