Command is not working
#1

Can you tell me what's wrong with this command?, actually it only works with one vehicle, it's suppose to find a vehicle with their plate number.

Код:
CMD:trackcar(playerid, params[])
{
	static
	    string[64];

	if (GetFactionType(playerid) != FACTION_POLICE)
		return SendErrorMessage(playerid, "You're not authorized to use this command.");

	if (!IsPlayerInAnyVehicle(playerid))
	    return SendErrorMessage(playerid, "You're not in any vehicle.");

	if (!IsACruiser(GetPlayerVehicleID(playerid)))
	    return SendErrorMessage(playerid, "This vehicle doesn't have a MDC.");

	if (sscanf(params, "s[64]", string))
	    return SendSyntaxMessage(playerid, "/trackcar [platenumber]");

	for (new id = 1; id < MAX_VEHICLES; id ++)
	{
		printf("%s", string);
		if (IsValidVehicle(id))
		{
			if (!strcmp(CarData[id][carNumberPlate], string, true))
			{
				if (!strcmp(CarData[id][carNumberPlate], "Unregistered", true))
				{
				   	SendErrorMessage(playerid, "This vehicle is not registered.");
				}
				else
				{
					SendServerMessage(playerid, "The MDC Satellite System is now trying to track %s[%s]...", ReturnVehicleModelName(CarData[id][carModel]), string);
				   	PlayerData[playerid][pMDCVehicle] = id;
				 	PlayerData[playerid][pTrackTime] = 3;
				}
				printf("%s", CarData[id][carNumberPlate]);
				return 1;
			}
			else
			{
				SendErrorMessage(playerid, "You have specified an invalid vehicle Number.");
				return 1;
			}
		}
	}
	return 1;
}
Reply
#2

PHP код:
if (!strcmp(CarData[id][carNumberPlate], stringtrue)) 
(checks they are not equal)
does that supposed to be false? (as you used !)
PHP код:
if (!strcmp(CarData[id][carNumberPlate], stringfalse)) 
(checks if they are equal)
Reply
#3

What your code does is to return an error that the plate was not found even if it did not look every single vehicle.

pawn Код:
CMD: trackcar(playerid, params[])
{
    if(GetFactionType(playerid) != FACTION_POLICE) return SendErrorMessage(playerid, "You're not authorized to use this command.");
    if(!IsPlayerInAnyVehicle(playerid)) return SendErrorMessage(playerid, "You're not in any vehicle.");
    if(!IsACruiser(GetPlayerVehicleID(playerid))) return SendErrorMessage(playerid, "This vehicle doesn't have a MDC.");
    if(isnull(params)) return SendSyntaxMessage(playerid, "/trackcar [platenumber]");
 
    for(new id = 1, j = GetVehiclePoolSize(); id <= j; id++)
    {
        if(IsValidVehicle(id) && !strcmp(CarData[id][carNumberPlate], params, true))
        {
            if(!strcmp(CarData[id][carNumberPlate], "Unregistered", true)) SendErrorMessage(playerid, "This vehicle is not registered.");
            else
            {
                SendServerMessage(playerid, "The MDC Satellite System is now trying to track %s[%s]...", ReturnVehicleModelName(CarData[id][carModel]), params);
                PlayerData[playerid][pMDCVehicle] = id;
                PlayerData[playerid][pTrackTime] = 3;
            }
            return 1;
        }
    }
 
    SendErrorMessage(playerid, "You have specified an invalid vehicle Number.");
    return 1;
}
EDIT: I don't see any reason of checking if it's "Unregistered" as the player won't type it anyway.
Reply
#4

deleted
Reply
#5

Thanks very much.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)