Damage erro - 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: Damage erro (
/showthread.php?tid=535562)
Damage erro -
Gogeta101 - 04.09.2014
pawn Код:
//local variable "playerid" shadows a variable at a preceding level
public OnPlayerGiveDamage(playerid, damagedid, Float: amount, weaponid)
{
PlayerPlaySound(playerid, 17802, 0.0, 0.0, 0.0); // Ding Sound
new Float:HP;
GetPlayerHealth(playerid, HP);
if(weaponid == 24) SetPlayerHealth(playerid, HP-75);//DesertEagle
if(weaponid == 22) SetPlayerHealth(playerid, HP-30);//Colt45
if(weaponid == 32) SetPlayerHealth(playerid, HP-10);//Tec9
if(weaponid == 28) SetPlayerHealth(playerid, HP-10);//Uzi
if(weaponid == 23) SetPlayerHealth(playerid, HP-35);//SilencedColt
if(weaponid == 31) SetPlayerHealth(playerid, HP-45);//M4
if(weaponid == 30) SetPlayerHealth(playerid, HP-45);//AK
if(weaponid == 29) SetPlayerHealth(playerid, HP-35);//MP5
if(weaponid == 34) SetPlayerHealth(playerid, HP-30);//SniperRifle
if(weaponid == 33) SetPlayerHealth(playerid, HP-50);//CuntGun
if(weaponid == 25) SetPlayerHealth(playerid, HP-55);//PumpShotgun
if(weaponid == 27) SetPlayerHealth(playerid, HP-65);//Spaz12
return 1;
}
Re: Damage erro -
CutX - 04.09.2014
the identifer of a global variable has to be unique.
meaning something like
pawn Код:
#include "a_samp"
main(){}
new random_stuff;
public OnGamemodeInit()
{
new random_stuff;
return 1;
}
will throw the same warning.
"
warning 219: local variable "random_stuff" shadows a variable at a preceding level"
this means that somewhere in your script is a variable by the name "playerid"
search for it and get rid of it.
especially "playerid" as identifer... really bad choice if it's a global one,
as most of the callbacks contain a "playerid" param.
also, generating too much global variables isn't good.
Stuff will get messy after some time.
Try to stay local & use
pointers wherever you can
also, i suggest using a switch instead of these endless control structures
Re: Damage erro -
Gogeta101 - 05.09.2014
So what should i do
Re: Damage erro -
CutX - 05.09.2014
Quote:
Originally Posted by Gogeta101
So what should i do
|
search for the variable shadowing "playerid" with the identifer "playerid" and get rid of it or rename it.
example:
pawn Код:
#include "a_samp"
main(){}
new random_stuff_ABC;//now it's not shadowing other variables (like the one in OnGamemodeinit), it's unique now, just as it should be.
public OnGamemodeInit()
{
new random_stuff;
return 1;
}
identifers of global variables HAVE to be unique, just like
id's in CSS