搜索
查看: 2270|回复: 3

玩家进入或退出游戏时有音效提示

[复制链接]
发表于 2007-7-31 20:12:22 | 显示全部楼层 |阅读模式 来自 中国–甘肃–兰州
最近对Enter_Leave.sma这个源代码作了修改,往里面加进了玩家进入或退出游戏时的音效提示(参见源代码的红色部分),测试成功,玩家进入或退出都能听到音效了。

但有个美中不足的地方,就是假如有两个或者两个以上的玩家同时(或者间隔时间很短)进入或退出了服务器,那么这些音效就会重复播放N次,造成声音混杂在一起。

所以我想请问一下,怎么才能让这些音效只向进入或退出服务器的玩家播放,而不让别的玩家听到呢?
  1. /*
  2. * Enter and Leave Message + show IP
  3. *  v 0.1X
  4. *
  5. *  by [Kindzhon] China
  6. *   [email]kindzhon@szonline.net[/email]
  7. *
  8. *
  9. */
  10. /*
  11. * Cvars:
  12. * amx_enter_message "%name% has joined!\nEnjoy in this game!\n(Rank is %rankpos%,IP:%IP%)"
  13. * amx_leave_message "%name% has left!\nI hope you will come back."
  14. *
  15. * If you are using csstats module then you may use
  16. * %rankpos% expression in amx_enter_message cvar.
  17. *
  18. */
  19. #include <amxmod>
  20. #include <csstats>
  21. public client_putinserver(id){
  22.    new param[34], len
  23.    param[0] = id
  24.    len = get_user_name(id,param[1],31)
  25.    set_task(2.0, "enter_msg", 0, param,len + 2)
  26.    return PLUGIN_CONTINUE
  27. }
  28. public client_disconnect(id){
  29.    new param[34], len
  30.    param[0] = id
  31.    len = get_user_name(id, param[1], 31)
  32.    set_task(2.0, "leave_msg", 0, param, len + 2)
  33.    return PLUGIN_CONTINUE
  34. }
  35. public enter_msg(param[]) {
  36.    new message[192],hostname[64]
  37.    get_cvar_string("amx_enter_message", message, 191)
  38.    get_cvar_string("hostname", hostname, 63)
  39.    replace(message,191, "%hostname%", hostname)
  40.    new address[32]
  41.    get_user_ip(param[0],address,31,1)
  42.    replace(message,191, "%IP%", address)
  43.    if (cvar_exists("csstats_reset")){
  44.       new data[8], rankpos[8], pos
  45.       pos = get_user_stats(param[0],data,data)
  46.       numtostr(pos,rankpos,7)
  47.       replace(message, 191, "%rankpos%", rankpos)
  48.    }
  49.    replace(message, 191, "%name%", param[1])
  50.    while(replace(message, 191, "\n", "^n")){}
  51.    [color=red]client_cmd(0,"spk misc/enter")[/color]
  52.    set_hudmessage(0, 255, 0, 0.10, 0.55, 0, 6.0, 6.0, 0.5, 0.15, 3)
  53.    show_hudmessage(0, message)
  54.    return PLUGIN_CONTINUE
  55. }
  56. public leave_msg(param[]) {
  57.    new message[192],hostname[64]
  58.    get_cvar_string("amx_leave_message", message, 191)
  59.    get_cvar_string("hostname", hostname, 63)
  60.    replace(message, 191, "%hostname%", hostname)
  61.    replace(message, 191, "%name%", param[1])
  62.    while(replace(message, 191, "\n", "^n")){}
  63.    [color=red]client_cmd(0,"spk misc/leave")[/color]
  64.    set_hudmessage(255, 0, 255, 0.10, 0.55, 0, 6.0, 6.0, 0.5, 0.15, 3)
  65.    show_hudmessage(0, message)
  66.    return PLUGIN_CONTINUE
  67. }
  68. public plugin_init() {
  69.   register_plugin("Enter-Leave Message","0.2","[Kindzhon] China")
  70.   register_cvar("amx_enter_message", "%name% has joined!\nEnjoy in this game!\n(Rank is %rankpos%,IP:%IP%)")
  71.   register_cvar("amx_leave_message", "%name% has left!\nI hope you will come back.")
  72.   return PLUGIN_CONTINUE
  73. }
  74. [color=red]public plugin_precache()[/color]
  75. [color=red]{[/color]
  76. [color=red]precache_sound( "misc/enter.wav")[/color]
  77. [color=red]precache_sound( "misc/leave.wav")[/color]
  78. [color=red]return PLUGIN_CONTINUE [/color]
  79. [color=black]}[/color]
复制代码
 楼主| 发表于 2007-7-31 21:45:30 | 显示全部楼层 来自 中国–甘肃–兰州

回复: 玩家进入或退出游戏时有音效提示

是不是把client_cmd(0,"spk misc/enter")改成client_cmd(id,"spk misc/enter")就行了呢?我试过了,但编译时出错......:burn:
回复

使用道具 举报

发表于 2007-7-31 23:02:21 | 显示全部楼层 来自 中国–云南–西双版纳傣族自治州–景洪市

回复: 玩家进入或退出游戏时有音效提示

你把0改成param[0]试试
回复

使用道具 举报

 楼主| 发表于 2007-8-1 19:28:40 | 显示全部楼层 来自 中国–甘肃–兰州

回复: 玩家进入或退出游戏时有音效提示

测试成功!再次感谢zhangsheng大哥!:byebye:
回复

使用道具 举报

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

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