How to check if there's a number in a string and get that number as a variable
#1

Hi guys,
my problem is that i want to use a function that checks if there's a number inside a string
and i want that number to be stored in a variable so i can use it later but i couldn't do that

here's my code
pawn Код:
format(string, sizeof(string), "%s - ID: %d\n", VehicleName[vModel - 400], v);
ShowPlayerDialog(playerid, vehiclename, DIALOG_STYLE_LIST, "my vehicles", string, "Select", "");
then, in OnDialogResponse, i want to get that integer "ID: %d" but how?

pawn Код:
//OnDialogResponse
case vehiclename:
        {
            if(!response) return 0;
            else
            {
                //i wanna get the integer "ID: %d" here from listitem or something
            }
        }
I need help
thanks in advance !
Reply
#2

anyone guys?
Reply
#3

Quote:
Originally Posted by okaym8
Посмотреть сообщение
anyone guys?
Код:
//OnDialogResponse
case vehiclename:
		{
			if(!response) return 0;
			else
			{
			    new string[600];
                            format(string, sizeof(string), "%d blahbfbfbfbf\n", vehiclename, string);
			}
		}
Reply
#4

Quote:
Originally Posted by MD5
Посмотреть сообщение
Код:
//OnDialogResponse
case vehiclename:
		{
			if(!response) return 0;
			else
			{
			    new string[600];
                            format(string, sizeof(string), "%d blahbfbfbfbf\n", vehiclename, string);
			}
		}
I don't understand what u added

im trying to get the vehicle id so i can use it later to make a vehicle location
because my command is /locatev, it'll show u a dialog with ur vehicles and the vehicle u'll select will be located on the map with a mini-map
i've been struggling to get the id but couldnt
i tried ur code but didnt work
Reply
#5

Where are you getting v from? Are you looping through the players selectable vehicles that are stored in an array?
Reply
#6

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
Where are you getting v from? Are you looping through the players selectable vehicles that are stored in an array?
Yes
Код:
for(new v = 0; v < MaxPersonalVehicles; v++)
	{
		if(playerpersonalVehicle[v])
		{
                         .............
                 }
        }
Reply
#7

pawn Код:
// Inside of the dialog response callback

case vehiclename:
{
    if(!response) {
        DestroyVehiclePVar(playerid); //Making sure to clean up the PVars if they don't actually select anything as well
        return 0;
    }
    else
    {

        new tmp[20];
        format(tmp, sizeof(tmp), "PersonalVehicle_%i", listitem);
        new vehicle_to_make = GetPVarInt(playerid, tmp); // Set it to the model stored in the pvar

        //Destroying the PVars to free up some memory since you aren't using them for anything other than this.
        DestroyVehiclePVar(playerid);


        // Now you can use vehicle_to_make to create the vehicle or what ever you're going to do with it
        return 1;
    }
}


// Where your old loop was

new string[30], larger_string[150], tmp_index;
for(new v = 0; v < MaxPersonalVehicles; v++)
{
    if(playerpersonalVehicle[v])
    {
        format(string, sizeof(string), "PersonalVehicle_%i", tmp_index); // Set our tmp string to the current tmp_index (example: PersonalVehicle_0, PersonalVehicle_1)
        SetPVarInt(playerid, string, playerpersonalVehicle[v]); // Set the PVar named above to the current vehicle index in their playerpersonalvehicle array

        format(string, sizeof(string), "%s - ID: %d\n", VehicleName[vModel - 400], v); // what you had before
        strcat(larger_string, string);

        tmp_index++;
    }
}
ShowPlayerDialog(playerid, vehiclename, DIALOG_STYLE_LIST, "my vehicles", larger_string, "Select", "");


DestroyVehiclePVar(playerid)
{
    new tmp[20];
    for(new i=0; i < MaxPersonalVehicles; ++i)  {
        format(tmp, sizeof(tmp), "PersonalVehicle_%i", i);
        DeletePVar(playerid, tmp);
    }
    return 1;
}
So you're looking for something along the lines of this?


EDIT: Oops, forgot listitem would be different than v. Had to move the PersonalVehicle_%i off of v and put it onto it's own index instead.
Reply
#8

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
pawn Код:
// Inside of the dialog response callback

case vehiclename:
{
    if(!response) {
        DestroyVehiclePVar(playerid); //Making sure to clean up the PVars if they don't actually select anything as well
        return 0;
    }
    else
    {

            //here
                if(listitem == ?)
                {
                            SetPlayerMapIcon(playerid, icon, vehicleInfo[v?][X], vehicleInfo[v][Y], vehicleInfo[v][Z], .... . ... etc);
                          SendClientMessage(playerid, COLOR_YELLOW, "a map icon showing your vehicle has been played on your map.");
                }
        return 1;
    }
}
So you're looking for something along the lines of this?
what i wanted to do is get the vehicle selected by the player in the command when showing the dialog and then check the listitem that the player has chosen so then, the code puts a map icon on the player's minimap to get to his vehicle's position
what i didn't know to do is doing the listitem thing, what should i put there to check for the list item?
"if(listitem == ?)"

then if i get the id which i will name "v" like above, i continue my work

did you get me my friend?
Reply
#9

SetPlayerMapicon(playerid, icon, vehicleInfo[vehicle_to_make][X],vehicleInfo[vehicle_to_make][Y],vehicleInfo[vehicle_to_make][Z], etc);

The way I set it up (make sure you look after the edit) will set vehicle_to_make to the ID you got in the initial loop (when using the command). You can rename vehicle_to_make to whatever you want of course, wasn't sure what you were doing entirely so the naming may seem a bit off. listitem will always equal to the vehicle id if playerpersonalVehicle[v] contains the vehicles ID.



You can think of it doing;

PersonalVehicle_1 is set in the initial loop
if you select the second item (0,1,2 etc) in the list, it will pull an int from PersonalVehicle_1
Reply
#10

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
SetPlayerMapicon(playerid, icon, vehicleInfo[vehicle_to_make][X],vehicleInfo[vehicle_to_make][Y],vehicleInfo[vehicle_to_make][Z], etc);

The way I set it up (make sure you look after the edit) will set vehicle_to_make to the ID you got in the initial loop (when using the command). You can rename vehicle_to_make to whatever you want of course, wasn't sure what you were doing entirely so the naming may seem a bit off. listitem will always equal to the vehicle id if playerpersonalVehicle[v] contains the vehicles ID.



You can think of it doing;

PersonalVehicle_1 is set in the initial loop
if you select the second item (0,1,2 etc) in the list, it will pull an int from PersonalVehicle_1
I thought about that but during the loop, the loop will set every value equal to the listitem value right?

but when on dialogresponse, should i loop again and make a check through all player vehicles or ?
because if i don't, the value of "vehicle_to_make" will be set to the listitem value i think because of the loop
otherwise, should i use "break;"
kinda confused here
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)