[HELP]Reading car names with ID's - Read. (giving +1 rep who soolve it for me)
#2

pawn Код:
COMMAND:car(playerid,params[])
{
    if (IsPlayerInAnyVehicle(playerid) != 1)
    {
        //rest of code... sscanf...
        if(isNumeric(params))
        {
            if((vehicle < 400 || vehicle > 611) != true )
            {
                GetPlayerPos(playerid,x,y,z);
                GetPlayerFacingAngle(playerid,r);
                vehicle =  CreateVehicle(vehicle, x, y, z, r, 0, 1, 0);
                PutPlayerInVehicle(playerid,vehicle,0);
            }
            else  SendClientMessage(playerid,-1,"***"#COL_CYAN" ID's: "COL_BLUE"    400-611");
        }
        else
        {
            vehicle = GetVehicleModelIDFromName(params);
            CreateVehicle(vehicle, x, y, z, r, 0, 1, 0);
            PutPlayerInVehicle(playerid,vehicle,0);
        }
        //other code
}
That's not the whole code, just the changes I've made! Add the messages etc by yourself. It should work.
The only thing you need to do is use "isNumeric(params)" and check if it is numeric.
If it is create the ID specified, if not convert the name using GetVehicleModelIDFromName...
Add this:
pawn Код:
stock isNumeric(const string[]) {
    new length=strlen(string);
    if (length==0) return false;
    for (new i = 0; i < length; i++) {
        if (
        (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
        || (string[i]=='-' && i!=0)                                             // A '-' but not at first.
        || (string[i]=='+' && i!=0)                                             // A '+' but not at first.
        ) return false;
    }
    if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
    return true;
}
Reply


Messages In This Thread
[HELP]Reading car names with ID's - Read. (giving +1 rep who soolve it for me) - by aco_SRBIJA - 22.01.2012, 18:03
Re: [HELP]Reading car names with ID's - Read. (giving +1 rep who soolve it for me) - by [XST]O_x - 22.01.2012, 18:45
Re: [HELP]Reading car names with ID's - Read. (giving +1 rep who soolve it for me) - by pop.nicku - 22.01.2012, 18:50
Re: [HELP]Reading car names with ID's - Read. (giving +1 rep who soolve it for me) - by aco_SRBIJA - 23.01.2012, 07:30

Forum Jump:


Users browsing this thread: 1 Guest(s)