SA-MP Forums Archive
CheckPh - 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: CheckPh (/showthread.php?tid=382444)



CheckPh - Why - 03.10.2012

Hello, I am creating a cellphone system and in order to make sure noone get the same number, I have a CheckPh function, but I don't know exactly how to make it.

pawn Код:
stock CheckPh(nmbr)
{
    new string[20];
    new File: file = fopen("phone.cfg", io_read);
    if(!fexist("phone.cfg")) { print("Couldn't find phone.cfg, created file."); fcreate("phone.cfg"); return 0; }
    while(fread(file, string))
    {
        if(strval(nmbr) == ???) // Help me on this please
        {
            fclose(file);
            return 1;
        }
    }
    fclose(file);
    return 0;
}
If someone could help me on that one above I can make the rest, thank you.


Re: CheckPh - Roel - 03.10.2012

Well, before i start helping you with that, I have one question,
Why?

Are you creating a file for only one number?
Where do you use it for?


Re: CheckPh - Why - 03.10.2012

phone.cfg is to list ALL the unusable numbers, however the number will save on a playerfile.

So that means if someone wants to get a phone, it will check through phone.cfg if its already taken.

Say in my phone.cfg is like this:

Код:
5432
55433
14343
23
654341
654342
453256
and someone selects a number that is in the phone.cfg, it will check on CheckPh if the number is taken.


Re: CheckPh - Roel - 03.10.2012

Ah ok, I suggest you to use a simpel random(999999); or something, it will almost never happen, that there are two the same numbers used, and that those two players are at the same time online.

But if you wan't it that way, you should put this at the
Код:
if(strcmp(string, "number", true) == 0)
Remember to set the number format to a string.


Re: CheckPh - Why - 03.10.2012

Quote:
Originally Posted by Roel
Посмотреть сообщение
Ah ok, I suggest you to use a simpel random(999999); or something, it will almost never happen, that there are two the same numbers used, and that those two players are at the same time online.
I thought about that too, but I might need the CheckPh in case I want to make players able to have custom numbers aswell.


Re: CheckPh - SuperViper - 03.10.2012

pawn Код:
stock CheckPh(nmbr)
{
    new string[20];
    new File: file = fopen("phone.cfg", io_read);
    if(!fexist("phone.cfg")) { print("Couldn't find phone.cfg, created file."); fcreate("phone.cfg"); return 0; }
    while(fread(file, string))
    {
        if(strval(string) == nmbr)
        {
            fclose(file);
            return 1;
        }
    }
    fclose(file);
    return 0;
}
I would recommend using MySQL for these kinds of things.


Re: CheckPh - Roel - 03.10.2012

pawn Код:
stock CheckPh(nmbr[])
{
    new string[20];
    new File: file = fopen("phone.cfg", io_read);
    if(!fexist("phone.cfg")) { print("Couldn't find phone.cfg, created file."); fcreate("phone.cfg"); return 0; }
    while(fread(file, string))
    {
        if(strcmp(string,nmbr,true) == 0)// Help me on this please
        {
            return -1; // if Checkph returns false the number is already taken.
        }
    }
    fclose(file);
    return 0;
}
[EDIT] Ofcourse the way SuperViper does it is better.


Re: CheckPh - Why - 03.10.2012

Quote:
Originally Posted by Roel
Посмотреть сообщение
Ah ok, I suggest you to use a simpel random(999999); or something, it will almost never happen, that there are two the same numbers used, and that those two players are at the same time online.

But if you wan't it that way, you should put this at the
Код:
if(strcmp(string, "number", true) == 0)
Remember to set the number format to a string.
Quote:
Originally Posted by SuperViper
Посмотреть сообщение
pawn Код:
stock CheckPh(nmbr)
{
    new string[20];
    new File: file = fopen("phone.cfg", io_read);
    if(!fexist("phone.cfg")) { print("Couldn't find phone.cfg, created file."); fcreate("phone.cfg"); return 0; }
    while(fread(file, string))
    {
        if(strval(string) == nmbr)
        {
            fclose(file);
            return 1;
        }
    }
    fclose(file);
    return 0;
}
I would recommend using MySQL for these kinds of things.
I guess I will go to MySQL later, but right now I'd like to use flatfiles.

Thank you.


Re: CheckPh - SuperViper - 03.10.2012

Quote:
Originally Posted by Roel
Посмотреть сообщение
pawn Код:
stock CheckPh(nmbr[])
{
    new string[20];
    new File: file = fopen("phone.cfg", io_read);
    if(!fexist("phone.cfg")) { print("Couldn't find phone.cfg, created file."); fcreate("phone.cfg"); return 0; }
    while(fread(file, string))
    {
        if(strcmp(string,nmbr,true) == 0)// Help me on this please
        {
            return -1; // if Checkph returns false the number is already taken.
        }
    }
    fclose(file);
    return 0;
}
Won't work. You can't use strcmp with integers. You either need to convert all integers to strings and do a strcmp check, or convert all strings to integers and do a regular == check.


Re: CheckPh - Roel - 03.10.2012

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
Won't work. You can't use strcmp with integers. You either need to convert all integers to strings and do a strcmp check, or convert all strings to integers and do a regular == check.
Yep I saw, i did it to fast lol. because I thought that maybe somebody else was before me, and yea it was haha.
And I indeed with the fact that mysql is much faster is such things like this.