SA-MP Forums Archive
Registered User Count [SQLite] - 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: Registered User Count [SQLite] (/showthread.php?tid=473387)



Registered User Count [SQLite] - SsHady - 02.11.2013

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 ) );
                    }
                }
            }
        }
    }



Re: Registered User Count [SQLite] - Ada32 - 02.11.2013

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.


Re: Registered User Count [SQLite] - SsHady - 03.11.2013

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!


Re: Registered User Count [SQLite] - cessil - 03.11.2013

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);



Re: Registered User Count [SQLite] - SsHady - 03.11.2013

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


Re: Registered User Count [SQLite] - cessil - 03.11.2013

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


Re: Registered User Count [SQLite] - Champ - 03.11.2013

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.


Re: Registered User Count [SQLite] - iZN - 03.11.2013

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!


Re: Registered User Count [SQLite] - Ada32 - 03.11.2013

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.


Re: Registered User Count [SQLite] - SsHady - 03.11.2013

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.