Help: problem unknown vehicle
#1

the problem is the following:

when i type example.. /v vehiclenotfound281

not send the message "Name not found"

but spawn the vehicle... last spawned

code:

pawn Код:
if(isnull(params)) return SendClientMessage(playerid, -1, "use /v vehicle or id");

    sscanf(params, "s[24]", temp_str);

    if(IsNumeric(temp_str))
    {
        temp_id = strval(temp_str) - 400;
    }
    else
    {
        for(new i; i < sizeof(vehicle_list); i++)
        {
            if(strfind(vehicle_list[i], temp_str, true) != -1)
            {
                temp_id = i;

                break;
            }
        }
    }
    if(temp_id < 0 || temp_id > 211) return SendClientMessage(playerid, -1, "Name not found");

    SendClientMessage(playerid, -1, "vehicle spawned!");


    GetPlayerPos(playerid, stat[0], stat[1], stat[2]), GetPlayerFacingAngle(playerid, stat[3]);

    DestroyVehicle(user_vehicle[playerid]);

    if(color[0] == -1) color[0] = random(125);
    if(color[1] == -1) color[1] = random(125);

    user_vehicle[playerid] = CreateVehicle(temp_id + 400, stat[0], stat[1], stat[2], stat[3], color[0], color[1], -1);
    PutPlayerInVehicle(playerid, user_vehicle[playerid], 0);
Reply
#2

Thanks but.. my code is only command .. not a dialog
Reply
#3

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
Well, if you want to spawn the first matched vehicle simple remove the dialog, break the loop at the first match and return the ID:

pawn Код:
FormatSearchDialog(playerid, query[])
{
    new id;

    if(IsNumeric(query))
    {
        id = strval(query);
        if(400 <= id <= 611)return id;
        else if(0 <= id <= 211)return id+400;
    }
    else
    {
        if(strlen(query) < 2)return -1;
        while(id < 212)
        {
            if(strfind(VehicleNames[id], query, true) != -1)
                return id+400;

            id++;
        }
    }
    return 0;
}
yes.. but my problem is when i type example.. /v vehiclenotfound281 not send the message "Name not found" ...
Reply
#4

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
That's what the return values are for, read my posts again! I've added an example.
OK, i tried...

give me a error. symbol is never used: "playerid"

code:

pawn Код:
// in the command
    if(isnull(params)) return SendClientMessage(playerid, -1, "usage /v name or id");

    sscanf(params, "s[24]", temp_str);

    new result = FormatSearchDialog(playerid, params);
    if(result == -1) return SendClientMessage(playerid, -1, "the query is too short"); // Tell the user the query is too short
    else if(result == 0) return SendClientMessage(playerid, -1, "no match was found"); // Tell the user no match was found
    else if(400 <= result <= 611)
    {
        SendClientMessage(playerid, -1, "vehicle spawned");

        GetPlayerPos(playerid, stat[0], stat[1], stat[2]), GetPlayerFacingAngle(playerid, stat[3]);

        DestroyVehicle(user_vehicle[playerid]);

        if(color[0] == -1) color[0] = random(125);
        if(color[1] == -1) color[1] = random(125);

        user_vehicle[playerid] = CreateVehicle(temp_id + 400, stat[0], stat[1], stat[2], stat[3], color[0], color[1], -1);

        PutPlayerInVehicle(playerid, user_vehicle[playerid], 0);
    }

// function
FormatSearchDialog(playerid, query[])
{
    new id;

    if(IsNumeric(query))
    {
        id = strval(query);
        if(400 <= id <= 611)return id;
        else if(0 <= id <= 211)return id+400;
    }
    else
    {
        if(strlen(query) < 2)return -1;
        while(id < 212)
        {
            if(strfind(VehicleNames[id], query, true) != -1)
                return id+400;

            id++;
        }
    }
    return 0;
}

// isnumeric
IsNumeric(text[])
{
    for(new i, j = strlen(text); i < j; i++)
    {
        if(text[i] < '0' || text[i] > '9')

        return 0;
    }

    return 1;
}
Reply
#5

??
Reply
#6

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
That is from my first example, and "Symbol is never used" is a warning not an error.
Just remove it from the function header.
yes i have tried to remove the playerid.. but in game don't work

pawn Код:
// in the command
    if(isnull(params)) return SendClientMessage(playerid, -1, "usage /v name or id");

    sscanf(params, "s[24]", temp_str);

    new result = FormatSearchDialog(params);
    if(result == -1) return SendClientMessage(playerid, -1, "the query is too short"); // Tell the user the query is too short
    else if(result == 0) return SendClientMessage(playerid, -1, "no match was found"); // Tell the user no match was found
    else if(400 <= result <= 611)
    {
        SendClientMessage(playerid, -1, "vehicle spawned");

        GetPlayerPos(playerid, stat[0], stat[1], stat[2]), GetPlayerFacingAngle(playerid, stat[3]);

        DestroyVehicle(user_vehicle[playerid]);

        if(color[0] == -1) color[0] = random(125);
        if(color[1] == -1) color[1] = random(125);

        user_vehicle[playerid] = CreateVehicle(temp_id + 400, stat[0], stat[1], stat[2], stat[3], color[0], color[1], -1);

        PutPlayerInVehicle(playerid, user_vehicle[playerid], 0);
    }

// function
FormatSearchDialog(query[])
{
    new id;

    if(IsNumeric(query))
    {
        id = strval(query);
        if(400 <= id <= 611)return id;
        else if(0 <= id <= 211)return id+400;
    }
    else
    {
        if(strlen(query) < 2)return -1;
        while(id < 212)
        {
            if(strfind(VehicleNames[id], query, true) != -1)
                return id+400;

            id++;
        }
    }
    return 0;
}

// isnumeric
IsNumeric(text[])
{
    for(new i, j = strlen(text); i < j; i++)
    {
        if(text[i] < '0' || text[i] > '9')

        return 0;
    }

    return 1;
}
Reply
#7

?
Reply
#8

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
You are using the wrong variables from your old code. You don't need "temp_str" or "temp_id", you use "params" as the query and "result" as the ID.

You also don't need sscanf as you already have an isnull check and you aren't splitting the string (What sscanf is designed for)

And the "result" variable will already be a vehicle ID so no need to add 400 to it.
wow thanks! , i solved the problem
Reply
#9

edit: question.. how to get with your function the name of the vehicle..

i tried this but dosent work...

pawn Код:
new
            string[128];

        format(string, sizeof(string), "* You have created new vehicle \"%s\" (ID:%d)", vehicle_list[result], result);

        SendClientMessage(playerid, -1, string);
Reply
#10

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
Well the result will be a number from 400 to 611 if a vehicle is found, so that's an offset from 0 of 400. And I bet your vehicle list is 0 to 211. So simply take 400 from the result when you use it in the array.
mhm i tried this, i have added + 400, but dosent work

PHP код:
new
    
string[128];
format(stringsizeof(string), "* You have created new vehicle \"%s\" (ID:%d)"vehicle_list[result 400], result);
SendClientMessage(playerid, -1string); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)