Vehicle Names Part
#1

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

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
}
Reply
#3

This won't work in case we enter 'ultan'.
Reply
#4

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)