冰河 发表于 2007-7-27 14:30:08

steamid记录如何改成ID记录

以下是代码
#include <amxmodx>
#include <amxmisc>
#include <dbi>
#include <engine>

#define PLUGIN "Total Kills On Server"
#define VERSION "1.0"
#define AUTHOR "Sonic"

new Sql:dbc
new Result:result

public plugin_init() {
        register_plugin(PLUGIN, VERSION, AUTHOR)
        register_event("DeathMsg","death","a")
        set_task(0.5,"hudmessage",0,"",0,"b")
        new error
        new hostname
        new sqluser
        new sqlpass
        new sqldb
        get_cvar_string("amx_sql_host", hostname, 63)
        get_cvar_string("amx_sql_db", sqldb, 63)
        get_cvar_string("amx_sql_pass", sqlpass, 63)
        get_cvar_string("amx_sql_user", sqluser, 63)
       
        dbc = dbi_connect(hostname, sqluser, sqlpass, sqldb, error, 32)
       
       
        if (dbc == SQL_FAILED)
                {
                server_print(" Could Not Connect To SQL Database. Check your login details.")
                pause("ae")
                return PLUGIN_HANDLED
        }
        result = dbi_query(dbc,"CREATE TABLE IF NOT EXISTS `steamids` (`steamid` text, `name` text, `kills` int)")
        server_print(" Connected to SQL Database, logging all users.")
        return PLUGIN_CONTINUE
}

public client_authorized(id){
        new clientname
        get_user_name(id,clientname,31)
        new usersteam
        get_user_authid(id,usersteam,31)
        result = dbi_query(dbc,"SELECT * FROM `steamids` WHERE `steamid` = '%s' LIMIT 0 , 1", usersteam)
        if( result == RESULT_NONE )
                {
               
                dbi_free_result(result)
                result = dbi_query(dbc, "INSERT INTO steamids VALUES ('%s','%s','0')",usersteam,clientname)
                client_print(id, print_chat, " Welcome to our server.We've logged your information.Enjoy your stay.")
                server_print(" Logged into database: %s (%s).", clientname, usersteam)
               
        }
        else if( result <= RESULT_FAILED )
                {
                server_print(" error occured in SQL.")
        }
        else
        {
                client_print(id, print_chat, " Welcome back.Enjoy your stay.")
                server_print(" %s (%s) has returned to the server!", clientname, usersteam)
        }
       
        return PLUGIN_CONTINUE
}

public death() {
        new killerid = read_data(1)
        new killersteamid
        get_user_authid(killerid,killersteamid,31)
        new usersteam
        get_user_authid(killerid,usersteam,31)
        result = dbi_query(dbc,"SELECT kills FROM `steamids` WHERE `steamid` = '%s' LIMIT 1", usersteam)
        dbi_nextrow(result)
       
        dbi_free_result(result)
        result = dbi_query(dbc, "UPDATE steamids SET kills=kills+1 WHERE steamid='%s'",killersteamid)
        dbi_free_result(result)
}
public hudmessage(){
        for(new p = 1 ; p <= get_maxplayers() ; p++) {
                if(is_user_connected( p )) {
                        set_hudmessage(255,0,0,0.0,0.5)
                        new psteam
                        get_user_authid(p,psteam,31)
                        result = dbi_query(dbc,"SELECT `kills` FROM `steamids` WHERE `steamid` = '%s' LIMIT 0, 1", psteam)
                        if( result == RESULT_NONE )
                                {
                                server_print(" No user found in database - inserstion probably failed.")
                        }
                       
                        else if( result <= RESULT_FAILED )
                                {
                                server_print(" Unexpected error occured in SQL.")
                        }
                        else
                        {
                                dbi_nextrow(result)
                                new totalkills = dbi_field(result,1)
                                show_hudmessage(p,"Total Kills On Server: %i",totalkills)
                                dbi_free_result(result)
                        }
                       
                }
        }
        return PLUGIN_HANDLED
       
}
页: [1]
查看完整版本: steamid记录如何改成ID记录