Raised This Month: $23 Target: $400
 5% 

Change Name (with SQL)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
spiider
AlliedModders Donor
Join Date: Jan 2010
Old 01-21-2010 , 17:09   Change Name (with SQL)
Reply With Quote #1

Hi.
Some one can help me code a script for search in MySQL db for user steamid and then change user name for the name in database.
spiider is offline
Old 01-21-2010, 18:19
spiider
This message has been deleted by Exolent[jNr]. Reason: Don't bump until 2 weeks have passed since last post.
Old 01-22-2010, 07:20
help
This message has been deleted by YamiKaitou. Reason: "me too" post, bump
spiider
AlliedModders Donor
Join Date: Jan 2010
Old 03-15-2010 , 12:53   Re: Change Name (with SQL)
Reply With Quote #2

Here is the code maybe help someone.
I'm now with a problem every time change map my plugin say can't connect to database and i don't change anything in plugin.

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <dbi>
#include <engine>
#include <csx>

#define PLUGIN "Change Name and Kick no registered steamID"
#define VERSION "1.0"
#define AUTHOR "spiider"


#define CVAR_CHHOST            "reg_host"
#define CVAR_CHUSER            "reg_user"
#define CVAR_CHPASS            "reg_pass"
#define CVAR_CHDB            "reg_db"
#define TABLE                "users"


//new names[32] // id->playername
new g_regged[33]
// vars going here
new gate_matchID
//public pug_cvar_shield = 1;

public plugin_modules() {
    
require_module("engine")
    
require_module("dbi")
}

// here goes check client and change name :)

public client_authorized(id) {
    if (
is_user_bot(id))
        return 
PLUGIN_CONTINUE
    
    
new authid[32]
    
get_user_authid(id,authid,31)
    new 
Sql:sql
    
if (!connect(sql))
        return 
false
    
    
const LONGER 128
    
new query[LONGER 1]
    
    
format(queryLONGER"SELECT `name` FROM %s WHERE `steamid` = '%s' LIMIT 1"TABLEauthid)
    new 
Result:result dbi_query(sqlquery)
    
    
    
//Loop through the result set   
    
while (result && dbi_nextrow(result)>0) {
        new 
qry[32]
        
//Get the column/field called "keyname" from the result set
        
dbi_result(result"name"qry32)
        
set_user_info(id,"name",qry)
        
    }
    
    
dbi_close(sql)
    
    
    
g_regged[id] = checkregister(authid)
    
    if (
g_regged[id]) {
        
        } else {
        
server_cmd("kick #%d Your steamID %s is not registered for this game."get_user_userid(id), authid)
    }
    
    
    
    
    return 
true
}

// now when change name in game
public client_infochanged(id) {
    if (
is_user_bot(id) || is_user_connecting(id))
        return 
PLUGIN_CONTINUE
    
new nick[32]
    new 
newnick[32]
    new 
authid[32]
    
get_user_authid(id,authid,31)
    new 
Sql:sql
    
if (!connect(sql))
        return 
false
    
    
const LONGER 128
    
new query[LONGER 1]
    
    
format(queryLONGER"SELECT `name` FROM %s WHERE `steamid` = '%s' LIMIT 1"TABLEauthid)
    new 
Result:result dbi_query(sqlquery)
    
    
    
//Loop through the result set   
    
while (result && dbi_nextrow(result)>0) {
        new 
qry[32]
        
dbi_result(result"name"qry32)
        
// set_user_info(id,"name",qry)
        
nick qry;
    }
    
    
    
format(newnick31"%s"nick)
    
set_user_info(id"name"newnick)
    
    
dbi_close(sql)
    
    return 
true
}
// here goes check if is registered for this game
bool:checkregister(authid[]) {
    new 
Sql:sql
    
if (!connect(sql))
        return 
false
    
const LONGER 128
    
new query[LONGER 1]
    
gate_matchID get_cvar_pointer "matchID" )
    
format(queryLONGER"SELECT `playerID` FROM players WHERE `steamID` = ^"%s^" AND `matchID` = '%d' LIMIT 1"authid,get_pcvar_num(gate_matchID))
    new 
Result:result dbi_query(sqlquery)
    if (
result <= RESULT_FAILED) {
        new 
error[256]
        
dbi_error(sqlerror255)
        
log_amx("Error while quering SQL server for %s, can't check registration: %s"authiderror)
        
dbi_close(sql)
        return 
false
    
}
    else if (
result == RESULT_NONE || !dbi_nextrow(result)) {
        
dbi_close(sql)
        return 
false
    
}
    
    
gate_matchID get_cvar_pointer "matchID" )
    
format(queryLONGER"UPDATE players SET `in`='1' WHERE `matchID`='%d' AND `steamid`=^"%s^""get_pcvar_num(gate_matchID), authid)
    
dbi_query(sqlquery)
    
dbi_close(sql)
    
    return 
true
}

// here goes the database connection
bool:connect(&Sql:sql) {
    const 
LEN 128
    
new host[LEN], user[LEN], pass[LEN], db[LEN], error_msg[LEN]
    
    
get_cvar_string(CVAR_CHHOSThostLEN 2)
    
get_cvar_string(CVAR_CHUSERuserLEN 2)
    
get_cvar_string(CVAR_CHPASSpassLEN 2)
    
get_cvar_string(CVAR_CHDBdbLEN 2)
    
    
sql dbi_connect(hostuserpassdberror_msgLEN 2)
    
    if (!
sql) {
        
log_amx("ERROR - Can't connect to SQL db: %s"error_msg)
        return 
false
    
}
    
    return 
true
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
    
register_cvar(CVAR_CHHOST"ip")
    
register_cvar(CVAR_CHUSER"user")
    
register_cvar(CVAR_CHPASS"pw")
    
register_cvar(CVAR_CHDB"db")
    
register_cvar("matchID""1")
    
    new 
Sql:sql
    
if (!connect(sql)) {
        
log_amx("Couldn't connect to SQL database at plugin_init! Pausing plugin.")
        
pause("a")
        return
    }
    
    else
        
server_print("[%s] Connected successfully to SQL database."PLUGIN)
    
dbi_close(sql)
    
    

And offcurse i know SQLx is better but i'm without time to change the script to SQLx. And this is my first script in AMXX
And the variable warmup is part of a project I'm developing and this script make part.

Last edited by spiider; 03-15-2010 at 13:04. Reason: Change text to inglish and add some comments
spiider is offline
Old 03-15-2010, 12:59
xPaw
This message has been deleted by xPaw. Reason: Misunderstood syntax.
spiider
AlliedModders Donor
Join Date: Jan 2010
Old 03-15-2010 , 13:00   Re: Change Name (with SQL)
Reply With Quote #3

the querys are working without problem but i'm go change.
spiider is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-15-2010 , 23:40   Re: Change Name (with SQL)
Reply With Quote #4

Quote:
Originally Posted by xPaw View Post
`steamid` = ^"%s^"
should be
`steamid` = '%s'
It's fine the way it is.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
puttsmobiles
Senior Member
Join Date: Mar 2009
Location: Chicago
Old 03-17-2010 , 14:41   Re: Change Name (with SQL)
Reply With Quote #5

Would you mind if I tested this?
__________________
Dan Hiorns - www.danhiorns.us
puttsmobiles is offline
Send a message via AIM to puttsmobiles Send a message via MSN to puttsmobiles Send a message via Yahoo to puttsmobiles Send a message via Skype™ to puttsmobiles
spiider
AlliedModders Donor
Join Date: Jan 2010
Old 03-18-2010 , 12:48   Re: Change Name (with SQL)
Reply With Quote #6

no problem you can test, is working in my server without problem, and i fix the connection problem with server.

If have some one interrest in this plugin i can make a better version and post plugin for be accepted.
spiider is offline
puttsmobiles
Senior Member
Join Date: Mar 2009
Location: Chicago
Old 03-18-2010 , 17:51   Re: Change Name (with SQL)
Reply With Quote #7

I tried it and it wont force the name change.

can you post a test SQL file so i can try it?
__________________
Dan Hiorns - www.danhiorns.us
puttsmobiles is offline
Send a message via AIM to puttsmobiles Send a message via MSN to puttsmobiles Send a message via Yahoo to puttsmobiles Send a message via Skype™ to puttsmobiles
spiider
AlliedModders Donor
Join Date: Jan 2010
Old 03-19-2010 , 11:59   Re: Change Name (with SQL)
Reply With Quote #8

Code:
-- ----------------------------
-- Table structure for `users`
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `steamid` varchar(32) default 'STEAM_0:0:0000',
  `name` varchar(32) default NULL,
  PRIMARY KEY  (`steamid`),
  UNIQUE KEY `unique` (`name`)
) ENGINE=MyISAM AUTO_INCREMENT=328 DEFAULT CHARSET=latin1;
The script change name automatic, but your previous name ingame will be the same in console only. Only in the server will be the db name. Later i post some screen.
spiider 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 04:00.


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