[HELP] Lights
#1

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.
Reply
#2

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;
Reply
#3

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;
        }
     }
Reply
#4

Код:
warning 219: local variable "vehicleid" shadows a variable at a preceding level
And the line is
pawn Код:
new vehicleid = GetPlayerVehicleID(playerid);
Reply
#5

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).
Reply
#6

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;
        }
     }
Reply
#7

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)