搜索
查看: 1899|回复: 0

steamid记录如何改成ID记录

[复制链接]
发表于 2007-7-27 14:30:08 | 显示全部楼层 |阅读模式 来自 中国–浙江–温州
以下是代码
[PHP]#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[33]
        new hostname[64]
        new sqluser[64]
        new sqlpass[64]
        new sqldb[64]
        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("[AMXX] 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("[AMXX] Connected to SQL Database, logging all users.")
        return PLUGIN_CONTINUE
}

public client_authorized(id){
        new clientname[32]
        get_user_name(id,clientname,31)
        new usersteam[32]
        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, "[AMXX] Welcome to our server.  We've logged your information.  Enjoy your stay.")
                server_print("[AMXX] Logged into database: %s (%s).", clientname, usersteam)
               
        }
        else if( result <= RESULT_FAILED )
                {
                server_print("[AMXX] error occured in SQL.")
        }
        else
        {
                client_print(id, print_chat, "[AMXX] Welcome back.  Enjoy your stay.")
                server_print("[AMXX] %s (%s) has returned to the server!", clientname, usersteam)
        }
       
        return PLUGIN_CONTINUE
}

public death() {
        new killerid = read_data(1)
        new killersteamid[32]
        get_user_authid(killerid,killersteamid,31)
        new usersteam[32]
        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[32]
                        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("[AMXX] No user found in database - inserstion probably failed.")
                        }
                       
                        else if( result <= RESULT_FAILED )
                                {
                                server_print("[AMXX] 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
       
}
[/PHP]
游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表