01.06.2013, 17:32
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