搜索
查看: 3946|回复: 6

这样修改对吗(杀人奖励插件)?(已解决)

[复制链接]
发表于 2009-10-2 21:35:36 | 显示全部楼层 |阅读模式 来自 日本
本帖最后由 cityhonghu 于 2009-10-4 16:17 编辑

虽然不是很懂,觉得连续杀人奖励部分有些不对改了一下(1局只能有1人?)。1楼为原始代码。2楼为改之后的代码,帮忙看一下是否对?
谢谢
  1. #include <amxmodx>
  2. #include <unlimited_money>

  3. new p_lastk=0,p_lastk_count=0

  4. public plugin_init() {
  5.         register_plugin("MultiKill", "1.1", "Marshall")
  6.         register_event("DeathMsg", "hook_death", "a")
  7.         register_logevent("hook_roundstart",2,"0=World triggered","1=Round_Start")
  8. }

  9. public hook_death(){
  10.         new msg[128]
  11.         new Killer = read_data(1)
  12.         new headshot = read_data(3)
  13.         new p_weapon[16]
  14.         read_data(4,p_weapon,15)
  15.         new p_name[16]
  16.         get_user_name(Killer,p_name,15)       
  17.        
  18.         //爆头奖励
  19.         if(headshot){
  20.                 format(msg,127,"^x04爆头奖励:^x03%s^x01 获得$1000!",p_name)
  21.                 client_color(Killer, Killer, msg)
  22.                 cs_set_user_money2(Killer,cs_get_user_money2(Killer) + 1000)
  23.         }
  24.         //刀杀奖励
  25.         if(strcmp(p_weapon,"knife")==0){
  26.                 format(msg,127,"^x04刀杀奖励:^x03%s^x01 获得$5000!",p_name)
  27.                 client_color(Killer, Killer, msg)
  28.                 cs_set_user_money2(Killer,cs_get_user_money2(Killer) + 5000)
  29.         }
  30.        
  31.         //雷杀奖励
  32.         if(strcmp(p_weapon,"grenade")==0){
  33.                 format(msg,127,"^x04雷杀奖励:^x03%s^x01 获得$1500!",p_name)
  34.                 client_color(Killer, Killer, msg)
  35.                 cs_set_user_money2(Killer,cs_get_user_money2(Killer) + 1500)
  36.         }
  37.        
  38.         //连续杀人奖励
  39.         if(p_lastk != Killer){
  40.                 p_lastk = Killer
  41.                 p_lastk_count =1
  42.         }
  43.         else
  44.                 p_lastk_count++
  45.        
  46.         if(p_lastk_count>=5){
  47.                 format(msg,127,"^x04连续杀人奖励:^x03%s^x01 连续杀人5次,获得$3000!",p_name)
  48.                 client_color(Killer, Killer, msg)
  49.                 cs_set_user_money2(Killer,cs_get_user_money2(Killer) + 3000)
  50.         }
  51. }

  52. public hook_roundstart(){
  53.         p_lastk=0
  54.         p_lastk_count=0
  55. }

  56. public client_color(playerid,colorid,msg[])
  57. {
  58.         message_begin(playerid?MSG_ONE:MSG_ALL, get_user_msgid("SayText"), {0,0,0}, playerid)
  59.         write_byte(colorid)
  60.         write_string(msg)
  61.         message_end()
  62. }

  63. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  64. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang2052\\ f0\\ fs16 \n\\ par }
  65. */
复制代码
 楼主| 发表于 2009-10-2 21:56:16 | 显示全部楼层 来自 日本
修改之后,编译不通过。
问题:
1。数组的初始化(0)是不是要这样写?p_count[32] = [0, 0, ...]
2。killer = read_data(1)的话,被杀的人target是否为read_data(2) ?
以下为修改之后的代码。
  1. #include <amxmodx>
  2. #include <unlimited_money>

  3. new k_count[32] = [0, 0, ...]

  4. public plugin_init() {
  5.         register_plugin("MultiKill", "1.1", "Marshall")
  6.         register_event("DeathMsg", "hook_death", "a")
  7.         register_logevent("hook_roundstart",2,"0=World triggered","1=Round_Start")
  8. }

  9. public hook_death(){
  10.         new msg[128]
  11.         new Killer = read_data(1)
  12.         new headshot = read_data(3)
  13.         new p_weapon[16]
  14.         read_data(4,p_weapon,15)
  15.         new p_name[16]
  16.         get_user_name(Killer,p_name,15)       
  17.        
  18.         //爆头奖励
  19.         if(headshot){
  20.                 format(msg,127,"^x04爆头奖励:^x03%s^x01 获得$1000!",p_name)
  21.                 client_color(Killer, Killer, msg)
  22.                 cs_set_user_money2(Killer,cs_get_user_money2(Killer) + 1000)
  23.         }
  24.         //刀杀奖励
  25.         if(strcmp(p_weapon,"knife")==0){
  26.                 format(msg,127,"^x04刀杀奖励:^x03%s^x01 获得$5000!",p_name)
  27.                 client_color(Killer, Killer, msg)
  28.                 cs_set_user_money2(Killer,cs_get_user_money2(Killer) + 5000)
  29.         }
  30.        
  31.         //雷杀奖励
  32. if(strcmp(p_weapon,"grenade")==0){
  33.                 format(msg,127,"^x04雷杀奖励:^x03%s^x01 获得$1500!",p_name)
  34.                 client_color(Killer, Killer, msg)
  35.                 cs_set_user_money2(Killer,cs_get_user_money2(Killer) + 1500)
  36.         }
  37.        
  38.         //连续杀人奖励
  39.         k_count[Killer]++
  40.         if(k_count[Killer]>=5){
  41.                 format(msg,127,"^x04连续杀人奖励:^x03%s^x01 连续杀人5次,获得$3000!",p_name)
  42.                 client_color(Killer, Killer, msg)
  43.                 cs_set_user_money2(Killer,cs_get_user_money2(Killer) + 3000)
  44.                 k_count[Killer] = 0
  45.         }
  46. }

  47. public hook_roundstart(){
  48.         k_count[32] = [0, 0, ...]
  49. }

  50. public client_color(playerid,colorid,msg[])
  51. {
  52.         message_begin(playerid?MSG_ONE:MSG_ALL, get_user_msgid("SayText"), {0,0,0}, playerid)
  53.         write_byte(colorid)
  54.         write_string(msg)
  55.         message_end()
  56. }

  57. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  58. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang2052\\ f0\\ fs16 \n\\ par }
  59. */
复制代码
回复

使用道具 举报

 楼主| 发表于 2009-10-2 22:06:25 | 显示全部楼层 来自 日本
晕,发错区了。麻烦版主移动到脚本编写讨论区。
真的对不起。
回复

使用道具 举报

发表于 2009-10-3 00:36:11 | 显示全部楼层 来自 台湾
new k_count[32] = [0, 0, ...]
正常要寫成
new k_count[32] = {0, 0, ...}
才對吧
回复

使用道具 举报

 楼主| 发表于 2009-10-4 09:03:50 | 显示全部楼层 来自 日本
谢谢,但是该行会出现如下错误,无法编译。
// E:\HLDS27016\cstrike\addons\amxmodx\scripting\kill_bonus.sma(61) : error 032:
array index out of bounds (variable "k_count")
回复

使用道具 举报

发表于 2009-10-4 12:30:55 | 显示全部楼层 来自 台湾
第52行的部份你有改嗎?
回复

使用道具 举报

 楼主| 发表于 2009-10-4 16:17:19 | 显示全部楼层 来自 日本
问题已经解决了。使我的用法不对。
k_count[32] = {0, 0, ...}初始化只能在定义阶段这样使用。

所以改为用for语句,对数组进行了归零。
回复

使用道具 举报

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

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