SA-MP Forums Archive
Vehicle Names Part - 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 Names Part (/showthread.php?tid=532626)



Vehicle Names Part - hiok - 19.08.2014

Hello,

You all know the 'Part of Name' features in commands.

What I want to do is: Part of Model

I have an array with model names and now I need to find the best fitting name.

Example:

I enter "Sul" in the command then it should return "Sultan" as it fits best.
Or for "L" it should return "Landstalker" as that's the first Model that fits best.


Re: Vehicle Names Part - Jefff - 19.08.2014

pawn Код:
FindModelByName(const name[], len = 0)
{
    len = strlen(name);
    for(new i=0; i != sizeof(VehicleNames); i++)
    {
        if(!strcmp(VehicleNames[i], name, true, len))
            return i + 400;
    }
    return INVALID_VEHICLE_ID;
}

new Model = FindModelByName("Sul");
if(Model != INVALID_VEHICLE_ID)
{
    CreateVehicle(Model, ....);
}
else
{
//error not found
}



Re: Vehicle Names Part - hiok - 20.08.2014

This won't work in case we enter 'ultan'.


Re: Vehicle Names Part - Sawalha - 20.08.2014

Just remove the "length" parameter , So it would be:
pawn Код:
FindModelByName(const name[])
{
    for(new i=0; i != sizeof(VehicleNames); i++)
    {
        if(strfind(VehicleNames[i], name, true) != -1)
        return i + 400;
    }
    return -1; // same as INVALID_VEHICLE_ID , no problems.
}
I just replaced strcmp with strfind, and remove the length parameter, test it now