Need help with destroying unwanted Veh
#1

Hey I have made a command for admins to spawn a vehicle, but when the are done with this and leave it, it just stays there. But I want something like when they are done with it, it destory the vehicle. I need a little help with it. Here is my code.

pawn Код:
CMD:veh(playerid, params[])
{
    if(GetAdminLevel(playerid) >= 2) {
        new car;
        if(IsPlayerInAnyVehicle(playerid)) return 1;
        if(sscanf(params, "i", car)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /veh [vehid]");
        if(strval(params) >611 || strval(params) <400) return SendClientMessage(playerid, COLOR_RED, "Invalid model id!");
        new Float:x, Float:y, Float:z, Float:a;
        GetPlayerPos(playerid, x,y,z);
        GetPlayerFacingAngle(playerid, a);
        car = CreateVehicle(strval(params), x, y, z,a, -1, -1, 60);
        PutPlayerInVehicle(playerid, car, 0);
    }
    return 1;
}
Reply
#2

CMD:

pawn Код:
CMD:veh(playerid, params[])
{
    if(GetAdminLevel(playerid) >= 2) {
        new car;
        if(IsPlayerInAnyVehicle(playerid)) return 1;
        if(sscanf(params, "i", car)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /veh [vehid]");
        if(strval(params) >611 || strval(params) <400) return SendClientMessage(playerid, COLOR_RED, "Invalid model id!");
        new Float:x, Float:y, Float:z, Float:a;
        GetPlayerPos(playerid, x,y,z);
        GetPlayerFacingAngle(playerid, a);
        car = CreateVehicle(strval(params), x, y, z,a, -1, -1, 60);
        PutPlayerInVehicle(playerid, car, 0);
        SetPVarInt(playerid, "AdminVeh", car);
    }
    return 1;
}

Add inside PlayerExitVehicle public

pawn Код:
if(vehicleid == GetPVarInt(playerid, "AdminVeh"))
{
    DestroyVehicle(vehicleid);
    DeletePVar(playerid, "AdminVeh");
    SendClientMessage(playerid, -1, "You have left your admin vehicle and it has been destroyed.");
}
Reply
#3

So for adding the last block on public will be like this?

[pawn]

public OnPlayerExitVehicle (playerid, vehicleid)
{
DestroyVehicle(vehicleid);
DeletePVar (playerid, AdminVeh");
SendClientMessage(playerid, 0xFFFFFAA, "Your left vehicle now has been destroyed.");
}
Reply
#4

Nope, it would be like this:
PHP код:
public OnPlayerExitVehicle (playeridvehicleid)
{
if(
vehicleid == GetPVarInt(playerid"AdminVeh")) // You need to include this or it will always destroy the vehicle when the player exits it, regardless of if it is a server vehicle or not
{
    
DestroyVehicle(vehicleid);
    
DeletePVar(playerid"AdminVeh");
    
SendClientMessage(playerid, -1"You have left your admin vehicle and it has been destroyed.");
}

Reply
#5

Thanks Paul and Bennie!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)