/veh cmd
#1

Hey all
I wanna ask you can I make that vehicle command if some1 write wrong vehicle ID or Name to send him two diffrent error messages for vehicle ID and name?

thanks,
BGEdition
Reply
#2

You have to check if the number input after /veh [id] is more/less than the standard vehicle ID's. So, when the player uses /veh 896, it will show error. Please show us your /veh CMD so we can modify it out.
Reply
#3

This is my command. It works fine for now!
Код:
CMD:veh(playerid, params[]) {
	new Vehicle[50], VehicleID, Color[2], Siren, Float:pX, Float:pY, Float:pZ, Float:pA, string[512];
	format(string, sizeof(string), "[USAGE]: /veh [VehicleName/VehicleID] [Color 1 (optional)] [Color 2 (optional)] [Siren 0/1 (optional)]");
	if(sscanf(params, "s[50]D(0)D(0)D(0)", Vehicle, Color[0], Color[1], Siren)) return SendClientMessage(playerid, -1, string);
	VehicleID = GetVehicleIDFromName(Vehicle);
	if(VehicleID == -1) {
		VehicleID = strval(Vehicle);
		format(string, sizeof(string), "[WARNING]: Invalid vehicle ID! To find vehicle's ID use /vid.");
		if(VehicleID < 400 || VehicleID > 611) return SendClientMessage(playerid, -1, string);
	}
	if(Siren < 0 || Siren > 1) return SendClientMessage(playerid, -1, "[INFO]: Add siren 0/1. 0 - No, 1 - Yes.");
	if(IsPlayerInAnyVehicle(playerid) == 1) return SendClientMessage(playerid, -1, "[WARNING]: You are now in vehicle. Please exit and then spawn new one!");
	GetPlayerPos(playerid, pX, pY, pZ);
	GetPlayerFacingAngle(playerid, pA);
	DestroyVehicle(SpawnedVehicle[playerid]);
	SpawnedVehicle[playerid] = CreateVehicle(VehicleID, pX, pY, pZ + 0.5, pA, Color[0], Color[1], -1, Siren);
	LinkVehicleToInterior(SpawnedVehicle[playerid], GetPlayerInterior(playerid));
	SetVehicleVirtualWorld(SpawnedVehicle[playerid], GetPlayerVirtualWorld(playerid));
	PutPlayerInVehicle(playerid, SpawnedVehicle[playerid], 0);
	format(string, sizeof(string), "[INFO]: You successfully spawned \"%s\" (ID: %d). Enjoy it!", GetVehicleName(GetPlayerVehicleID(playerid)), GetVehicleIDFromName(GetVehicleName(GetPlayerVehicleID(playerid))));
	SendClientMessage(playerid, -1, string);
	return 1;
}
But I want one more error message which will show - Error for invalid vehicle's NAME
Reply
#4

I see you already got the message there:

pawn Код:
format(string, sizeof(string), "[WARNING]: Invalid vehicle ID! To find vehicle's ID use /vid.");
        if(VehicleID < 400 || VehicleID > 611) return SendClientMessage(playerid, -1, string);
And since you're using GetVehicleIDFromName, it means you're using vehicle names already. Just change string format, and you're ready to go, unless I didn't get your question right.
Reply
#5

Код:
CMD:veh(playerid, params[]) {
	new Vehicle[50], VehicleID, Color[2], Siren, Float:pX, Float:pY, Float:pZ, Float:pA, string[512];
	format(string, sizeof(string), "[USAGE]: /veh [VehicleName/VehicleID] [Color 1 (optional)] [Color 2 (optional)] [Siren 0/1 (optional)]");
	if(sscanf(params, "s[50]D(0)D(0)D(0)", Vehicle, Color[0], Color[1], Siren)) return SendClientMessage(playerid, -1, string);
	VehicleID = GetVehicleIDFromName(Vehicle);
	if(VehicleID == -1) {
		VehicleID = strval(Vehicle);
	}
	format(string, sizeof(string), "[WARNING]: Invalid vehicle ID! To find vehicle's ID use /vid.");
	if(VehicleID < 400 || VehicleID > 611) return SendClientMessage(playerid, -1, string);
	if(Siren < 0 || Siren > 1) return SendClientMessage(playerid, -1, "[INFO]: Add siren 0/1. 0 - No, 1 - Yes.");
	if(IsPlayerInAnyVehicle(playerid) == 1) return SendClientMessage(playerid, -1, "[WARNING]: You are now in vehicle. Please exit and then spawn new one!");
	GetPlayerPos(playerid, pX, pY, pZ);
	GetPlayerFacingAngle(playerid, pA);
	DestroyVehicle(SpawnedVehicle[playerid]);
	SpawnedVehicle[playerid] = CreateVehicle(VehicleID, pX, pY, pZ + 0.5, pA, Color[0], Color[1], -1, Siren);
	LinkVehicleToInterior(SpawnedVehicle[playerid], GetPlayerInterior(playerid));
	SetVehicleVirtualWorld(SpawnedVehicle[playerid], GetPlayerVirtualWorld(playerid));
	PutPlayerInVehicle(playerid, SpawnedVehicle[playerid], 0);
	format(string, sizeof(string), "[INFO]: You successfully spawned \"%s\" (ID: %d). Enjoy it!", GetVehicleName(GetPlayerVehicleID(playerid)), GetVehicleIDFromName(GetVehicleName(GetPlayerVehicleID(playerid))));
	SendClientMessage(playerid, -1, string);
	return 1;
}
Reply
#6

@iPrivate Yes I have one message that shows to player when that player is wroten invalid ID - Invalid vehicle ID. To find vehicle's ID use /vid.
But I want and second message that will shows to player when that player is wroten INVALID VEHICLE'S NAME - Invalid vehicle name. Look at /vname for all names of vehicles. or sth other

@bondowocopz Same
Reply
#7

Something like that should work:
PHP код:
if ('0' <= Vehicle[0] <= '9')
{
    
VehicleID strval(Vehicle);
    if (!(
400 <= VehicleID <= 611)) return SendClientMessage(playerid, -1"Invalid model ID");
}
else
{
    
VehicleID GetVehicleIDFromName(Vehicle);
    if(
VehicleID == -1) return SendClientMessage(playerid, -1"Invalid vehicle name");

Reply
#8

@Konstantinos Can you explain the first line of your code?
Reply
#9

Sure.

It checks if the first character of the string is between 0 and 9 thus numeric.
Reply
#10

Sloved
@Konstantinos Ok thank you I can't +rep you and sorry for that. the reason: "You must spread some Reputation around before giving it to Konstantinos again". Again SORRY
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)