SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 04/02/2014, 09:00 PM   #31
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,844
Reputation: 1399
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

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..
}
__________________
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
Old 04/02/2014, 09:08 PM   #32
Blast3r
Banned
 
Join Date: Aug 2011
Location: Croatia, Knin
Posts: 635
Reputation: 115
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

Worked like a charm, thanks a lot mate!
Blast3r is offline   Reply With Quote
Old 04/02/2014, 09:36 PM   #33
PowerPC603
High-roller
 
Join Date: Nov 2010
Location: Belgium
Posts: 1,734
Reputation: 238
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

Ty, I didn't know this.
I've modified my own code to use cache_insert_id() and it works.
__________________
Gamemode: PPC_Trucking
Extras-file (for PPC_Trucking): /delproperty, /evict, /propertyid, /porthouse, /portbus, /properties
------------------------------------------------------------------------------------
PPC-Trucking-V2 (home-hosted, only open on occasion for testing purposes): ppctruckingv2.no-ip.info:7777
Youtube channel: https://www.youtube.com/channel/UC-4...Mpglma8f0Ld-YQ
------------------------------------------------------------------------------------
Filterscripts: PPC_Speedometer - PPC_Housing - PPC_Business
PowerPC603 is offline   Reply With Quote
Old 08/02/2014, 07:07 AM   #34
Dorito
Little Clucker
 
Join Date: Jan 2014
Posts: 36
Reputation: 1
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

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.
Dorito is offline   Reply With Quote
Old 08/02/2014, 04:18 PM   #35
Zinedine
Little Clucker
 
Zinedine's Avatar
 
Join Date: Feb 2014
Posts: 5
Reputation: 0
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

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;
}
Zinedine is offline   Reply With Quote
Old 08/02/2014, 04:23 PM   #36
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,844
Reputation: 1399
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

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).
__________________
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
Old 08/02/2014, 04:25 PM   #37
Zinedine
Little Clucker
 
Zinedine's Avatar
 
Join Date: Feb 2014
Posts: 5
Reputation: 0
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

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!
Zinedine is offline   Reply With Quote
Old 09/02/2014, 12:12 AM   #38
Zinedine
Little Clucker
 
Zinedine's Avatar
 
Join Date: Feb 2014
Posts: 5
Reputation: 0
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

EDIT: Fail sorry I figured it out.

Last edited by Zinedine; 09/02/2014 at 12:47 AM.
Zinedine is offline   Reply With Quote
Old 20/02/2014, 05:21 PM   #39
Ryan_Undering
Big Clucker
 
Ryan_Undering's Avatar
 
Join Date: Mar 2009
Posts: 97
Reputation: 15
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

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...)
Ryan_Undering is offline   Reply With Quote
Old 20/02/2014, 05:29 PM   #40
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,844
Reputation: 1399
Default Re: MySQL Registration System [Threaded Queries(R33+) + Whirlpool]

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.
__________________
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 09:13 AM.


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