CheckPh
#1

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.
Reply
#2

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?
Reply
#3

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.
Reply
#4

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.
Reply
#5

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.
Reply
#6

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.
Reply
#7

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.
Reply
#8

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.
Reply
#9

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.
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)