Registered User Count [SQLite]
#1

hello everyone,

As I'm trying to create something Like that so When a User registers it should send a Message to everyone regarding that
Derp has registered making the server have total 9 players
But i'm not quite sure on how can i make one like this :3
I'm willing to give you Any Piece of code you want Relating to my Registration System
Here's the part where registration takes place
pawn Код:
if ( dialogid == Register2 )
    {
        if ( response )
        {
            new
                String[ 245 ]
            ;

            if ( strlen( inputtext ) == 0)
                return ShowDialog( playerid, Register2, DIALOG_STYLE_PASSWORD, "{FFFFFF}Enter Password", ""#COL_RED"No password entered!\n{FFFFFF}Please enter your desired password:", "Enter", "");
            if ( strlen( inputtext ) < 4 || strlen( inputtext ) > 20)
                return ShowDialog( playerid, Register2, DIALOG_STYLE_PASSWORD, "{FFFFFF}Enter Password", ""#COL_RED"Minimum password length is 4 and maximum is 20!\n{FFFFFF}Please enter your desired password:", "Enter", "");


            if ( BUD::RegisterName( PlayerName2( playerid ), inputtext ) )
            {
                new Date[5],DateStr[ 50 ];
                getdate( Date[ 0 ], Date[ 1 ], Date[ 2 ] );
                gettime( Date[ 3 ], Date[ 4 ]);
                format( DateStr, 50, "%i/%i/%i %d:%d", Date[ 2 ], Date[ 1 ], Date[ 0 ], Date[ 3 ], Date[ 4 ] );

                new iUID = BUD::GetNameUID( PlayerName2( playerid ) );
                BUD::MultiSet( iUID, "ss", "Password", inputtext, "Registered", DateStr );

                format( String, sizeof( String ),   ""#COL_GREEN"Account succesfully created!\n\n\
                                                    "#COL_LIGHTBLUE"Account: {FFFFFF}%s\n\
                                                    "#COL_LIGHTBLUE"Password: {FFFFFF}%s\n\
                                                    "#COL_LIGHTBLUE"Account id: {FFFFFF}%d\n\
                                                    Remember! Don't give your password to anyone!\n\n\
                                                    {FFFFFF}Would you like to login?",PlayerName2( playerid ),inputtext,iUID+2 );
                ShowDialog( playerid, Register3, BOX, "{FFFFFF}Account created!", String, "Login", "");
                foreach(Player, Admin)
                {
                    if ( P_DATA[ Admin ][ P_Level ] > 2 )
                    {
                        FormMessage( Admin, -1, "> "COL_ORANGE"%s{FFFFFF} registered an account!", PlayerName2( playerid ) );
                    }
                }
            }
            else
            {
                foreach(Player, Admin)
                {
                    if ( P_DATA[ Admin ][ P_Level ] > 2 )
                    {
                        FormMessage( Admin, -1, "> "COL_ORANGE"%s{FFFFFF} failed to register an account!", PlayerName2( playerid ) );
                    }
                }
            }
        }
    }
Reply
#2

Quote:
Originally Posted by SsHad
As I'm trying to create something Like that so When a User registers it should send a Message to everyone regarding that
Derp has registered making the server have total 9 players
ahh, BUD. uid is a primary key and increments whenever a new record is added. when the player register, simply get his uid (BUD::GetNameUID) format the string and send the message.
Reply
#3

Well , Sorry As i'm learning SQLite I'm not quite sure on how can i implement it
Can you please Provide a Basic Example of this
EDIT:
I tried the following code as an Example but it gave me an error
pawn Код:
new nameplaerr[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1];
                BUD::GetNameUID( nameplaerr[], sizeof(nameplaerr));
                 format(string, sizeof(string), "%s has joined the server.", nameplaerr);
                 SendClientMessageToAll(0xC4C4C4FF, string);
Код:
error 029: invalid expression, assumed zero
P.S I've never worked with BUD before :P

-thanks!
Reply
#4

you can use COUNT in sqlite like this
pawn Код:
new DBResult:Answer;
        Answer = BUD::RunQuery("SELECT COUNT(*) FROM `users`",true);
        db_get_field(Answer,0,string,sizeof(string));
        RegAccounts = strval(string);
Reply
#5

And How can it give a Message to everyone, as I've stated in my first post!
Reply
#6

by using format and SendClientMessageToAll, this is scripting help section not a script for me section
Reply
#7

From my opinion, The only way i know is

1. Create a variable.
2. Increase the variable value ( ++; ) when player registers.
3. Save the variable in the database.
4. Call the variable in Send Client Message when players registers.
Reply
#8

Why don't you create an value for registered ID? Registered ID will be assign to the player when they register. Then you can simple place your Registered ID variable, that's it!
Reply
#9

Quote:
Originally Posted by Champ
Посмотреть сообщение
From my opinion, The only way i know is

1. Create a variable.
2. Increase the variable value ( ++; ) when player registers.
3. Save the variable in the database.
4. Call the variable in Send Client Message when players registers.
WHY??

Quote:
Originally Posted by iZN
Why don't you create an value for registered ID? Registered ID will be assign to the player when they register. Then you can simple place your Registered ID variable, that's it!
Well, that's what the uid is!

Anyway, cessil's way is better. You can get the uid, but if someone is removed from the database, the latest uid doesn't mean that that's actually how many players are currently registered.
Reply
#10

As prescribed by Cessil i'm using this
pawn Код:
new DBResult:Answer;
                Answer = BUD::RunQuery("SELECT COUNT(*) FROM `users`",true);
                db_get_field(Answer,0,string,sizeof(string));
                iUID = strval(string);
                format(string, sizeof(string), "Total players %s.", Answer);
                SendClientMessageToAll(0xC4C4C4FF, string);
Its returning this
Код:
Total players   3/11/2013 9:37.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)