Help please
#1

Hello there, i'm trying to make a command called /buypackage and when player enters it, it shows a dialog to the player and they should enter a number in the text bar. there will be a txt file in scriptsfiles called buypackage.txt and i want to know how to detect if the entered number exists in the file buypackage.txt for example:
There are 3 number in buypackage.txt which is in the scriptfiles folder like this:
13546
35464
53634
So, they are in different lines. However player enters number 13546 and i want it to detect if the entered number exists in buypackage.txt.. How should i do it? if there is any include for it tell me, and how to use that include? I will be thankful oh and also +Rep for the answer.
Reply
#2

Example:

pawn Код:
#define MAX_PACKAGES 20
#define DIALOG_BUY_PACKAGE 1

enum PackInfo
{
    PackNumber[5], // Length of package number will be 5 as you said for ex. 13546 or 35464 or 53634
    PackPrice //You ccould just not use this , its for ex.
}
new PackageInfo[MAX_PACKAGES][PackInfo];
Then you need to make loading and saving system.When youll make it you just simply need to compare it.Like:

pawn Код:
CMD:buypackage(playerid,params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 3, x, y, z)) // the position where player should be
    {
        ShowPlayerDialog(playerid, DIALOG_BUY_PACKAGE, DIALOG_STYLE_INPUT, "Buy package", "Please enter the number of the package", "OK", "Cancel");
    }
    return 1;
}


public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_BUY_PACKAGE:
        {
            if(response)
            {
                if(!IsNumeric(inputtext)) return ShowPlayerDialog(playerid, DIALOG_BUY_PACKAGE, DIALOG_STYLE_INPUT, "Buy package", "You can only write numbers!\nPlease enter the number of the package", "OK", "Cancel");
                for(new p;p < MAX_PACKAGES;p++)
                {
                    if(strval(inputtext) == PackageInfo[p][PackNumber] && GetPlayerMoney(playerid) > PackageInfo[p][PackPrice])
                    {
                        //Do your desired actions here
                    }
                }
            }
        }
    }
    return 1;
}

IsNumeric(const string[])
{
    for (new i = 0, j = strlen(string); i < j; i++)
    {
        if (string[i] > '9' || string[i] < '0') return 0;
    }
    return 1;
}
Just an Example.
Reply
#3

How can it detect if the entered number is a number that exists in scriptfiles/buypackage.txt ?
My question is the loading and saving system, i dunno how to make the loading and saving. I dunno how to load the buypackage.txt number in the script. and how to delete the used number from buypackage.txt
Reply
#4

please someone help me, i really need this.
Reply
#5

its the same way as for players...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)