HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <fakemeta_util>
  4. #include <fun>
  5. #include <hamsandwich>
  6. #include <cstrike>
  7. #include <zombieplague>
  8. #include <engine>
  9.  
  10. // Info Plugin
  11. #define VERSION "1.0"
  12. #define AUTHOR "NST"
  13.  
  14.  
  15. // Info Weapon
  16. #define CURENT_WEAPON CSW_SCOUT
  17. new models_weapon[64] = "Crossbow"
  18. new name_weapon[64] = "Crossbow"
  19.  
  20.  
  21. new plugin_name[64] = "[ZP] Extra: %s"
  22. new name_class_weapon[64] = "nst_%s"
  23. new V_MODEL[64] = "models/cso_wpn/v_%s.mdl"
  24. new P_MODEL[64] = "models/cso_wpn/p_%s.mdl"
  25. new W_MODEL[64] = "models/cso_wpn/w_%s.mdl"
  26.  
  27. new cvar_dmg_name[64] = "nst_%s_dmg"
  28. new cvar_uclip_name[64] = "nst_%s_uclip"
  29. new cvar_speed_name[64] = "nst_%s_speed"
  30. new cvar_zoom_name[64] = "nst_%s_zoom"
  31. new cvar_clip_name[64] = "nst_%s_clip"
  32. new cvar_ammo_name[64] = "nst_%s_ammo"
  33. new cvar_recoil_name[64] = "nst_%s_recoil"
  34. new cvar_round_name[64] = "nst_%s_round"
  35.  
  36. #define is_valid_player(%1) (1 <= %1 <= 32)
  37. new user_clip[33], user_ammo[33]
  38. new cvar_dmgmultiplier, cvar_uclip, cvar_speed, cvar_zoom, cvar_clip, cvar_ammo, cvar_recoil, cvar_round
  39. new g_itemid
  40. new bool:G_HasWp[33]
  41. new g_hasZoom[ 33 ]
  42. const Wep_drop = ((1<<CURENT_WEAPON))
  43. new szWeapon[17]
  44. new Float:cl_pushangle[33][3]
  45.  
  46.  
  47. ////////////////////////////////// Ammo //////////////////////////////////
  48.  
  49. const SILENT_BS = ((1<<CSW_USP)|(1<<CURENT_WEAPON))
  50.  
  51. // weapons offsets
  52. const m_pPlayer = 41
  53. const m_iId = 43
  54. const m_fKnown = 44
  55. const m_flNextPrimaryAttack = 46
  56. const m_flNextSecondaryAttack = 47
  57. const m_flTimeWeaponIdle = 48
  58. const m_iPrimaryAmmoType = 49
  59. const m_iClip = 51
  60. const m_fInReload = 54
  61. const m_fInSpecialReload = 55
  62. const m_fSilent = 74
  63. const m_flNextAttack = 83
  64. const m_rgAmmo_player_Slot0 = 376
  65.  
  66. stock const g_iDftMaxClip[CSW_P90+1] = {
  67. -1, 13, -1, 10, 1, 7, 1, 30, 30, 1, 30,
  68. 20, 25, 30, 35, 25, 12, 20, 10, 30, 100,
  69. 8 , 30, 30, 20, 2, 7, 30, 30, -1, 50}
  70.  
  71. stock const g_iReloadAnims[CSW_P90+1] = {
  72. -1, 5, -1, 3, -1, 6, -1, 1, 1, -1, 14,
  73. 4, 2, 3, 1, 1, 13, 7, 4, 1, 3,
  74. 6, 11, 1, 3, -1, 4, 1, 1, -1, 1}
  75.  
  76. stock const Float:g_fDelay[CSW_P90+1] = {
  77. 0.00, 2.70, 0.00, 2.00, 0.00, 0.55, 0.00, 3.15, 3.30, 0.00, 4.50,
  78. 2.70, 3.50, 3.35, 2.45, 3.30, 2.70, 2.20, 2.50, 2.63, 4.70,
  79. 0.55, 3.05, 2.12, 3.50, 0.00, 2.20, 3.00, 2.45, 0.00, 3.40
  80. }
  81.  
  82.  
  83. public plugin_init()
  84. {
  85. // Create value
  86. format(V_MODEL, 63, V_MODEL, models_weapon)
  87. format(P_MODEL, 63, P_MODEL, models_weapon)
  88. format(W_MODEL, 63, W_MODEL, models_weapon)
  89.  
  90. format(cvar_dmg_name, 63, cvar_dmg_name, models_weapon)
  91. format(cvar_uclip_name, 63, cvar_uclip_name, models_weapon)
  92. format(cvar_speed_name, 63, cvar_speed_name, models_weapon)
  93. format(cvar_zoom_name, 63, cvar_zoom_name, models_weapon)
  94. format(cvar_clip_name, 63, cvar_clip_name, models_weapon)
  95. format(cvar_ammo_name, 63, cvar_ammo_name, models_weapon)
  96. format(cvar_recoil_name, 63, cvar_recoil_name, models_weapon)
  97. format(cvar_round_name, 63, cvar_round_name, models_weapon)
  98.  
  99. format(plugin_name, 63, plugin_name, name_weapon)
  100. format(name_class_weapon, 63, name_class_weapon, models_weapon)
  101.  
  102. // Reg Cvar
  103. cvar_dmgmultiplier = register_cvar(cvar_dmg_name, "3")
  104. cvar_uclip = register_cvar(cvar_uclip_name, "0")
  105. cvar_speed = register_cvar(cvar_speed_name,"0.2")
  106. cvar_zoom = register_cvar(cvar_zoom_name,"0")
  107. cvar_clip = register_cvar(cvar_clip_name,"50")
  108. cvar_ammo = register_cvar(cvar_ammo_name,"100")
  109. cvar_recoil = register_cvar(cvar_recoil_name,"0.1")
  110.  
  111.  
  112.  
  113. register_plugin(plugin_name, VERSION, AUTHOR)
  114. g_itemid = zp_register_extra_item(name_weapon, 25, ZP_TEAM_HUMAN)
  115.  
  116. //register_event("WeapPickup","checkModel","b","1=19")
  117. register_event("DeathMsg", "Death", "a")
  118. register_event("CurWeapon","checkWeapon","be","1=1")
  119. register_event("HLTV", "event_start_freezetime", "a", "1=0", "2=0")
  120.  
  121. // Ham
  122. RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
  123. //RegisterHam(Ham_Spawn, "player", "fwHamPlayerSpawnPost", 1)
  124. get_weaponname(CURENT_WEAPON, szWeapon, charsmax(szWeapon))
  125. RegisterHam(Ham_Item_PostFrame, szWeapon, "Item_PostFrame")
  126. register_forward( FM_CmdStart, "fw_CmdStart" )
  127.  
  128. // Recoil
  129. RegisterHam(Ham_Weapon_PrimaryAttack, szWeapon, "fw_primary_attack")
  130. RegisterHam(Ham_Weapon_PrimaryAttack, szWeapon, "fw_primary_attack_post",1)
  131.  
  132. register_clcmd("drop","cmd_drop", 0)
  133. }
  134.  
  135. // Other Public
  136. public plugin_precache()
  137. {
  138. format(V_MODEL, 63, V_MODEL, models_weapon)
  139. format(P_MODEL, 63, P_MODEL, models_weapon)
  140. format(W_MODEL, 63, W_MODEL, models_weapon)
  141.  
  142. precache_model(V_MODEL)
  143. precache_model(P_MODEL)
  144. precache_model(W_MODEL)
  145. }
  146.  
  147. public client_connect(id)
  148. {
  149. G_HasWp[id] = false
  150. }
  151.  
  152. public client_disconnect(id)
  153. {
  154. G_HasWp[id] = false
  155. }
  156.  
  157. public Death()
  158. {
  159. new id = read_data(2)
  160. if(G_HasWp[id])
  161. {
  162. create_w_class(id, user_clip[id], user_ammo[id], 0)
  163. G_HasWp[id] = false
  164. return PLUGIN_HANDLED
  165. }
  166.  
  167. return PLUGIN_CONTINUE
  168. }
  169.  
  170. public fwHamPlayerSpawnPost(id)
  171. {
  172. if (!get_pcvar_num(cvar_round)) G_HasWp[id] = false
  173. }
  174.  
  175. public zp_user_infected_post(id)
  176. {
  177. if (zp_get_user_zombie(id))
  178. {
  179. G_HasWp[id] = false
  180. }
  181. }
  182.  
  183. public zp_extra_item_selected(player, itemid)
  184. {
  185. if ( itemid == g_itemid )
  186. {
  187. drop_prim(player)
  188. give_weapon(player, get_pcvar_num(cvar_clip), get_pcvar_num(cvar_ammo))
  189. }
  190. }
  191.  
  192. public event_start_freezetime()
  193. {
  194. remove_class_wpn()
  195. }
  196. // End Other Public
  197.  
  198.  
  199. // Check Weapon
  200. public checkModel(id)
  201. {
  202. if ( zp_get_user_zombie(id) )
  203. return PLUGIN_HANDLED
  204.  
  205. new szWeapID = read_data(2)
  206.  
  207. if ( szWeapID == CURENT_WEAPON && G_HasWp[id] == true)
  208. {
  209. set_pev(id, pev_viewmodel2, V_MODEL)
  210. set_pev(id, pev_weaponmodel2, P_MODEL)
  211. }
  212. return PLUGIN_HANDLED
  213. }
  214.  
  215. public checkWeapon(id)
  216. {
  217. new plrClip, plrAmmo, plrWeapId
  218. plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
  219.  
  220.  
  221. if (plrWeapId == CURENT_WEAPON && G_HasWp[id])
  222. {
  223. checkModel(id)
  224.  
  225. // Speed
  226. new Ent = get_weapon_ent(id,plrWeapId)
  227. new Float:N_Speed
  228. if(Ent)
  229. {
  230. N_Speed = get_pcvar_float(cvar_speed)
  231. new Float:Delay = get_pdata_float( Ent, 46, 4) * N_Speed
  232. if (Delay > 0.0) {
  233. set_pdata_float( Ent, 46, Delay, 4)
  234. }
  235. }
  236. }
  237. else
  238. {
  239. return PLUGIN_CONTINUE
  240. }
  241.  
  242.  
  243.  
  244. return PLUGIN_HANDLED
  245. }
  246. // End Check Weapon
  247.  
  248.  
  249. // Control Damage
  250. public fw_TakeDamage(victim, inflictor, attacker, Float:damage)
  251. {
  252. if ( is_valid_player( attacker ) && get_user_weapon(attacker) == CURENT_WEAPON && G_HasWp[attacker] )
  253. {
  254. SetHamParamFloat(4, damage * get_pcvar_float( cvar_dmgmultiplier ) )
  255. }
  256. }
  257. // End Control Damage
  258.  
  259.  
  260.  
  261. // Zoom Wepaon
  262. public fw_CmdStart( id, uc_handle, seed )
  263. {
  264. if( !is_user_alive( id ) )
  265. return PLUGIN_HANDLED
  266.  
  267.  
  268. new szClip, szAmmo
  269. new szWeapID = get_user_weapon( id, szClip, szAmmo )
  270.  
  271. if( szWeapID == CURENT_WEAPON && G_HasWp[id] == true)
  272. {
  273. // Zoom Weapon
  274. if (get_pcvar_num(cvar_zoom))
  275. {
  276. if( ( get_uc( uc_handle, UC_Buttons ) & IN_ATTACK2 ) && !( pev( id, pev_oldbuttons ) & IN_ATTACK2 ) )
  277. {
  278. if(!g_hasZoom[id] == true)
  279. {
  280. g_hasZoom[id] = true
  281. cs_set_user_zoom( id, CS_SET_AUGSG552_ZOOM, 0 )
  282. client_cmd(id,"spk weapons/zoom")
  283. }
  284. else if (g_hasZoom[id])
  285. {
  286. g_hasZoom[ id ] = false
  287. cs_set_user_zoom( id, CS_RESET_ZOOM, 0 )
  288. }
  289. }
  290. }
  291. // UClip
  292. if (get_pcvar_num(cvar_uclip))
  293. {
  294. new ent = get_weapon_ent(id,CURENT_WEAPON)
  295. cs_set_weapon_ammo(ent, get_pcvar_num(cvar_clip))
  296. }
  297.  
  298. user_clip[id] = szClip
  299. user_ammo[id] = szAmmo
  300.  
  301. }
  302.  
  303. if ( (g_hasZoom[ id ] && (pev(id, pev_button) & IN_RELOAD)) || (g_hasZoom[id] && szWeapID != CURENT_WEAPON) )
  304. {
  305. g_hasZoom[id] = false
  306. cs_set_user_zoom( id, CS_RESET_ZOOM, 0 )
  307. }
  308.  
  309.  
  310. return PLUGIN_HANDLED
  311. }
  312. // End Zoom Wepaon
  313.  
  314.  
  315. // Recoil of Weapon
  316. public fw_primary_attack(ent)
  317. {
  318. new id = pev(ent,pev_owner)
  319. pev(id,pev_punchangle,cl_pushangle[id])
  320.  
  321. return HAM_IGNORED
  322. }
  323. public fw_primary_attack_post(ent)
  324. {
  325. new id = pev(ent,pev_owner)
  326. new szClip, szAmmo
  327. new szWeapID = get_user_weapon( id, szClip, szAmmo )
  328.  
  329. if( szWeapID == CURENT_WEAPON && G_HasWp[id] == true)
  330. {
  331. new Float:push[3]
  332. pev(id,pev_punchangle,push)
  333. xs_vec_sub(push,cl_pushangle[id],push)
  334.  
  335. xs_vec_mul_scalar(push,get_pcvar_float(cvar_recoil),push)
  336. xs_vec_add(push,cl_pushangle[id],push)
  337. set_pev(id,pev_punchangle,push)
  338. }
  339.  
  340. return HAM_IGNORED
  341. }
  342. // End Recoil of Weapon
  343.  
  344.  
  345. // Drop Weapon
  346. public cmd_drop(id)
  347. {
  348. new plrClip, plrAmmo
  349. new plrWeapId
  350. plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
  351.  
  352. if(plrWeapId == CURENT_WEAPON && G_HasWp[id] && is_user_alive(id)) {
  353. create_w_class(id, plrClip, plrAmmo, 1)
  354. return PLUGIN_HANDLED
  355. }
  356. return PLUGIN_CONTINUE
  357. }
  358.  
  359. public create_w_class(id, clip, ammo, type)
  360. {
  361. new Float:Aim[3],Float:origin[3]
  362. VelocityByAim(id, 64, Aim)
  363. entity_get_vector(id,EV_VEC_origin,origin)
  364.  
  365. if (type == 1) {
  366. origin[0] += 2*Aim[0]
  367. origin[1] += 2*Aim[1]
  368. }
  369.  
  370. new nst_cre_class = create_entity("info_target")
  371. entity_set_string(nst_cre_class,EV_SZ_classname,name_class_weapon)
  372. entity_set_model(nst_cre_class,W_MODEL)
  373.  
  374. entity_set_size(nst_cre_class,Float:{-2.0,-2.0,-2.0},Float:{5.0,5.0,5.0})
  375. entity_set_int(nst_cre_class,EV_INT_solid,1)
  376.  
  377. entity_set_int(nst_cre_class,EV_INT_movetype,6)
  378. entity_set_int(nst_cre_class, EV_INT_iuser1, clip)
  379. entity_set_int(nst_cre_class, EV_INT_iuser2, ammo)
  380. entity_set_vector(nst_cre_class,EV_VEC_origin,origin)
  381. G_HasWp[id] = false
  382. remowegun(id)
  383. }
  384. // End Drop Weapon
  385.  
  386.  
  387. // Remove Class Wepaons in new round
  388. public remove_class_wpn()
  389. {
  390. new nextitem = find_ent_by_class(-1,name_class_weapon)
  391. while(nextitem) {
  392. remove_entity(nextitem)
  393. nextitem = find_ent_by_class(-1,name_class_weapon)
  394. }
  395. return PLUGIN_CONTINUE
  396. }
  397. // End Remove Class Wepaons in new round
  398.  
  399.  
  400. // Weapon Pickup
  401. public pfn_touch(ptr, ptd) {
  402. if(is_valid_ent(ptr)) {
  403.  
  404. new classname[32]
  405. entity_get_string(ptr,EV_SZ_classname,classname,31)
  406. if(equal(classname, name_class_weapon)) {
  407. if(is_valid_ent(ptd)) {
  408. new id = ptd
  409. if(id > 0 && id < 34) {
  410. if(!G_HasWp[id] && is_user_alive(id) && !zp_get_user_zombie(id)) {
  411. give_weapon(id,entity_get_int(ptr, EV_INT_iuser1), entity_get_int(ptr, EV_INT_iuser2))
  412. remove_entity(ptr)
  413. }
  414. }
  415. }
  416. }
  417. }
  418. }
  419. // End Weapon Pickup
  420.  
  421.  
  422. // remove gun and save all guns
  423. public remowegun(id) {
  424. new wpnList[32]
  425. new number
  426. get_user_weapons(id,wpnList,number)
  427. for (new i = 0;i < number ;i++) {
  428. if (wpnList[i] == CURENT_WEAPON) {
  429. fm_strip_user_gun(id, wpnList[i])
  430. }
  431. }
  432. }
  433.  
  434. //give wpn
  435. public give_weapon(id, clip, ammo){
  436. G_HasWp[id] = true
  437. give_item(id,szWeapon)
  438. cs_set_user_bpammo(id, CURENT_WEAPON, ammo)
  439. new ent = get_weapon_ent(id,CURENT_WEAPON)
  440. cs_set_weapon_ammo(ent, clip)
  441.  
  442. }
  443.  
  444.  
  445. // Give Ammo Clip
  446. public Item_PostFrame(iEnt)
  447. {
  448. static id ; id = get_pdata_cbase(iEnt, m_pPlayer, 4)
  449. new plrClip, plrAmmo, plrWeapId
  450. plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
  451.  
  452. if (plrWeapId == CURENT_WEAPON && G_HasWp[id])
  453. {
  454.  
  455. static iId ; iId = get_pdata_int(iEnt, m_iId, 4)
  456. static iMaxClip ; iMaxClip = get_pcvar_num(cvar_clip)
  457. static fInReload ; fInReload = get_pdata_int(iEnt, m_fInReload, 4)
  458. static Float:flNextAttack ; flNextAttack = get_pdata_float(id, m_flNextAttack, 5)
  459.  
  460. static iAmmoType ; iAmmoType = m_rgAmmo_player_Slot0 + get_pdata_int(iEnt, m_iPrimaryAmmoType, 4)
  461. static iBpAmmo ; iBpAmmo = get_pdata_int(id, iAmmoType, 5)
  462. static iClip ; iClip = get_pdata_int(iEnt, m_iClip, 4)
  463.  
  464.  
  465. if( fInReload && flNextAttack <= 0.0 )
  466. {
  467. new j = min(iMaxClip - iClip, iBpAmmo)
  468. set_pdata_int(iEnt, m_iClip, iClip + j, 4)
  469. set_pdata_int(id, iAmmoType, iBpAmmo-j, 5)
  470. set_pdata_int(iEnt, m_fInReload, 0, 4)
  471. fInReload = 0
  472. }
  473.  
  474. static iButton ; iButton = pev(id, pev_button)
  475. if( (iButton & IN_ATTACK2 && get_pdata_float(iEnt, m_flNextSecondaryAttack, 4) <= 0.0)
  476. || (iButton & IN_ATTACK && get_pdata_float(iEnt, m_flNextPrimaryAttack, 4) <= 0.0) )
  477. {
  478. return
  479. }
  480.  
  481. if( iButton & IN_RELOAD && !fInReload )
  482. {
  483. if( iClip >= iMaxClip )
  484. {
  485. set_pev(id, pev_button, iButton & ~IN_RELOAD)
  486. if( SILENT_BS & (1<<iId) && !get_pdata_int(iEnt, m_fSilent, 4) )
  487. {
  488. SendWeaponAnim( id, iId == CSW_USP ? 8 : 7 )
  489. }
  490. else
  491. {
  492. SendWeaponAnim(id, 0)
  493. }
  494. }
  495. else if( iClip == g_iDftMaxClip[iId] )
  496. {
  497. if( iBpAmmo )
  498. {
  499. set_pdata_float(id, m_flNextAttack, g_fDelay[iId], 5)
  500.  
  501. if( SILENT_BS & (1<<iId) && get_pdata_int(iEnt, m_fSilent, 4) )
  502. {
  503. SendWeaponAnim( id, iId == CSW_USP ? 5 : 4 )
  504. }
  505. else
  506. {
  507. SendWeaponAnim(id, g_iReloadAnims[iId])
  508. }
  509. set_pdata_int(iEnt, m_fInReload, 1, 4)
  510.  
  511. set_pdata_float(iEnt, m_flTimeWeaponIdle, g_fDelay[iId] + 0.5, 4)
  512. }
  513. }
  514. }
  515.  
  516. }
  517. }
  518. SendWeaponAnim(id, iAnim)
  519. {
  520. set_pev(id, pev_weaponanim, iAnim)
  521.  
  522. message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, _, id)
  523. write_byte(iAnim)
  524. write_byte(pev(id,pev_body))
  525. message_end()
  526. }
  527. // End Give Ammo Clip
  528.  
  529.  
  530. // Stock
  531. stock drop_prim(id)
  532. {
  533. new weapons[32], num
  534. get_user_weapons(id, weapons, num)
  535. for (new i = 0; i < num; i++) {
  536. if (Wep_drop & (1<<weapons[i]))
  537. {
  538. static wname[32]
  539. get_weaponname(weapons[i], wname, sizeof wname - 1)
  540. engclient_cmd(id, "drop", wname)
  541. G_HasWp[id] = false
  542. }
  543. }
  544. }
  545. //get weapon id
  546. stock get_weapon_ent(id,wpnid=0,wpnName[]="")
  547. {
  548. // who knows what wpnName will be
  549. static newName[24];
  550.  
  551. // need to find the name
  552. if(wpnid) get_weaponname(wpnid,newName,23);
  553.  
  554. // go with what we were told
  555. else formatex(newName,23,"%s",wpnName);
  556.  
  557. // prefix it if we need to
  558. if(!equal(newName,"weapon_",7))
  559. format(newName,23,"weapon_%s",newName);
  560.  
  561. return fm_find_ent_by_owner(get_maxplayers(),newName,id);
  562. }