??? Vehicle command
#1

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;
}
Reply
#2

Add
Код:
return 0;
Reply
#3

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.
Reply
#4

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?
Reply
#5

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.
Reply
#6

Sorry for bumping but I fixed it and Thanks Konstantinos
Reply
#7

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

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.
Reply
#9

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


Forum Jump:


Users browsing this thread: 1 Guest(s)