AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Make nick change in mySQL work (https://forums.alliedmods.net/showthread.php?t=308144)

4ever16 06-08-2018 10:26

Make nick change in mySQL work
 
So i have a plugin and it sends data to mySQL.
But i would like the plugin to update the nickname if i change it.
If my nickname ingame is Player 1 and i change it to Player 2 then mySQL doesnt update to the new nickname.

Can someone check these parts of the code and see if it has some errors or something?


Here are parts from the plugin which i think should change the nickname in mySQL but it doesnt.
PHP Code:

new Team[33], OldName[33][32

PHP Code:

public client_infochanged(id

    new 
newname[32],oldname[32
    
get_user_info(id"name"newname,31
    
get_user_name(idoldname31
    
    if(!
equali(newnameoldname))
    {
        
OldName[id] = oldname;
        
MySQL_UpdateName(id);
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;


PHP Code:

public MySQL_UpdateName(id) {
    
replace_all(OldName[id], 32"'""\'"); 
    
replace_all(OldName[id], 32"^"", "\^""); 

    
formatexMySQL_QuerycharsmaxMySQL_Query ), "UPDATE `online_players` SET `username` = '%s' WHERE `username` = '%s'"get_user_name_ex(id), OldName[id] ) 
    
SQL_ThreadQuery(MySQL_Tuple"SQL_TrashHandler"MySQL_Query);   


PHP Code:

stock get_user_name_ex(id

    new 
szName[33]; 
    
get_user_name(idszNamecharsmax(szName)); 

    
replace_all(szNamecharsmax(szName), "'""\'"); 
    
replace_all(szNamecharsmax(szName), "^"", "\^""); 

    return 
szName



CrazY. 06-08-2018 13:26

Re: Make nick change in mySQL work
 
Poorly coded...

Code:
const MAXPLAYERS = 32; new g_szOldName[MAXPLAYERS+1][32];

Code:
public client_infochanged(pPlayer)   {     new szName[32];     get_user_name(pPlayer, szName, charsmax(szName));     if(!equali(szName, g_szOldName[pPlayer]))     {         formatex(g_szOldName[pPlayer], charsmax(g_szOldName[]), "%s", szName);         MySQL_UpdateName(pPlayer);     } } MySQL_UpdateName(pPlayer) {     new szQuery[32], szName[32];     get_user_name(pPlayer, szName, charsmax(szName));     replace_all(g_szOldName[pPlayer], charsmax(g_szOldName[]), "'", "\'");     replace_all(g_szOldName[pPlayer], charsmax(g_szOldName[]), "^"", "\^"");     replace_all(szName, charsmax(szName), "'", "\'");     replace_all(szName, charsmax(szName), "^"", "\^"");     formatex(szQuery, charsmax(szQuery), "UPDATE `online_players` SET `username` = '%s' WHERE `username` = '%s'", szName, g_szOldName[pPlayer]);     SQL_ThreadQuery(MySQL_Tuple, "SQL_TrashHandler", szQuery); }

4ever16 06-08-2018 15:05

Re: Make nick change in mySQL work
 
Compile error.

CrazY. 06-08-2018 16:35

Re: Make nick change in mySQL work
 
Updated.

^SmileY 06-08-2018 18:13

Re: Make nick change in mySQL work
 
Why not only update name on client disconnect?

4ever16 06-08-2018 18:48

Re: Make nick change in mySQL work
 
Compiling worked fine this time but it didnt update the nickname in the database.
When i changed my nickname it still shouwed the old nickname inthe database.

CrazY. 06-09-2018 08:24

Re: Make nick change in mySQL work
 
Quote:

Originally Posted by ^SmileY (Post 2595900)
Why not only update name on client disconnect?

I used the code given by @4ever16 as an base, but can be any way.

Quote:

Originally Posted by 4ever16 (Post 2595903)
Compiling worked fine this time but it didnt update the nickname in the database.
When i changed my nickname it still shouwed the old nickname inthe database.

So something it's wrong with your tuple or connection.

4ever16 06-09-2018 08:39

Re: Make nick change in mySQL work
 
Turple?
Connection no... Cause it writes my old name to database if im in the server but when i change my name it doesnt update.

4ever16 06-12-2018 06:44

Re: Make nick change in mySQL work
 
Bump!


All times are GMT -4. The time now is 04:34.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.