A simple question with spawning cars.
#1

Alright, I have a question..

Say, I made an admin vehicle spawn. How could I make it despawn when it blows up, i.e destroy? But only for that vehicle and not like player owned ones.

pawn Код:
CMD:spawncar(playerid, params[])
{
    if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
   
    if(AdminLevel[playerid] < 1) return SendClientMessage(playerid, COLOUR_GREY, "You are not authorized to use this command.");
    new vmodel, colour1, colour2;
    if(sscanf(params, "ddd", vmodel, colour1, colour2)) return SendClientMessage(playerid, COLOUR_GREY, "Usage: /spawncar [model] [colour 1] [colour 2]");
   
    new Float:scx,Float:scy, Float:scz, Float:sca;
    GetPlayerPos(playerid, scx, scy, scz);
    GetPlayerFacingAngle(playerid, sca);
   
    new vehicleid = CreateVehicle(vmodel, scx, scy+5, scz, sca, colour1, colour2, -1);
    new plate[50];
    format(plate, sizeof(plate), "BCRP%d", vehicleid);
    SetVehicleNumberPlate(vehicleid, plate);
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
    EngineStartStatus[vehicleid] = 0;
    return 1;
}
Reply
#2

I don't understand.
Do you want a command to despawn cars?
or..

When a car is unused it will despawn?
Reply
#3

Effectively. When I use that command, it spawns a car, how do I later destroy that car?
Reply
#4

Try this, not sure if it works, I didn't test it.

pawn Код:
CMD:destroycar(playerid) {
    if(IsPlayerInAnyVehicle(playerid)) {
        new veh = GetPlayerVehicleId(playerid);
        DestroyVehicle(veh);
    } else {
        SendClientMessage(playerid, CHOOSE_A_COLOR, "You cannot destroy this vehicle as you are not in one!");
    }
    return 1;
}
 // Add admin variables, and anti-login vars if you need.
Reply
#5

Use the function
pawn Код:
DestroyVehicle(vehicleid);
Reply
#6

Try taking this, and experiment as you'll have to do a tweak it a bit for it to work. (Such as finding out if it's an admin spawned vehicle, ect.

pawn Код:
public OnVehicleDeath(vehicleid)
{
    DestroyVehicle(vehicleid);
    return 1;
}
Reply
#7

Ahh I wasn't thinking, that's really simple! Thank you very much!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)