Guest User

knife

a guest
Apr 25th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.50 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <fakemeta>
  4. #include <fakemeta_util>
  5. #include <fun>
  6. #include <hamsandwich>
  7. #include <cstrike>
  8. #include <engine>
  9. #include <nst_wpn>
  10. #include <zombieplague>
  11. #define PLUGIN "NST Wpn Mod"
  12. #define VERSION "1.0"
  13. #define AUTHOR "NST"
  14.  
  15. // Var main
  16. const TYPE_WPN = 3
  17. const MAX_WPN = 40
  18. new HAS_WEAPON[33]
  19. new g_wpn_name[MAX_WPN][32]
  20. new g_wpn_model[MAX_WPN][32]
  21. new g_wpn_change[MAX_WPN]
  22. new g_wpn_cmdbuy[MAX_WPN][32]
  23. new Name_WpnChange[MAX_WPN][32]
  24. new current_select[33]
  25. // Models
  26. new P_MODEL[MAX_WPN][64]
  27. new V_MODEL[MAX_WPN][64]
  28. // Sound
  29. new Sound_miss[MAX_WPN][64]
  30. new Sound_hitwall[MAX_WPN][64]
  31. new Sound_hit1[MAX_WPN][64]
  32. new Sound_hit2[MAX_WPN][64]
  33. new Sound_stab[MAX_WPN][64]
  34. // Cvar
  35. new cvar_dmg_name[MAX_WPN][64]
  36. new cvar_cost_name[MAX_WPN][64]
  37. new cvar_dmgmultiplier[MAX_WPN]
  38. new cvar_cost[MAX_WPN]
  39. new cvar_buy
  40. #define is_valid_player(%1) (1 <= %1 <= 32)
  41.  
  42. public plugin_init()
  43. {
  44. register_plugin(PLUGIN, VERSION, AUTHOR)
  45.  
  46. // Reg Public
  47. register_event("CurWeapon","checkWeapon","be","1=1")
  48. register_event("DeathMsg", "Death", "a")
  49. RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
  50. register_forward(FM_EmitSound,"fw_emitsound")
  51.  
  52. // Reg Cmd
  53. register_clcmd("nst_wpn_3", "menu_wpn")
  54. register_clcmd("nst_wpn_3_rebuy", "rebuy_wpn")
  55. cvar_buy = register_cvar("nst_buy_model3", "nst")
  56. register_clcmd("nst_buy_wpn3", "buy_weapon_cvar")
  57.  
  58. new i = 1, check_value = 1
  59. while(check_value && i<MAX_WPN)
  60. {
  61. if (g_wpn_change[i] <= 0) check_value = 0
  62. if (check_value)
  63. {
  64. new szWpnName[32]
  65. get_weaponname(g_wpn_change[i], szWpnName, 31)
  66. format(Name_WpnChange[i], 31, "%s", szWpnName)
  67. register_clcmd(g_wpn_cmdbuy[i],"buy_weapon", i)
  68. }
  69. i++
  70. }
  71. }
  72. public plugin_precache()
  73. {
  74. new configfile[200]
  75. get_configsdir(configfile,199)
  76. format(configfile,199,"%s/nst_wpn.ini",configfile)
  77. if(file_exists(configfile))
  78. {
  79. new row[200], left[64], trash, right[64], idwpn = 1
  80. new size=file_size(configfile,1)
  81. for(new i=0;i<size;i++)
  82. {
  83.  
  84. new name[64], model[64], wpn_change, damage[32], cost[32]
  85. read_file(configfile,i,row,200,trash)
  86. if( (contain(row,";")!=0) && strlen(row) && idwpn<MAX_WPN)
  87. {
  88.  
  89. // Create Value
  90. replace(row, 199, " ", "_")
  91. replace(row, 199, "[name]", "")
  92. replace(row, 199, "[model]", " ")
  93. replace(row, 199, "[wpn_change]", " ")
  94. replace(row, 199, "[damage]", " ")
  95. replace(row, 199, "[cost]", " ")
  96.  
  97. strbreak(row,left,63,right,63)
  98. format(row, 199, "%s", right)
  99. format(name, 63, "%s", left)
  100. replace(name, 63, "_", " ")
  101.  
  102. strbreak(row,left,63,right,63)
  103. format(row, 199, "%s", right)
  104. format(model, 63, "%s", left)
  105. strbreak(row,left,63,right,63)
  106. format(row, 199, "%s", right)
  107. wpn_change = str_to_num(left)
  108. strbreak(row,left,63,right,63)
  109. format(row, 199, "%s", right)
  110. format(damage, 31, "%s", left)
  111. strbreak(row,left,63,right,63)
  112. format(row, 199, "%s", right)
  113. format(cost, 31, "%s", left)
  114.  
  115. if (nst_get_weapon_type(wpn_change) == TYPE_WPN)
  116. {
  117. // Set Value
  118. format(g_wpn_name[idwpn], 31, "%s", name)
  119. format(g_wpn_model[idwpn], 31, "%s", model)
  120. format(g_wpn_cmdbuy[idwpn], 31, "nst_buywpn %s", model)
  121. g_wpn_change[idwpn] = wpn_change
  122.  
  123.  
  124.  
  125. // Create Vvar
  126. format(cvar_dmg_name[idwpn], 63, "nst_%s_dmg", model)
  127. format(cvar_cost_name[idwpn], 63, "nst_%s_cost", model)
  128. cvar_dmgmultiplier[idwpn] = register_cvar(cvar_dmg_name[idwpn], damage)
  129. cvar_cost[idwpn] = register_cvar(cvar_cost_name[idwpn], cost)
  130.  
  131.  
  132. // Precache
  133. format(P_MODEL[idwpn], 63, "models/nst_wpn/p_%s.mdl", model)
  134. format(V_MODEL[idwpn], 63, "models/nst_wpn/v_%s.mdl", model)
  135. precache_model(P_MODEL[idwpn])
  136. precache_model(V_MODEL[idwpn])
  137.  
  138. format(Sound_miss[idwpn], 63, "weapons/%s_miss.wav", model)
  139. format(Sound_hitwall[idwpn], 63, "weapons/%s_hitwall.wav", model)
  140. format(Sound_hit1[idwpn], 63, "weapons/%s_hit1.wav", model)
  141. format(Sound_hit2[idwpn], 63, "weapons/%s_hit2.wav", model)
  142. format(Sound_stab[idwpn], 63, "weapons/%s_stab.wav", model)
  143. precache_sound(Sound_miss[idwpn])
  144. precache_sound(Sound_hitwall[idwpn])
  145. precache_sound(Sound_hit1[idwpn])
  146. precache_sound(Sound_hit2[idwpn])
  147. precache_sound(Sound_stab[idwpn])
  148. idwpn++
  149. }
  150. }
  151. }
  152.  
  153. }
  154. }
  155. // Human Death
  156. public zp_user_infected_post(id)
  157. {
  158. if (zp_get_user_zombie(id) && HAS_WEAPON[id])
  159. {
  160. HAS_WEAPON[id] = 0
  161. }
  162. }
  163. public Death()
  164. {
  165. new id = read_data(2)
  166. if(HAS_WEAPON[id])
  167. {
  168. HAS_WEAPON[id] = 0
  169. return PLUGIN_HANDLED
  170. }
  171.  
  172. return PLUGIN_CONTINUE
  173. }
  174. // Change Sound
  175. public fw_emitsound(entity,channel,sample[],Float:volume,Float:attenuation,fFlags,pitch)
  176. {
  177. for (new id = 1; id < 33; id++)
  178. {
  179. new CURENT_WEAPON = HAS_WEAPON[id]
  180. new CHANGE_WEAPON = g_wpn_change[CURENT_WEAPON]
  181. new plrClip, plrAmmo, plrWeapId
  182. plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
  183.  
  184. if (plrWeapId == CHANGE_WEAPON && HAS_WEAPON[id])
  185. {
  186. new sound_new[64]
  187. if( (equal(sample,"weapons/knife_slash1.wav")) || (equal(sample,"weapons/knife_slash2.wav")) ) copy(sound_new, 63, Sound_miss[CURENT_WEAPON])
  188. else if(equal(sample,"weapons/knife_hitwall1.wav")) copy(sound_new, 63, Sound_hitwall[CURENT_WEAPON])
  189. else if( (equal(sample,"weapons/knife_hit1.wav")) || (equal(sample,"weapons/knife_hit3.wav"))) copy(sound_new, 63, Sound_hit1[CURENT_WEAPON])
  190. else if( (equal(sample,"weapons/knife_hit2.wav")) || (equal(sample,"weapons/knife_hit4.wav"))) copy(sound_new, 63, Sound_hit2[CURENT_WEAPON])
  191. else if(equal(sample,"weapons/knife_stab.wav")) copy(sound_new, 63, Sound_stab[CURENT_WEAPON])
  192. emit_sound(entity,channel,sound_new,volume,attenuation,fFlags,pitch)
  193. return FMRES_SUPERCEDE
  194. }
  195. }
  196. return FMRES_IGNORED;
  197. }
  198. // Menu Wpn
  199. public menu_wpn(id)
  200. {
  201. if (!g_wpn_change[1]) return PLUGIN_HANDLED
  202.  
  203. new mHandleID = menu_create("[NST Wpn] Menu Knife:", "menu_wpn_handler")
  204. menu_additem(mHandleID, "Default Knife", "0", 0)
  205. new i = 1, check_value = 1
  206. while(check_value && i<MAX_WPN)
  207. {
  208. if (g_wpn_change[i] <= 0) check_value = 0
  209. if (check_value)
  210. {
  211. new wpn_cost = get_pcvar_num(cvar_cost[i])
  212. new item_name[150], idwpn[32]
  213. format(item_name, 149, "%s: %i$", g_wpn_name[i], wpn_cost)
  214. format(idwpn, 31, "%i", i)
  215.  
  216. new check_money[33], user_money = cs_get_user_money(id)
  217. if(user_money < wpn_cost) check_money[id] = 1
  218. else check_money[id] = 0
  219.  
  220. menu_additem(mHandleID, item_name, idwpn, check_money[id])
  221. }
  222. i++
  223. }
  224.  
  225. menu_addblank(mHandleID, 1) // add blank got problem
  226. menu_setprop(mHandleID, MPROP_PERPAGE, 7)
  227. menu_display(id, mHandleID, 0)
  228.  
  229. return PLUGIN_HANDLED
  230. }
  231. public menu_wpn_handler(id, menu, item)
  232. {
  233. if (item == MENU_EXIT)
  234. {
  235. menu_destroy(menu)
  236. return PLUGIN_HANDLED
  237. }
  238. new idwpn[32], name[32], access
  239. menu_item_getinfo(menu, item, access, idwpn, 31, name, 31, access)
  240. new idweapon = str_to_num(idwpn)
  241. if (!idweapon) HAS_WEAPON[id] = 0
  242. else buy_weapon(id, idweapon)
  243.  
  244. menu_destroy(menu)
  245. //client_print(id, print_chat, "item: %i - id: %s", item, idwpn);
  246. return PLUGIN_HANDLED
  247. }
  248. public rebuy_wpn(id)
  249. {
  250. new idwpn = current_select[id]
  251. if (idwpn>0) buy_weapon(id, idwpn)
  252.  
  253. return PLUGIN_HANDLED
  254. }
  255.  
  256. // Change Damage
  257. public fw_TakeDamage(victim, inflictor, attacker, Float:damage)
  258. {
  259. new CURENT_WEAPON = HAS_WEAPON[attacker]
  260. new CHANGE_WEAPON = g_wpn_change[CURENT_WEAPON]
  261.  
  262. if ( is_valid_player( attacker ) && get_user_weapon(attacker) == CHANGE_WEAPON && HAS_WEAPON[attacker] )
  263. {
  264. SetHamParamFloat(4, damage * get_pcvar_float( cvar_dmgmultiplier[CURENT_WEAPON] ) )
  265. }
  266. }
  267.  
  268. // Buy Weapon
  269. public buy_weapon_cvar(id)
  270. {
  271. new models[62]
  272. get_pcvar_string(cvar_buy, models, 61)
  273.  
  274. for(new i=1; i<MAX_WPN; i++)
  275. {
  276. if (g_wpn_change[i] > 0)
  277. {
  278. if (equali(g_wpn_model[i],models))
  279. {
  280. buy_weapon(id, i)
  281. return PLUGIN_HANDLED
  282. }
  283. }
  284. }
  285. return PLUGIN_HANDLED
  286. }
  287. public buy_weapon(id, idwpn)
  288. {
  289. //client_print(id, print_chat, "Mua %i", idwpn)
  290. new buyzone = cs_get_user_buyzone(id)
  291. new mod_runing = nst_get_mod_runing()
  292. if (mod_runing == 1 || mod_runing == 2 || mod_runing == 3) buyzone = 1
  293.  
  294. if (buyzone == 0) client_print(id, print_chat, "[NST Wpn] Ban khong the mua Vu khi o vi tri nay")
  295. else
  296. {
  297. new plrClip, plrAmmo
  298. get_user_weapon(id, plrClip , plrAmmo)
  299.  
  300. new user_money = cs_get_user_money(id)
  301. new wp_cost = get_pcvar_num(cvar_cost[idwpn])
  302.  
  303. if (zp_get_user_zombie(id))
  304. {
  305. client_print(id, print_chat, "[NST Wpn] Ban dang la Zombie nen khong the mua %s", g_wpn_name[idwpn])
  306. }
  307. else if(!is_user_alive(id))
  308. {
  309. client_print(id, print_chat, "[NST Wpn] Ban chi co the mua duoc %s khi con song", g_wpn_name[idwpn]);
  310. }
  311. else if(user_money < wp_cost)
  312. {
  313. client_print(id, print_chat, "[NST Wpn] Ban khong du tien de mua");
  314. }
  315. else if(HAS_WEAPON[id] == idwpn)
  316. {
  317. client_print(id, print_chat, "[NST Wpn] Ban da co %s roi", g_wpn_name[idwpn])
  318. }
  319. else
  320. {
  321. current_select[id] = idwpn
  322. HAS_WEAPON[id] = idwpn
  323. give_weapon(id)
  324. cs_set_user_money(id, user_money-wp_cost)
  325. checkModel(id)
  326. client_print(id, print_chat, "[NST Wpn] Ban da mua %s", g_wpn_name[idwpn])
  327. }
  328. }
  329. }
  330.  
  331. // Give Weapon
  332. public give_weapon(id)
  333. {
  334. if (zp_get_user_zombie(id)) return PLUGIN_HANDLED
  335.  
  336. new CURENT_WEAPON = HAS_WEAPON[id]
  337. give_item(id,Name_WpnChange[CURENT_WEAPON])
  338.  
  339. return PLUGIN_HANDLED
  340. }
  341.  
  342. // Check Weapon
  343. public checkModel(id)
  344. {
  345. if (zp_get_user_zombie(id)) return PLUGIN_HANDLED
  346.  
  347.  
  348. new CURENT_WEAPON = HAS_WEAPON[id]
  349. new CHANGE_WEAPON = g_wpn_change[CURENT_WEAPON]
  350.  
  351. new plrClip, plrAmmo, plrWeapId
  352. plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
  353. if ( plrWeapId == CHANGE_WEAPON && HAS_WEAPON[id])
  354. {
  355. set_pev(id, pev_viewmodel2, V_MODEL[CURENT_WEAPON])
  356. set_pev(id, pev_weaponmodel2, P_MODEL[CURENT_WEAPON])
  357. }
  358. return PLUGIN_HANDLED
  359. }
  360. public checkWeapon(id)
  361. {
  362. new CURENT_WEAPON = HAS_WEAPON[id]
  363. new CHANGE_WEAPON = g_wpn_change[CURENT_WEAPON]
  364.  
  365. new plrClip, plrAmmo, plrWeapId
  366. plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
  367.  
  368. if (plrWeapId == CHANGE_WEAPON && HAS_WEAPON[id])
  369. {
  370. checkModel(id)
  371. }
  372.  
  373. return PLUGIN_HANDLED
  374. }
  375.  
  376. // Other Public
  377. public client_connect(id)
  378. {
  379. HAS_WEAPON[id] = 0
  380. }
  381. public client_disconnect(id)
  382. {
  383. HAS_WEAPON[id] = 0
  384. }
  385. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  386. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1034\\ f0\\ fs16 \n\\ par }
  387. */
Add Comment
Please, Sign In to add comment