搜索
查看: 2418|回复: 6

请教一些关于事件触发函数的问题

[复制链接]
发表于 2007-12-18 14:07:37 | 显示全部楼层 |阅读模式 来自 中国–甘肃–兰州
大家请看下面的这些代码:
[php]register_logevent( "on_PlayerAction" , 3 , "1=triggered" );

register_logevent( "on_FreezeTimeComplete" , 2 , "0=World triggered" , "1=Round_Start" );

register_event( "SendAudio" , "on_TerroristWin" , "a" , "2=%!MRAD_terwin" );

register_event( "StatusValue" , "on_ShowStatus" , "be" , "1=2" ,"2!0" );

register_event( "StatusValue" , "on_HideStatus" , "be" , "1=1" ,"2=0" );

register_event( "BarTime" , "on_BombPlanting" , "be" , "1=3" );

register_event( "BarTime" , "on_BombStopPlanting" , "b" , "1=0" );[/php]
里面数字和字母诸如:"2", "3", "a", "be", "1=1", "1=3", 2=0", "2=%", "1=triggered"...... 到底是表示什么意思呢?(嘿嘿~ 问的东西可能太基础了,大家别见笑啊,因为我就这个水平.:p )
发表于 2007-12-18 14:20:07 | 显示全部楼层 来自 中国–广东–广州–白云区

回复: 请教一些关于事件触发函数的问题

这些数字参数还真不好懂!
回复

使用道具 举报

发表于 2007-12-18 14:36:19 | 显示全部楼层 来自 中国–广东–惠州

回复: 请教一些关于事件触发函数的问题

看下amxmodx.inc文件就明白了
回复

使用道具 举报

 楼主| 发表于 2007-12-18 14:52:16 | 显示全部楼层 来自 中国–甘肃–兰州

回复: 请教一些关于事件触发函数的问题

/* Registers event on which a given function will be called
* Flags:
* "a" - global event.
* "b" - specified.
* "c" - send only once when repeated to other players.
* "d" - call if is send to dead player.
* "e" - to alive.
* Examples for conditions:
* "2=c4" - 2nd parameter of message must be sting "c4".
* "3>10" - 3rd parameter must be greater then 10.
* "3!4" - 3rd must be different from 4.
* "2&Buy" - 2nd parameter of message must contain "Buy" substring.
* "2!Buy" - 2nd parameter of message can't contain "Buy" substring. */
native register_event(const event[],const function[],const flags[],const cond[]="", ... );
/* Registers log event on which the given function will be called
* Examples for conditions:
* "0=World triggered" "1=Game_Commencing"
* "1=say"
* "3=Terrorists_Win"
* "1=entered the game"
* "0=Server cvar"
*/
native register_logevent(const function[], argsnum,  ... );
有点晕~ 一知半解啊.:eek:
回复

使用道具 举报

发表于 2007-12-19 02:15:36 | 显示全部楼层 来自 中国–福建–漳州

回复: 请教一些关于事件触发函数的问题

语法:
register_event ( const event[], const function[], const flags[], [ cond=[], ... ] )

说明:
event(事件)是一个消息,如 "DeathMsg"、"Damage"等等。
function(函数)是一个public函数,事件发生时此函数将被调用。
flags(标志)是一组合标志,确定事件是否是需要调用的:
"a" - 公共事件
"b" - 此事件发送到一个单独的玩家
"c" - 如果重复发送至其他玩家时,只发送一次。
"d" - 只发送到死亡的玩家
"e" - 只发送到活着的玩家

你可以定义可选列表,给此事件限制或设置条件,如:
"2=c4" - 第二个参数必须是字符串"c4". “=”代表相等;
"3>10" - 第三个参数必须大小10. “>”代表大于。
"3!4" - 第三个参数不能是4.“!”代表不相等(用于数值比较时)。
"2&Buy" - 第二个参数必须包含"Buy"子串。“&”代表包含。
"2!Buy" - 第二个参数不能包含"Buy"子串。“!”代表不包含(用于字符串比较时)

例子:
  1. public plugin_init()
  2.    //只有killer不为woldspawn(KillerID不为0, 即是被玩家打死的,而不是摔死或被处死的)才会被调用。
  3.    register_event("DeathMsg", "hook_death", "a", "1>0")
  4. }
  5. public hook_death()
  6.    new Killer = read_data(1)
  7.    new Victim = read_data(2)
  8. }
复制代码

要理解该怎么设置后面的可选限制/条件列表,就要了解各个事件各个参数的意义,例如 DeathMsg 事件,其参数是这样的:
byte KillerID           //杀人者ID(参数类型:字节)
byte VictimID           //死亡者ID(参数类型:字节)
byte IsHeadshot         //是否爆头(参数类型:字节,1为爆头,0为非爆头)
string TruncatedWeaponName //缩短的武器名称(参数类型:字符串,如刀杀为knife)
此事件是发送此所有玩家的,即公共事件,了解message_begin的会知道,相当于message_begin第一个参数为 MSG_BROADCAST 或 MSG_ALL 才会被调用。
回复

使用道具 举报

发表于 2007-12-19 10:56:40 | 显示全部楼层 来自 中国–广东–佛山–禅城区

回复: 请教一些关于事件触发函数的问题

难得的教程,收藏了,谢谢Rulzy老大!
回复

使用道具 举报

发表于 2007-12-19 14:44:42 | 显示全部楼层 来自 中国–山东–青岛

回复: 请教一些关于事件触发函数的问题

非常好的教程,雪中送炭啊!!
回复

使用道具 举报

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

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