大神快來幫我看看這個源碼為什麼錯了!!感激不盡!!

Home Home
引用 | 編輯 z2352671213
2014-02-09 16:00
樓主
推文 x0
複製程式
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <sqlx>
#include <zombieplague>


#define PLUGIN    "SIGN IN SYSTEM"
#define VERSION    "1.0"
#define AUTHOR    "NAG"
#define LOADING    "^n^t%s v%s, Copyright (C) 2014 by %s^n"

new Handle:g_SqlTuple;
new g_Error[512];

new g_SetAllow[33];

new g_host[33];
new g_user[33];
new g_pass[33];
new g_dbname[33];
new g_tabname[33];
new g_retryonce[33];
new Handle:g_Sql = Empty_Handle
public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR);
    server_print(LOADING,PLUGIN,VERSION,AUTHOR);
    register_forward(FM_ClientUserInfoChanged, "fwdClientUserInfoChanged");
    
    register_cvar("amx_sql_host", "127.0.0.1");
    register_cvar("amx_sql_user", "");
    register_cvar("amx_sql_pass", "");
    register_cvar("amx_sql_db", "");
    register_cvar("amx_sql_table", "");

    register_clcmd("say /qiandao","sign_say",ADMIN_ALL,"读取玩家说的话")

    new configsDir[64];
    get_configsdir(configsDir, 63);
    server_cmd("exec %s/sql.cfg", configsDir);
    server_exec();
}

public plugin_cfg()
{
    get_cvar_string("amx_sql_host",g_host,32);
    get_cvar_string("amx_sql_user",g_user,32);
    get_cvar_string("amx_sql_pass",g_pass,32);
    get_cvar_string("amx_sql_db",g_dbname,32);
    get_cvar_string("amx_sql_table",g_tabname,32);
    MySql_Init();
}

public MySql_Init()
{
    g_SqlTuple = SQL_MakeDbTuple(g_host,g_user,g_pass,g_dbname);
    new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error));
    if(SqlConnection == Empty_Handle)
        set_fail_state(g_Error);
    
    new Handle:Queries;
    Queries = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS %s (date int(30),name varchar(64), state varchar(64))", g_tabname);
    if(!SQL_Execute(Queries))
    {
        SQL_QueryError(Queries,g_Error,charsmax(g_Error));
        set_fail_state(g_Error);
    }
    SQL_FreeHandle(Queries);
    SQL_FreeHandle(SqlConnection);
}


public plugin_end()
    SQL_FreeHandle(g_SqlTuple);


public sign_say(id){
    new ErrorCode,Handle:SqlConnectionc = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error));
    new username[64]
    new timed[9]
    new xyb
    xyb = random_num(10,100)
    get_time("%m%d%Y",timed,8) 
    get_user_name(id,username,63)
    if(is_user_connected(id))
    {


    new chaxun;
    chaxun = SQL_QueryAndIgnore(SqlConnectionc,"SELECT * FROM  %s WHERE date = %d AND name = %s", g_tabname, str_to_num(timed) ,username[id]);


    if(chaxun == 0){
        SQL_QueryAndIgnore(SqlConnectionc,"INSERT INTO %s SET date = %d , name = %s, state = 'on'", g_tabname, str_to_num(timed) ,username[id])

        client_print(0,print_chat,"【元朝天尊每日签到】玩家[%s]签到成功,获得%d天尊币随机奖励!",username[id],xyb)
        zp_set_user_ammo_packs(id,zp_get_user_ammo_packs(id) + xyb)
    }
    else
    {
        client_print(id,print_chat,"【元朝天尊每日签到】您今日已经签过到了,赶明儿再来签到吧!")

    }


    SQL_FreeHandle(chaxun) ;

}

}

我寫的這個插件,不過在遊戲中一說/qiandao,馬上服務器就崩潰了,求破。。!

獻花 x0
引用 | 編輯 Nailaz
2014-02-09 18:38
1樓
  
读取玩家说的话
改成英文試看看..

獻花 x0
引用 | 編輯 a7811311622
2014-02-09 19:40
2樓
  
下面是引用 z2352671213 於 2014-02-09 16:00 發表的 大神快來幫我看看這個源碼為什麼錯了!!感激不盡!!: 到引言文
.......
我只寫過VB的SQL…所以不是很清楚AMXX的SQL…
不過…我看了<sqlx.inc>裡的 SQL_QueryAndIgnore …
說明不是說:
複製程式
/**
 * Use this for executing a query and not caring about the error.
 * Returns -1 on error, >=0 on success (with number of affected rows)
 */
可是你的邏輯是 if(chaxun == 0) …
這樣不會有問題嗎…?

獻花 x0
引用 | 編輯 z2352671213
2014-02-09 20:08
3樓
  
下面是引用 a7811311622 於 2014-02-09 19:40 發表的 : 到引言文

我只寫過VB的SQL…所以不是很清楚AMXX的SQL…
不過…我看了<sqlx.inc>裡的 SQL_QueryAndIgnore …
說明不是說:
複製程式
/**
 * Use this for executing a query and not caring about the error.
 * Returns -1 on error, >=0 on success (with number of affected rows)
 */
可是你的邏輯是 if(chaxun == 0) …
這樣不會有問題嗎…?

謝了。確實是-1

再問一下,為什麼用get_user_name獲取的玩家ID,保存到SQL裏都變成亂碼了?而且玩家的ID有時候獲取出來是空的。怎麼回事

獻花 x0
引用 | 編輯 a7811311622
2014-02-09 21:27
4樓
  
下面是引用 z2352671213 於 2014-02-09 20:08 發表的 : 到引言文


謝了。確實是-1

再問一下,為什麼用get_user_name獲取的玩家ID,保存到SQL裏都變成亂碼了?而且玩家的ID有時候獲取出來是空的。怎麼回事
有試過SMA存成UTF-8嗎?
如果你的玩家名字是中文的…可能會出問題吧…
不知道AMXX能否正確存取中文…

獻花 x0
引用 | 編輯 85607417
2014-02-20 01:45
5樓
  

圖 1.

圖 2.

圖 3.


SQL裡面亂碼,但只要PHP能正常顯示就可以
如果是空的,應該是保存方式有問題,編碼統一用utf8
http://imgur.com/t6LevFG,ZXBlKZu,jSDGlO6

獻花 x0