SA-MP Forums Archive
pName Shadows a variable - 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: pName Shadows a variable (/showthread.php?tid=498079)



pName Shadows a variable - Hybris - 01.03.2014

Hello I'm having some trouble so recently I wanted to make my own anti-cheat on my script which would ban players who would spawn a jetpack and aren't admins and I keep getting this error
Код:
(337) : warning 219: local variable "pName" shadows a variable at a preceding level
this is the command
Код:
CMD:jetpack(playerid, params[])
{
	if(User[playerid][USER_ADMIN] >= 4)
	{
	    new string[90],pName[MAX_PLAYER_NAME];
	    GetPlayerName(playerid, pName, sizeof(pName));
	    format(string, sizeof(string), "%s has spawned jetpack", pName);
	    SendClientMessageToAll(-1, string);
	    SetPlayerSpecialAction(playerid, 2);
	}
	return 1;
}
line 337:
Код:
new string[90],pName[MAX_PLAYER_NAME];
Please help me out


Re: pName Shadows a variable - ConnorHunter - 01.03.2014

You don't need to make a variable,

use

GetPlayerName(playerid);

instead.


Re: pName Shadows a variable - Kar - 01.03.2014

Because pName is already declared in the global scope.

pawn Код:
CMD:jetpack(playerid, params[])
{
    if(User[playerid][USER_ADMIN] >= 4)
    {
        new string[64], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "%s has spawned jetpack", name);
        SendClientMessageToAll(-1, string);
        SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USEJETPACK);
    }
    return 1;
}



Re: pName Shadows a variable - Hybris - 02.03.2014

How to I make it disappear after I'm done using it?


Re: pName Shadows a variable - ConnorHunter - 02.03.2014

Press the enter button


Re: pName Shadows a variable - Hybris - 02.03.2014

no but after I press it I want it to be gone so no one else can use it


Re: pName Shadows a variable - BKarner - 02.03.2014

Just make it so that when you press enter it c;clears the animation. For example:

Код:
if(GetPlayerSpecialAction(playerid)==2){
ClearAnimations(playerid);
}
That should remove the Jetpack from the player, rather than dropping it. You'd need to tweak it a little bit to make sure people don't fall to the ground and such.


Re: pName Shadows a variable - Kar - 02.03.2014

SetPlayerSpecialAction(playerid, SPECIAL_ACTION_NONE);


Re: pName Shadows a variable - Hybris - 03.03.2014

Quote:
Originally Posted by Kar
Посмотреть сообщение
SetPlayerSpecialAction(playerid, SPECIAL_ACTION_NONE);
Where should I be adding this?


Re: pName Shadows a variable - Hybris - 03.03.2014

*BUMP*