SA-MP Forums Archive
Command is not working - 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: Command is not working (/showthread.php?tid=605176)



Command is not working - Antoniohl - 15.04.2016

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;
}



Re: Command is not working - SyS - 15.04.2016

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)


Re: Command is not working - Konstantinos - 15.04.2016

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.


Re: Command is not working - SyS - 15.04.2016

deleted


Re: Command is not working - Antoniohl - 15.04.2016

Thanks very much.