Custom Po Po lights problem
#1

I have a custom police light system. When you are in a certain vehicle and press H or Caps Lock, a light is attached to your vehicle. The thing is, I can't get it to destroy when the key is pressed again. Here is the code:

pawn Код:
new pdlight;
    if(newkeys & KEY_CROUCH)
    {
        if(light == 0)
        {
            if(IsPlayerInVehicle(playerid, Cars[PD09]) || IsPlayerInVehicle(playerid, Cars[PD10]))
            {
                pdlight = CreateObject(18646, 0, 0, -500,0, 0, 0, 5000);
                AttachObjectToVehicle(pdlight, GetPlayerVehicleID(playerid), 0.4, 0.6, 0.41, 0 ,0 ,0);
                light = 1;
            }
        }else {
            if(IsPlayerInVehicle(playerid, Cars[PD09]) || IsPlayerInVehicle(playerid, Cars[PD10])) {
                DestroyObject(pdlight);
                light = 0;
            }
        }
    }
PS: Is there any way to define a new key?
Reply
#2

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    new pdlight = CreateObject(18646, 0, 0, -500,0, 0, 0, 5000);
    if(newkeys & KEY_CROUCH)
    {
        if(light[vehicleid] == 0)
        {
            if(IsPlayerInVehicle(playerid, Cars[PD09]) || IsPlayerInVehicle(playerid, Cars[PD10]))
            {
                AttachObjectToVehicle(pdlight, GetPlayerVehicleID(playerid), 0.4, 0.6, 0.41, 0 ,0 ,0);
                light[vehicleid] = 1;
            }
        }
        else if(light[vehicleid] != 0)
        {
            if(IsPlayerInVehicle(playerid, Cars[PD09]) || IsPlayerInVehicle(playerid, Cars[PD10]))
            {
                RemoveAttachedObject(pdlight);
                light[vehicleid] = 0;
            }
        }
    }
    return 1;
}
Change your
pawn Код:
new light; // I assume that here you're doing a GLOBAL variable. (for all cars and players)
to
pawn Код:
new light[MAX_VEHICLES]; // And here you doing a variable for a vehicle.
But i still see the createobject useless cause when you add AttachObjectToVehicle the object creates automaticly?
Reply
#3

Quote:
Originally Posted by Marricio
Посмотреть сообщение
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    new pdlight = CreateObject(18646, 0, 0, -500,0, 0, 0, 5000);
    if(newkeys & KEY_CROUCH)
    {
        if(light[vehicleid] == 0)
        {
            if(IsPlayerInVehicle(playerid, Cars[PD09]) || IsPlayerInVehicle(playerid, Cars[PD10]))
            {
                AttachObjectToVehicle(pdlight, GetPlayerVehicleID(playerid), 0.4, 0.6, 0.41, 0 ,0 ,0);
                light[vehicleid] = 1;
            }
        }
        else if(light[vehicleid] != 0)
        {
            if(IsPlayerInVehicle(playerid, Cars[PD09]) || IsPlayerInVehicle(playerid, Cars[PD10]))
            {
                RemoveAttachedObject(pdlight);
                light[vehicleid] = 0;
            }
        }
    }
    return 1;
}
Change your
pawn Код:
new light; // I assume that here you're doing a GLOBAL variable. (for all cars and players)
to
pawn Код:
new light[MAX_VEHICLES]; // And here you doing a variable for a vehicle.
But i still see the createobject useless cause when you add AttachObjectToVehicle the object creates automaticly?
I made light an array, but still no go. BTW, AttachObjectToVehicle doesn't create the object. I tried it.

I can get the object to create, just can't get it to destroy.
Reply
#4

Did you even test it? I changed DestroyObject to RemovePlayerAttachedObject
Reply
#5

Yes, I tested it. I just changed it to a command, which works. I'll fix the key later.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)