HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <engine>
  3. #include <fakemeta>
  4. #include <fakemeta_util>
  5. #include <hamsandwich>
  6. #include <cstrike>
  7. #include <zombieplague>
  8.  
  9. #define PLUGIN "Compound Bow"
  10. #define VERSION "1.0"
  11. #define AUTHOR "Dias Pendragon"
  12.  
  13. #define V_MODEL "models/v_bow.mdl"
  14. #define P_MODEL "models/p_bow.mdl"
  15. #define P_MODEL_EMPTY "models/p_bow_empty.mdl"
  16. #define W_MODEL "models/w_bow.mdl"
  17.  
  18. #define ARROW_MODEl "models/arrow.mdl"
  19.  
  20. new const WeaponSounds[7][] =
  21. {
  22. "weapons/bow_shoot1.wav",
  23. "weapons/bow_charge_shoot1_empty.wav",
  24. "weapons/bow_charge_shoot2.wav",
  25. "weapons/bow_draw.wav",
  26. "weapons/bow_charge_start1.wav",
  27. "weapons/bow_charge_start2.wav",
  28. "weapons/bow_charge_finish1.wav"
  29. }
  30.  
  31. new const WeaponResources[3][] =
  32. {
  33. "sprites/weapon_bow.txt",
  34. "sprites/640hud12_2.spr",
  35. "sprites/640hud98_2.spr"
  36. }
  37.  
  38. enum
  39. {
  40. BOW_ANIM_IDLE = 0,
  41. BOW_ANIM_IDLE_EMPTY,
  42. BOW_ANIM_SHOOT1, // 0.45
  43. BOW_ANIM_SHOOT1_EMPTY,
  44. BOW_ANIM_DRAW,
  45. BOW_ANIM_DRAW_EMPTY,
  46. BOW_ANIM_CHARGE_START, // 0.5
  47. BOW_ANIM_CHARGE_FINISH, // 0.35
  48. BOW_ANIM_CHARGE_IDLE1, // 0.35
  49. BOW_ANIM_CHARGE_IDLE2, // 0.35
  50. BOW_ANIM_CHARGE_SHOOT1, // 1.3
  51. BOW_ANIM_CHARGE_SHOOT1_EMPTY, // 0.6
  52. BOW_ANIM_CHARGE_SHOOT2, // 1.3
  53. BOW_ANIM_CHARGE_SHOOT2_EMPTY // 0.6
  54. }
  55.  
  56. #define CSW_BOW CSW_M4A1
  57. #define weapon_bow "weapon_m4a1"
  58. #define BOW_AMMOID 4
  59.  
  60. #define ARROW_DEFAULT 60
  61. #define ARROW_CLASSNAME "arrow"
  62. #define ARROW_SPEED 2000.0
  63.  
  64. #define TIME_DRAW 0.75
  65. #define TIME_RELOADA 0.45
  66. #define TIME_RELOADB 1.25
  67. #define TIME_CHARGE 0.5
  68.  
  69. #define DAMAGE_A 70
  70. #define DAMAGE_B 140
  71.  
  72. #define WEAPON_SECRETCODE 3102013 // Create Date
  73. #define WEAPON_ANIMEXT "carbine"
  74. #define WEAPON_OLDWMODEL "models/w_m4a1.mdl"
  75.  
  76. #define WL_NAME "weapon_bow"
  77. #define WL_PRIAMMOID 4
  78. #define WL_PRIAMMOMAX 60 // 30
  79. #define WL_SECAMMOID -1
  80. #define WL_SECAMMOIDMAX -1
  81. #define WL_SLOTID 0
  82. #define WL_NUMINSLOT 6
  83. #define WL_FLAG 0
  84.  
  85. // MACROS
  86. #define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
  87. #define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
  88. #define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))
  89.  
  90. enum
  91. {
  92. TEAM_T = 1,
  93. TEAM_CT
  94. }
  95.  
  96. enum
  97. {
  98. WEAPON_NONE = 0,
  99. WEAPON_STARTCHARGING,
  100. WEAPON_WAITCHARGING,
  101. WEAPON_CHARGING,
  102. WEAPON_FINISHCHARGING
  103. }
  104.  
  105. new g_Had_CompoundBow, g_InTempingAttack, g_BowArrow[33], g_WeaponState[33], Float:g_TimeCharge[33]
  106. new g_MsgCurWeapon, g_MsgAmmoX, g_MsgWeaponList
  107. new g_SprId_LaserBeam, g_Extra_Compound_Bow
  108.  
  109. public plugin_init()
  110. {
  111. register_plugin(PLUGIN, VERSION, AUTHOR)
  112.  
  113. register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
  114.  
  115. register_think(ARROW_CLASSNAME, "fw_Think_Arrow")
  116. register_touch(ARROW_CLASSNAME, "*", "fw_Touch_Arrow")
  117.  
  118. register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
  119. register_forward(FM_CmdStart, "fw_CmdStart")
  120. register_forward(FM_SetModel, "fw_SetModel")
  121. register_forward(FM_EmitSound, "fw_EmitSound")
  122. register_forward(FM_TraceLine, "fw_TraceLine")
  123. register_forward(FM_TraceHull, "fw_TraceHull")
  124.  
  125. RegisterHam(Ham_Item_AddToPlayer, weapon_bow, "fw_Item_AddToPlayer_Post", 1)
  126. RegisterHam(Ham_Item_Deploy, weapon_bow, "fw_Item_Deploy_Post", 1)
  127. RegisterHam(Ham_Weapon_WeaponIdle, weapon_bow, "fw_Weapon_WeaponIdle_Post", 1)
  128.  
  129. g_MsgCurWeapon = get_user_msgid("CurWeapon")
  130. g_MsgAmmoX = get_user_msgid("AmmoX")
  131. g_MsgWeaponList = get_user_msgid("WeaponList")
  132.  
  133. g_Extra_Compound_Bow = zp_register_extra_item("Compound Bow", 0, ZP_TEAM_HUMAN)
  134.  
  135. register_clcmd(WL_NAME, "WeaponList_Hook")
  136. }
  137.  
  138. public plugin_precache()
  139. {
  140. engfunc(EngFunc_PrecacheModel, V_MODEL)
  141. engfunc(EngFunc_PrecacheModel, P_MODEL)
  142. engfunc(EngFunc_PrecacheModel, P_MODEL_EMPTY)
  143. engfunc(EngFunc_PrecacheModel, W_MODEL)
  144. engfunc(EngFunc_PrecacheModel, ARROW_MODEl)
  145.  
  146. new i
  147. for(i = 0; i < sizeof(WeaponSounds); i++)
  148. engfunc(EngFunc_PrecacheSound, WeaponSounds[i])
  149. for(i = 0; i < sizeof(WeaponResources); i++)
  150. {
  151. if(i == 0) engfunc(EngFunc_PrecacheGeneric, WeaponResources[i])
  152. else engfunc(EngFunc_PrecacheModel, WeaponResources[i])
  153. }
  154.  
  155. g_SprId_LaserBeam = engfunc(EngFunc_PrecacheModel, "sprites/laserbeam.spr")
  156. }
  157.  
  158. public zp_extra_item_selected(id, item)
  159. {
  160. if(item == g_Extra_Compound_Bow)
  161. {
  162. Get_CompoundBow(id)
  163. }
  164. }
  165.  
  166. public zp_user_infected_post(id)
  167. {
  168. UnSet_BitVar(g_Had_CompoundBow, id)
  169. g_BowArrow[id] = 0
  170. }
  171.  
  172. public Get_CompoundBow(id)
  173. {
  174. if(!is_user_alive(id))
  175. return
  176.  
  177. Set_BitVar(g_Had_CompoundBow, id)
  178. g_BowArrow[id] = ARROW_DEFAULT
  179. g_WeaponState[id] = WEAPON_NONE
  180.  
  181. fm_give_item(id, weapon_bow)
  182. UpdateAmmo(id, CSW_BOW, BOW_AMMOID, -1, g_BowArrow[id])
  183. }
  184.  
  185. public Remove_CompoundBow(id)
  186. {
  187. UnSet_BitVar(g_Had_CompoundBow, id)
  188. g_BowArrow[id] = 0
  189. }
  190.  
  191. public WeaponList_Hook(id)
  192. {
  193. engclient_cmd(id, weapon_bow)
  194. return PLUGIN_HANDLED
  195. }
  196.  
  197. public UpdateAmmo(id, CSWID, AmmoID, Ammo, BpAmmo)
  198. {
  199. message_begin(MSG_ONE_UNRELIABLE, g_MsgCurWeapon, _, id)
  200. write_byte(1)
  201. write_byte(CSWID)
  202. write_byte(Ammo)
  203. message_end()
  204.  
  205. message_begin(MSG_ONE_UNRELIABLE, g_MsgAmmoX, _, id)
  206. write_byte(AmmoID)
  207. write_byte(BpAmmo)
  208. message_end()
  209.  
  210. cs_set_user_bpammo(id, CSWID, BpAmmo)
  211. }
  212.  
  213. public Event_CurWeapon(id)
  214. {
  215. static CSWID; CSWID = read_data(2)
  216. if(CSWID != CSW_BOW) return
  217. if(!Get_BitVar(g_Had_CompoundBow, id)) return
  218.  
  219. UpdateAmmo(id, CSW_BOW, BOW_AMMOID, -1, g_BowArrow[id])
  220. }
  221.  
  222. public fw_Think_Arrow(Ent)
  223. {
  224. if(!pev_valid(Ent))
  225. return
  226. if(pev(Ent, pev_iuser4))
  227. {
  228. engfunc(EngFunc_RemoveEntity, Ent)
  229. return
  230. }
  231. static Id; Id = pev(Ent, pev_iuser1)
  232. if(!is_user_connected(Id))
  233. return
  234.  
  235. if(!pev(Ent, pev_iuser3))
  236. {
  237. if(entity_range(Ent, Id) < 250.0)
  238. {
  239. set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
  240. return
  241. }
  242.  
  243. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  244. write_byte(TE_BEAMFOLLOW)
  245. write_short(Ent)
  246. write_short(g_SprId_LaserBeam)
  247. write_byte(10)
  248. write_byte(2)
  249. write_byte(255)
  250. write_byte(127)
  251. write_byte(127)
  252. write_byte(127)
  253. message_end()
  254.  
  255. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  256. write_byte(TE_BEAMFOLLOW)
  257. write_short(Ent)
  258. write_short(g_SprId_LaserBeam)
  259. write_byte(10)
  260. write_byte(2)
  261. write_byte(255)
  262. write_byte(255)
  263. write_byte(255)
  264. write_byte(127)
  265. message_end()
  266.  
  267. set_pev(Ent, pev_iuser3, 1)
  268. }
  269.  
  270. set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
  271. }
  272.  
  273. public fw_Touch_Arrow(Ent, Id)
  274. {
  275. if(!pev_valid(Ent))
  276. return
  277. if(pev(Ent, pev_movetype) == MOVETYPE_NONE)
  278. return
  279.  
  280. // Remove Ent
  281. set_pev(Ent, pev_movetype, MOVETYPE_NONE)
  282. set_pev(Ent, pev_solid, SOLID_NOT)
  283.  
  284. if(!is_user_alive(Id)) // Wall
  285. {
  286. set_pev(Ent, pev_iuser4, 1)
  287. set_pev(Ent, pev_nextthink, get_gametime() + 3.0)
  288.  
  289. static Float:Origin[3]; pev(Ent, pev_origin, Origin)
  290. MakeBulletDecal(Origin)
  291. } else { // Player
  292. static Attacker; Attacker = pev(Ent, pev_iuser1)
  293. if(!is_user_connected(Attacker) || Attacker == Id)
  294. {
  295. engfunc(EngFunc_RemoveEntity, Ent)
  296. return
  297. }
  298.  
  299. do_attack(Attacker, Id, 0, float(DAMAGE_A) * 1.5)
  300. engfunc(EngFunc_RemoveEntity, Ent)
  301. }
  302. }
  303.  
  304. public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
  305. {
  306. if(get_user_weapon(id) != CSW_BOW || !Get_BitVar(g_Had_CompoundBow, id))
  307. return FMRES_IGNORED
  308.  
  309. set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001)
  310.  
  311. return FMRES_HANDLED
  312. }
  313.  
  314. public fw_CmdStart(id, uc_handle, seed)
  315. {
  316. if(get_user_weapon(id) != CSW_BOW || !Get_BitVar(g_Had_CompoundBow, id))
  317. return
  318.  
  319. static CurButton; CurButton = get_uc(uc_handle, UC_Buttons)
  320. if(CurButton & IN_ATTACK)
  321. {
  322. CurButton &= ~IN_ATTACK
  323. set_uc(uc_handle, UC_Buttons, CurButton)
  324.  
  325. Bow_NormalAttackHandle(id, 0)
  326. }
  327.  
  328. static Ent; Ent = fm_get_user_weapon_entity(id, CSW_BOW)
  329. if(!pev_valid(Ent)) return
  330.  
  331. if(CurButton & IN_ATTACK2)
  332. {
  333. CurButton &= ~IN_ATTACK2
  334. set_uc(uc_handle, UC_Buttons, CurButton)
  335.  
  336. if(get_pdata_float(Ent, 46, 4) > 0.0 || get_pdata_float(Ent, 47, 4) > 0.0)
  337. return
  338. if(!g_BowArrow[id])
  339. return
  340.  
  341. switch(g_WeaponState[id])
  342. {
  343. case WEAPON_NONE:
  344. {
  345. Set_Weapon_Anim(id, BOW_ANIM_CHARGE_START)
  346. Set_Weapon_TimeIdle(id, CSW_BOW, 0.5)
  347. Set_Player_NextAttack(id, 0.5)
  348.  
  349. g_WeaponState[id] = WEAPON_STARTCHARGING
  350. }
  351. case WEAPON_STARTCHARGING:
  352. {
  353. Set_Weapon_Anim(id, BOW_ANIM_CHARGE_IDLE1)
  354. Set_Weapon_TimeIdle(id, CSW_BOW, 0.35)
  355. Set_Player_NextAttack(id, 0.35)
  356.  
  357. g_TimeCharge[id] = get_gametime()
  358. g_WeaponState[id] = WEAPON_WAITCHARGING
  359. }
  360. case WEAPON_WAITCHARGING:
  361. {
  362. Set_Weapon_Anim(id, BOW_ANIM_CHARGE_IDLE1)
  363. Set_Weapon_TimeIdle(id, CSW_BOW, 0.35)
  364. Set_Player_NextAttack(id, 0.35)
  365.  
  366. g_WeaponState[id] = WEAPON_WAITCHARGING
  367.  
  368. if(get_gametime() >= (g_TimeCharge[id] + TIME_CHARGE))
  369. {
  370. Set_Weapon_Anim(id, BOW_ANIM_CHARGE_FINISH)
  371. Set_Weapon_TimeIdle(id, CSW_BOW, 0.35)
  372. Set_Player_NextAttack(id, 0.35)
  373.  
  374. g_WeaponState[id] = WEAPON_FINISHCHARGING
  375. }
  376. }
  377. case WEAPON_FINISHCHARGING:
  378. {
  379. Set_Weapon_Anim(id, BOW_ANIM_CHARGE_IDLE2)
  380. Set_Weapon_TimeIdle(id, CSW_BOW, 0.35)
  381. Set_Player_NextAttack(id, 0.35)
  382.  
  383. g_WeaponState[id] = WEAPON_FINISHCHARGING
  384. }
  385. }
  386. } else {
  387. static OldButton; OldButton = pev(id, pev_oldbuttons)
  388. if(OldButton & IN_ATTACK2)
  389. {
  390. if(g_WeaponState[id] == WEAPON_WAITCHARGING)
  391. {
  392. set_pdata_float(id, 83, 0.0, 5)
  393. Bow_NormalAttackHandle(id, 1)
  394. } else if(g_WeaponState[id] == WEAPON_FINISHCHARGING) {
  395. Bow_ChargeAttackHandle(id)
  396. }
  397. } else {
  398. if(get_pdata_float(Ent, 46, 4) > 0.0 || get_pdata_float(Ent, 47, 4) > 0.0)
  399. return
  400.  
  401. if(g_WeaponState[id] == WEAPON_STARTCHARGING)
  402. {
  403. set_pdata_float(id, 83, 0.0, 5)
  404. Bow_NormalAttackHandle(id, 1)
  405. }
  406.  
  407. g_WeaponState[id] = WEAPON_NONE
  408. }
  409. }
  410.  
  411. return
  412. }
  413.  
  414. public fw_SetModel(entity, model[])
  415. {
  416. if(!pev_valid(entity))
  417. return FMRES_IGNORED
  418.  
  419. static szClassName[33]
  420. pev(entity, pev_classname, szClassName, charsmax(szClassName))
  421.  
  422. if(!equal(szClassName, "weaponbox"))
  423. return FMRES_IGNORED
  424.  
  425. static id; id = pev(entity, pev_owner)
  426.  
  427. if(equal(model, WEAPON_OLDWMODEL))
  428. {
  429. static weapon
  430. weapon = fm_find_ent_by_owner(-1, weapon_bow, entity)
  431.  
  432. if(!pev_valid(weapon))
  433. return FMRES_IGNORED
  434.  
  435. if(Get_BitVar(g_Had_CompoundBow, id))
  436. {
  437. set_pev(weapon, pev_impulse, WEAPON_SECRETCODE)
  438. set_pev(weapon, pev_iuser1, g_BowArrow[id])
  439.  
  440. engfunc(EngFunc_SetModel, entity, W_MODEL)
  441. Remove_CompoundBow(id)
  442.  
  443. return FMRES_SUPERCEDE
  444. }
  445. }
  446.  
  447. return FMRES_IGNORED
  448. }
  449.  
  450.  
  451. public fw_EmitSound(id, channel, const sample[], Float:volume, Float:attn, flags, pitch)
  452. {
  453. if(!is_user_connected(id))
  454. return FMRES_IGNORED
  455. if(!Get_BitVar(g_InTempingAttack, id))
  456. return FMRES_IGNORED
  457.  
  458. if(sample[8] == 'k' && sample[9] == 'n' && sample[10] == 'i')
  459. {
  460. if(sample[14] == 's' && sample[15] == 'l' && sample[16] == 'a')
  461. return FMRES_SUPERCEDE
  462. if (sample[14] == 'h' && sample[15] == 'i' && sample[16] == 't')
  463. {
  464. if (sample[17] == 'w') return FMRES_SUPERCEDE
  465. else return FMRES_SUPERCEDE
  466. }
  467. if (sample[14] == 's' && sample[15] == 't' && sample[16] == 'a')
  468. return FMRES_SUPERCEDE;
  469. }
  470.  
  471. return FMRES_IGNORED
  472. }
  473.  
  474. public fw_TraceLine(Float:vector_start[3], Float:vector_end[3], ignored_monster, id, handle)
  475. {
  476. if(!is_user_alive(id))
  477. return FMRES_IGNORED
  478. if(!Get_BitVar(g_InTempingAttack, id))
  479. return FMRES_IGNORED
  480.  
  481. static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
  482.  
  483. pev(id, pev_origin, fOrigin)
  484. pev(id, pev_view_ofs, view_ofs)
  485. xs_vec_add(fOrigin, view_ofs, vecStart)
  486. pev(id, pev_v_angle, v_angle)
  487.  
  488. engfunc(EngFunc_MakeVectors, v_angle)
  489. get_global_vector(GL_v_forward, v_forward)
  490.  
  491. xs_vec_mul_scalar(v_forward, 0.0, v_forward)
  492. xs_vec_add(vecStart, v_forward, vecEnd)
  493.  
  494. engfunc(EngFunc_TraceLine, vecStart, vecEnd, ignored_monster, id, handle)
  495.  
  496. return FMRES_SUPERCEDE
  497. }
  498.  
  499. public fw_TraceHull(Float:vector_start[3], Float:vector_end[3], ignored_monster, hull, id, handle)
  500. {
  501. if(!is_user_alive(id))
  502. return FMRES_IGNORED
  503. if(!Get_BitVar(g_InTempingAttack, id))
  504. return FMRES_IGNORED
  505.  
  506. static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
  507.  
  508. pev(id, pev_origin, fOrigin)
  509. pev(id, pev_view_ofs, view_ofs)
  510. xs_vec_add(fOrigin, view_ofs, vecStart)
  511. pev(id, pev_v_angle, v_angle)
  512.  
  513. engfunc(EngFunc_MakeVectors, v_angle)
  514. get_global_vector(GL_v_forward, v_forward)
  515.  
  516. xs_vec_mul_scalar(v_forward, 0.0, v_forward)
  517. xs_vec_add(vecStart, v_forward, vecEnd)
  518.  
  519. engfunc(EngFunc_TraceHull, vecStart, vecEnd, ignored_monster, hull, id, handle)
  520.  
  521. return FMRES_SUPERCEDE
  522. }
  523.  
  524. public Bow_NormalAttackHandle(id, UnCharge)
  525. {
  526. if(get_pdata_float(id, 83, 5) > 0.0)
  527. return
  528. if(!g_BowArrow[id])
  529. {
  530. set_pdata_float(id, 83, 1.0, 5)
  531. Set_Weapon_Anim(id, BOW_ANIM_IDLE_EMPTY)
  532.  
  533. return
  534. }
  535.  
  536. g_BowArrow[id]--
  537. UpdateAmmo(id, CSW_BOW, BOW_AMMOID, -1, g_BowArrow[id])
  538.  
  539. Create_FakeAttack(id)
  540.  
  541. Set_Weapon_Anim(id, UnCharge ? BOW_ANIM_CHARGE_SHOOT1 : BOW_ANIM_SHOOT1)
  542. emit_sound(id, CHAN_WEAPON, WeaponSounds[UnCharge ? 1 : 0], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  543.  
  544. Create_ArrowA(id)
  545. Make_Push(id)
  546.  
  547. Set_Player_NextAttack(id, UnCharge ? TIME_RELOADB : TIME_RELOADA)
  548. Set_Weapon_TimeIdle(id, CSW_BOW, UnCharge ? TIME_RELOADB : TIME_RELOADA)
  549.  
  550. g_WeaponState[id] = WEAPON_NONE
  551. }
  552.  
  553. public Bow_ChargeAttackHandle(id)
  554. {
  555. if(!g_BowArrow[id])
  556. {
  557. set_pdata_float(id, 83, 1.0, 5)
  558. Set_Weapon_Anim(id, BOW_ANIM_IDLE_EMPTY)
  559.  
  560. return
  561. }
  562.  
  563. g_BowArrow[id]--
  564. UpdateAmmo(id, CSW_BOW, BOW_AMMOID, -1, g_BowArrow[id])
  565.  
  566. Create_FakeAttack(id)
  567.  
  568. Set_Weapon_Anim(id, BOW_ANIM_CHARGE_SHOOT2)
  569. emit_sound(id, CHAN_WEAPON, WeaponSounds[2], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  570.  
  571. ChargedShoot(id)
  572. Make_Push(id)
  573.  
  574. Set_Player_NextAttack(id, TIME_RELOADB)
  575. Set_Weapon_TimeIdle(id, CSW_BOW, TIME_RELOADB)
  576.  
  577. g_WeaponState[id] = WEAPON_NONE
  578. }
  579.  
  580. public ChargedShoot(id)
  581. {
  582. static Float:StartOrigin[3], Float:EndOrigin[3], Float:EndOrigin2[3]
  583.  
  584. Get_Position(id, 40.0, 0.0, 0.0, StartOrigin)
  585. Get_Position(id, 4096.0, 0.0, 0.0, EndOrigin)
  586.  
  587. static TrResult; TrResult = create_tr2()
  588. engfunc(EngFunc_TraceLine, StartOrigin, EndOrigin, IGNORE_MONSTERS, id, TrResult)
  589. get_tr2(TrResult, TR_vecEndPos, EndOrigin2)
  590. free_tr2(TrResult)
  591.  
  592. message_begin(MSG_BROADCAST ,SVC_TEMPENTITY)
  593. write_byte(TE_BEAMPOINTS)
  594. engfunc(EngFunc_WriteCoord, StartOrigin[0])
  595. engfunc(EngFunc_WriteCoord, StartOrigin[1])
  596. engfunc(EngFunc_WriteCoord, StartOrigin[2])
  597. engfunc(EngFunc_WriteCoord, EndOrigin2[0])
  598. engfunc(EngFunc_WriteCoord, EndOrigin2[1])
  599. engfunc(EngFunc_WriteCoord, EndOrigin2[2])
  600. write_short(g_SprId_LaserBeam) // sprite index
  601. write_byte(0) // starting frame
  602. write_byte(0) // frame rate in 0.1's
  603. write_byte(20) // life in 0.1's
  604. write_byte(10) // line width in 0.1's
  605. write_byte(0) // noise amplitude in 0.01's
  606. write_byte(255) // Red
  607. write_byte(127) // Green
  608. write_byte(127) // Blue
  609. write_byte(127) // brightness
  610. write_byte(0) // scroll speed in 0.1's
  611. message_end()
  612.  
  613. message_begin(MSG_BROADCAST ,SVC_TEMPENTITY)
  614. write_byte(TE_BEAMPOINTS)
  615. engfunc(EngFunc_WriteCoord, StartOrigin[0])
  616. engfunc(EngFunc_WriteCoord, StartOrigin[1])
  617. engfunc(EngFunc_WriteCoord, StartOrigin[2])
  618. engfunc(EngFunc_WriteCoord, EndOrigin2[0])
  619. engfunc(EngFunc_WriteCoord, EndOrigin2[1])
  620. engfunc(EngFunc_WriteCoord, EndOrigin2[2])
  621. write_short(g_SprId_LaserBeam) // sprite index
  622. write_byte(0) // starting frame
  623. write_byte(0) // frame rate in 0.1's
  624. write_byte(20) // life in 0.1's
  625. write_byte(10) // line width in 0.1's
  626. write_byte(0) // noise amplitude in 0.01's
  627. write_byte(255) // Red
  628. write_byte(255) // Green
  629. write_byte(255) // Blue
  630. write_byte(127) // brightness
  631. write_byte(0) // scroll speed in 0.1's
  632. message_end()
  633.  
  634. ChargedDamage(id, StartOrigin, EndOrigin2)
  635. }
  636.  
  637. public ChargedDamage(id, Float:Start[3], Float:End[3])
  638. {
  639. static TrResult; TrResult = create_tr2()
  640.  
  641. // Trace First Time
  642. engfunc(EngFunc_TraceLine, Start, End, DONT_IGNORE_MONSTERS, id, TrResult)
  643. static pHit1; pHit1 = get_tr2(TrResult, TR_pHit)
  644. static Float:End1[3]; get_tr2(TrResult, TR_vecEndPos, End1)
  645.  
  646. if(is_user_alive(pHit1))
  647. {
  648. do_attack(id, pHit1, 0, float(DAMAGE_B) * 1.5)
  649. engfunc(EngFunc_TraceLine, End1, End, DONT_IGNORE_MONSTERS, pHit1, TrResult)
  650. } else engfunc(EngFunc_TraceLine, End1, End, DONT_IGNORE_MONSTERS, -1, TrResult)
  651.  
  652. // Trace Second Time
  653. static pHit2; pHit2 = get_tr2(TrResult, TR_pHit)
  654. static Float:End2[3]; get_tr2(TrResult, TR_vecEndPos, End2)
  655.  
  656. if(is_user_alive(pHit2))
  657. {
  658. do_attack(id, pHit2, 0, float(DAMAGE_B) * 1.5)
  659. engfunc(EngFunc_TraceLine, End2, End, DONT_IGNORE_MONSTERS, pHit2, TrResult)
  660. } else engfunc(EngFunc_TraceLine, End2, End, DONT_IGNORE_MONSTERS, -1, TrResult)
  661.  
  662. // Trace Third Time
  663. static pHit3; pHit3 = get_tr2(TrResult, TR_pHit)
  664. static Float:End3[3]; get_tr2(TrResult, TR_vecEndPos, End3)
  665.  
  666. if(is_user_alive(pHit3))
  667. {
  668. do_attack(id, pHit3, 0, float(DAMAGE_B) * 1.5)
  669. engfunc(EngFunc_TraceLine, End3, End, DONT_IGNORE_MONSTERS, pHit3, TrResult)
  670. } else engfunc(EngFunc_TraceLine, End3, End, DONT_IGNORE_MONSTERS, -1, TrResult)
  671.  
  672. // Trace Fourth Time
  673. static pHit4; pHit4 = get_tr2(TrResult, TR_pHit)
  674. if(is_user_alive(pHit4)) do_attack(id, pHit4, 0, float(DAMAGE_B) * 1.5)
  675.  
  676. free_tr2(TrResult)
  677. }
  678.  
  679. public Create_ArrowA(id)
  680. {
  681. static Float:StartOrigin[3], Float:EndOrigin[3], Float:Angles[3]
  682.  
  683. Get_Position(id, 40.0, 0.0, 0.0, StartOrigin)
  684. Get_Position(id, 4096.0, 0.0, 0.0, EndOrigin)
  685. pev(id, pev_v_angle, Angles)
  686.  
  687. Angles[0] *= -1
  688.  
  689. static Arrow; Arrow = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_sprite"))
  690. if(!pev_valid(Arrow)) return
  691.  
  692. set_pev(Arrow, pev_movetype, MOVETYPE_FLY)
  693. set_pev(Arrow, pev_iuser1, id) // Better than pev_owner
  694. set_pev(Arrow, pev_iuser2, Get_SpecialTeam(id, cs_get_user_team(id)))
  695. set_pev(Arrow, pev_iuser3, 0)
  696. set_pev(Arrow, pev_iuser4, 0)
  697.  
  698. entity_set_string(Arrow, EV_SZ_classname, ARROW_CLASSNAME)
  699. engfunc(EngFunc_SetModel, Arrow, ARROW_MODEl)
  700. set_pev(Arrow, pev_mins, Float:{-1.0, -1.0, -1.0})
  701. set_pev(Arrow, pev_maxs, Float:{1.0, 1.0, 1.0})
  702. set_pev(Arrow, pev_origin, StartOrigin)
  703. set_pev(Arrow, pev_angles, Angles)
  704. set_pev(Arrow, pev_gravity, 0.01)
  705. set_pev(Arrow, pev_solid, SOLID_BBOX)
  706.  
  707. set_pev(Arrow, pev_nextthink, get_gametime() + 0.1)
  708.  
  709. static Float:Velocity[3]
  710. get_speed_vector(StartOrigin, EndOrigin, ARROW_SPEED, Velocity)
  711. set_pev(Arrow, pev_velocity, Velocity)
  712. }
  713.  
  714. public Create_FakeAttack(id)
  715. {
  716. static Ent; Ent = fm_get_user_weapon_entity(id, CSW_KNIFE)
  717. if(!pev_valid(Ent)) return
  718.  
  719. Set_BitVar(g_InTempingAttack, id)
  720. ExecuteHamB(Ham_Weapon_PrimaryAttack, Ent)
  721.  
  722. // Set Real Attack Anim
  723. static iAnimDesired, szAnimation[64]
  724.  
  725. formatex(szAnimation, charsmax(szAnimation), (pev(id, pev_flags) & FL_DUCKING) ? "crouch_shoot_%s" : "ref_shoot_%s", WEAPON_ANIMEXT)
  726. if((iAnimDesired = lookup_sequence(id, szAnimation)) == -1)
  727. iAnimDesired = 0
  728.  
  729. set_pev(id, pev_sequence, iAnimDesired)
  730. UnSet_BitVar(g_InTempingAttack, id)
  731. }
  732.  
  733. public Make_Push(id)
  734. {
  735. static Float:VirtualVec[3]
  736. VirtualVec[0] = random_float(-1.0, -2.0)
  737. VirtualVec[1] = random_float(1.0, -1.0)
  738. VirtualVec[2] = 0.0
  739.  
  740. set_pev(id, pev_punchangle, VirtualVec)
  741. }
  742.  
  743. public fw_Item_AddToPlayer_Post(Ent, Id)
  744. {
  745. if(pev(Ent, pev_impulse) == WEAPON_SECRETCODE)
  746. {
  747. Set_BitVar(g_Had_CompoundBow, Id)
  748.  
  749. g_BowArrow[Id] = pev(Ent, pev_iuser1)
  750. UpdateAmmo(Id, CSW_BOW, BOW_AMMOID, -1, g_BowArrow[Id])
  751.  
  752. set_pev(Ent, pev_impulse, 0)
  753. }
  754.  
  755. g_WeaponState[Id] = WEAPON_NONE
  756.  
  757. message_begin(MSG_ONE_UNRELIABLE, g_MsgWeaponList, _, Id)
  758. write_string((Get_BitVar(g_Had_CompoundBow, Id) ? WL_NAME : weapon_bow))
  759. write_byte(WL_PRIAMMOID)
  760. write_byte(WL_PRIAMMOMAX)
  761. write_byte(WL_SECAMMOID)
  762. write_byte(WL_SECAMMOIDMAX)
  763. write_byte(WL_SLOTID)
  764. write_byte(WL_NUMINSLOT)
  765. write_byte(CSW_BOW)
  766. write_byte(WL_FLAG)
  767. message_end()
  768. }
  769.  
  770. public fw_Item_Deploy_Post(Ent)
  771. {
  772. if(!pev_valid(Ent))
  773. return
  774.  
  775. static Id; Id = get_pdata_cbase(Ent, 41, 4)
  776. if(!Get_BitVar(g_Had_CompoundBow, Id))
  777. return
  778.  
  779. set_pev(Id, pev_viewmodel2, V_MODEL)
  780. set_pev(Id, pev_weaponmodel2, g_BowArrow[Id] ? P_MODEL : P_MODEL_EMPTY)
  781.  
  782. set_pdata_string(Id, (492) * 4, WEAPON_ANIMEXT, -1 , 20)
  783.  
  784. Set_Weapon_TimeIdle(Id, CSW_BOW, TIME_DRAW)
  785. Set_Player_NextAttack(Id, TIME_DRAW)
  786.  
  787. Set_Weapon_Anim(Id, g_BowArrow[Id] ? BOW_ANIM_DRAW : BOW_ANIM_DRAW_EMPTY)
  788. }
  789.  
  790. public fw_Weapon_WeaponIdle_Post(Ent)
  791. {
  792. if(!pev_valid(Ent))
  793. return
  794.  
  795. static Id; Id = get_pdata_cbase(Ent, 41, 4)
  796. if(!Get_BitVar(g_Had_CompoundBow, Id))
  797. return
  798.  
  799. if(get_pdata_float(Ent, 48, 4) <= 0.1)
  800. {
  801. Set_Weapon_Anim(Id, g_BowArrow[Id] ? BOW_ANIM_IDLE : BOW_ANIM_IDLE_EMPTY)
  802. set_pdata_float(Ent, 48, 20.0, 4)
  803. }
  804.  
  805. return
  806. }
  807.  
  808. public Get_SpecialTeam(Ent, CsTeams:Team)
  809. {
  810. if(Team == CS_TEAM_T) return TEAM_T
  811. else if(Team == CS_TEAM_CT) return TEAM_CT
  812.  
  813. return 0
  814. }
  815.  
  816. public CsTeams:Get_ArrowTeam(Ent)
  817. {
  818. if(pev(Ent, pev_iuser2) == TEAM_T) return CS_TEAM_T
  819. else if(pev(Ent, pev_iuser2) == TEAM_CT) return CS_TEAM_CT
  820.  
  821. return CS_TEAM_UNASSIGNED
  822. }
  823.  
  824. stock MakeBulletDecal(Float:Origin[3])
  825. {
  826. // Find target
  827. static decal; decal = random_num(41, 45)
  828.  
  829. // Put decal on "world" (a wall)
  830. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  831. write_byte(TE_WORLDDECAL)
  832. engfunc(EngFunc_WriteCoord, Origin[0])
  833. engfunc(EngFunc_WriteCoord, Origin[1])
  834. engfunc(EngFunc_WriteCoord, Origin[2])
  835. write_byte(decal)
  836. message_end()
  837. }
  838.  
  839. stock Set_Weapon_Anim(id, WeaponAnim)
  840. {
  841. set_pev(id, pev_weaponanim, WeaponAnim)
  842.  
  843. message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
  844. write_byte(WeaponAnim)
  845. write_byte(pev(id, pev_body))
  846. message_end()
  847. }
  848.  
  849. stock Set_Weapon_TimeIdle(id, WeaponId ,Float:TimeIdle)
  850. {
  851. static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
  852. if(!pev_valid(entwpn))
  853. return
  854.  
  855. set_pdata_float(entwpn, 46, TimeIdle, 4)
  856. set_pdata_float(entwpn, 47, TimeIdle, 4)
  857. set_pdata_float(entwpn, 48, TimeIdle + 0.5, 4)
  858. }
  859.  
  860. stock Set_Player_NextAttack(id, Float:nexttime)
  861. {
  862. set_pdata_float(id, 83, nexttime, 5)
  863. }
  864.  
  865. stock Get_Position(id,Float:forw, Float:right, Float:up, Float:vStart[])
  866. {
  867. static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
  868.  
  869. pev(id, pev_origin, vOrigin)
  870. pev(id, pev_view_ofs,vUp) //for player
  871. xs_vec_add(vOrigin,vUp,vOrigin)
  872. pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
  873.  
  874. angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
  875. angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
  876. angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
  877.  
  878. vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
  879. vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
  880. vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
  881. }
  882.  
  883. stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
  884. {
  885. new_velocity[0] = origin2[0] - origin1[0]
  886. new_velocity[1] = origin2[1] - origin1[1]
  887. new_velocity[2] = origin2[2] - origin1[2]
  888. static Float:num; num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
  889. new_velocity[0] *= num
  890. new_velocity[1] *= num
  891. new_velocity[2] *= num
  892.  
  893. return 1;
  894. }
  895.  
  896. do_attack(Attacker, Victim, Inflictor, Float:fDamage)
  897. {
  898. fake_player_trace_attack(Attacker, Victim, fDamage)
  899. fake_take_damage(Attacker, Victim, fDamage, Inflictor)
  900. }
  901.  
  902. fake_player_trace_attack(iAttacker, iVictim, &Float:fDamage)
  903. {
  904. // get fDirection
  905. static Float:fAngles[3], Float:fDirection[3]
  906. pev(iAttacker, pev_angles, fAngles)
  907. angle_vector(fAngles, ANGLEVECTOR_FORWARD, fDirection)
  908.  
  909. // get fStart
  910. static Float:fStart[3], Float:fViewOfs[3]
  911. pev(iAttacker, pev_origin, fStart)
  912. pev(iAttacker, pev_view_ofs, fViewOfs)
  913. xs_vec_add(fViewOfs, fStart, fStart)
  914.  
  915. // get aimOrigin
  916. static iAimOrigin[3], Float:fAimOrigin[3]
  917. get_user_origin(iAttacker, iAimOrigin, 3)
  918. IVecFVec(iAimOrigin, fAimOrigin)
  919.  
  920. // TraceLine from fStart to AimOrigin
  921. static pentru; pentru = create_tr2()
  922. engfunc(EngFunc_TraceLine, fStart, fAimOrigin, DONT_IGNORE_MONSTERS, iAttacker, pentru)
  923. static pHit; pHit = get_tr2(pentru, TR_pHit)
  924. static iHitgroup; iHitgroup = get_tr2(pentru, TR_iHitgroup)
  925. static Float:fEndPos[3]
  926. get_tr2(pentru, TR_vecEndPos, fEndPos)
  927.  
  928. // get target & body at aiming
  929. static iTarget, iBody
  930. get_user_aiming(iAttacker, iTarget, iBody)
  931.  
  932. // if aiming find target is iVictim then update iHitgroup
  933. if (iTarget == iVictim)
  934. {
  935. iHitgroup = iBody
  936. }
  937.  
  938. // if pentru find target not is iVictim
  939. else if (pHit != iVictim)
  940. {
  941. // get AimOrigin in iVictim
  942. static Float:fVicOrigin[3], Float:fVicViewOfs[3], Float:fAimInVictim[3]
  943. pev(iVictim, pev_origin, fVicOrigin)
  944. pev(iVictim, pev_view_ofs, fVicViewOfs)
  945. xs_vec_add(fVicViewOfs, fVicOrigin, fAimInVictim)
  946. fAimInVictim[2] = fStart[2]
  947. fAimInVictim[2] += get_distance_f(fStart, fAimInVictim) * floattan( fAngles[0] * 2.0, degrees )
  948.  
  949. // check aim in size of iVictim
  950. static iAngleToVictim; iAngleToVictim = get_angle_to_target(iAttacker, fVicOrigin)
  951. iAngleToVictim = abs(iAngleToVictim)
  952. static Float:fDis; fDis = 2.0 * get_distance_f(fStart, fAimInVictim) * floatsin( float(iAngleToVictim) * 0.5, degrees )
  953. static Float:fVicSize[3]
  954. pev(iVictim, pev_size , fVicSize)
  955. if ( fDis <= fVicSize[0] * 0.5 )
  956. {
  957. // TraceLine from fStart to aimOrigin in iVictim
  958. static ptr2; ptr2 = create_tr2()
  959. engfunc(EngFunc_TraceLine, fStart, fAimInVictim, DONT_IGNORE_MONSTERS, iAttacker, ptr2)
  960. static pHit2; pHit2 = get_tr2(ptr2, TR_pHit)
  961. static iHitgroup2; iHitgroup2 = get_tr2(ptr2, TR_iHitgroup)
  962.  
  963. // if ptr2 find target is iVictim
  964. if ( pHit2 == iVictim && (iHitgroup2 != HIT_HEAD || fDis <= fVicSize[0] * 0.25) )
  965. {
  966. pHit = iVictim
  967. iHitgroup = iHitgroup2
  968. get_tr2(ptr2, TR_vecEndPos, fEndPos)
  969. }
  970.  
  971. free_tr2(ptr2)
  972. }
  973.  
  974. // if pHit still not is iVictim then set default HitGroup
  975. if (pHit != iVictim)
  976. {
  977. // set default iHitgroup
  978. iHitgroup = HIT_GENERIC
  979.  
  980. static ptr3; ptr3 = create_tr2()
  981. engfunc(EngFunc_TraceLine, fStart, fVicOrigin, DONT_IGNORE_MONSTERS, iAttacker, ptr3)
  982. get_tr2(ptr3, TR_vecEndPos, fEndPos)
  983.  
  984. // free ptr3
  985. free_tr2(ptr3)
  986. }
  987. }
  988.  
  989. // set new Hit & Hitgroup & EndPos
  990. set_tr2(pentru, TR_pHit, iVictim)
  991. set_tr2(pentru, TR_iHitgroup, iHitgroup)
  992. set_tr2(pentru, TR_vecEndPos, fEndPos)
  993.  
  994. // ExecuteHam
  995. fake_trake_attack(iAttacker, iVictim, fDamage, fDirection, pentru)
  996.  
  997. // free pentru
  998. free_tr2(pentru)
  999. }
  1000.  
  1001. stock fake_trake_attack(iAttacker, iVictim, Float:fDamage, Float:fDirection[3], iTraceHandle, iDamageBit = (DMG_NEVERGIB | DMG_BULLET))
  1002. {
  1003. ExecuteHamB(Ham_TraceAttack, iVictim, iAttacker, fDamage, fDirection, iTraceHandle, iDamageBit)
  1004. }
  1005.  
  1006. stock fake_take_damage(iAttacker, iVictim, Float:fDamage, iInflictor, iDamageBit = (DMG_NEVERGIB | DMG_BULLET))
  1007. {
  1008. ExecuteHamB(Ham_TakeDamage, iVictim, iInflictor, iAttacker, fDamage, iDamageBit)
  1009. }
  1010.  
  1011. stock get_angle_to_target(id, const Float:fTarget[3], Float:TargetSize = 0.0)
  1012. {
  1013. static Float:fOrigin[3], iAimOrigin[3], Float:fAimOrigin[3], Float:fV1[3]
  1014. pev(id, pev_origin, fOrigin)
  1015. get_user_origin(id, iAimOrigin, 3) // end position from eyes
  1016. IVecFVec(iAimOrigin, fAimOrigin)
  1017. xs_vec_sub(fAimOrigin, fOrigin, fV1)
  1018.  
  1019. static Float:fV2[3]
  1020. xs_vec_sub(fTarget, fOrigin, fV2)
  1021.  
  1022. static iResult; iResult = get_angle_between_vectors(fV1, fV2)
  1023.  
  1024. if (TargetSize > 0.0)
  1025. {
  1026. static Float:fTan; fTan = TargetSize / get_distance_f(fOrigin, fTarget)
  1027. static fAngleToTargetSize; fAngleToTargetSize = floatround( floatatan(fTan, degrees) )
  1028. iResult -= (iResult > 0) ? fAngleToTargetSize : -fAngleToTargetSize
  1029. }
  1030.  
  1031. return iResult
  1032. }
  1033.  
  1034. stock get_angle_between_vectors(const Float:fV1[3], const Float:fV2[3])
  1035. {
  1036. static Float:fA1[3], Float:fA2[3]
  1037. engfunc(EngFunc_VecToAngles, fV1, fA1)
  1038. engfunc(EngFunc_VecToAngles, fV2, fA2)
  1039.  
  1040. static iResult; iResult = floatround(fA1[1] - fA2[1])
  1041. iResult = iResult % 360
  1042. iResult = (iResult > 180) ? (iResult - 360) : iResult
  1043.  
  1044. return iResult
  1045. }
  1046.