Vehicle command
#1

I would like to add a command that when putting the wrong car ID appears: "Vehicle not found", the command I created has some properties, I will be leaving it below:

Код:
ACMD:veiculo[3](playerid, params[])
{
	if(!IsPlayerOnAdminDuty(playerid) && GetPlayerAdminLevel(playerid) < STAFF_LEVEL_LEAD)
		return 6;

	new
		command[30],
		vehicleid;

	if(sscanf(params, "s[30]D(-1)", command, vehicleid))
	{
		Msg(playerid, NovoA, "[ > ] Uso correto: /veiculo []/ir/entrar/dono/deletar/respawn/resetar/trancar/destrancar/removerchave] [id]");
		return 1;
	}

	if(vehicleid == -1)
		vehicleid = GetPlayerVehicleID(playerid);

	if(!IsValidVehicle(vehicleid))
		return 4;

	if(!strcmp(command, "puxar"))
	{
		new
			Float:x,
			Float:y,
			Float:z;

		GetPlayerPos(playerid, x, y, z);
		PutPlayerInVehicle(playerid, vehicleid, 0);
		SetVehiclePos(vehicleid, x, y, z);
		SetPlayerPos(playerid, x, y, z + 2);
		SetCameraBehindPlayer(playerid);
        MsgAdminsF(1, NovoA, "{00CED1}[ > ] O(a) administrador(a) %P{00CED1} puxou o veнculo de ID {FFFFFF}%d !", playerid, vehicleid);
		return 1;
	}

	if(!strcmp(command, "ir"))
	{
		new
			Float:x,
			Float:y,
			Float:z;

		GetVehiclePos(vehicleid, x, y, z);
		SetPlayerPos(playerid, x, y, z);
        MsgAdminsF(1, NovoA, "{00CED1}[ > ] O(a) administrador(a) %P{00CED1} foi atй o veнculo de ID {FFFFFF}%d !", playerid, vehicleid);
		return 1;
	}

	if(!strcmp(command, "entrar"))
	{
		PutPlayerInVehicle(playerid, vehicleid, 0);
        MsgAdminsF(1, NovoA, "{00CED1}[ > ] O(a) administrador(a) %P{00CED1} usou o comando de entrar no veнculo de ID {FFFFFF}%d !", playerid, vehicleid);
		return 1;
	}

	if(!strcmp(command, "dono"))
	{
		new owner[MAX_PLAYER_NAME];

		GetVehicleOwner(vehicleid, owner);

		MsgF(playerid, NovoA, "[ > ] O dono desse veнculo й: {FFFFFF}'%s'", owner);
        MsgAdminsF(1, NovoA, "{00CED1}[ > ] O(a) administrador(a) %P{00CED1} estб vendo quem й o dono do veнculo de ID {FFFFFF}%d !", playerid, vehicleid);
		return 1;
	}

	if(!strcmp(command, "deletar"))
	{
		DestroyWorldVehicle(vehicleid);

		MsgF(playerid, RED, "[x] Veнculo %d foi deletado!", vehicleid);
        MsgAdminsF(1, NovoA, "{00CED1}[ > ] O(a) administrador(a) %P{00CED1} deletou o veнculo de ID {FFFFFF}%d !", playerid, vehicleid);
		return 1;
	}

	if(!strcmp(command, "respawn"))
	{
		RespawnVehicle(vehicleid);

		MsgF(playerid, RED, "[x] Veнculo %d foi respawnado!", vehicleid);
        MsgAdminsF(1, NovoA, "{00CED1}[ > ] O(a) administrador(a) %P {00CED1}respawnou o veнculo de ID {FFFFFF}%d !", playerid, vehicleid);
		return 1;
	}

	 if(!strcmp(command, "resetar"))
	{
		ResetVehicle(vehicleid);

		MsgF(playerid, RED, "[x] Veнculo %d foi resetado!", vehicleid);
        MsgAdminsF(1, NovoA, "{00CED1}[ > ] O(a) administrador(a) %P {00CED1}resetou o veнculo de ID {FFFFFF}%d !", playerid, vehicleid);
		return 1;
	}

	if(!strcmp(command, "trancar"))
	{
		SetVehicleExternalLock(vehicleid, 1);

		MsgF(playerid, RED, "[x] Veнculo %d foi trancado!", vehicleid);
        MsgAdminsF(1, NovoA, "{00CED1}[ > ] O(a) administrador(a) %P {00CED1}trancou o veнculo de ID {FFFFFF}%d !", playerid, vehicleid);
		return 1;
	}

	if(!strcmp(command, "destrancar"))
	{
		SetVehicleExternalLock(vehicleid, 0);

		MsgF(playerid, RED, "[x] Veнculo %d foi destrancado!", vehicleid);
        MsgAdminsF(1, NovoA, "{00CED1}[ > ] O(a) administrador(a) %P {00CED1}destrancou o veнculo de ID {FFFFFF}%d !", playerid, vehicleid);
		return 1;
	}

	if(!strcmp(command, "removerchave"))
	{
		SetVehicleKey(vehicleid, 0);

		MsgF(playerid, RED, "[x] Veнculo %d teve sua chave removida!", vehicleid);
        MsgAdminsF(1, NovoA, "{00CED1}[ > ] O(a) administrador(a) %P{00CED1} removeu a chave do veнculo de ID {FFFFFF}%d !", playerid, vehicleid);
		return 1;
	}
	Msg(playerid, NovoA, "[ > ] Uso correto: /veiculo [puxar/entrar/dono/deletar/respawn/resetar/trancar/destrancar] [id]");
	return 1;
}
Reply
#2

Quote:

when putting the wrong car ID appears: "Vehicle not found"

The logic you need for what u are asking for is here:

PHP код:
CMD:vehicle(playeridparams[])
{
    new 
vehicleid;
    
sscanf(params"d"vehicleid);
    if(
vehicleid 400 || vehicleid 611) {
        
SendClientMessage(playerid, -1"Vehicle not found");
        return 
1;
    }
    return 
1;

Reply
#3

According to this "veiculo [3]" I imagine that there are 3 vehicle slots for each player, then:

PHP код:
ACMD:veiculo(playeridparams[])
{
    if(!
IsPlayerOnAdminDuty(playerid) && GetPlayerAdminLevel(playerid) < STAFF_LEVEL_LEAD) return 0;
    new 
command[24], vehicleid;
    if(
sscanf(params"s[24]d"commandvehicleid)) return Msg(playeridNovoA"[ > ] Uso correto: /veiculo /ir/entrar/dono/deletar/respawn/resetar/trancar/destrancar/removerchave] [id]");
    if(
vehicleid || vehicleid 3) return SendClientMessage(playerid, -1"Error: vehicle slots 1 - 3.");
    if(!
IsValidVehicle(vehicleid)) return 0;
    if(!
strcmp(command"puxar"true))
    {
        new 
Float:xFloat:yFloat:z;
        
GetPlayerPos(playeridxyz);
        
PutPlayerInVehicle(playeridvehicleid0);
        
SetVehiclePos(vehicleidxyz);
        
SetPlayerPos(playeridxy2);
        
SetCameraBehindPlayer(playerid);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P{00CED1} puxou o veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"ir"true))
    {
        new 
Float:xFloat:yFloat:z;
        
GetVehiclePos(vehicleidxyz);
        
SetPlayerPos(playeridxyz);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P{00CED1} foi atй o veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"entrar"true))
    {
        
PutPlayerInVehicle(playeridvehicleid0);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P{00CED1} usou o comando de entrar no veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"dono"true))
    {
        new 
owner[MAX_PLAYER_NAME];
        
GetVehicleOwner(vehicleidowner);
        
MsgF(playeridNovoA"[ > ] O dono desse veнculo й: {FFFFFF}'%s'"owner);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P{00CED1} estб vendo quem й o dono do veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"deletar"true))
    {
        
DestroyWorldVehicle(vehicleid);
        
MsgF(playeridRED"[x] Veнculo %d foi deletado!"vehicleid);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P{00CED1} deletou o veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"respawn"true))
    {
        
RespawnVehicle(vehicleid);
        
MsgF(playeridRED"[x] Veнculo %d foi respawnado!"vehicleid);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P {00CED1}respawnou o veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"resetar"true))
    {
        
ResetVehicle(vehicleid);
        
MsgF(playeridRED"[x] Veнculo %d foi resetado!"vehicleid);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P {00CED1}resetou o veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"trancar"true))
    {
        
SetVehicleExternalLock(vehicleid1);
        
MsgF(playeridRED"[x] Veнculo %d foi trancado!"vehicleid);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P {00CED1}trancou o veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"destrancar"true))
    {
        
SetVehicleExternalLock(vehicleid0);
        
MsgF(playeridRED"[x] Veнculo %d foi destrancado!"vehicleid);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P {00CED1}destrancou o veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"removerchave"true))
    {
        
SetVehicleKey(vehicleid0);
        
MsgF(playeridRED"[x] Veнculo %d teve sua chave removida!"vehicleid);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P{00CED1} removeu a chave do veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else 
Msg(playeridNovoA"[ > ] Uso correto: /veiculo /ir/entrar/dono/deletar/respawn/resetar/trancar/destrancar/removerchave] [id]");
    return 
1;

Reply
#4

Do you check on command received callback if the returned value is X and send the error message there? You return the value 4 if the vehicle does not exist. You can replace it with another (available) value and return the error "Vehicle not found" if the returned value is that.

If this is not the case, you need to post more information about the command processor as I am clueless.
Reply
#5

Quote:
Originally Posted by Undef1ned
Посмотреть сообщение
According to this "veiculo [3]" I imagine that there are 3 vehicle slots for each player, then:

PHP код:
ACMD:veiculo(playeridparams[])
{
    if(!
IsPlayerOnAdminDuty(playerid) && GetPlayerAdminLevel(playerid) < STAFF_LEVEL_LEAD) return 0;
    new 
command[24], vehicleid;
    if(
sscanf(params"s[24]d"commandvehicleid)) return Msg(playeridNovoA"[ > ] Uso correto: /veiculo /ir/entrar/dono/deletar/respawn/resetar/trancar/destrancar/removerchave] [id]");
    if(
vehicleid || vehicleid 3) return SendClientMessage(playerid, -1"Error: vehicle slots 1 - 3.");
    if(!
IsValidVehicle(vehicleid)) return 0;
    if(!
strcmp(command"puxar"true))
    {
        new 
Float:xFloat:yFloat:z;
        
GetPlayerPos(playeridxyz);
        
PutPlayerInVehicle(playeridvehicleid0);
        
SetVehiclePos(vehicleidxyz);
        
SetPlayerPos(playeridxy2);
        
SetCameraBehindPlayer(playerid);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P{00CED1} puxou o veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"ir"true))
    {
        new 
Float:xFloat:yFloat:z;
        
GetVehiclePos(vehicleidxyz);
        
SetPlayerPos(playeridxyz);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P{00CED1} foi atй o veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"entrar"true))
    {
        
PutPlayerInVehicle(playeridvehicleid0);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P{00CED1} usou o comando de entrar no veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"dono"true))
    {
        new 
owner[MAX_PLAYER_NAME];
        
GetVehicleOwner(vehicleidowner);
        
MsgF(playeridNovoA"[ > ] O dono desse veнculo й: {FFFFFF}'%s'"owner);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P{00CED1} estб vendo quem й o dono do veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"deletar"true))
    {
        
DestroyWorldVehicle(vehicleid);
        
MsgF(playeridRED"[x] Veнculo %d foi deletado!"vehicleid);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P{00CED1} deletou o veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"respawn"true))
    {
        
RespawnVehicle(vehicleid);
        
MsgF(playeridRED"[x] Veнculo %d foi respawnado!"vehicleid);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P {00CED1}respawnou o veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"resetar"true))
    {
        
ResetVehicle(vehicleid);
        
MsgF(playeridRED"[x] Veнculo %d foi resetado!"vehicleid);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P {00CED1}resetou o veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"trancar"true))
    {
        
SetVehicleExternalLock(vehicleid1);
        
MsgF(playeridRED"[x] Veнculo %d foi trancado!"vehicleid);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P {00CED1}trancou o veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"destrancar"true))
    {
        
SetVehicleExternalLock(vehicleid0);
        
MsgF(playeridRED"[x] Veнculo %d foi destrancado!"vehicleid);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P {00CED1}destrancou o veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else if(!
strcmp(command"removerchave"true))
    {
        
SetVehicleKey(vehicleid0);
        
MsgF(playeridRED"[x] Veнculo %d teve sua chave removida!"vehicleid);
        
MsgAdminsF(1NovoA"{00CED1}[ > ] O(a) administrador(a) %P{00CED1} removeu a chave do veнculo de ID {FFFFFF}%d !"playeridvehicleid);
        return 
1;
    }
    else 
Msg(playeridNovoA"[ > ] Uso correto: /veiculo /ir/entrar/dono/deletar/respawn/resetar/trancar/destrancar/removerchave] [id]");
    return 
1;

The [3] means that the command is only for admins of level 3 or higher..

However the IsValidVehicle part is correct, simply check if the given id ("vehicleid") is valid, and if not, send an error and return.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)