HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <engine>
  3. #include <fakemeta>
  4. #include <fun>
  5. #include <hamsandwich>
  6. #include <xs>
  7. #include <cstrike>
  8. #include <zombieplague>
  9.  
  10. enum
  11. {
  12. anim_idle,
  13. anim_reload,
  14. anim_draw,
  15. anim_shoot1,
  16. anim_shoot2,
  17. anim_shoot3
  18. }
  19.  
  20. #define ENG_NULLENT -1
  21. #define EV_INT_WEAPONKEY EV_INT_impulse
  22. #define Skull1_WEAPONKEY 901
  23. #define MAX_PLAYERS 32
  24. #define IsValidUser(%1) (1 <= %1 <= g_MaxPlayers)
  25.  
  26. const USE_STOPPED = 0
  27. const OFFSET_ACTIVE_ITEM = 373
  28. const OFFSET_WEAPONOWNER = 41
  29. const OFFSET_LINUX = 5
  30. const OFFSET_LINUX_WEAPONS = 4
  31.  
  32. #define WEAP_LINUX_XTRA_OFF 4
  33. #define m_fKnown 44
  34. #define m_flNextPrimaryAttack 46
  35. #define m_flTimeWeaponIdle 48
  36. #define m_iClip 51
  37. #define m_fInReload 54
  38. #define PLAYER_LINUX_XTRA_OFF 5
  39. #define m_flNextAttack 83
  40.  
  41. #define Skull1_RELOAD_TIME 3.0
  42.  
  43. const SECONDARY_WEAPONS_BIT_SUM = (1<<CSW_USP)|(1<<CSW_DEAGLE)|(1<<CSW_GLOCK18)|(1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)
  44. new const WEAPONENTNAMES[][] = { "", "weapon_deagle", "", "weapon_scout", "weapon_hegrenade", "weapon_xm1014", "weapon_c4", "weapon_mac10",
  45. "weapon_aug", "weapon_smokegrenade", "weapon_elite", "weapon_fiveseven", "weapon_ump45", "weapon_sg550",
  46. "weapon_p228", "weapon_famas", "weapon_usp", "weapon_glock18", "weapon_awp", "weapon_mp5navy", "weapon_m249",
  47. "weapon_m3", "weapon_m4a1", "weapon_tmp", "weapon_g3sg1", "weapon_flashbang", "weapon_deagle", "weapon_sg552",
  48. "weapon_ak47", "weapon_knife", "weapon_p90" }
  49. new const Fire_Sounds[][] = { "weapons/skull1-1.wav" }
  50. new const GUNSHOT_DECALS[] = { 41, 42, 43, 44, 45 }
  51. new Skull1_V_MODEL[64] = "models/cso_pistols/v_Skull1.mdl"
  52. new Skull1_P_MODEL[64] = "models/cso_pistols/p_Skull1.mdl"
  53. new Skull1_W_MODEL[64] = "models/cso_pistols/w_Skull1.mdl"
  54. new cvar_dmg_Skull1, cvar_recoil_Skull1, cvar_clip_Skull1, cvar_Skull1_ammo, g_itemid_Skull1
  55. new g_has_Skull1[33]
  56. new g_MaxPlayers, g_orig_event_Skull1, g_clip_ammo[33]
  57. new Float:cl_pushangle[MAX_PLAYERS + 1][3], m_iBlood[2]
  58. new g_Skull1_TmpClip[33]
  59. new g_iClip;
  60.  
  61. public plugin_init()
  62. {
  63. register_plugin("[ZP] Extra: Skull1", "1.0", "misna")
  64. register_message(get_user_msgid("DeathMsg"), "message_DeathMsg")
  65. register_event("CurWeapon","CurrentWeapon","be","1=1")
  66. RegisterHam(Ham_Item_AddToPlayer, "weapon_deagle", "fw_Skull1_AddToPlayer")
  67. RegisterHam(Ham_Use, "func_tank", "fw_UseStationary_Post", 1)
  68. RegisterHam(Ham_Use, "func_tankmortar", "fw_UseStationary_Post", 1)
  69. RegisterHam(Ham_Use, "func_tankrocket", "fw_UseStationary_Post", 1)
  70. RegisterHam(Ham_Use, "func_tanklaser", "fw_UseStationary_Post", 1)
  71. for (new i = 1; i < sizeof WEAPONENTNAMES; i++)
  72. if (WEAPONENTNAMES[i][0]) RegisterHam(Ham_Item_Deploy, WEAPONENTNAMES[i], "fw_Item_Deploy_Post", 1)
  73. RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_deagle", "fw_Skull1_PrimaryAttack")
  74. RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_deagle", "fw_Skull1_PrimaryAttack_Post", 1)
  75. RegisterHam(Ham_Item_PostFrame, "weapon_deagle", "Skull1__ItemPostFrame");
  76. RegisterHam(Ham_Weapon_Reload, "weapon_deagle", "Skull1__Reload");
  77. RegisterHam(Ham_Weapon_Reload, "weapon_deagle", "Skull1__Reload_Post", 1);
  78. RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
  79. register_forward(FM_SetModel, "fw_SetModel")
  80. register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
  81. register_forward(FM_PlaybackEvent, "fwPlaybackEvent")
  82.  
  83. cvar_dmg_Skull1 = register_cvar("zp_Skull1_dmg", "6.0")
  84. cvar_recoil_Skull1 = register_cvar("zp_Skull1_recoil", "0.5")
  85. cvar_clip_Skull1 = register_cvar("zp_Skull1_clip", "7")
  86. cvar_Skull1_ammo = register_cvar("zp_Skull1_ammo", "35")
  87.  
  88. g_itemid_Skull1 = zp_register_extra_item("Skull1", 10, ZP_TEAM_HUMAN)
  89. g_MaxPlayers = get_maxplayers()
  90. }
  91.  
  92. public plugin_precache()
  93. {
  94. precache_model(Skull1_V_MODEL)
  95. precache_model(Skull1_P_MODEL)
  96. precache_model(Skull1_W_MODEL)
  97. precache_sound(Fire_Sounds[0])
  98. precache_sound("weapons/skull1-2.wav")
  99. precache_sound("weapons/skull1_clipin.wav")
  100. precache_sound("weapons/skull1_clipout.wav")
  101. precache_sound("weapons/skull1_draw.wav")
  102. m_iBlood[0] = precache_model("sprites/blood.spr")
  103. m_iBlood[1] = precache_model("sprites/bloodspray.spr")
  104. precache_model("sprites/640hud5.spr")
  105. register_forward(FM_PrecacheEvent, "fwPrecacheEvent_Post", 1)
  106. }
  107. public fwPrecacheEvent_Post(type, const name[])
  108. {
  109. if (equal("events/deagle.sc", name))
  110. {
  111. g_orig_event_Skull1 = get_orig_retval()
  112. return FMRES_HANDLED
  113. }
  114.  
  115. return FMRES_IGNORED
  116. }
  117.  
  118. public client_connect(id)
  119. {
  120. g_has_Skull1[id] = false
  121. }
  122. public client_disconnect(id)
  123. {
  124. g_has_Skull1[id] = false
  125. }
  126.  
  127. public zp_user_infected_post(id)
  128. {
  129. if (zp_get_user_zombie(id))
  130. {
  131. g_has_Skull1[id] = false
  132. }
  133. }
  134.  
  135. public fw_SetModel(entity, model[])
  136. {
  137. if(!is_valid_ent(entity))
  138. return FMRES_IGNORED;
  139.  
  140. static szClassName[33]
  141. entity_get_string(entity, EV_SZ_classname, szClassName, charsmax(szClassName))
  142.  
  143. if(!equal(szClassName, "weaponbox"))
  144. return FMRES_IGNORED;
  145.  
  146. static iOwner
  147.  
  148. iOwner = entity_get_edict(entity, EV_ENT_owner)
  149.  
  150. if(equal(model, "models/w_deagle.mdl"))
  151. {
  152. static iStoredSVDID
  153.  
  154. iStoredSVDID = find_ent_by_owner(ENG_NULLENT, "weapon_deagle", entity)
  155.  
  156. if(!is_valid_ent(iStoredSVDID))
  157. return FMRES_IGNORED;
  158.  
  159. if(g_has_Skull1[iOwner])
  160. {
  161. entity_set_int(iStoredSVDID, EV_INT_WEAPONKEY, Skull1_WEAPONKEY)
  162. g_has_Skull1[iOwner] = false
  163.  
  164. entity_set_model(entity, Skull1_W_MODEL)
  165.  
  166. return FMRES_SUPERCEDE;
  167. }
  168. }
  169.  
  170.  
  171. return FMRES_IGNORED;
  172. }
  173.  
  174. public give_Skull1(id)
  175. {
  176. drop_weapons(id, 1)
  177. new iWep2 = give_item(id,"weapon_deagle")
  178. if( iWep2 > 0 )
  179. {
  180. cs_set_weapon_ammo(iWep2, get_pcvar_num(cvar_clip_Skull1))
  181. cs_set_user_bpammo (id, CSW_DEAGLE, get_pcvar_num(cvar_Skull1_ammo))
  182. }
  183. g_has_Skull1[id] = true;
  184. }
  185.  
  186. public zp_extra_item_selected(id, itemid)
  187. {
  188. if(itemid == g_itemid_Skull1)
  189. {
  190. give_Skull1(id)
  191. }
  192. }
  193.  
  194. public fw_Skull1_AddToPlayer(Skull1, id)
  195. {
  196. if(!is_valid_ent(Skull1) || !is_user_connected(id))
  197. return HAM_IGNORED;
  198.  
  199. if(entity_get_int(Skull1, EV_INT_WEAPONKEY) == Skull1_WEAPONKEY)
  200. {
  201. g_has_Skull1[id] = true
  202.  
  203. entity_set_int(Skull1, EV_INT_WEAPONKEY, 0)
  204.  
  205. return HAM_HANDLED;
  206. }
  207.  
  208. return HAM_IGNORED;
  209. }
  210.  
  211. public fw_UseStationary_Post(entity, caller, activator, use_type)
  212. {
  213. if (use_type == USE_STOPPED && is_user_connected(caller))
  214. replace_weapon_models(caller, get_user_weapon(caller))
  215. }
  216.  
  217. public fw_Item_Deploy_Post(weapon_ent)
  218. {
  219. static owner
  220. owner = fm_cs_get_weapon_ent_owner(weapon_ent)
  221.  
  222. static weaponid
  223. weaponid = cs_get_weapon_id(weapon_ent)
  224.  
  225. replace_weapon_models(owner, weaponid)
  226. }
  227.  
  228. public CurrentWeapon(id)
  229. {
  230. replace_weapon_models(id, read_data(2))
  231. }
  232.  
  233. replace_weapon_models(id, weaponid)
  234. {
  235. switch (weaponid)
  236. {
  237. case CSW_DEAGLE:
  238. {
  239. if (zp_get_user_zombie(id) || zp_get_user_survivor(id))
  240. return;
  241.  
  242. if(g_has_Skull1[id])
  243. {
  244. set_pev(id, pev_viewmodel2, Skull1_V_MODEL)
  245. set_pev(id, pev_weaponmodel2, Skull1_P_MODEL)
  246. }
  247. }
  248. }
  249. }
  250.  
  251. public fw_UpdateClientData_Post(Player, SendWeapons, CD_Handle)
  252. {
  253. if(!is_user_alive(Player) || (get_user_weapon(Player) != CSW_DEAGLE) || !g_has_Skull1[Player])
  254. return FMRES_IGNORED
  255.  
  256. set_cd(CD_Handle, CD_flNextAttack, halflife_time () + 0.001)
  257. return FMRES_HANDLED
  258. }
  259.  
  260. public fw_Skull1_PrimaryAttack(Weapon)
  261. {
  262. new Player = get_pdata_cbase(Weapon, 41, 4)
  263.  
  264. if (!g_has_Skull1[Player])
  265. return;
  266.  
  267. pev(Player,pev_punchangle,cl_pushangle[Player])
  268.  
  269. g_clip_ammo[Player] = cs_get_weapon_ammo(Weapon)
  270. g_iClip = cs_get_weapon_ammo(Weapon)
  271. }
  272.  
  273. public fwPlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
  274. {
  275. if ((eventid != g_orig_event_Skull1))
  276. return FMRES_IGNORED
  277. if (!(1 <= invoker <= g_MaxPlayers))
  278. return FMRES_IGNORED
  279.  
  280. playback_event(flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
  281. return FMRES_SUPERCEDE
  282. }
  283.  
  284. public fw_Skull1_PrimaryAttack_Post(Weapon)
  285. {
  286. new Player = get_pdata_cbase(Weapon, 41, 4)
  287.  
  288. new szClip, szAmmo
  289. get_user_weapon(Player, szClip, szAmmo)
  290.  
  291. if (g_iClip <= cs_get_weapon_ammo(Weapon))
  292. return;
  293.  
  294. if(Player > 0 && Player < 33)
  295. {
  296. if(!g_has_Skull1[Player])
  297. {
  298. if(szClip > 0) emit_sound(Player, CHAN_WEAPON, "weapons/deagle-1.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  299. }
  300. if(g_has_Skull1[Player])
  301. {
  302. new Float:push[3]
  303. pev(Player,pev_punchangle,push)
  304. xs_vec_sub(push,cl_pushangle[Player],push)
  305.  
  306. xs_vec_mul_scalar(push,get_pcvar_float(cvar_recoil_Skull1),push)
  307. xs_vec_add(push,cl_pushangle[Player],push)
  308. set_pev(Player,pev_punchangle,push)
  309.  
  310. if(!g_clip_ammo[Player])
  311. return
  312.  
  313. emit_sound(Player, CHAN_WEAPON, Fire_Sounds[0], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  314. UTIL_PlayWeaponAnimation(Player, 3)
  315.  
  316. make_blood_and_bulletholes(Player)
  317. }
  318. }
  319. }
  320.  
  321. public fw_TakeDamage(victim, inflictor, attacker, Float:damage)
  322. {
  323. if (victim != attacker && is_user_connected(attacker))
  324. {
  325. if(get_user_weapon(attacker) == CSW_DEAGLE)
  326. {
  327. if(g_has_Skull1[attacker])
  328. SetHamParamFloat(4, damage * get_pcvar_float(cvar_dmg_Skull1))
  329. }
  330. }
  331. }
  332.  
  333. public message_DeathMsg(msg_id, msg_dest, id)
  334. {
  335. static szTruncatedWeapon[33], iAttacker, iVictim
  336.  
  337. get_msg_arg_string(4, szTruncatedWeapon, charsmax(szTruncatedWeapon))
  338.  
  339. iAttacker = get_msg_arg_int(1)
  340. iVictim = get_msg_arg_int(2)
  341.  
  342. if(!is_user_connected(iAttacker) || iAttacker == iVictim)
  343. return PLUGIN_CONTINUE
  344.  
  345. if(equal(szTruncatedWeapon, "deagle") && get_user_weapon(iAttacker) == CSW_DEAGLE)
  346. {
  347. if(g_has_Skull1[iAttacker])
  348. set_msg_arg_string(4, "Skull1")
  349. }
  350.  
  351. return PLUGIN_CONTINUE
  352. }
  353.  
  354. stock fm_cs_get_current_weapon_ent(id)
  355. {
  356. return get_pdata_cbase(id, OFFSET_ACTIVE_ITEM, OFFSET_LINUX);
  357. }
  358.  
  359. stock fm_cs_get_weapon_ent_owner(ent)
  360. {
  361. return get_pdata_cbase(ent, OFFSET_WEAPONOWNER, OFFSET_LINUX_WEAPONS);
  362. }
  363.  
  364. stock UTIL_PlayWeaponAnimation(const Player, const Sequence )
  365. {
  366. set_pev(Player, pev_weaponanim, Sequence)
  367.  
  368. message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = Player)
  369. write_byte(Sequence)
  370. write_byte(pev(Player, pev_body))
  371. message_end()
  372. }
  373.  
  374. stock make_blood_and_bulletholes(id)
  375. {
  376. new aimOrigin[3], target, body
  377. get_user_origin(id, aimOrigin, 3)
  378. get_user_aiming(id, target, body)
  379.  
  380. if(target > 0 && target <= g_MaxPlayers && zp_get_user_zombie(target))
  381. {
  382. new Float:fStart[3], Float:fEnd[3], Float:fRes[3], Float:fVel[3]
  383. pev(id, pev_origin, fStart)
  384.  
  385. velocity_by_aim(id, 64, fVel)
  386.  
  387. fStart[0] = float(aimOrigin[0])
  388. fStart[1] = float(aimOrigin[1])
  389. fStart[2] = float(aimOrigin[2])
  390. fEnd[0] = fStart[0]+fVel[0]
  391. fEnd[1] = fStart[1]+fVel[1]
  392. fEnd[2] = fStart[2]+fVel[2]
  393.  
  394. new res
  395. engfunc(EngFunc_TraceLine, fStart, fEnd, 0, target, res)
  396. get_tr2(res, TR_vecEndPos, fRes)
  397.  
  398. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  399. write_byte(TE_BLOODSPRITE)
  400. write_coord(floatround(fStart[0]))
  401. write_coord(floatround(fStart[1]))
  402. write_coord(floatround(fStart[2]))
  403. write_short( m_iBlood [ 1 ])
  404. write_short( m_iBlood [ 0 ] )
  405. write_byte(70)
  406. write_byte(random_num(1,2))
  407. message_end()
  408.  
  409.  
  410. }
  411. else if(!is_user_connected(target))
  412. {
  413. if(target)
  414. {
  415. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  416. write_byte(TE_DECAL)
  417. write_coord(aimOrigin[0])
  418. write_coord(aimOrigin[1])
  419. write_coord(aimOrigin[2])
  420. write_byte(GUNSHOT_DECALS[random_num ( 0, sizeof GUNSHOT_DECALS -1 ) ] )
  421. write_short(target)
  422. message_end()
  423. }
  424. else
  425. {
  426. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  427. write_byte(TE_WORLDDECAL)
  428. write_coord(aimOrigin[0])
  429. write_coord(aimOrigin[1])
  430. write_coord(aimOrigin[2])
  431. write_byte(GUNSHOT_DECALS[random_num ( 0, sizeof GUNSHOT_DECALS -1 ) ] )
  432. message_end()
  433. }
  434.  
  435. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  436. write_byte(TE_GUNSHOTDECAL)
  437. write_coord(aimOrigin[0])
  438. write_coord(aimOrigin[1])
  439. write_coord(aimOrigin[2])
  440. write_short(id)
  441. write_byte(GUNSHOT_DECALS[random_num ( 0, sizeof GUNSHOT_DECALS -1 ) ] )
  442. message_end()
  443. }
  444. }
  445.  
  446. public Skull1__ItemPostFrame(weapon_entity) {
  447. new id = pev(weapon_entity, pev_owner)
  448. if (!is_user_connected(id))
  449. return HAM_IGNORED;
  450.  
  451. if (!g_has_Skull1[id])
  452. return HAM_IGNORED;
  453.  
  454. new Float:flNextAttack = get_pdata_float(id, m_flNextAttack, PLAYER_LINUX_XTRA_OFF)
  455.  
  456. new iBpAmmo = cs_get_user_bpammo(id, CSW_DEAGLE);
  457. new iClip = get_pdata_int(weapon_entity, m_iClip, WEAP_LINUX_XTRA_OFF)
  458.  
  459. new fInReload = get_pdata_int(weapon_entity, m_fInReload, WEAP_LINUX_XTRA_OFF)
  460.  
  461. if( fInReload && flNextAttack <= 0.0 )
  462. {
  463. new j = min(get_pcvar_num(cvar_clip_Skull1) - iClip, iBpAmmo)
  464.  
  465. set_pdata_int(weapon_entity, m_iClip, iClip + j, WEAP_LINUX_XTRA_OFF)
  466. cs_set_user_bpammo(id, CSW_DEAGLE, iBpAmmo-j);
  467.  
  468. set_pdata_int(weapon_entity, m_fInReload, 0, WEAP_LINUX_XTRA_OFF)
  469. fInReload = 0
  470. }
  471.  
  472. return HAM_IGNORED;
  473. }
  474.  
  475. public Skull1__Reload(weapon_entity) {
  476. new id = pev(weapon_entity, pev_owner)
  477. if (!is_user_connected(id))
  478. return HAM_IGNORED;
  479.  
  480. if (!g_has_Skull1[id])
  481. return HAM_IGNORED;
  482.  
  483. g_Skull1_TmpClip[id] = -1;
  484.  
  485. new iBpAmmo = cs_get_user_bpammo(id, CSW_DEAGLE);
  486. new iClip = get_pdata_int(weapon_entity, m_iClip, WEAP_LINUX_XTRA_OFF)
  487.  
  488. if (iBpAmmo <= 0)
  489. return HAM_SUPERCEDE;
  490.  
  491. if (iClip >= get_pcvar_num(cvar_clip_Skull1))
  492. return HAM_SUPERCEDE;
  493.  
  494.  
  495. g_Skull1_TmpClip[id] = iClip;
  496.  
  497. return HAM_IGNORED;
  498. }
  499.  
  500. public Skull1__Reload_Post(weapon_entity) {
  501. new id = pev(weapon_entity, pev_owner)
  502. if (!is_user_connected(id))
  503. return HAM_IGNORED;
  504.  
  505. if (!g_has_Skull1[id])
  506. return HAM_IGNORED;
  507.  
  508. if (g_Skull1_TmpClip[id] == -1)
  509. return HAM_IGNORED;
  510.  
  511. set_pdata_int(weapon_entity, m_iClip, g_Skull1_TmpClip[id], WEAP_LINUX_XTRA_OFF)
  512.  
  513. set_pdata_float(weapon_entity, m_flTimeWeaponIdle, Skull1_RELOAD_TIME, WEAP_LINUX_XTRA_OFF)
  514.  
  515. set_pdata_float(id, m_flNextAttack, Skull1_RELOAD_TIME, PLAYER_LINUX_XTRA_OFF)
  516.  
  517. set_pdata_int(weapon_entity, m_fInReload, 1, WEAP_LINUX_XTRA_OFF)
  518.  
  519. // relaod animation
  520. UTIL_PlayWeaponAnimation(id, 6)
  521.  
  522. return HAM_IGNORED;
  523. }
  524.  
  525. stock drop_weapons(id, dropwhat)
  526. {
  527. static weapons[32], num, i, weaponid
  528. num = 0
  529. get_user_weapons(id, weapons, num)
  530.  
  531. for (i = 0; i < num; i++)
  532. {
  533. weaponid = weapons[i]
  534.  
  535. if (dropwhat == 1 && ((1<<weaponid) & SECONDARY_WEAPONS_BIT_SUM))
  536. {
  537. static wname[32]
  538. get_weaponname(weaponid, wname, sizeof wname - 1)
  539. engclient_cmd(id, "drop", wname)
  540. }
  541. }
  542. }
  543.