Checking attached vehicle object
#1

Is there a way to check if an object is attached to a vehicle?

I've attached siren lights to vehicles, and I'm writing a command to get them to flash (Basically just attaching the flashing light bar). But I need some script to check if the non-flashing lightbar is attached to the vehicle, and get the position of it so I can add the flashing one over it when the command it used.
Reply
#2

Variables.
Reply
#3

I have different variables for each one. There's going to be several vehicles with the non-flashing light bar.

pawn Код:
// Attach light bars to Huntleys
    new lights_huntley1 = CreateObject(19420,0.0,0.0,0.0,0.0,0.0,0.0,100.0);
    AttachObjectToVehicle(lights_huntley1, SAPDVehicles[27], 0.0, 0.0, 1.2, 0.0, 0.0, 0.0);
    new lights_huntley2 = CreateObject(19420,0.0,0.0,0.0,0.0,0.0,0.0,100.0);
    AttachObjectToVehicle(lights_huntley2, SAPDVehicles[28], 0.0, 0.0, 1.2, 0.0, 0.0, 0.0);
    new lights_huntley3 = CreateObject(19420,0.0,0.0,0.0,0.0,0.0,0.0,100.0);
    AttachObjectToVehicle(lights_huntley3, SAPDVehicles[29], 0.0, 0.0, 1.2, 0.0, 0.0, 0.0);
    new lights_huntley4 = CreateObject(19420,0.0,0.0,0.0,0.0,0.0,0.0,100.0);
    AttachObjectToVehicle(lights_huntley4, SAPDVehicles[30], 0.0, 0.0, 1.2, 0.0, 0.0, 0.0);
    new lights_huntley5 = CreateObject(19420,0.0,0.0,0.0,0.0,0.0,0.0,100.0);
    AttachObjectToVehicle(lights_huntley5, SAPDVehicles[31], 0.0, 0.0, 1.2, 0.0, 0.0, 0.0);
    new lights_huntley6 = CreateObject(19420,0.0,0.0,0.0,0.0,0.0,0.0,100.0);
    AttachObjectToVehicle(lights_huntley6, SAPDVehicles[32], 0.0, 0.0, 1.2, 0.0, 0.0, 0.0);
I'm guessing it might be better to make a global variable like LightBars[MAX_VEHICLES], and do it that way, if you know what i mean?
Reply
#4

That's what he meant. I suggest doing it that way and see if it works like you intended.
Reply
#5

Yeah. I don't know why I even started doing it the way I did in the first place lol. Tired I guess.

This is what I have now, incase anybody else is trying to figure it out.

pawn Код:
for(new i = SAPDVehicles[27]; i < SAPDVehicles[33]; i++)
    {
        LightBarOff[i] = CreateObject(19420,0.0,0.0,0.0,0.0,0.0,0.0,100.0);
        AttachObjectToVehicle(LightBarOff[i], i, 0.0, 0.0, 1.2, 0.0, 0.0, 0.0);
    }
SAPDVehicles[x] stores the vehicle ID. This just selects a certain set of vehicles to attach the bars too. I would share my script that turns the lightbars on and off using a command but it probably wouldn't be much help as everybody's script works differently. But with this script here, it's easy to make a command, just checking if the non-flashing bar exists to the vehicle the player is in, then getting the object position of it, and then adding the flashing one.

Much more simple than I anticipated.
Reply
#6

Here is the working project:

http://www.youtube.com/watch?v=FRGRh...ature=*********
Reply
#7

I personally would never even think of doing this, as the lights disappear when the vehicle is at an angle.
Reply
#8

Didn't you say you have a fix for that?
Reply
#9

Not in this topic, no. It only works for 'PointLight' objects which have no 'object'. Won't work for this.
Reply
#10

Ahh well. It doesn't matter too much. The flashing lightbar was just an extra 'cool' touch. It'll work well in most cases, like for warning traffic of a hazard or whatever.
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)