SA-MP Forums Archive
Help please - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help please (/showthread.php?tid=523860)



Help please - alinategh - 04.07.2014

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.


Re: Help please - Dziugsas - 04.07.2014

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.


Re: Help please - alinategh - 04.07.2014

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


Re: Help please - alinategh - 04.07.2014

please someone help me, i really need this.


Re: Help please - Dziugsas - 04.07.2014

its the same way as for players...