Help with warning and /eject command?
#1

How do I fix this warning?

Код:
C:\Users\Dustin\Desktop\WW3 v0.3 Edition\gamemodes\WW3.pwn(1523) : warning 219: local variable "PlayerName" shadows a variable at a preceding level
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
And how would I make it so if a player typed /eject, it would kick the player out of the car?
Thanks
Reply
#2

1.You have defined (new varName) the variable "PlayerName" more than 1 time in your script (1 global and 1 local)

2. RemovePlayerFromVehicle
Reply
#3

Quote:
Originally Posted by lrZ^ aka LarzI
1.You have defined (new varName) the variable "PlayerName" more than 1 time in your script (1 global and 1 local)

2. RemovePlayerFromVehicle
Umm...? So where should I type what? (to fix the warning) Sorry, I am kinda noobish with scripting sometime....
Reply
#4

just delete the variable you've created inside a function/callback called "PlayerName" and keep the global one
Reply
#5

Quote:
Originally Posted by lrZ^ aka LarzI
just delete the variable you've created inside a function/callback called "PlayerName" and keep the global one
I don't really understand your "high roller" talk, lol, sorry can you explain a lil more with a lil more detail? Sorry for my noobish-ness
Reply
#6

I'll give you an example:
pawn Код:
new PlayerName[24];
//As you can see, this line is all by itself, not inside any braces ( { and } )

public OnPlayerConnect(playerid)
{
  new PlayerName[24];
  /*This line is "making" the warning. Since we already have
  defined "PlayerName" global (as I said, not inside any braces)
  and we're trying to define it again inside a function. This is not
  necesarry, since when you define a variable "global" all callbacks
  and functions will "use" that variable, so you don't have to make a new one.*/

  return true;
}
So to fix, delete the PlayerName vars (new PlayerName[MAX_PLAYER_NAME]; or w/e you have defined it as) which is inside { and } and leave the global one ( whichi isn't inside any braces), since that's the one you "need"
Reply
#7

Quote:
Originally Posted by lrZ^ aka LarzI
I'll give you an example:
pawn Код:
new PlayerName[24];
//As you can see, this line is all by itself, not inside any braces ( { and } )

public OnPlayerConnect(playerid)
{
  new PlayerName[24];
  /*This line is "making" the warning. Since we already have
  defined "PlayerName" global (as I said, not inside any braces)
  and we're trying to define it again inside a function. This is not
  necesarry, since when you define a variable "global" all callbacks
  and functions will "use" that variable, so you don't have to make a new one.*/

  return true;
}
So to fix, delete the PlayerName vars (new PlayerName[MAX_PLAYER_NAME]; or w/e you have defined it as) which is inside { and } and leave the global one ( whichi isn't inside any braces), since that's the one you "need"
Ohhhh! I get it! Thanks!
Reply
#8

NP :P
And for the command..

Simple Example:
pawn Код:
if( !strcmp( cmdtext, "/eject", true ))
{
  if( GetPlayerState( playerid ) != PLAYER_STATE_DRIVER )
    return SendClientMessage( playerid, 0xFF0000FF, "**[ERROR]You must be the driver of a vehicle to use this command" );
  RemovePlayerFromVehicle( playerid );
  return true;
}
Easy as pie :P

NOTE: This is for ejecting the driver (which also is the one who types the command)
This can easily be edited for seatids, for other players etc, etc.
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)