AttachObjectToVehicle Arrays
#1

Hi, I need help with arrays, I have an array of coords for two vehicles which are PD vehicles and I need to use the array coords with AttachObjectToVehicle.

pawn Код:
new Float:PDObjects[2][] = {
    {0.009999,3.435001,-0.435000,90.359909,-90.179969,0.000000},
    {-0.000000,2.400000,0.075000,89.099983,-89.099983,0.000001}
};

new rand = random(sizeof(PDObjects));
AttachObjectToVehicle(myobject, i, PDObjects[rand][0], PDObjects[rand][1], PDObjects[rand][2], PDObjects[rand][3], PDObjects[rand][4], PDObjects[rand][5]);
Reply
#2

Ah, sorry! I want to put some coords in a array which has been posted on the OP and then when I spawn my vehicles it does a check to see if one of the vehicles is a police car, then it should attach the object I created to the police car using the coords in the array.
Reply
#3

You created the object 'myobject' ?

pawn Код:
public OnVehicleSpawn(vehicleid)
{
    if(GetVehicleModel(vehicleid) == 596) // LSPD
    {
        new rand = random(sizeof(PDObjects));
        AttachObjectToVehicle(myobject, vehicleid, PDObjects[rand][0], PDObjects[rand][1], PDObjects[rand][2], PDObjects[rand][3], PDObjects[rand][4], PDObjects[rand][5]);
    }
    return true;
}
Reply
#4

It did work but the coords are set for two vehicles. One if the cruiser and the other is the enforcer.
Reply
#5

What is the model ID of them?
Adapt.

Ex:
pawn Код:
public OnVehicleSpawn(vehicleid)
{
    new rand;
    if(GetVehicleModel(vehicleid) == MODEL_ENFORCER) // Enforcer
        rand = 0;
    else if(GetVehicleModel(vehicleid) == MODEL_CRUISER) // Cruiser
        rand = 1;

    AttachObjectToVehicle(myobject, vehicleid, PDObjects[rand][0], PDObjects[rand][1], PDObjects[rand][2], PDObjects[rand][3], PDObjects[rand][4], PDObjects[rand][5]);
    return true;
}
Reply
#6

Thanks, it worked like a charm!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)