SA-MP Forums Archive
??? Vehicle command - 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: ??? Vehicle command (/showthread.php?tid=573411)



??? Vehicle command - bgedition - 07.05.2015

Hello!

I have one question. - What is wrong
Who can tell me what is wrong? The command WORKS fine but it shows me - SERVER: Unknown command.
Код:
CMD:veh(playerid, params[]) {
	new Option[5], SecOption[128], Vehicle[50], VehicleID, Color[2], RespawnTime, Siren[5], Float:X, Float:Y, Float:Z, Float:A, Float:vX, Float:vY, Float:vZ, string[512], vehicleid = GetPlayerVehicleID(playerid);
	if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid, -1, "[ERROR]: You are not connected to the server. :D Please connect. xD");
	format(string, sizeof(string), "[USAGE]: /veh [Name/ID/Spawn]");
	if(sscanf(params, "s[5]S(NULL)[128]", Option, SecOption)) return SendClientMessage(playerid, -1, string);
	if(!strcmp(Option, "spawn", true)) {
		//if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "[WARNING]: You are now in vehicle. Please exit and then spawn new one!");
		format(string, sizeof(string), "[USAGE]: /veh %s [VehicleName/VehicleID] [Color 1 (optional)] [Color 2 (optional)]", Option);
		format(string[88], sizeof(string), "[Respawn time in minutes (optional)] [Siren Yes/No (optional)]");
		if(sscanf(params, "{s[5]}s[50]D(0)D(0)D(0)S(No)[5]", Vehicle, Color[0], Color[1], RespawnTime, Siren)) return SendClientMessage(playerid, -1, string), SendClientMessage(playerid, -1, string[88]);
		VehicleID = GetVehicleIDFromNameEx(Vehicle);
		if('0' <= Vehicle[0] <= '9') {
			VehicleID = strval(Vehicle);
			format(string, sizeof(string), "[WARNING]: Invalid vehicle ID! To find vehicle's ID use \"/veh id\".");
			if(!(400 <= VehicleID <= 611)) return SendClientMessage(playerid, -1, string);
		} else { 
			format(string, sizeof(string), "[WARNING]: Invalid vehicle name! To find vehicle's name use \"/veh name\".");
			if(VehicleID == -1) return SendClientMessage(playerid, -1, string);
		}
		if(!strcmp(Siren, "yes", true)) {
			Siren[4] = 1;
		} else if(!strcmp(Siren, "no", true)) {
			Siren[4] = 0;
		} else return SendClientMessage(playerid, -1, "[INFO]: Add siren: Yes/No.");
		if(IsPlayerInAnyVehicle(playerid)) {
			GetVehicleVelocity(SpawnedVehicle[playerid], vX, vY, vZ);
			GetVehiclePos(SpawnedVehicle[playerid], X, Y, Z);
			GetVehicleZAngle(SpawnedVehicle[playerid], A);
		} else {
			GetPlayerPos(playerid, X, Y, Z);
			GetPlayerFacingAngle(playerid, A);
		}
		DestroyVehicle(SpawnedVehicle[playerid]);
		SpawnedVehicle[playerid] = CreateVehicle(VehicleID, X, Y, Z + 1, A, Color[0], Color[1], RespawnTime*60*1000, Siren[4]);
		LinkVehicleToInterior(SpawnedVehicle[playerid], GetPlayerInterior(playerid));
		SetVehicleVirtualWorld(SpawnedVehicle[playerid], GetPlayerVirtualWorld(playerid));
		PutPlayerInVehicle(playerid, SpawnedVehicle[playerid], 0);
		SetVehicleVelocity(SpawnedVehicle[playerid], vX, vY, vZ);
		format(string, sizeof(string), "[INFO]: You successfully spawned \"%s\" (ID: %d). Enjoy it!", GetVehicleName(vehicleid), GetVehicleIDFromName(GetVehicleName(GetPlayerVehicleID(playerid))));
		SendClientMessage(playerid, -1, string);
	}
	return 1;
}



Re: ??? Vehicle command - Bingo - 07.05.2015

Add
Код:
return 0;



Re: ??? Vehicle command - Konstantinos - 07.05.2015

I'm pretty sure run time error 4 is caused by this line (if not, you'll need to load crashdetect and compile with -d3):
pawn Код:
format(string, sizeof(string), "[INFO]: You successfully spawned \"%s\" (ID: %d). Enjoy it!", GetVehicleName(vehicleid), GetVehicleIDFromName(GetVehicleName(GetPlayerVehicleID(playerid))));

Are you sure that GetVehicleName function needs the vehicleid and not the modelid?


pawn Код:
GetVehicleIDFromName(GetVehicleName(GetPlayerVehicleID(playerid)))
I don't really get what you're trying to do here. You got already your vehicle ID:
pawn Код:
SpawnedVehicle[playerid]
and the modelid:
pawn Код:
GetVehicleModel(SpawnedVehicle[playerid])
Quote:
Originally Posted by Bingo
Посмотреть сообщение
Add
Код:
return 0;
This would also give "unknown command" message even if the command is fine.


Re: ??? Vehicle command - bgedition - 07.05.2015

I found many of these in my console : sscanf warning: String buffer overflow.
I don't know what to do. Can someone tell me, please?


Re: ??? Vehicle command - Konstantinos - 07.05.2015

That's probably because option is 5 and the input is longer than that.

I still don't get why do you use the first options though. Even if you type as an option "Name", "ID" or "Spawn", it will still spawn the vehicle and since you use functions to retrieve the vehicleid from either the name or numeric input, it's still pointless as the IsPlayerConnected check.


Re: ??? Vehicle command - bgedition - 07.05.2015

Sorry for bumping but I fixed it and Thanks Konstantinos


Re: ??? Vehicle command - bgedition - 07.05.2015

One more thing when I set Time for respawn isn't works


Re: ??? Vehicle command - Konstantinos - 07.05.2015

Because if you don't enter a parameter in the command for it, it sets "RespawnTime" to 0 by default (sscanf).
Just change the value of it.


Re: ??? Vehicle command - bgedition - 07.05.2015

@Konstantinos When I'm trying to use it I'm entering 1 for parameter and it should respawn it but it isn't