[Tutorial] MySQL Registration System [Threaded Queries(R33+) + Whirlpool]
#21

Quote:
Originally Posted by PowerPC603
View Post
If some gamemode uses many tables, it would be nice to see the script creating them automatically.
Would you feel fine if a downloaded gamemode needs 10 tables, where every table has more than 10 columns, to create them by hand?
Should the author of the gamemode write a manual about how the tables should be named, which column has which name, content-type (int, float, text, byte, ...), instead of adding a line of code which will be used only once, as you said?

I'd rather have the gamemode create them in such a case, even if that code is executed only once.
Then everyone is certain they have the proper table-name and table-structure and don't have to fiddle around trying to get all tables created manually and testing if the script works using your manually created table.
I created a table with 35 columns a few days ago and it took a while to set it up.



Nice tutorial btw, I'll be using this.
They can create a .txt file with the queries for creating each table. All you will need then is just to copy them, paste them into phpMyAdmin and execute them once.
Reply
#22

There's a better way about getting the player's ID when register.

Set a callback while executing a query with INSERT INTO clause and use cache_insert_id function to get the value (auto increment must be on).

An example (consider of using default values while creating the table):
pawn Code:
mysql_format(mysql, query, sizeof (query), "INSERT INTO `players` (`Username`, `Password`, `IP`) VALUES ('%e', '%s', '%s')", Name[playerid], pInfo[playerid][Password], IP[playerid]);
mysql_tquery(mysql, query, "OnAccountCreate", "i", playerid);
pawn Code:
forward OnAccountCreate(playerid);
public OnAccountCreate(playerid)
{
    pInfo[playerid][ID] = cache_insert_id();
    // some other code such as SetSpawnInfo and SpawnPlayer or whatever..
}
Reply
#23

Worked like a charm, thanks a lot mate!
Reply
#24

Ty, I didn't know this.
I've modified my own code to use cache_insert_id() and it works.
Reply
#25

First of all, great job on the script.

Secondly, I'm currently working on a roleplay server. Basically, I want it that the first time they log in, they spawn at the set location, and second time, they'd spawn at their last logged off location. How would I go about doing this? Would I do something that would save in the database that would make it like 'LoggedInFirstTime = 1", if it's 1 it spawns them at the location, and 0 where they last logged?

Thanks.
Reply
#26

So, it worked like a charm in the way you did it. But since I added some data, it is not saving it in "OnPlayerDisconnect". I even stretched the query to 3000 (which is clearly above what it actually is) and it is still not working. Please help me:

Code:
public OnPlayerDisconnect(playerid, reason)
{
    new query[3000], Float:pos[3];
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `Admin`=%d, `VIP`=%d, `Money`=%d, `posX`=%f, `posY`=%f, `posZ`=%f, `Int`=%d, `VW`=%d, `Skin`=%d, `Edad`=%d, `Origen`=%s WHERE `ID`=%d",\
    pInfo[playerid][Admin], pInfo[playerid][VIP], pInfo[playerid][Money], pos[0],pos[1],pos[2],GetPlayerInterior(playerid),GetPlayerVirtualWorld(playerid),GetPlayerSkin(playerid),pInfo[playerid][Edad], pInfo[playerid][Origen],pInfo[playerid][ID]);
    mysql_tquery(mysql, query, "", "");
    return 1;
}
Reply
#27

Change:
pawn Code:
`Origen`=%s
to:
pawn Code:
`Origen`='%s'
If the same occurs again, check the mysql log and do some debugging (print the query).
Reply
#28

Quote:
Originally Posted by Konstantinos
View Post
Change:
pawn Code:
`Origen`=%s
to:
pawn Code:
`Origen`='%s'
If the same occurs again, check the mysql log and do some debugging (print the query).
Genius! It worked! Thank you very much!
Reply
#29

EDIT: Fail sorry I figured it out.
Reply
#30

Okay, so the whole script works thus far, besides updating the player info.. I've tried reading through the previous comments and haven't noticed anything unusual in my code... anyone got any idea as to why this doesn't update?

Code:
public SaveAccount(playerid)
{
	new qString[128], Float:pos[3];
	GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
	
	mysql_format(mysql, qString, sizeof(qString), "UPDATE `paccounts` SET `Level`=%d, `Money`=%d, `Health`=%f, `Armour`=%f, `Admin`=%d, `Helper`=%d, `posX`=%f, `posY`=%f, `posZ`=%f WHERE `ID`=%d",\
    pInfo[playerid][pLevel], pInfo[playerid][pMoney], pInfo[playerid][pHealth], pInfo[playerid][pArmour], pInfo[playerid][pAdmin], pInfo[playerid][pHelper], pos[0], pos[1], pos[2], pInfo[playerid][ID]);
    print(pInfo[playerid][ID]);
	mysql_tquery(mysql, qString, "", "");
}

public OnPlayerDisconnect(playerid, reason)
{
	SaveAccount(playerid);
	return 1;
}

public OnAccountCreate(playerid)
{
    pInfo[playerid][ID] = cache_insert_id();
    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Login Panel", "Thank you for registering!\nAn account has been found in our files;\nIn order to access the server however, you must first login: ", "Login", "Quit");
    return 1;
}

I inserted :
Code:
print(pInfo[playerid][ID]);
To try and debug the ID that's being sent, but in the console, it's just sending Symbols? (i.e. smiley face, diamond, hearts, etc...)
Reply
#31

It's integer, so the debugging would be:
pawn Code:
printf("-> %i", pInfo[playerid][ID]);
Make the size of qString larger and you don't need this character "\" after the text and before the arguments.
Reply
#32

pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case 1: //login dialog
        {
            if(!response) Kick(playerid);
            new hpass[129];
            new query[100];
            WP_Hash(hpass, 129, inputtext);
            if(!strcmp(hpass, pInfo[playerid][Password]))
            {
                mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]);
                mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
            }
            else
            {
                ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Login", "In order to play, you need to login\nWrong password!", "Login", "Quit");
            }
        }
        case 2: //register dialog
        {
            if(!response) return Kick(playerid);
            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");
            new query[300];
            WP_Hash(pInfo[playerid][Password], 129, inputtext); //hashing inputtext
            mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`) VALUES ('%e', '%s', '%s')", Name[playerid], pInfo[playerid][Password], IP[playerid]);
           
            mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
           
        }
    }
    return 1;
}
Reply
#33

And are you sure you've loaded the password and assign it correctly to pInfo[playerid][Password]? Do the debugging:
pawn Code:
printf("hpass: \"%s\" & Password: \"%s\"", hpass, pInfo[playerid][Password]);
if(!strcmp(hpass, pInfo[playerid][Password]))
Try again and post what it printed in the console. If the second one is empty, then the loading and/or assigning is wrong.
Reply
#34

Do what Konstantinos said AND make sure you used the updateD tutorial ESPECIALLY at this part
pawn Code:
public OnAccountCheck(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields, mysql);
    if(rows)
    {
        cache_get_field_content(0, "PASS", pInfo[playerid][Password], mysql, 129); //THIS PART
Reply
#35

Fixed ! thanks ^^. But i have some problems with the OnDialogResponse the compilation on pawn is Okay but when i want to start he didnt responding (sorry for the english i'm french)
Reply
#36

Quote:
Originally Posted by Cam972
View Post
Fixed ! thanks ^^. But i have some problems with the OnDialogResponse the compilation on pawn is Okay but when i want to start he didnt responding (sorry for the english i'm french)
Do this;
- change your dialog id (check back the tutorial, I have defined the dialog id. completely forgot about dialog id)
- post your server log and mysql log
Reply
#37

same problem :/. The compilation is ok and when i start my server in local : " [19:16:31] Script[gamemodes/OLU.amx]: Run time error 19: "File or function is not found"
[19:16:31] Number of vehicle models: 0 "
Reply
#38

Load nativechecker plugin (it must be loaded last) and post the server log. Plugin(s) failed to load or you forgot to load them.
Reply
#39

when i removed the "OnDialogResponse" of this tutorial, the server start correctly
Reply
#40

Fixed!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)