搜索
查看: 2060|回复: 3

代码求助

[复制链接]
发表于 2006-12-3 04:36:15 | 显示全部楼层 |阅读模式 来自 中国–香港
下列是我的代码
我做了一个c4随机奖励武器
我不知道怎么做到,手上已经有武器的..
随机奖励武器,刚好奖励你手上的武器
怎么做到不奖励你已经有的武器呢??
  1. #include <amxmodx>
  2. #include <cstrike>
  3. #include <engine>
  4. #include <csx>
  5. #include <fun>
  6. new primary_weapon[32]
  7. new name[32]
  8. new id
  9. new weapon[2][21]
  10. new ammo_type[21]
  11. new gBombReward = 1
  12. public plugin_init()
  13. {
  14. register_plugin("C4成功拆除或爆炸,随机奖励武器", "0.1", "你的人")
  15. register_concmd("amx_bombreward","admin_bombreward",0,"C4成功拆除或爆炸,随机奖励武器 <1 | 0 >")
  16. }
  17. public admin_bombreward(id,level,cid)
  18. {
  19. if (!(get_user_flags(id)&ADMIN_IMMUNITY)){
  20.   client_print(id, print_console, "你没有权限执行这个参数")
  21.   return PLUGIN_HANDLED
  22. }
  23. if (read_argc() < 2)
  24. {
  25.   console_print(id,"使用方法: amx_bombreward < 1 | 0 >")
  26.   return PLUGIN_HANDLED
  27. }
  28. new bombtarget = find_ent_by_class(-1, "func_bomb_target")
  29. if ( !bombtarget )
  30. {
  31.   gBombReward = 0
  32.   console_print(id,"此地图没有炸弹安装点^nC4成功拆除或爆炸,随机奖励武器 - 已关闭")
  33. }
  34. new sArg1[32]
  35. read_argv(1,sArg1,31)
  36. if (str_to_num(sArg1) == 1)
  37. {
  38.   if ( bombtarget )
  39.   {
  40.    gBombReward = 1
  41.    client_print(id,print_console,"[AMXX]C4成功拆除或爆炸,随机奖励武器 - 已开启.")
  42.    client_print(0,print_chat,"[AMXX]C4成功拆除或爆炸,随机奖励武器 - 已开启.")
  43.   }
  44. }
  45. if (str_to_num(sArg1) == 0)
  46. {
  47.   if ( bombtarget )
  48.   {
  49.    gBombReward = 0
  50.    client_print(id,print_console,"[AMXX]C4成功拆除或爆炸,随机奖励武器 - 已关闭.")
  51.    client_print(0,print_chat,"[AMXX]C4成功拆除或爆炸,随机奖励武器 - 已关闭.")
  52.   }
  53. }
  54. if ( str_to_num(sArg1) > 1 )
  55. {
  56.   console_print(id,"使用方法: amx_bombreward < 1 | 0 >")
  57. }
  58. return PLUGIN_HANDLED
  59. }
  60. public bomb_explode(planter, defuser)
  61. {
  62. if (gBombReward == 0)
  63. {
  64. }
  65. if (gBombReward)
  66. {
  67.   get_user_name(planter,name,31)
  68.   randomize_primary(id)
  69.   get_weaponname(primary_weapon[id], weapon[1], 20)
  70.   give_item(planter, weapon[1])  
  71.   ammo_type = get_ammotype(primary_weapon[id])
  72.   give_item(planter, ammo_type)
  73.   give_item(planter, ammo_type)
  74.   set_hudmessage(200,200,200,-1.0,0.40,0,6.0,6.0,0.5,0.15,2)
  75.   show_hudmessage(0,"C4爆炸成功,奖励%s给予%s", weapon[1][7], name)
  76.   client_print(id, print_chat, "[AMXX]C4爆炸成功,奖励%s给予%s", weapon[1][7], name)
  77. }
  78. }
  79. public bomb_defused (defuser)
  80. {
  81. if (gBombReward == 0)
  82. {
  83. }
  84. if (gBombReward)
  85. {
  86.   get_user_name(defuser,name,31)
  87.   randomize_primary(id)
  88.   get_weaponname(primary_weapon[id], weapon[1], 20)
  89.   give_item(defuser, weapon[1])  
  90.   ammo_type = get_ammotype(primary_weapon[id])
  91.   give_item(defuser, ammo_type)
  92.   give_item(defuser, ammo_type)
  93.   set_hudmessage(200,200,200,-1.0,0.40,0,6.0,6.0,0.5,0.15,2)
  94.   show_hudmessage(0,"C4成功拆除,奖励%s给予%s", weapon[1][7], name)
  95.   client_print(id, print_chat, "[AMXX]C4成功拆除,奖励%s给予%s", weapon[1][7], name)
  96. }
  97. }
  98. public randomize_primary(id)
  99. {
  100. new rand = random_num(1, 18)
  101. switch(rand)
  102. {   
  103.   case 1: primary_weapon[id] = CSW_SCOUT
  104.   
  105.   case 2: primary_weapon[id] = CSW_XM1014
  106.   
  107.   case 3: primary_weapon[id] = CSW_MAC10
  108.   
  109.   case 4: primary_weapon[id] = CSW_AUG
  110.   
  111.   case 5: primary_weapon[id] = CSW_UMP45
  112.   
  113.   case 6: primary_weapon[id] = CSW_SG550
  114.   
  115.   case 7: primary_weapon[id] = CSW_FAMAS
  116.   
  117.   case 8: primary_weapon[id] = CSW_AWP
  118.          
  119.   case 9: primary_weapon[id] = CSW_MP5NAVY
  120.   
  121.          case 10: primary_weapon[id] = CSW_M249
  122.   
  123.   case 11: primary_weapon[id] = CSW_M3
  124.   
  125.   case 12: primary_weapon[id] = CSW_M4A1
  126.   
  127.   case 13: primary_weapon[id] = CSW_TMP
  128.   
  129.   case 14: primary_weapon[id] = CSW_G3SG1
  130.   
  131.   case 15: primary_weapon[id] = CSW_SG552
  132.   
  133.          case 16: primary_weapon[id] = CSW_AK47
  134.   
  135.   case 17: primary_weapon[id] = CSW_P90
  136.   
  137.   case 18: primary_weapon[id] = CSW_HEGRENADE
  138. }
  139. return PLUGIN_CONTINUE
  140. }
  141. stock get_ammotype(weapon)
  142. {
  143. new ammo[21]
  144. switch(weapon)
  145. {
  146.   case CSW_SCOUT: ammo = "ammo_762nato"
  147.   case CSW_XM1014: ammo = "ammo_buckshot"
  148.   case CSW_MAC10: ammo = "ammo_45acp"
  149.   case CSW_AUG: ammo = "ammo_556nato"
  150.   case CSW_UMP45: ammo = "ammo_45acp"
  151.   case CSW_SG550: ammo = "ammo_556nato"
  152.   case CSW_FAMAS: ammo = "ammo_556nato"
  153.   case CSW_AWP: ammo = "ammo_338magnum"
  154.   case CSW_MP5NAVY: ammo = "ammo_9mm"
  155.   case CSW_M249: ammo = "ammo_556natobox"
  156.   case CSW_M3: ammo = "ammo_buckshot"
  157.   case CSW_M4A1: ammo = "ammo_556nato"
  158.   case CSW_TMP: ammo = "ammo_9mm"
  159.   case CSW_G3SG1: ammo = "ammo_762nato"
  160.   case CSW_SG552: ammo = "ammo_556nato"
  161.   case CSW_AK47: ammo = "ammo_762nato"
  162.   case CSW_P90: ammo = "ammo_57mm"
  163. }
  164. return ammo
  165. }
复制代码
发表于 2006-12-3 11:22:44 | 显示全部楼层 来自 中国–北京–北京–朝阳区

回复: 代码求助

get_user_weapons
回复

使用道具 举报

 楼主| 发表于 2006-12-3 12:00:34 | 显示全部楼层 来自 中国–香港

回复: 代码求助

Post by jim_yang
get_user_weapons
我已經想過用get_user_weapons
但是我不懂用這涵數= ="
回复

使用道具 举报

发表于 2006-12-3 12:07:03 | 显示全部楼层 来自 中国–北京–北京–朝阳区

回复: 代码求助

Syntax:

     get_user_weapons ( index, weapons[32], &num ) Type:

    Native Notes:

index is a player index from 1 to 32.

The weapons array passed as the second parameter is filled with a list of weapon indices, from 0 to num-1. num will be filled with the number of weapons found (passed byref).

Example:
new Weapons[32]
new numWeapons, i, weapon
get_user_weapons(id, Weapons, numWeapons)
for (i=0; i<numWeapns; i++)
{
   weapon = Weapons
}
回复

使用道具 举报

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

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