玩家进入或退出游戏时有音效提示
最近对Enter_Leave.sma这个源代码作了修改,往里面加进了玩家进入或退出游戏时的音效提示(参见源代码的红色部分),测试成功,玩家进入或退出都能听到音效了。但有个美中不足的地方,就是假如有两个或者两个以上的玩家同时(或者间隔时间很短)进入或退出了服务器,那么这些音效就会重复播放N次,造成声音混杂在一起。
所以我想请问一下,怎么才能让这些音效只向进入或退出服务器的玩家播放,而不让别的玩家听到呢?
/*
* Enter and Leave Message + show IP
*v 0.1X
*
*by China
* kindzhon@szonline.net
*
*
*/
/*
* 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, len
param = id
len = get_user_name(id,param,31)
set_task(2.0, "enter_msg", 0, param,len + 2)
return PLUGIN_CONTINUE
}
public client_disconnect(id){
new param, len
param = id
len = get_user_name(id, param, 31)
set_task(2.0, "leave_msg", 0, param, len + 2)
return PLUGIN_CONTINUE
}
public enter_msg(param[]) {
new message,hostname
get_cvar_string("amx_enter_message", message, 191)
get_cvar_string("hostname", hostname, 63)
replace(message,191, "%hostname%", hostname)
new address
get_user_ip(param,address,31,1)
replace(message,191, "%IP%", address)
if (cvar_exists("csstats_reset")){
new data, rankpos, pos
pos = get_user_stats(param,data,data)
numtostr(pos,rankpos,7)
replace(message, 191, "%rankpos%", rankpos)
}
replace(message, 191, "%name%", param)
while(replace(message, 191, "\n", "^n")){}
client_cmd(0,"spk misc/enter")
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,hostname
get_cvar_string("amx_leave_message", message, 191)
get_cvar_string("hostname", hostname, 63)
replace(message, 191, "%hostname%", hostname)
replace(message, 191, "%name%", param)
while(replace(message, 191, "\n", "^n")){}
client_cmd(0,"spk misc/leave")
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"," 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
}
public plugin_precache()
{
precache_sound( "misc/enter.wav")
precache_sound( "misc/leave.wav")
return PLUGIN_CONTINUE
}
回复: 玩家进入或退出游戏时有音效提示
是不是把client_cmd(0,"spk misc/enter")改成client_cmd(id,"spk misc/enter")就行了呢?我试过了,但编译时出错......:burn:回复: 玩家进入或退出游戏时有音效提示
你把0改成param试试回复: 玩家进入或退出游戏时有音效提示
测试成功!再次感谢zhangsheng大哥!:byebye:
页:
[1]