SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 02/02/2015, 11:25 AM   #141
VenomMancer
Gangsta
 
VenomMancer's Avatar
 
Join Date: May 2013
Location: Indonesia (Manado)
Posts: 637
Reputation: 28
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

Linux or windows is usefull for runing samp server with MySQL ?
VenomMancer is offline   Reply With Quote
Old 24/02/2015, 11:55 AM   #142
rainbowPUKE
Little Clucker
 
Join Date: Jan 2015
Location: Under The Sea
Posts: 21
Reputation: 0
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

Quote:
Originally Posted by PowerPC603 View Post
pawn Code:
case 2: //register dialog
        {
            if(!response) return Kick(playerid); //if they clicked Quit, we will kick them
            if(strlen(inputtext) < 6) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Register", "In order to play, you need to register.\nYour password must be at least 6 characters long!", "Register", "Quit");
            //strlen checks a lenght of a string. so if player types their password that is lower than 6, we tell them; Your password must be at least 6 characters long!
            WP_Hash(pInfo[playerid][Password], 129, inputtext); //hashing inputtext
            mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `posX` ,`posY`, `posZ`) VALUES ('%e', '%s', '%s', 0, 0, 0, 0.0, 0.0, 0.0)", Name[playerid], pInfo[playerid][Password], IP[playerid]);
            //Now let's create a new row and insert player's information in it
            mysql_tquery(mysql, query, "", "");
            //let's execute the query
        }
    }
When the player registers his account, the data is inserted properly.
BUT the tutorial doesn't have the ID of the player in the database.
Only the player's name, password and IP are inserted.
The table auto-creates the ID in MySQL, but it's not loaded and stays 0 in the script.

When exiting the game, OnPlayerDisconnect tries to update data for ID 0, which doesn't exist.

When the player logs back in (using the code from the tutorial), ALL data is read properly, including the ID.
Therefore it can be saved properly during OnPlayerDisconnect because now the script holds the proper ID of the player to update the data.




The code above should become (adjusted the query here):
pawn Code:
case 2: //register dialog
        {
            if(!response) return Kick(playerid); //if they clicked Quit, we will kick them
            if(strlen(inputtext) < 6) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Register", "In order to play, you need to register.\nYour password must be at least 6 characters long!", "Register", "Quit");
            //strlen checks a lenght of a string. so if player types their password that is lower than 6, we tell them; Your password must be at least 6 characters long!
            WP_Hash(pInfo[playerid][Password], 129, inputtext); //hashing inputtext
            mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `posX` ,`posY`, `posZ`) VALUES ('%e', '%s', '%s', 0, 0, 0, 0.0, 0.0, 0.0)", Name[playerid], pInfo[playerid][Password], IP[playerid]);
            //Now let's create a new row and insert player's information in it
            mysql_tquery(mysql, query, "OnAccountCreate", "i", playerid);  // Adjusted the query
            //let's execute the query
        }
    }


Then use code like this:
pawn Code:
// This custom callback is used after creating a new account (playername and password are inserted, but the ID must be loaded now to reference the player later on using this ID)
forward OnAccountCreate(playerid);
public OnAccountCreate(playerid)
{
    // Setup local variables
    new Query[128];

    // Construct the query to get the new player's SQLID for later referencing and execute it
    mysql_format(SQL_db, Query, sizeof(Query), "SELECT ID FROM %s WHERE PlayerName = '%e' LIMIT 1", table_playerdata, APlayerData[playerid][PlayerName]);
    mysql_tquery(SQL_db, Query, "OnAccountCreateLoadID", "i", playerid);

    return 1;
}

// This custom callback is used after creating a new account and executing the query to load the new player's SQLID for later referencing
forward OnAccountCreateLoadID(playerid);
public OnAccountCreateLoadID(playerid)
{
    // Store the loaded ID
    APlayerData[playerid][SQLID] = cache_get_field_content_int(0, "ID", SQL_db);

    return 1;
}

Of course, adjust database names, variablenames and mysql-connectionhandle to the proper values in your script, as this was literally taken out of my script.
I am pretty new to mysql, and have been following this tutorial to learn. I am having the issue regarding stats not saving. I read over your advice and code, but am a little confused I think with the differing variablenames etc. Can anyone help me out and put it in aspect with the variables etc used in this tut.

I would really appreciate it.
rainbowPUKE is offline   Reply With Quote
Old 05/03/2015, 03:24 AM   #143
AchievementMaster360
Huge Clucker
 
AchievementMaster360's Avatar
 
Join Date: Apr 2012
Location: New York, United States
Posts: 233
Reputation: 24
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

So everything compiled smoothly and i have the database setup and the server can connect to it with no problem. The only issue I'm facing at the moment is when i hop in game the login and registration dialog does not pop-up. Any ideas?

Console:

Database:
AchievementMaster360 is offline   Reply With Quote
Old 09/03/2015, 11:05 AM   #144
AroseKhanNiazi
High-roller
 
AroseKhanNiazi's Avatar
 
Join Date: Jan 2014
Location: Pakistan
Posts: 1,352
Reputation: 78
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

Just asking is this the best tutorial to learn mysql (Threaded one) ? I don't know anything about mysql, and now i am gonna get from y_ini to mysql.
AroseKhanNiazi is offline   Reply With Quote
Old 21/03/2015, 10:26 AM   #145
Dorito
Little Clucker
 
Join Date: Jan 2014
Posts: 36
Reputation: 1
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

How would you go about spawning the player, SetSpawnInfo and SpawnPlayer?
Dorito is offline   Reply With Quote
Old 30/03/2015, 02:57 PM   #146
BR3TT
Big Clucker
 
Join Date: Sep 2012
Location: Australia
Posts: 101
Reputation: 14
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

Quote:
Originally Posted by AchievementMaster360 View Post
So everything compiled smoothly and i have the database setup and the server can connect to it with no problem. The only issue I'm facing at the moment is when i hop in game the login and registration dialog does not pop-up. Any ideas?

Console:

Database:
I'm the same as this, I've got everything running, server's got no errors or warnings, but no dialog box comes up when I enter the game. Any assistance?
BR3TT is offline   Reply With Quote
Old 30/03/2015, 04:01 PM   #147
BleverCastard
Gangsta
 
Join Date: Dec 2011
Posts: 845
Reputation: 43
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

Quote:
Originally Posted by BR3TT View Post
I'm the same as this, I've got everything running, server's got no errors or warnings, but no dialog box comes up when I enter the game. Any assistance?
Both of you aren't connected to the database correctly. Have you inserted the correct info in mysql_connect?
__________________
Quote:
Originally Posted by Mauzen View Post
You earned 8000 euros by luring credulous people into your gingerbread house of paid-click reflinks?
BleverCastard is offline   Reply With Quote
Old 30/03/2015, 11:56 PM   #148
BR3TT
Big Clucker
 
Join Date: Sep 2012
Location: Australia
Posts: 101
Reputation: 14
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

Disregard I got this to work. Thanks for the help
BR3TT is offline   Reply With Quote
Old 19/04/2015, 03:25 PM   #149
naveen
Big Clucker
 
naveen's Avatar
 
Join Date: Apr 2015
Location: India
Posts: 82
Reputation: 0
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

bro i have used this coding in my GM BUT it shows an error like cant read from <a_mysql >...?
what is the solution for this
naveen is offline   Reply With Quote
Old 19/04/2015, 03:28 PM   #150
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,846
Reputation: 1399
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

Quote:
Originally Posted by naveen View Post
bro i have used this coding in my GM BUT it shows an error like cant read from <a_mysql >...?
what is the solution for this
http://wiki.sa-mp.com/wiki/Errors_Li...2.3Cfile.3E.22
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Baffled - mySQL Vehicle Loading (threaded queries) Moglizorz. Server Support 0 18/05/2013 02:14 AM
Comparing password [MySQL Threaded queries] emokidx Scripting Help 3 02/04/2013 01:07 PM
MySQL Threaded Queries CONTROLA Scripting Help 4 25/11/2012 04:02 PM
Threaded Queries - BlueG's MYSQL Plugin R7 Ballu Miaa Scripting Help 3 05/11/2012 06:36 PM
[Help] BlueG's MySQL Plugin R7 - Threaded Queries Maxips2 Scripting Help 4 19/10/2012 10:35 AM


All times are GMT. The time now is 01:06 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.