Destory vehicle problem
#1

Hello, I've been making a command to destroy the vehicle that the player is in for
my server, but I keep getting the problem where the command doesn't actually work, and sends the
"You need to be in a vehicle" text and then unknown command text, So i changed it to the new
command below and i keep getting the error: error 017: undefined symbol "GetPlayerVehicledID"

Код:
CMD:dveh(playerid, params[])
{
	new
	vehicleid = GetPlayerVehicledID(playerid),
	string[128];
	if(IsPlayerInVehicle(playerid, vehicleid)) 
	{
	    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	    {
    		DestroyVehicle(vehicleid);
			format(string, sizeof(string), "The %s has been destroyed.", VehicleName(vehicleid));
			SendClientMessage(playerid, YELLOW, string);
		}
	}
	else(SendClientMessage(playerid, RED, "You need to be in a vehicle to destroy it."));
}
Reply
#2

Remove the "d" from the GetPlayerVehicledID, correct is GetPlayerVehicleID
Reply
#3

Well that fixed the deletion problem, but whenever I do the command, it still comes up with the unknown command error :/
Reply
#4

Under "else return etc.."
do return 1;
Sorry for lately help
Reply
#5

You always have to return a command to something, else you will keep getting that unknown command thing and it wont work.

pawn Код:
CMD:dveh(playerid, params[])
{
    new vehicleid = GetPlayerVehicleID(playerid), string[128];
    if(IsPlayerInVehicle(playerid, vehicleid))
    {
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            DestroyVehicle(vehicleid);
            format(string, sizeof(string), "The %s has been destroyed.", VehicleName(vehicleid));
            SendClientMessage(playerid, YELLOW, string);
        }
    }else{SendClientMessage(playerid, RED, "You need to be in a vehicle to destroy it.");}
    return 1;
}
Fixed your issue here I think.
Reply
#6

You're also doing too many checks.
First you use GetVehicleID, then you re-check if the same player is inside the same vehicle.

pawn Код:
CMD:dveh(playerid, params[])
{
    // If the player isn't the driver of a vehicle, exit the command
    if(GetPlayerVehicleSeat(playerid) != 0) return SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You need to be in a vehicle to destroy it.");

    new vehicleid = GetPlayerVehicleID(playerid), string[128];
    DestroyVehicle(vehicleid);
    format(string, sizeof(string), "The %s has been destroyed.", VehicleName(vehicleid));
    SendClientMessage(playerid, YELLOW, string);

    return 1;
}
Reply
#7

The above will fail too because you destroy the vehicle and then you call VehicleName. The modelid of the vehicleid will be 0 so array index out of bounds for accessing negative element at -400.

Array index out of bounds may cause the unknown command too, if it is still displayed after returning true at the end of the command so the solution will be to check if the model is valid before getting the name.
Reply
#8

He already stored the id, It will work:

new vehicleid = GetPlayerVehicleID(playerid);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)