SA-MP Forums Archive
/veh cmd - 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: /veh cmd (/showthread.php?tid=573072)



/veh cmd - bgedition - 04.05.2015

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


Re: /veh cmd - iPrivate - 04.05.2015

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.


Re: /veh cmd - bgedition - 04.05.2015

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


Re: /veh cmd - iPrivate - 04.05.2015

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.


Re: /veh cmd - X337 - 04.05.2015

Код:
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;
}



Re: /veh cmd - bgedition - 04.05.2015

@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


Re: /veh cmd - Konstantinos - 04.05.2015

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




Re: /veh cmd - bgedition - 04.05.2015

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


Re: /veh cmd - Konstantinos - 04.05.2015

Sure.

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


Re: /veh cmd - bgedition - 04.05.2015

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