[HELP] Lights -
monster010 - 08.04.2014
I have this script. What is wrong there?
pawn Код:
if(IsPlayerInAnyVehicle(playerid))
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
if(newkeys & KEY_YES)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(VehicleLights[vehicleid] == 0)
{
new vehicleid, engine, lights, alarm, doors, bonnet, boot, objective;
VehicleLights[vehicleid] = 1;
SendClientMessage(playerid, COLOR_YELLOW, "You have enabled your car lights.");
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, true, alarm, doors, bonnet, boot, objective);
}
else if(VehicleLights[vehicleid] == 1)
{
new vehicleid, engine, lights, alarm, doors, bonnet, boot, objective;
VehicleLights[vehicleid] = 0;
SendClientMessage(playerid, COLOR_YELLOW, "You have disabled your car lights.");
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, false, alarm, doors, bonnet, boot, objective);
}
}
return 1;
}
}
and the warnings...
Код:
C:\local\gf.pwn(30949) : warning 219: local variable "vehicleid" shadows a variable at a preceding level
C:\local\gf.pwn(30952) : warning 219: local variable "vehicleid" shadows a variable at a preceding level
C:\local\gf.pwn(30960) : warning 219: local variable "vehicleid" shadows a variable at a preceding level
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
Header size: 7504 bytes
Code size: 1294868 bytes
Data size: 5702028 bytes
Stack/heap size: 16384 bytes; estimated max. usage=5802 cells (23208 bytes)
Total requirements: 7020784 bytes
3 Warnings.
Re: [HELP] Lights -
Konstantinos - 08.04.2014
You declared it and got the vehicle ID here:
pawn Код:
new vehicleid = GetPlayerVehicleID(playerid);
so remove the other 2 declarations of "vehicleid" in that callback:
pawn Код:
new vehicleid, engine, lights, alarm, doors, bonnet, boot, objective;
should be:
pawn Код:
new engine, lights, alarm, doors, bonnet, boot, objective;
Re: [HELP] Lights -
iThePunisher - 08.04.2014
try this
pawn Код:
if(IsPlayerInAnyVehicle(playerid))
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
if(newkeys & KEY_YES)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(VehicleLights[vehicleid] == 0)
{
new engine, lights, alarm, doors, bonnet, boot, objective;
VehicleLights[vehicleid] = 1;
SendClientMessage(playerid, COLOR_YELLOW, "You have enabled your car lights.");
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, true, alarm, doors, bonnet, boot, objective);
}
else if(VehicleLights[vehicleid] == 1)
{
new engine, lights, alarm, doors, bonnet, boot, objective;
VehicleLights[vehicleid] = 0;
SendClientMessage(playerid, COLOR_YELLOW, "You have disabled your car lights.");
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, false, alarm, doors, bonnet, boot, objective);
}
}
return 1;
}
}
Re: [HELP] Lights -
monster010 - 08.04.2014
Код:
warning 219: local variable "vehicleid" shadows a variable at a preceding level
And the line is
pawn Код:
new vehicleid = GetPlayerVehicleID(playerid);
Re: [HELP] Lights -
Konstantinos - 08.04.2014
It's declared as global or in that callback but at the top of it. Just rename "vehicleid" to some other name (to the code uses "vehicleid" as well).
Re: [HELP] Lights -
iThePunisher - 08.04.2014
ok then you should remove that too..
so copy and paste this
pawn Код:
if(IsPlayerInAnyVehicle(playerid))
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
if(newkeys & KEY_YES)
{
if(VehicleLights[vehicleid] == 0)
{
new engine, lights, alarm, doors, bonnet, boot, objective;
VehicleLights[vehicleid] = 1;
SendClientMessage(playerid, COLOR_YELLOW, "You have enabled your car lights.");
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, true, alarm, doors, bonnet, boot, objective);
}
else if(VehicleLights[vehicleid] == 1)
{
new engine, lights, alarm, doors, bonnet, boot, objective;
VehicleLights[vehicleid] = 0;
SendClientMessage(playerid, COLOR_YELLOW, "You have disabled your car lights.");
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, engine, false, alarm, doors, bonnet, boot, objective);
}
}
return 1;
}
}
Re: [HELP] Lights -
Konstantinos - 08.04.2014
That's not what I meant. You never got the vehicle ID and it will only result in script bugs. Also checking if the player is in any vehicle and then checking if he's driver is pointless. If the player is driver, then he's in a vehicle!
pawn Код:
if(newkeys & KEY_YES)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new vehicle_ID = GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicle_ID, engine, lights, alarm, doors, bonnet, boot, objective);
if(VehicleLights[vehicle_ID] == 0)
{
VehicleLights[vehicle_ID] = 1;
SendClientMessage(playerid, COLOR_YELLOW, "You have enabled your car lights.");
SetVehicleParamsEx(vehicle_ID, engine, true, alarm, doors, bonnet, boot, objective);
}
else
{
VehicleLights[vehicle_ID] = 0;
SendClientMessage(playerid, COLOR_YELLOW, "You have disabled your car lights.");
SetVehicleParamsEx(vehicle_ID, engine, false, alarm, doors, bonnet, boot, objective);
}
}
return 1;
}