Raised This Month: $12 Target: $400
 3% 

*solution found* pls remove this


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bob1
Member
Join Date: Sep 2011
Location: Denmark
Old 12-28-2015 , 05:52   *solution found* pls remove this
Reply With Quote #1

How do I just update the username in the database when a player changes name?
It should update in the Top List (!top) but still shows old name...

What's wrong here:
Code:
public Action:Event_player_changename(Handle:event, const String:name[], bool:dontBroadcast) 
{ 
decl String:clientname[64], String:clientid[32], String:query[512]; 

new client = GetClientOfUserId(GetEventInt(event, "userid")); 

GetClientName(client, clientname, sizeof(clientname)); 

ReplaceString(clientname, sizeof(clientname), "'", ""); 

GetClientAuthString(client, clientid, sizeof(clientid)); 

Format(query, sizeof(query), "UPDATE elostats SET name='%s' WHERE steamid='%s'", client, clientname, clientid); 

SQL_TQuery(db, SQLErrorCheckCallback, query); 
}
The whole plugin:
PHP Code:
#include <sourcemod> 

#define PL_VERSION "1.0" 

#pragma semicolon 1 

new Handle:g_kValue INVALID_HANDLE
new 
Handle:db INVALID_HANDLE
new 
bool:colour true
new 
bool:roundend false
new 
bool:sqlite false
new 
bool:notify[MAXPLAYERS+1] = {true, ...}; 
new 
rankcount
new 
rank[MAXPLAYERS+1]; 
new 
rating[MAXPLAYERS+1]; 
new 
kills[MAXPLAYERS+1]; 
new 
deaths[MAXPLAYERS+1]; 
new 
sessionrating[MAXPLAYERS+1]; 
new 
sessionkills[MAXPLAYERS+1]; 
new 
sessiondeaths[MAXPLAYERS+1]; 

public 
Plugin:myinfo 

name "ELO Ranking System"
author "GoogleGames"
description "ELO Ranking System with MySQL & Local SqLite"
version PL_VERSION
url "http://www.twitch.tv/googlegames" 
}; 

public 
OnPluginStart() 

decl String:error[256]; 

if(
SQL_CheckConfig("elo")) 

db SQL_Connect("elo"trueerrorsizeof(error)); 

else 

db SQL_Connect("storage-local"trueerrorsizeof(error)); 


if(
db==INVALID_HANDLE

LogError("Could not connect to database: %s"error); 

return; 


decl String:ident[16]; 

SQL_ReadDriver(dbidentsizeof(ident)); 

if(
strcmp(ident"mysql"false)==0

sqlite false

else if(
strcmp(ident"sqlite"false)==0

sqlite true

else 

LogError("No database found or invalid database input."); 

return; 


if(
sqlite

SQL_TQuery(dbSQLErrorCheckCallback"CREATE TABLE IF NOT EXISTS elostats (steamid TEXT, name TEXT, rating INTEGER, kills INTEGER, deaths INTEGER, notify INTEGER)"); 

else 

SQL_TQuery(dbSQLErrorCheckCallback"CREATE TABLE IF NOT EXISTS elostats (steamid varchar(32) NOT NULL, name varchar(64) NOT NULL, rating int(8) NOT NULL, kills int(8) NOT NULL, deaths int(8) NOT NULL, notify int(2) NOT NULL)"); 


CreateConVar("sm_elo_version"PL_VERSION"ELO Ranking version."FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FC VAR_NOTIFY); 
g_kValue CreateConVar("sm_elo_k""16""K-Value for ELO Ranking."FCVAR_PLUGIN|FCVAR_NOTIFY); 

RegConsoleCmd("say"Command_say); 
RegConsoleCmd("say_team"Command_say); 

HookEvent("player_changename"Event_player_changename); 
HookEvent("player_death"Event_player_death); 

decl String:mod[16]; 

GetGameFolderName(modsizeof(mod)); 

if(
strcmp(mod"dod")==0

HookEvent("dod_restart_round"Event_round_start); 
HookEvent("dod_round_start"Event_round_start); 
HookEvent("dod_round_win"Event_round_win); 

else if(
strcmp(mod"hl2mp")==0

colour false



public 
OnClientPutInServer(client

if(!
IsFakeClient(client)) 

decl String:clientid[32], String:query[256]; 

new 
userid GetClientUserId(client); 

GetClientAuthString(clientclientidsizeof(clientid)); 

Format(querysizeof(query), "SELECT rating,kills,deaths,notify FROM elostats WHERE steamid='%s'"clientid); 

SQL_TQuery(dbSQLQueryConnectqueryuserid); 

sessionrating[client] = 0
sessionkills[client] = 0
sessiondeaths[client] = 0



public 
SQLQueryConnect(Handle:ownerHandle:hndl, const String:error[], any:data

new 
client

if((
client GetClientOfUserId(data)) == 0

return; 


if(
hndl == INVALID_HANDLE

LogError("Query failed: %s"error); 

else 

decl String:query[512], String:clientname[64], String:clientid[32]; 

GetClientName(clientclientnamesizeof(clientname)); 

ReplaceString(clientnamesizeof(clientname), "'"""); 

GetClientAuthString(clientclientidsizeof(clientid)); 

if(!
SQL_MoreRows(hndl)) 

if(
sqlite

Format(querysizeof(query), "INSERT INTO elostats VALUES('%s', '%N', 1500, 0, 0, 1)"clientidclient); 
SQL_TQuery(dbSQLErrorCheckCallbackquery); 

else 

Format(querysizeof(query), "INSERT INTO elostats (steamid, name, rating, kills, deaths, notify) VALUES ('%s', '%N', 1500, 0, 0, 1)"clientidclient); 
SQL_TQuery(dbSQLErrorCheckCallbackquery); 


rating[client] = 1500
kills[client] = 0
deaths[client] = 0
notify[client] = true


else 

Format(querysizeof(query), "UPDATE elostats SET name='%s' WHERE steamid='%s'"clientclientnameclientid); 
SQL_TQuery(dbSQLErrorCheckCallbackquery); 

while(
SQL_FetchRow(hndl)) 

rating[client] = SQL_FetchInt(hndl0); 
kills[client] = SQL_FetchInt(hndl1); 
deaths[client] = SQL_FetchInt(hndl2); 
notify[client] = SQL_FetchInt(hndl3) == false:true


CreateTimer(7.0EloWelcomeclient); 


public 
Action:EloWelcome(Handle:timerany:client

if(
IsClientInGame(client)) 

PrintToChat(client"\x01[\x04DBS\x01] Available commands: \x04rank\x01 & \x04top\x01."); 



public 
SQLQueryRank(Handle:ownerHandle:hndl, const String:error[], any:data

new 
client

if((
client GetClientOfUserId(data))==0

return; 


if(
hndl==INVALID_HANDLE

LogError("Query failed: %s"error); 

else 

rank[client] = SQL_GetRowCount(hndl) + 1


SQL_TQuery(dbSQLQueryCount"SELECT * FROM elostats"GetClientUserId(client)); 


public 
SQLQueryCount(Handle:ownerHandle:hndl, const String:error[], any:data

new 
client

if((
client GetClientOfUserId(data))==0

return; 


rankcount SQL_GetRowCount(hndl); 

decl String:rankstr[16]; 

new 
Float:kpd deaths[client]==0?1.0:float(kills[client])/float(deaths[client]); 

if((
rank[client]%100)>10 && (rank[client]%100)<14

Format(rankstrsizeof(rankstr), "%i"rank[client]); 

else 

switch(
rank[client]%10

case 
0Format(rankstrsizeof(rankstr), "%i"rank[client]); 
case 
1Format(rankstrsizeof(rankstr), "%i"rank[client]); 
case 
2Format(rankstrsizeof(rankstr), "%i"rank[client]); 
case 
3Format(rankstrsizeof(rankstr), "%i"rank[client]); 
case 
4Format(rankstrsizeof(rankstr), "%i"rank[client]); 
case 
5Format(rankstrsizeof(rankstr), "%i"rank[client]); 
case 
6Format(rankstrsizeof(rankstr), "%i"rank[client]); 
case 
7Format(rankstrsizeof(rankstr), "%i"rank[client]); 
case 
8Format(rankstrsizeof(rankstr), "%i"rank[client]); 
case 
9Format(rankstrsizeof(rankstr), "%i"rank[client]); 



PrintToChat(client"\x01[\x04DBS\x01] Rank: \x04%s \x01of \x04%i \x01| ELO: \x04%i \x01| Kills: \x04%i \x01| Deaths: \x04%i \x01| KDR: \x04%.2f"rankstrrankcountrating[client], kills[client], deaths[client], kpd); 


public 
SQLQueryTop10(Handle:ownerHandle:hndl, const String:error[], any:data

new 
client

if((
client GetClientOfUserId(data))==0

return; 


if(
hndl==INVALID_HANDLE

LogError("Query failed: %s"error); 

else 

decl String:qname[64], String:qrating[8], String:buffer[68]; 

new 
0num 1Handle:panel CreatePanel(); 

SetPanelTitle(panel"[DBS] Top 10 Players:"); 

DrawPanelText(panel"--------------------------"); 

while(
SQL_FetchRow(hndl)) { 
SQL_FetchString(hndl0qnamesizeof(qname)); 
SQL_FetchString(hndl1qratingsizeof(qrating)); 
Format(buffersizeof(buffer), "%i. %s [%s]",numqnameqrating); 
num++; 
DrawPanelText(panelbuffer); 
i++; 


DrawPanelText(panel"--------------------------"); 

DrawPanelItem(panel"Close"); 

SendPanelToClient(panelclientPanelHandlerNothing15); 

CloseHandle(panel); 



public 
SQLErrorCheckCallback(Handle:ownerHandle:hndl, const String:error[], any:data

if(!
StrEqual(""error)) 

LogError("Query failed: %s"error); 



public 
Action:Event_player_changename(Handle:event, const String:name[], bool:dontBroadcast

decl String:clientname[64], String:clientid[32], String:query[512]; 

new 
client GetClientOfUserId(GetEventInt(event"userid")); 

GetClientName(clientclientnamesizeof(clientname)); 

ReplaceString(clientnamesizeof(clientname), "'"""); 

GetClientAuthString(clientclientidsizeof(clientid)); 

Format(querysizeof(query), "UPDATE elostats SET name='%s' WHERE steamid='%s'"clientclientnameclientid); 

SQL_TQuery(dbSQLErrorCheckCallbackquery); 


public 
Action:Event_player_death(Handle:event, const String:name[], bool:dontBroadcast

if(!
roundend

new 
client GetClientOfUserId(GetEventInt(event"userid")); 
new 
attacker GetClientOfUserId(GetEventInt(event"attacker")); 

if(
client!=&& attacker!=0

if(!
IsFakeClient(client)&&!IsFakeClient(attac ker)&&client!=attacker

decl String:clientid[32], String:attackerid[32], String:query[512], String:buffer[256]; 

GetClientAuthString(clientclientidsizeof(clientid)); 
GetClientAuthString(attackerattackeridsizeof(attackerid)); 

new 
Float:prob 1/(Pow(10.0float((rating[client]-rating[attacker]))/400)+1); 
new 
diff RoundFloat(GetConVarFloat(g_kValue)*(1-prob)); 

rating[client] = rating[client]-diff
rating[attacker] = rating[attacker]+diff

sessionrating[client] = sessionrating[client]-diff
sessionrating[attacker] = sessionrating[attacker]+diff

kills[attacker]++; 
deaths[client]++; 
sessionkills[attacker]++; 
sessiondeaths[client]++; 

Format(querysizeof(query), "UPDATE elostats SET rating=%i,deaths=%i WHERE steamid='%s'"rating[client], deaths[client], clientid); 
SQL_TQuery(dbSQLErrorCheckCallbackquery); 

Format(querysizeof(query), "UPDATE elostats SET rating=%i,kills=%i WHERE steamid='%s'"rating[attacker], kills[attacker], attackerid); 
SQL_TQuery(dbSQLErrorCheckCallbackquery); 

if(
notify[client]) 

if(
colour

Format(buffersizeof(buffer), "\x01You(\x04%i\x01) got killed by \x03%N\x01(\x04%i\x01) and lost \x04%i\x01 ELO"rating[client], attackerrating[attacker], diff); 
SayText2One(clientattackerbuffer); 

else 

PrintToChat(client"You(%i) were killed by %N(%i) and lost %i ELO"rating[client], attackerrating[attacker], diff); 



if(
notify[attacker]) 

if(
colour

Format(buffersizeof(buffer), "\x01You(\x04%i\x01) gained \x04%i\x01 ELO for killing \x03%N\x01(\x04%i\x01)"rating[attacker], diffclientrating[client]); 
SayText2One(attackerclientbuffer); 

else 

PrintToChat(client"You(%i) gained %i ELO for killing %N(%i)"rating[attacker], diffclientrating[client]); 







public 
Action:Event_round_start(Handle:event, const String:name[], bool:dontBroadcast

roundend false


public 
Action:Event_round_win(Handle:event, const String:name[], bool:dontBroadcast

roundend true


public 
Action:Command_say(clientargs

decl String:text[192]; 

if(
GetCmdArgString(textsizeof(text))<1

return 
Plugin_Continue


new 
startidx

if(
text[strlen(text)-1]=='"'

text[strlen(text)-1] = '\0'
startidx 1


if(
strcmp(text[startidx], "/elo_notify"false)==|| strcmp(text[startidx], "elo_notify"false)==0

decl String:clientid[32], String:query[512]; 

GetClientAuthString(clientclientidsizeof(clientid)); 

if(
notify[client]==false

notify[client] = true

if(
colour

PrintToChat(client"\x01Rank notifications enabled. Say \x04/elo_notify\x01 again to disable them."); 

else 

PrintToChat(client"Rank notifications enabled. Say /elo_notify again to disable them."); 


Format(querysizeof(query), "UPDATE elostats SET notify=1 WHERE steamid='%s'"clientid); 

SQL_TQuery(dbSQLErrorCheckCallbackquery); 

else 

notify[client] = false

if(
colour

PrintToChat(client"\x01Rank notifications disabled. Say \x04/elo_notify\x01 again to enable them."); 

else 

PrintToChat(client"Rank notifications enabled. Say /elo_notify again to disable them."); 


Format(querysizeof(query), "UPDATE elostats SET notify=0 WHERE steamid='%s'"clientid); 

SQL_TQuery(dbSQLErrorCheckCallbackquery); 


return 
Plugin_Handled

else if(
strcmp(text[startidx], "rank"false)==|| strcmp(text[startidx], "/rank"false)==|| strcmp(text[startidx], "!rank"false)==|| strcmp(text[startidx], "secretunknowncommandKappa123"false)==|| strcmp(text[startidx], "/secretunknowncommandKappa123"false)==0

decl String:clientid[32]; 

GetClientAuthString(clientclientidsizeof(clientid)); 

if(
StrContains(text[startidx], "rank"false)!=-1

decl String:query[512]; 

Format(querysizeof(query), "SELECT * FROM elostats WHERE steamid=%i"clientid); 

SQL_TQuery(dbSQLQueryRankqueryGetClientUserId(client)); 

return 
Plugin_Handled

else 

decl String:buffer[64]; 

new 
Handle:panel CreatePanel(); 

SetPanelTitle(panel"Session stats:"); 

Format(buffersizeof(buffer), "Rating: %i"sessionrating[client]); 
DrawPanelText(panelbuffer); 

Format(buffersizeof(buffer), "Kills: %i"sessionkills[client]); 
DrawPanelText(panelbuffer); 

Format(buffersizeof(buffer), "Deaths: %i"sessiondeaths[client]); 
DrawPanelText(panelbuffer); 

DrawPanelItem(panel"Close"); 
SendPanelToClient(panelclientPanelHandlerNothing15); 
CloseHandle(panel); 


return 
Plugin_Handled

else if(
strcmp(text[startidx], "top10"false)==|| strcmp(text[startidx], "/top10"false)==|| strcmp(text[startidx], "!top10"false)==|| strcmp(text[startidx], "/top"false)==|| strcmp(text[startidx], "top"false)==|| strcmp(text[startidx], "!top"false)==0

SQL_TQuery(dbSQLQueryTop10"SELECT name,rating FROM elostats ORDER BY rating DESC LIMIT 0,10"GetClientUserId(client)); 
return 
Plugin_Handled


return 
Plugin_Continue


public 
PanelHandlerNothing(Handle:menuMenuAction:actionparam1param2

// Do nothing 


SayText2One(clientuser, const String:message[] ) 

new 
Handle:buffer StartMessageOne("SayText2"client); 

if(
buffer!=INVALID_HANDLE

BfWriteByte(bufferuser); 
BfWriteByte(buffertrue); 
BfWriteString(buffermessage); 
EndMessage(); 


__________________
Mini-Scripter.

Last edited by Dr!fter; 12-28-2015 at 08:50. Reason: Restore post
Bob1 is offline
nhnkl159
Senior Member
Join Date: Jul 2012
Location: Israel 3>
Old 12-28-2015 , 07:53   Re: *solution found* pls remove this
Reply With Quote #2

Quote:
Do not blank out posts - if you solve your problem post the solution for others to find.
https://forums.alliedmods.net/misc.php?do=showrules
__________________
nhnkl159 is offline
Send a message via Skype™ to nhnkl159
Bob1
Member
Join Date: Sep 2011
Location: Denmark
Old 12-29-2015 , 02:09   Re: *solution found* pls remove this
Reply With Quote #3

ok i will next time
__________________
Mini-Scripter.
Bob1 is offline
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

Forum Jump


All times are GMT -4. The time now is 06:56.


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