|
最近对Enter_Leave.sma这个源代码作了修改,往里面加进了玩家进入或退出游戏时的音效提示(参见源代码的红色部分),测试成功,玩家进入或退出都能听到音效了。
但有个美中不足的地方,就是假如有两个或者两个以上的玩家同时(或者间隔时间很短)进入或退出了服务器,那么这些音效就会重复播放N次,造成声音混杂在一起。
所以我想请问一下,怎么才能让这些音效只向进入或退出服务器的玩家播放,而不让别的玩家听到呢?
- /*
- * Enter and Leave Message + show IP
- * v 0.1X
- *
- * by [Kindzhon] China
- * [email]kindzhon@szonline.net[/email]
- *
- *
- */
- /*
- * Cvars:
- * amx_enter_message "%name% has joined!\nEnjoy in this game!\n(Rank is %rankpos%,IP:%IP%)"
- * amx_leave_message "%name% has left!\nI hope you will come back."
- *
- * If you are using csstats module then you may use
- * %rankpos% expression in amx_enter_message cvar.
- *
- */
- #include <amxmod>
- #include <csstats>
- public client_putinserver(id){
- new param[34], len
- param[0] = id
- len = get_user_name(id,param[1],31)
- set_task(2.0, "enter_msg", 0, param,len + 2)
- return PLUGIN_CONTINUE
- }
- public client_disconnect(id){
- new param[34], len
- param[0] = id
- len = get_user_name(id, param[1], 31)
- set_task(2.0, "leave_msg", 0, param, len + 2)
- return PLUGIN_CONTINUE
- }
- public enter_msg(param[]) {
- new message[192],hostname[64]
- get_cvar_string("amx_enter_message", message, 191)
- get_cvar_string("hostname", hostname, 63)
- replace(message,191, "%hostname%", hostname)
- new address[32]
- get_user_ip(param[0],address,31,1)
- replace(message,191, "%IP%", address)
- if (cvar_exists("csstats_reset")){
- new data[8], rankpos[8], pos
- pos = get_user_stats(param[0],data,data)
- numtostr(pos,rankpos,7)
- replace(message, 191, "%rankpos%", rankpos)
- }
- replace(message, 191, "%name%", param[1])
- while(replace(message, 191, "\n", "^n")){}
- [color=red]client_cmd(0,"spk misc/enter")[/color]
- set_hudmessage(0, 255, 0, 0.10, 0.55, 0, 6.0, 6.0, 0.5, 0.15, 3)
- show_hudmessage(0, message)
- return PLUGIN_CONTINUE
- }
- public leave_msg(param[]) {
- new message[192],hostname[64]
- get_cvar_string("amx_leave_message", message, 191)
- get_cvar_string("hostname", hostname, 63)
- replace(message, 191, "%hostname%", hostname)
- replace(message, 191, "%name%", param[1])
- while(replace(message, 191, "\n", "^n")){}
- [color=red]client_cmd(0,"spk misc/leave")[/color]
- set_hudmessage(255, 0, 255, 0.10, 0.55, 0, 6.0, 6.0, 0.5, 0.15, 3)
- show_hudmessage(0, message)
- return PLUGIN_CONTINUE
- }
- public plugin_init() {
- register_plugin("Enter-Leave Message","0.2","[Kindzhon] China")
- register_cvar("amx_enter_message", "%name% has joined!\nEnjoy in this game!\n(Rank is %rankpos%,IP:%IP%)")
- register_cvar("amx_leave_message", "%name% has left!\nI hope you will come back.")
- return PLUGIN_CONTINUE
- }
- [color=red]public plugin_precache()[/color]
- [color=red]{[/color]
- [color=red]precache_sound( "misc/enter.wav")[/color]
- [color=red]precache_sound( "misc/leave.wav")[/color]
- [color=red]return PLUGIN_CONTINUE [/color]
- [color=black]}[/color]
复制代码 |
|