HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <fakemeta_util>
  4. #include <hamsandwich>
  5. #include <cstrike>
  6. #include <zombieplague>
  7.  
  8. #define PLUGIN "[ZP] Weapon: AK47 [Balrog Edition]"
  9. #define VERSION "1.0"
  10. #define AUTHOR "[Z]KoaLa" // CODE BY DIAS PENDRAGON
  11.  
  12. #define V_MODEL "models/v_ak47be.mdl"
  13. #define P_MODEL "models/p_ak47be.mdl"
  14. #define W_MODEL "models/w_ak47be.mdl"
  15.  
  16. #define DAMAGE 90
  17. #define CLIP 40
  18. #define BPAMMO 240
  19. #define RECOIL 0.4
  20. #define ACTIVE_CLIP 20
  21.  
  22. #define CSW_AK47B CSW_AK47
  23. #define weapon_ak47b "weapon_ak47"
  24.  
  25. #define WEAPON_SECRETCODE 20151
  26. #define WEAPON_EVENT "events/ak47.sc"
  27. #define OLD_W_MODEL "models/w_ak47.mdl"
  28.  
  29. #define EXP_SPR "sprites/balrog4stack.spr"
  30.  
  31. new const AK47B_Sounds[4][] =
  32. {
  33. "weapons/balrogak47_1.wav",
  34. "weapons/balrogak47_clipin.wav",
  35. "weapons/balrogak47_clipout.wav",
  36. "weapons/balrogak47_draw.wav"
  37. }
  38.  
  39. enum
  40. {
  41. ANIM_IDLE1 = 0,
  42. ANIM_RELOAD,
  43. ANIM_DRAW,
  44. ANIM_SHOOT1,
  45. ANIM_SHOOT2,
  46. ANIM_SHOOT3,
  47. ANIM_SHOOTBCS1,
  48. ANIM_SHOOTBCS2
  49. }
  50.  
  51. new g_Ak47b
  52. new g_Had_Ak47b[33], g_Shoot_Special[33], g_Holding_Attack[33], g_Shoot_Count[33], g_Old_Weapon[33], g_Current_Weapon[33]
  53. new g_Exp_SprId, g_Ak47b_Event, g_ShellId, g_SmokePuff_SprId
  54.  
  55. public plugin_init()
  56. {
  57. register_plugin(PLUGIN, VERSION, AUTHOR)
  58.  
  59. register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
  60.  
  61. register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
  62. register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
  63. register_forward(FM_SetModel, "fw_SetModel")
  64. register_forward(FM_CmdStart, "fw_CmdStart")
  65.  
  66. RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack")
  67. RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack")
  68. RegisterHam(Ham_Weapon_PrimaryAttack, weapon_ak47b, "fw_Weapon_PrimaryAttack")
  69. RegisterHam(Ham_Weapon_PrimaryAttack, weapon_ak47b, "fw_Weapon_PrimaryAttack_Post", 1)
  70. RegisterHam(Ham_Item_AddToPlayer, weapon_ak47b, "fw_Item_AddToPlayer_Post", 1)
  71. RegisterHam(Ham_Item_PostFrame, weapon_ak47b, "fw_Item_PostFrame")
  72.  
  73. register_clcmd("admin_get_ak47b", "Get_Ak47b", ADMIN_BAN)
  74. }
  75.  
  76. public plugin_precache()
  77. {
  78. engfunc(EngFunc_PrecacheModel, V_MODEL)
  79. engfunc(EngFunc_PrecacheModel, P_MODEL)
  80. engfunc(EngFunc_PrecacheModel, W_MODEL)
  81.  
  82. for(new i = 0; i < sizeof(AK47B_Sounds); i++)
  83. engfunc(EngFunc_PrecacheSound, AK47B_Sounds[i])
  84.  
  85. g_Exp_SprId = engfunc(EngFunc_PrecacheModel, EXP_SPR)
  86. g_SmokePuff_SprId = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
  87. g_ShellId = engfunc(EngFunc_PrecacheModel, "models/pshell.mdl")
  88.  
  89. register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
  90. g_Ak47b = zp_register_extra_item("AK47 [Balrog Edition]", 12000, ZP_TEAM_HUMAN)
  91. }
  92.  
  93. public fw_PrecacheEvent_Post(type, const name[])
  94. {
  95. if(equal(WEAPON_EVENT, name))
  96. g_Ak47b_Event = get_orig_retval()
  97. }
  98.  
  99. public zp_extra_item_selected(id, itemid)
  100. {
  101. if(itemid == g_Ak47b) Get_Ak47b(id)
  102. }
  103.  
  104. public zp_user_infected_post(id) Remove_Ak47b(id)
  105. public zp_user_humanized_post(id) Remove_Ak47b(id)
  106.  
  107. public Get_Ak47b(id)
  108. {
  109. if(!is_user_alive(id))
  110. return
  111.  
  112. g_Had_Ak47b[id] = 1
  113. g_Shoot_Special[id] = 0
  114. g_Holding_Attack[id] = 0
  115. g_Shoot_Count[id] = 0
  116.  
  117. fm_give_item(id, weapon_ak47b)
  118.  
  119. static Ent; Ent = fm_get_user_weapon_entity(id, CSW_AK47B)
  120. if(!pev_valid(Ent)) return
  121.  
  122. cs_set_weapon_ammo(Ent, CLIP)
  123.  
  124. cs_set_user_bpammo(id, CSW_AK47B, BPAMMO)
  125. }
  126.  
  127. public Remove_Ak47b(id)
  128. {
  129. if(!is_user_connected(id))
  130. return
  131.  
  132. g_Had_Ak47b[id] = 0
  133. g_Shoot_Special[id] = 0
  134. }
  135.  
  136. public Event_CurWeapon(id)
  137. {
  138. if(!is_user_alive(id))
  139. return
  140.  
  141. if(get_user_weapon(id) != g_Current_Weapon[id]) g_Current_Weapon[id] = get_user_weapon(id)
  142.  
  143. if(get_user_weapon(id) == CSW_AK47B && g_Had_Ak47b[id])
  144. {
  145. if(g_Old_Weapon[id] != CSW_AK47B)
  146. {
  147. set_pev(id, pev_viewmodel2, V_MODEL)
  148. set_pev(id, pev_weaponmodel2, P_MODEL)
  149. }
  150. }
  151.  
  152. g_Old_Weapon[id] = get_user_weapon(id)
  153. }
  154.  
  155. public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
  156. {
  157. if(!is_user_alive(id) || !is_user_connected(id))
  158. return FMRES_IGNORED
  159. if(get_user_weapon(id) == CSW_AK47B && g_Had_Ak47b[id])
  160. set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001)
  161.  
  162. return FMRES_HANDLED
  163. }
  164.  
  165. public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
  166. {
  167. if (!is_user_connected(invoker))
  168. return FMRES_IGNORED
  169. if(get_user_weapon(invoker) != CSW_AK47B || !g_Had_Ak47b[invoker])
  170. return FMRES_IGNORED
  171. if(eventid != g_Ak47b_Event)
  172. return FMRES_IGNORED
  173.  
  174. engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
  175.  
  176. if(!g_Shoot_Special[invoker] && cs_get_user_bpammo(invoker, CSW_AK47B) > 0)
  177. {
  178. g_Shoot_Count[invoker]++
  179. if(g_Shoot_Count[invoker] >= ACTIVE_CLIP)
  180. {
  181. g_Shoot_Special[invoker] = 1
  182.  
  183. static Ent; Ent = fm_get_user_weapon_entity(invoker, CSW_AK47B)
  184. if(pev_valid(Ent)) g_Shoot_Count[invoker] = cs_get_weapon_ammo(Ent)
  185. }
  186. } else if(g_Shoot_Special[invoker]) {
  187. cs_set_user_bpammo(invoker, CSW_AK47B, cs_get_user_bpammo(invoker, CSW_AK47B) - 1)
  188.  
  189. if(cs_get_user_bpammo(invoker, CSW_AK47B) <= 0)
  190. {
  191. g_Shoot_Special[invoker] = 0
  192. g_Shoot_Count[invoker] = 0
  193. }
  194. }
  195.  
  196. set_weapon_anim(invoker, g_Shoot_Special[invoker] == 1 ? ANIM_SHOOTBCS2 : ANIM_SHOOTBCS1)
  197. emit_sound(invoker, CHAN_WEAPON, g_Shoot_Special[invoker] == 1 ? AK47B_Sounds[1] : AK47B_Sounds[0], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  198.  
  199. Eject_Shell(invoker, g_ShellId, 0.0)
  200.  
  201. return FMRES_SUPERCEDE
  202. }
  203.  
  204. public fw_SetModel(entity, model[])
  205. {
  206. if(!pev_valid(entity))
  207. return FMRES_IGNORED
  208.  
  209. static Classname[32]
  210. pev(entity, pev_classname, Classname, sizeof(Classname))
  211.  
  212. if(!equal(Classname, "weaponbox"))
  213. return FMRES_IGNORED
  214.  
  215. static iOwner
  216. iOwner = pev(entity, pev_owner)
  217.  
  218. if(equal(model, OLD_W_MODEL))
  219. {
  220. static weapon; weapon = fm_find_ent_by_owner(-1, weapon_ak47b, entity)
  221.  
  222. if(!pev_valid(weapon))
  223. return FMRES_IGNORED;
  224.  
  225. if(g_Had_Ak47b[iOwner])
  226. {
  227. Remove_Ak47b(iOwner)
  228.  
  229. set_pev(weapon, pev_impulse, WEAPON_SECRETCODE)
  230. engfunc(EngFunc_SetModel, entity, W_MODEL)
  231.  
  232. return FMRES_SUPERCEDE
  233. }
  234. }
  235.  
  236. return FMRES_IGNORED;
  237. }
  238.  
  239. public fw_CmdStart(id, uc_handle, seed)
  240. {
  241. if(!is_user_alive(id))
  242. return
  243. if(g_Current_Weapon[id] != CSW_AK47B || !g_Had_Ak47b[id])
  244. return
  245.  
  246. static NewButton; NewButton = get_uc(uc_handle, UC_Buttons)
  247. static OldButton; OldButton = pev(id, pev_oldbuttons)
  248.  
  249. if(NewButton & IN_ATTACK)
  250. {
  251. if(!g_Holding_Attack[id]) g_Holding_Attack[id] = 1
  252. } else if((NewButton & IN_ATTACK2) && !(OldButton & IN_ATTACK2)) {
  253. if(cs_get_user_zoom(id) == 1) cs_set_user_zoom(id, CS_SET_AUGSG552_ZOOM, 1)
  254. else cs_set_user_zoom(id, CS_SET_NO_ZOOM, 1)
  255. } else {
  256. if(OldButton & IN_ATTACK)
  257. {
  258. if(g_Holding_Attack[id])
  259. {
  260. g_Holding_Attack[id] = 0
  261. g_Shoot_Count[id] = 0
  262. g_Shoot_Special[id] = 0
  263. }
  264. }
  265. }
  266. }
  267.  
  268. public fw_TraceAttack(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits)
  269. {
  270. if(!is_user_alive(Attacker))
  271. return HAM_IGNORED
  272. if(get_user_weapon(Attacker) != CSW_AK47B || !g_Had_Ak47b[Attacker])
  273. return HAM_IGNORED
  274.  
  275. static Float:flEnd[3], Float:vecPlane[3]
  276.  
  277. get_tr2(Ptr, TR_vecEndPos, flEnd)
  278. get_tr2(Ptr, TR_vecPlaneNormal, vecPlane)
  279.  
  280. if(!is_user_alive(Victim))
  281. {
  282. Make_BulletHole(Attacker, flEnd, Damage)
  283. Make_BulletSmoke(Attacker, Ptr)
  284. }
  285.  
  286. if(g_Shoot_Special[Attacker])
  287. {
  288. Make_BalrogEffect(Attacker, Ptr)
  289. radius_damage(Attacker, flEnd, float(DAMAGE), 96.0)
  290. }
  291.  
  292. SetHamParamFloat(3, float(DAMAGE))
  293.  
  294. return HAM_IGNORED
  295. }
  296.  
  297. public fw_Weapon_PrimaryAttack(Ent)
  298. {
  299. if(!pev_valid(Ent))
  300. return
  301. static Id; Id = pev(Ent, pev_owner)
  302. if(!g_Had_Ak47b[Id])
  303. return
  304.  
  305. if(g_Shoot_Special[Id]) set_pdata_float(Ent, 62, 0.4, 4)
  306. else set_pdata_float(Ent, 62, 0.2, 4)
  307. }
  308.  
  309. public fw_Weapon_PrimaryAttack_Post(Ent)
  310. {
  311. if(!pev_valid(Ent))
  312. return
  313. static Id; Id = pev(Ent, pev_owner)
  314. if(!g_Had_Ak47b[Id])
  315. return
  316.  
  317. static Float:push[3]; pev(Id, pev_punchangle, push)
  318.  
  319. xs_vec_mul_scalar(push, RECOIL, push)
  320.  
  321. set_pev(Id, pev_punchangle, push)
  322.  
  323. if(g_Shoot_Special[Id] && cs_get_weapon_ammo(Ent) > 0)
  324. {
  325. cs_set_weapon_ammo(Ent, g_Shoot_Count[Id])
  326. set_pdata_float(Ent, 46, get_pdata_float(Ent, 46, 4) * 0.75, 4)
  327. }
  328. }
  329.  
  330. public fw_Item_AddToPlayer_Post(ent, id)
  331. {
  332. if(!pev_valid(ent))
  333. return HAM_IGNORED
  334.  
  335. if(pev(ent, pev_impulse) == WEAPON_SECRETCODE)
  336. {
  337. g_Had_Ak47b[id] = 1
  338. set_pev(ent, pev_impulse, 0)
  339. }
  340.  
  341. return HAM_HANDLED
  342. }
  343.  
  344. public fw_Item_PostFrame(Ent)
  345. {
  346. if(!pev_valid(Ent))
  347. return
  348.  
  349. static Id; Id = pev(Ent, pev_owner)
  350. if(!g_Had_Ak47b[Id])
  351. return
  352.  
  353. static Float:flNextAttack; flNextAttack = get_pdata_float(Id, 83, 5)
  354. static bpammo; bpammo = cs_get_user_bpammo(Id, CSW_AK47B)
  355. static iClip; iClip = get_pdata_int(Ent, 51, 4)
  356.  
  357. if(get_pdata_int(Ent, 54, 4) && flNextAttack <= 0.0)
  358. {
  359. static temp1; temp1 = min(CLIP - iClip, bpammo)
  360.  
  361. set_pdata_int(Ent, 51, iClip + temp1, 4)
  362. cs_set_user_bpammo(Id, CSW_AK47B, bpammo - temp1)
  363.  
  364. set_pdata_int(Ent, 54, 0, 4)
  365. }
  366. }
  367.  
  368. stock Make_BulletHole(id, Float:Origin[3], Float:Damage)
  369. {
  370. // Find target
  371. static Decal; Decal = random_num(41, 45)
  372. static LoopTime;
  373.  
  374. if(Damage > 100.0) LoopTime = 2
  375. else LoopTime = 1
  376.  
  377. for(new i = 0; i < LoopTime; i++)
  378. {
  379. // Put decal on "world" (a wall)
  380. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  381. write_byte(TE_WORLDDECAL)
  382. engfunc(EngFunc_WriteCoord, Origin[0])
  383. engfunc(EngFunc_WriteCoord, Origin[1])
  384. engfunc(EngFunc_WriteCoord, Origin[2])
  385. write_byte(Decal)
  386. message_end()
  387.  
  388. // Show sparcles
  389. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  390. write_byte(TE_GUNSHOTDECAL)
  391. engfunc(EngFunc_WriteCoord, Origin[0])
  392. engfunc(EngFunc_WriteCoord, Origin[1])
  393. engfunc(EngFunc_WriteCoord, Origin[2])
  394. write_short(id)
  395. write_byte(Decal)
  396. message_end()
  397. }
  398. }
  399.  
  400. public Make_BulletSmoke(id, TrResult)
  401. {
  402. static Float:vecSrc[3], Float:vecEnd[3], TE_FLAG
  403.  
  404. get_weapon_attachment(id, vecSrc)
  405. global_get(glb_v_forward, vecEnd)
  406.  
  407. xs_vec_mul_scalar(vecEnd, 8192.0, vecEnd)
  408. xs_vec_add(vecSrc, vecEnd, vecEnd)
  409.  
  410. get_tr2(TrResult, TR_vecEndPos, vecSrc)
  411. get_tr2(TrResult, TR_vecPlaneNormal, vecEnd)
  412.  
  413. xs_vec_mul_scalar(vecEnd, 2.5, vecEnd)
  414. xs_vec_add(vecSrc, vecEnd, vecEnd)
  415.  
  416. TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
  417. TE_FLAG |= TE_EXPLFLAG_NOSOUND
  418. TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
  419.  
  420. engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0)
  421. write_byte(TE_EXPLOSION)
  422. engfunc(EngFunc_WriteCoord, vecEnd[0])
  423. engfunc(EngFunc_WriteCoord, vecEnd[1])
  424. engfunc(EngFunc_WriteCoord, vecEnd[2] - 10.0)
  425. write_short(g_SmokePuff_SprId)
  426. write_byte(2)
  427. write_byte(50)
  428. write_byte(TE_FLAG)
  429. message_end()
  430. }
  431.  
  432. public Make_BalrogEffect(id, TrResult)
  433. {
  434. static Float:vecSrc[3], Float:vecEnd[3], TE_FLAG
  435.  
  436. get_weapon_attachment(id, vecSrc)
  437. global_get(glb_v_forward, vecEnd)
  438.  
  439. xs_vec_mul_scalar(vecEnd, 8192.0, vecEnd)
  440. xs_vec_add(vecSrc, vecEnd, vecEnd)
  441.  
  442. get_tr2(TrResult, TR_vecEndPos, vecSrc)
  443. get_tr2(TrResult, TR_vecPlaneNormal, vecEnd)
  444.  
  445. xs_vec_mul_scalar(vecEnd, 5.0, vecEnd)
  446. xs_vec_add(vecSrc, vecEnd, vecEnd)
  447.  
  448. TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
  449. TE_FLAG |= TE_EXPLFLAG_NOSOUND
  450. TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
  451.  
  452. engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0)
  453. write_byte(TE_EXPLOSION)
  454. engfunc(EngFunc_WriteCoord, vecEnd[0])
  455. engfunc(EngFunc_WriteCoord, vecEnd[1])
  456. engfunc(EngFunc_WriteCoord, vecEnd[2])
  457. write_short(g_Exp_SprId)
  458. write_byte(5)
  459. write_byte(30)
  460. write_byte(TE_FLAG)
  461. message_end()
  462. }
  463.  
  464. stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
  465. {
  466. new Float:vfEnd[3], viEnd[3]
  467. get_user_origin(id, viEnd, 3)
  468. IVecFVec(viEnd, vfEnd)
  469.  
  470. new Float:fOrigin[3], Float:fAngle[3]
  471.  
  472. pev(id, pev_origin, fOrigin)
  473. pev(id, pev_view_ofs, fAngle)
  474.  
  475. xs_vec_add(fOrigin, fAngle, fOrigin)
  476.  
  477. new Float:fAttack[3]
  478.  
  479. xs_vec_sub(vfEnd, fOrigin, fAttack)
  480. xs_vec_sub(vfEnd, fOrigin, fAttack)
  481.  
  482. new Float:fRate
  483.  
  484. fRate = fDis / vector_length(fAttack)
  485. xs_vec_mul_scalar(fAttack, fRate, fAttack)
  486.  
  487. xs_vec_add(fOrigin, fAttack, output)
  488. }
  489.  
  490. stock radius_damage(id, Float:Origin[3], Float:Damage, Float:Radius)
  491. {
  492. static Victim; Victim = -1
  493.  
  494. while((Victim = engfunc(EngFunc_FindEntityInSphere, Victim, Origin, Radius)) != 0)
  495. {
  496. if(!is_user_alive(Victim) || id == Victim)
  497. continue
  498. if(!zp_get_user_zombie(Victim))
  499. continue
  500.  
  501. ExecuteHamB(Ham_TakeDamage, Victim, fm_get_user_weapon_entity(id, get_user_weapon(id)), id, Damage, DMG_BULLET)
  502. }
  503. }
  504.  
  505. stock Eject_Shell(id, Shell_ModelIndex, Float:Time) // By Dias
  506. {
  507. static Ent; Ent = get_pdata_cbase(id, 373, 5)
  508. if(!pev_valid(Ent))
  509. return
  510.  
  511. set_pdata_int(Ent, 57, Shell_ModelIndex, 4)
  512. set_pdata_float(id, 111, get_gametime() + Time)
  513. }
  514.  
  515. stock set_weapon_anim(id, anim)
  516. {
  517. if(!is_user_alive(id))
  518. return
  519.  
  520. set_pev(id, pev_weaponanim, anim)
  521.  
  522. message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
  523. write_byte(anim)
  524. write_byte(pev(id, pev_body))
  525. message_end()
  526. }