Destroy attached objects when deleting a car
#1

Removed.
Reply
#2

Of course there's a solution, there's almost always a solution!

You need to create a variable that stores the object ID's of the objects attached to the vehicle. When you destroy the vehicle, run through the variable and delete any object's associated with it. You can do this automatically by hooking the DestroyVehicle function with ALS.
Reply
#3

Removed.
Reply
#4

I did this using a foreach iterator, it seemed like the most logical option to me! So, you'll need to download the latest version of the YSI library and include YSI\y_iterate.

pawn Код:
new
    Iterator:VehicleAttachedObjects[MAX_VEHICLES]<MAX_OBJECTS>; // you MAY need to increase MAX_OBJECTS if you're using a streamer to avoid the limit
   
public OnGameModeInit()
{
    Iter_Init(VehicleAttachedObjects);
    return 1;
}

CMD:siren(playerid, params)
{
    new
        v = GetPlayerVehicleID(playerid),
        tempID;

    Iter_Add(VehicleAttachedObjects[v], tempID = CreateDynamicObject(19419, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
    AttachDynamicObjectToVehicle(tempID, v, 0.000000, -1.349998, 0.354999, 0.000000, 0.000000, 0.000000); // sultan (light bar)
    Iter_Add(VehicleAttachedObjects[v], tempID = CreateDynamicObject(18646, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
    AttachDynamicObjectToVehicle(tempID, v, 0.000000, 0.789999, 0.439999, 0.000000, 0.000000, 0.000000); // Sultan (single light)
    return 1;
}

// when you want to remove an object, you'll need to use Iter_Remove(VehicleAttachedObjects[vehicleid], OBJECT_ID);

public OnVehicleDeath(vehicleid) // removes the objects when the vehicle dies (i.e. enters water, blows up)
{
    foreach(new i : VehicleAttachedObjects[vehicleid]) DestroyDynamicObject[i];
    Iter_Clear(VehicleAttachedObjects[vehicleid]);
    return 1;
}

// ------ DestroyVehicle hook ------ //

stock realDestroyVehicle(vehicleid)
{
    foreach(new i : VehicleAttachedObjects[vehicleid]) DestroyDynamicObject(i);
    Iter_Clear(VehicleAttachedObjects[vehicleid]);
   
    return DestroyVehicle(vehicleid);
}

#if defined _ALS_DestroyVehicle
    #undef DestroyVehicle
#else
    #define _ALS_DestroyVehicle
#endif
#define DestroyVehicle realDestroyVehicle
Reply
#5

Removed.
Reply
#6

You'll never learn if you don't do it yourself...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)