Unable to Remove Attached Object from vehicle
#1

Hello everyone,
I made this user friendly yet simple command so that players can shoot from the Helicopter.
I attached an object to it but now when I do spawn ALL vehicles then this object doesn't go OFF from the car/Helicopter.
I mean, How can I destroy this object ?
Already Tried doing some shits with " DestroyObject" !

I need a command which will REMOVE ALL the attached objects [ I mean these objects below] from ALL the vehicles
here's the code.

Код:
CMD:helisupport(playerid, params[])
{
    new objecta = CreateObject(18756,0,0,-1000,0,0,0,100);
AttachObjectToVehicle(objecta,GetPlayerVehicleID(playerid),0.525000,1.425000,-3.075001,-361.800292,91.799980,-268.379852);
    new objectb = CreateObject(18756,0,0,-1000,0,0,0,100);
	AttachObjectToVehicle(objectb, GetPlayerVehicleID(playerid), -2.625000,1.350000,-3.075001,-361.800292,91.799980,-268.379852);
	return 1;
}
Reply
#2

is removed with DestroyObject.

https://sampwiki.blast.hk/wiki/DestroyObject
Reply
#3

These variables should be global variables. This way, you can edit them anywhere throughout your script. The variables you have created in this case, 'objecta' and 'objectb' are local variables and can only be used within the command "/helisupport".

pawn Код:
new heliobjects[MAX_VEHICLES][2]; //At the top of your script

public OnGameModeInit()
{
    for(new i = 0; i < MAX_VEHICLES; i++) heliobjects[i][0] = heliobjects[i][1] = -1;
    return 1;
}

CMD:helisupport(playerid, params[])
{
    new vehicleid = GetPlayerVehicleID(playerid);
    switch(GetVehicleModel(vehicleid))
    {
        case 417, 425, 447, 469, 487, 488, 497, 548, 563: //Helicopters
        {
            if(heliobjects[vehicleid][0] != -1) return SendClientMessage(playerid, -1, "This vehicle already has doors attached to it.");
            heliobjects[vehicleid][0] = CreateObject(18756, 0, 0, -1000, 0, 0, 0, 100);
            heliobjects[vehicleid][1] = CreateObject(18756, 0, 0, -1000, 0, 0, 0, 100);
            AttachObjectToVehicle(heliobjects[vehicleid][0], vehicleid, 0.525000, 1.425000, -3.075001, -361.800292, 91.799980, -268.379852);
            AttachObjectToVehicle(heliobjects[vehicleid][1], vehicleid, -2.625000, 1.350000, -3.075001, -361.800292, 91.799980, -268.379852);
        }
        default: return SendClientMessage(playerid, -1, "You must be in a helicopter to use this command.");
    }
    return 1;
}

public OnVehicleDeath(vehicleid)
{
    if(heliobjects[vehicleid][0] != -1)
    {
        DestroyObject(heliobjects[vehicleid][0]);
        DestroyObject(heliobjects[vehicleid][1]);
        heliobjects[vehicleid][0] = heliobjects[vehicleid][1] = -1;
    }
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    if(heliobjects[vehicleid][0] != -1)
    {
        DestroyObject(heliobjects[vehicleid][0]);
        DestroyObject(heliobjects[vehicleid][1]);
        heliobjects[vehicleid][0] = heliobjects[vehicleid][1] = -1;
    }
    return 1;
}
This destroys the objects whenever the vehicle is destroyed, or whenever the vehicle respawns.

EDIT: To remove the objects from ALL vehicles:
pawn Код:
for(new i = 0; i < MAX_VEHICLES; i++)
{
    if(heliobjects[i][0] == -1) continue;
    DestroyObject(heliobjects[i][0]);
    DestroyObject(heliobjects[i][1]);
    heliobjects[i][0] = heliobjects[i][1] = -1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)