Errors - 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: Errors (
/showthread.php?tid=417849)
Errors -
POPkKnifezZ - 22.02.2013
I've been getting three errors now, for a while and haven't been able to find any solution.
Warning Code
Код:
C:\Users\Ryan\Desktop\Games\SAMP\gamemodes\VortexRoleplay.pwn(27488) : warning 217: loose indentation
C:\Users\Ryan\Desktop\Games\SAMP\gamemodes\VortexRoleplay.pwn(27491) : warning 219: local variable "string" shadows a variable at a preceding level
C:\Users\Ryan\Desktop\Games\SAMP\gamemodes\VortexRoleplay.pwn(27526) : warning 217: loose indentation
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
3 Warnings.
Actual command.
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
{
new string[128];
new PlayerVehicle = GetVehicleFileID(GetPlayerVehicleID(playerid));
if(Vehicles[PlayerVehicle][CarGroup] != 0 && Vehicles[PlayerVehicle][CarGroup] != Player[playerid][Group])
{
format(string, sizeof(string), "This vehicle is only usable by %s.", Groups[Vehicles[PlayerVehicle][CarGroup]][GroupName]);
SendClientMessage(playerid, WHITE, string);
RemovePlayerFromVehicle(playerid);
}
new vehicleid = GetPlayerVehicleID(playerid);
if(newstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_PASSENGER)
{
new vid = GetPlayerVehicleID(playerid);
new string[125];
format(string, sizeof string, "Fuel:%i", fuel[vid]); //quickly doing a small update on fuel (so it wont jump from 100 to its real value)
TextDrawSetString(td_fuel[playerid],string);
TextDrawShowForPlayer(playerid,td_fuel[playerid]); //showing if an player is a driver or passenger of the ar
}
else
{
TextDrawHideForPlayer(playerid,td_fuel[playerid]); //hiding if a player isnt driving/or an passenger
}
if(IsAnOwnedCar(vehicleid))
{
if(Player[playerid][AdminLevel] < 1)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(Player[i][LockedCar] == 1 && Player[i][CarLinkID] == vehicleid)
{
SendClientMessage(playerid, WHITE, "This vehicle is locked.");
RemovePlayerFromVehicle(i);
}
if(Player[i][LockedCar2] == 1 && Player[i][Car2LinkID] == vehicleid)
{
SendClientMessage(playerid, WHITE, "This vehicle is locked.");
RemovePlayerFromVehicle(i);
}
if(Player[i][LockedCar3] == 1 && Player[i][Car3LinkID] == vehicleid)
{
SendClientMessage(playerid, WHITE, "This vehicle is locked.");
RemovePlayerFromVehicle(i);
}
}
}
}
Player[playerid][LastCarID] = GetPlayerVehicleID(playerid);
new VehID = GetPlayerVehicleID(playerid), VehModel = GetVehicleModel(VehID);
if(VehModel == 596)
{
Player[playerid][GotInCopCar]++;
ResetPlayerWeapons(playerid);
GivePlayerSavedWeapons(playerid);
}
else if(VehModel == 427)
{
if(Groups[Player[playerid][Group]][CommandTypes] != 1)
{
SetPlayerArmour(playerid, 0);
}
else
{
SendClientMessage(playerid, WHITE, "You have collected some armour from the Enforcer.");
}
}
if(Player[playerid][Cuffed] >= 1)
{
RemovePlayerFromVehicle(playerid);
TogglePlayerControllable(playerid, false);
SendClientMessage(playerid, WHITE, "You may not execute that action right now.");
}
}
else if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT)
{
if(Player[playerid][GotInCopCar] >= 1)
{
ResetPlayerWeapons(playerid);
GivePlayerSavedWeapons(playerid);
Player[playerid][GotInCopCar] = 0;
}
if(Player[playerid][ModShop] == 1)
{
Player[playerid][ModShop] = 0;
SetPlayerPos(playerid, SpawnX, SpawnY, SpawnZ);
SetPlayerVirtualWorld(playerid, SpawnWorld);
SetPlayerInterior(playerid, SpawnInt);
SetPlayerFacingAngle(playerid, 0);
}
}
return 1;
}
The error seems to be coming up on this bit.
Код:
if(newstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_PASSENGER)
{
new vid = GetPlayerVehicleID(playerid);
new string[125];
format(string, sizeof string, "Fuel:%i", fuel[vid]); //quickly doing a small update on fuel (so it wont jump from 100 to its real value)
TextDrawSetString(td_fuel[playerid],string);
TextDrawShowForPlayer(playerid,td_fuel[playerid]); //showing if an player is a driver or passenger of the ar
}
else
{
TextDrawHideForPlayer(playerid,td_fuel[playerid]); //hiding if a player isnt driving/or an passenger
}
Any/all help is appreciated, thanks in advanced.
Re: Errors -
DrDoom151 - 22.02.2013
local variable "string" shadows a variable at a preceding level
This means that you created a new variable somewhere which already exists somewhere else. In this case you've already created a variable called "string" in another function. Rename one of the two.
loose indentation
Wouldn't know how to explain this. I'm guessing it's the following code:
pawn Код:
if(Player[i][LockedCar3] == 1 && Player[i][Car3LinkID] == vehicleid)
{
SendClientMessage(playerid, WHITE, "This vehicle is locked.");
RemovePlayerFromVehicle(i);
}
change that to:
pawn Код:
if(Player[i][LockedCar3] == 1 && Player[i][Car3LinkID] == vehicleid)
{
SendClientMessage(playerid, WHITE, "This vehicle is locked.");
RemovePlayerFromVehicle(i);
}