搜索
查看: 2876|回复: 1

register_srvcmd传数组问题 想把imessage改为SQL的

[复制链接]
发表于 2008-8-21 17:28:05 | 显示全部楼层 |阅读模式 来自 中国–河南–洛阳–西工区
官方的imessage.amxx是读AMXX.CFG里的amx_imessage的(就是屏幕上显示消息的那个插件)

这里是官方的代码:

#include <amxmodx>
#include <amxmisc>
#define X_POS         -1.0
#define Y_POS         0.20
#define HOLD_TIME     12.0
new Array:g_Values
new Array:g_Messages
new g_MessagesNum
new g_Current
#define charsof(%1) (sizeof(%1)-1)
new amx_freq_imessage;
public plugin_init()
{
g_Messages=ArrayCreate(384);
g_Values=ArrayCreate(3);
register_plugin("Info. Messages", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("imessage.txt")
register_dictionary("common.txt")
register_srvcmd("amx_imessage", "setMessage")  //////这里,从AMXX.CFG读出来应该是一组数据吧?
amx_freq_imessage=register_cvar("amx_freq_imessage", "10")

new lastinfo[8]
get_localinfo("lastinfomsg", lastinfo, 7)
g_Current = str_to_num(lastinfo)
set_localinfo("lastinfomsg", "")
}
public infoMessage()
{
if (g_Current >= g_MessagesNum)
  g_Current = 0
  
// No messages, just get out of here
if (g_MessagesNum==0)
{
  return;
}

new values[3];
new Message[384];

ArrayGetString(g_Messages, g_Current, Message, charsof(Message));
ArrayGetArray(g_Values, g_Current, values);

new hostname[64];

get_cvar_string("hostname", hostname, 63);
replace(Message, 380, "%hostname%", hostname);

set_hudmessage(values[0], values[1], values[2], X_POS, Y_POS, 0, 0.5, HOLD_TIME, 2.0, 2.0, -1);

show_hudmessage(0, "%s", Message);

client_print(0, print_console, "%s", Message);
++g_Current;

new Float:freq_im = get_pcvar_float(amx_freq_imessage);

if (freq_im > 0.0)
  set_task(freq_im, "infoMessage", 12345);
}
public setMessage()
{
new Message[384];

remove_task(12345)
read_argv(1, Message, 380)

while (replace(Message, 380, "\n", "^n")) {}

new mycol[12]
new vals[3];

read_argv(2, mycol, 11)  // RRRGGGBBB
vals[2] = str_to_num(mycol[6])

mycol[6] = 0
vals[1] = str_to_num(mycol[3])

mycol[3] = 0
vals[0] = str_to_num(mycol[0])

g_MessagesNum++

new Float:freq_im = get_pcvar_float(amx_freq_imessage)

ArrayPushString(g_Messages, Message);
ArrayPushArray(g_Values, vals);

if (freq_im > 0.0)
  set_task(freq_im, "infoMessage", 12345)

return PLUGIN_HANDLED
}
public plugin_end()
{
new lastinfo[8]
num_to_str(g_Current, lastinfo, 7)
set_localinfo("lastinfomsg", lastinfo)
}


我修改的版本如下:

#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#define X_POS         -1.0
#define Y_POS         0.20
#define HOLD_TIME     12.0
new Array:g_Values
new Array:g_Messages
new g_MessagesNum
new g_Current
#define charsof(%1) (sizeof(%1)-1)
new amx_freq_imessage;
public plugin_init()
{
new Messages[10][384];
new szQuery[] = "SELECT `body` FROM `message` LIMIT 10;";
new Handle:query = SQL_PrepareQuery( g_DBConn, szQuery );
if ( !SQL_Execute( query ) )
{
  server_print( "Database Error, unable to get Messages" );
  return;
}

new i = 0;
while ( SQL_MoreResults( query ) && i < 10 )
{
  SQL_ReadResult( query, 0, Messages, 383);
  SQL_NextRow( query );
  i++;
}
SQL_FreeHandle( query );
g_Messages=ArrayCreate(384);
g_Values=ArrayCreate(3);
register_plugin("Info. Messages", AMXX_VERSION_STR, "AMXX Dev Team")
register_dictionary("imessage.txt")
register_dictionary("common.txt")
register_srvcmd(Messages, "setMessage")
amx_freq_imessage=register_cvar("amx_freq_imessage", "10")

new lastinfo[8]
get_localinfo("lastinfomsg", lastinfo, 7)
g_Current = str_to_num(lastinfo)
set_localinfo("lastinfomsg", "")
}

下边的函数没必要动了

不太了解AMXX里register_srvcmd的用法?
哪位朋友可以指点一下?谢谢!
发表于 2008-8-23 16:29:42 | 显示全部楼层 来自 中国–福建–漳州

回复: register_srvcmd传数组问题 想把imessage改为SQL的

register_srvcmd与register_clcmd和register_concmd类似,只是一般都不需要判断权限。
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

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