搜索
查看: 5055|回复: 11

[AMXX 带源码] 每回合开始自动装满所有枪的子弹的插件

[复制链接]
发表于 2009-1-17 13:13:23 | 显示全部楼层 |阅读模式 来自 中国–浙江–温州–平阳县
RT.amx论坛上的一个插件.看起来不错,我把它转过来.
描述如下
This plugin gives Counter-Strike 1.6 players free full ammo for their weapons (primary and secondary) like Counter-Strike Source: on spawn, on buy and on new round.
Cvars:
- fa_enable, 1 to enable plugin (default is 1)
- fa_altclips, 1 to enable alternative method of filling backpack ammo by giving clips, for older versions of CS (default is 0)

代码如下
  1. #include <amxmodx>
  2. #include <cstrike>
  3. #include <fun>
  4. #include <engine>
  5. #include <fakemeta>

  6. new g_MaxBPAmmo[31] = {
  7. 0,
  8. 52,  //CSW_P228
  9. 0,
  10. 90,  //CSW_SCOUT
  11. 1,   //CSW_HEGRENADE
  12. 32,  //CSW_XM1014
  13. 1,   //CSW_C4
  14. 100, //CSW_MAC10
  15. 90,  //CSW_AUG
  16. 1,   //CSW_SMOKEGRENADE
  17. 120, //CSW_ELITE
  18. 100, //CSW_FIVESEVEN
  19. 100, //CSW_UMP45
  20. 90,  //CSW_SG550
  21. 90,  //CSW_GALIL
  22. 90,  //CSW_FAMAS
  23. 100, //CSW_USP
  24. 120, //CSW_GLOCK18
  25. 30,  //CSW_AWP
  26. 120, //CSW_MP5NAVY
  27. 200, //CSW_M249
  28. 21,  //CSW_M3
  29. 90,  //CSW_M4A1
  30. 120, //CSW_TMP
  31. 90,  //CSW_G3SG1
  32. 2,   //CSW_FLASHBANG
  33. 35,  //CSW_DEAGLE
  34. 90,  //CSW_SG552
  35. 90,  //CSW_AK47
  36. 0,   //CSW_KNIFE
  37. 100  //CSW_P90
  38. }

  39. new g_MaxClips[31] = {
  40. 0,
  41. 4, //CSW_P228
  42. 0,
  43. 3, //CSW_SCOUT
  44. 0, //CSW_HEGRENADE
  45. 4, //CSW_XM1014
  46. 0, //CSW_C4
  47. 9, //CSW_MAC10
  48. 3, //CSW_AUG
  49. 0, //CSW_SMOKEGRENADE
  50. 4, //CSW_ELITE
  51. 2, //CSW_FIVESEVEN
  52. 9, //CSW_UMP45
  53. 3, //CSW_SG550
  54. 3, //CSW_GALIL
  55. 3, //CSW_FAMAS
  56. 9, //CSW_USP
  57. 4, //CSW_GLOCK18
  58. 3, //CSW_AWP
  59. 4, //CSW_MP5NAVY
  60. 7, //CSW_M249
  61. 4, //CSW_M3
  62. 3, //CSW_M4A1
  63. 4, //CSW_TMP
  64. 3, //CSW_G3SG1
  65. 0, //CSW_FLASHBANG
  66. 5, //CSW_DEAGLE
  67. 3, //CSW_SG552
  68. 3, //CSW_AK47
  69. 0, //CSW_KNIFE
  70. 2  //CSW_P90
  71. }

  72. new g_ClipSize[31] = {
  73. 0,
  74. 13,  //CSW_P228
  75. 0,
  76. 10,  //CSW_SCOUT
  77. 0,   //CSW_HEGRENADE
  78. 7,   //CSW_XM1014
  79. 0,   //CSW_C4
  80. 30,  //CSW_MAC10
  81. 30,  //CSW_AUG
  82. 0,   //CSW_SMOKEGRENADE
  83. 30,  //CSW_ELITE
  84. 20,  //CSW_FIVESEVEN
  85. 25,  //CSW_UMP45
  86. 30,  //CSW_SG550
  87. 35,  //CSW_GALIL
  88. 25,  //CSW_FAMAS
  89. 12,  //CSW_USP
  90. 20,  //CSW_GLOCK18
  91. 10,  //CSW_AWP
  92. 30,  //CSW_MP5NAVY
  93. 100, //CSW_M249
  94. 8,   //CSW_M3
  95. 30,  //CSW_M4A1
  96. 30,  //CSW_TMP
  97. 20,  //CSW_G3SG1
  98. 0,   //CSW_FLASHBANG
  99. 7,   //CSW_DEAGLE
  100. 30,  //CSW_SG552
  101. 30,  //CSW_AK47
  102. 0,   //CSW_KNIFE
  103. 50   //CSW_P90
  104. }

  105. new g_AmmoType[31] = {
  106. 0,
  107. 9,  //CSW_P228
  108. 0,
  109. 2,  //CSW_SCOUT
  110. 12, //CSW_HEGRENADE
  111. 5,  //CSW_XM1014
  112. 14, //CSW_C4
  113. 6,  //CSW_MAC10
  114. 4,  //CSW_AUG
  115. 13, //CSW_SMOKEGRENADE
  116. 10, //CSW_ELITE
  117. 7,  //CSW_FIVESEVEN
  118. 6,  //CSW_UMP45
  119. 4,  //CSW_SG550
  120. 4,  //CSW_GALIL
  121. 4,  //CSW_FAMAS
  122. 6,  //CSW_USP
  123. 10, //CSW_GLOCK18
  124. 1,  //CSW_AWP
  125. 10, //CSW_MP5NAVY
  126. 3,  //CSW_M249
  127. 5,  //CSW_M3
  128. 4,  //CSW_M4A1
  129. 10, //CSW_TMP
  130. 2,  //CSW_G3SG1
  131. 11, //CSW_FLASHBANG
  132. 8,  //CSW_DEAGLE
  133. 4,  //CSW_SG552
  134. 2,  //CSW_AK47
  135. 0,  //CSW_KNIFE
  136. 7   //CSW_P90
  137. }

  138. new g_AmmoName[15][] = {
  139. "",
  140. "ammo_338magnum",
  141. "ammo_762nato",
  142. "ammo_556natobox",
  143. "ammo_556nato",
  144. "ammo_buckshot",
  145. "ammo_45acp",
  146. "ammo_57mm",
  147. "ammo_50ae",
  148. "ammo_357sig",
  149. "ammo_9mm",
  150. "",
  151. "",
  152. "",
  153. ""
  154. }

  155. new bool:g_restart_attempt[33]
  156. new bool:g_HideGiveClips[33]
  157. new bool:g_FirstSpawn[33]
  158. new g_LastMessageID
  159. new g_LastMessageType
  160. new g_LastMessage[33]
  161. new g_LastWeapPickup[33]
  162. new bool:g_Spawned[33]
  163. new g_BoughtWeapon[33]

  164. new g_WeapPickupMsg
  165. new g_MoneyMsg

  166. new pv_fa_enable
  167. new pv_fa_altclips

  168. public plugin_init()
  169. {
  170. register_plugin("Free ammo", "1.4", "asstolavista")
  171. register_event("ResetHUD", "event_hud_reset", "be")
  172. register_clcmd("fullupdate", "clcmd_fullupdate")
  173. register_event("TextMsg", "event_restart_attempt", "a", "2=#Game_will_restart_in")
  174. register_event("HLTV", "event_new_round", "a", "1=0", "2=0")
  175. register_message(get_user_msgid("AmmoPickup"), "message_ammo_pickup")

  176. g_WeapPickupMsg = get_user_msgid("WeapPickup")
  177. g_MoneyMsg = get_user_msgid("Money")
  178. register_forward(FM_MessageBegin, "forward_message_begin", 1)
  179. register_forward(FM_WriteByte, "forward_write_byte", 1)

  180. pv_fa_enable = register_cvar("fa_enable", "1")
  181. pv_fa_altclips = register_cvar("fa_altclips", "0")
  182. }

  183. public client_connect(id)
  184. {
  185. g_restart_attempt[id] = false
  186. g_HideGiveClips[id] = false
  187. g_FirstSpawn[id] = true
  188. g_LastMessage[id] = 0
  189. g_LastWeapPickup[id] = 0
  190. g_Spawned[id] = false
  191. g_BoughtWeapon[id] = 0
  192. }

  193. public client_disconnect(id)
  194. {
  195. g_restart_attempt[id] = false
  196. g_HideGiveClips[id] = false
  197. g_FirstSpawn[id] = true
  198. g_LastMessage[id] = 0
  199. g_LastWeapPickup[id] = 0
  200. g_Spawned[id] = false
  201. g_BoughtWeapon[id] = 0
  202. }

  203. public clcmd_fullupdate()
  204. {
  205. return PLUGIN_HANDLED
  206. }

  207. public event_restart_attempt()
  208. {
  209. new players[32], num_players
  210. get_players(players, num_players, "a")
  211. for (new i; i < num_players; ++i)
  212. g_restart_attempt[players[i]] = true
  213. }

  214. public event_hud_reset(id)
  215. {
  216. if (g_restart_attempt[id]) {
  217. g_restart_attempt[id] = false
  218. return
  219. }
  220. event_player_spawn(id)
  221. }

  222. public event_player_spawn(id)
  223. {
  224. if (get_pcvar_num(pv_fa_enable) == 1) {
  225. g_HideGiveClips[id] = true
  226. g_Spawned[id] = true
  227. }
  228. }

  229. public do_player_spawn(id)
  230. {
  231. new weap_ids[32], num_weaps
  232. get_user_weapons(id, weap_ids, num_weaps)
  233. for (new i = 0; i < num_weaps; i++) {
  234. new weap_id = weap_ids[i]
  235. if (fill_weapon(id, weap_id)) {
  236. if (g_FirstSpawn[id]) {
  237. if (get_pcvar_num(pv_fa_altclips) != 1)
  238. cs_set_user_bpammo(id, weap_id, 0)
  239. fill_bpammo_show(id, weap_id)
  240. }
  241. else
  242. fill_bpammo(id, weap_id)
  243. }
  244. }
  245. g_FirstSpawn[id] = false
  246. }

  247. public event_new_round()
  248. {
  249. if (get_pcvar_num(pv_fa_enable) == 1) {
  250. new players[32], num_players
  251. get_players(players, num_players, "a")
  252. for (new j = 0; j < num_players; j++) {
  253. new id = players[j]
  254. new weap_ids[32], num_weaps
  255. get_user_weapons(id, weap_ids, num_weaps)
  256. for (new i = 0; i < num_weaps; i++)
  257. if (fill_weapon(id, weap_ids[i]))
  258. fill_bpammo(id, weap_ids[i])
  259. }
  260. }
  261. }

  262. public message_ammo_pickup(msg_id, id, ent)
  263. {
  264. if (get_pcvar_num(pv_fa_enable) == 1) {
  265. if (g_HideGiveClips[id]) {
  266. g_HideGiveClips[id] = false
  267. return PLUGIN_HANDLED
  268. }
  269. }
  270. return PLUGIN_CONTINUE
  271. }

  272. public forward_message_begin(msg_dest, msg_type, const Float:ORIGIN[3], const ED)
  273. {
  274. if (ED < 1 || ED > 32)
  275. return
  276. new id = ED
  277. if (msg_type == g_MoneyMsg && g_LastMessage[id] == g_WeapPickupMsg)
  278. event_weapon_buy(id, g_LastWeapPickup[id])
  279. g_LastMessageID = id
  280. g_LastMessageType = msg_type
  281. g_LastMessage[id] = msg_type
  282. }

  283. public forward_write_byte(value)
  284. {
  285. if (g_LastMessageType == g_WeapPickupMsg)
  286. g_LastWeapPickup[g_LastMessageID] = value
  287. }

  288. public event_weapon_buy(id, weap_id)
  289. {
  290. g_BoughtWeapon[id] = weap_id
  291. }

  292. public do_weapon_buy(id, weap_id)
  293. {
  294. if (fill_weapon(id, weap_id))
  295. fill_bpammo_show(id, weap_id)
  296. }

  297. public client_PreThink(id)
  298. {
  299. if (get_pcvar_num(pv_fa_enable) == 1) {
  300. if (g_Spawned[id]) {
  301. g_Spawned[id] = false
  302. do_player_spawn(id)
  303. }
  304. if (g_BoughtWeapon[id] != 0) {
  305. new weap_id = g_BoughtWeapon[id]
  306. g_BoughtWeapon[id] = 0
  307. do_weapon_buy(id, weap_id)
  308. }
  309. }
  310. return PLUGIN_CONTINUE
  311. }

  312. public bool:weapon_has_ammo(weap_id)
  313. {
  314. return g_AmmoName[g_AmmoType[weap_id]][0] != 0
  315. }

  316. public bool:fill_bpammo(id, weap_id)
  317. {
  318. if (get_pcvar_num(pv_fa_altclips) == 1) {
  319. new ammo_clips = g_MaxClips[weap_id]
  320. if (weapon_has_ammo(weap_id)) {
  321. for (new i = 1; i <= ammo_clips; i++) {
  322. g_HideGiveClips[id] = true
  323. give_item(id, g_AmmoName[g_AmmoType[weap_id]])
  324. }
  325. g_HideGiveClips[id] = false
  326. return true
  327. }
  328. }
  329. else {
  330. new ammo = g_MaxBPAmmo[weap_id]
  331. if (weapon_has_ammo(weap_id)) {
  332. cs_set_user_bpammo(id, weap_id, ammo)
  333. g_HideGiveClips[id] = false
  334. return true
  335. }
  336. }
  337. return false
  338. }

  339. public bool:fill_weapon(id, weap_id)
  340. {
  341. new clip_size = g_ClipSize[weap_id]
  342. if (clip_size != 0) {
  343. new weap_name[41]
  344. get_weaponname(weap_id, weap_name, 40)
  345. new wpn = find_ent_by_owner(-1, weap_name, id)
  346. if (wpn != 0) {
  347. cs_set_weapon_ammo(wpn, clip_size)
  348. return true
  349. }
  350. }
  351. return false
  352. }

  353. public show_given_bpammo(id, weap_id, ammount)
  354. {
  355. g_HideGiveClips[id] = false
  356. if (ammount <= 0)
  357. return
  358. message_begin(MSG_ONE, get_user_msgid("AmmoPickup"), {0,0,0}, id)
  359. write_byte(g_AmmoType[weap_id])
  360. write_byte(ammount)
  361. message_end()
  362. }

  363. public bool:fill_bpammo_show(id, weap_id)
  364. {
  365. new given_ammo = g_MaxBPAmmo[weap_id]
  366. if (get_pcvar_num(pv_fa_altclips) != 1 && weapon_has_ammo(weap_id))
  367. given_ammo -= cs_get_user_bpammo(id, weap_id)
  368. if (fill_bpammo(id, weap_id)) {
  369. show_given_bpammo(id, weap_id, given_ammo)
  370. return true
  371. }
  372. return false
  373. }
复制代码
发表于 2009-1-18 00:50:01 | 显示全部楼层 来自 中国–北京–北京
好哦,不错
回复

使用道具 举报

发表于 2009-1-18 01:11:28 | 显示全部楼层 来自 中国–广西–百色
直接发插件啊。。
回复

使用道具 举报

发表于 2009-1-18 02:51:20 | 显示全部楼层 来自 中国–辽宁–沈阳
兄弟你太好了. 直接发源码, 可给大家省下 下载的钱了..我谢谢你喽 哈哈
回复

使用道具 举报

发表于 2009-1-18 08:59:18 | 显示全部楼层 来自 中国–北京–北京
这样省钱啊
回复

使用道具 举报

发表于 2009-1-18 14:17:20 | 显示全部楼层 来自 中国–山东–潍坊
:victory:不错哦
回复

使用道具 举报

发表于 2009-1-30 00:34:36 | 显示全部楼层 来自 中国–香港
路過支持一下 =]
回复

使用道具 举报

发表于 2009-1-30 14:42:18 | 显示全部楼层 来自 中国–香港
謝謝了~
回复

使用道具 举报

发表于 2009-1-31 23:09:31 | 显示全部楼层 来自 中国–香港
不錯不錯先收下囉
回复

使用道具 举报

发表于 2009-2-5 00:55:48 | 显示全部楼层 来自 中国–广东–东莞
谢谢了
不错
支持一下
回复

使用道具 举报

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

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