SA-MP Forums Archive
Need help with destroying unwanted Veh - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Need help with destroying unwanted Veh (/showthread.php?tid=431679)



Need help with destroying unwanted Veh - Goldilox - 19.04.2013

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;
}



Re: Need help with destroying unwanted Veh - PaulDinam - 19.04.2013

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.");
}



Re: Need help with destroying unwanted Veh - Goldilox - 19.04.2013

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.");
}


Re: Need help with destroying unwanted Veh - bensmart469 - 19.04.2013

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.");
}




Re: Need help with destroying unwanted Veh - Goldilox - 20.04.2013

Thanks Paul and Bennie!