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 "Balrog-XI"
  9. #define VERSION "2.0"
  10. #define AUTHOR "Dias"
  11.  
  12. #define V_MODEL "models/v_balrog11_2.mdl"
  13. #define P_MODEL "models/p_balrog11.mdl"
  14. #define W_MODEL "models/w_balrog11.mdl"
  15.  
  16. #define CSW_BALROG11 CSW_XM1014
  17. #define weapon_balrog11 "weapon_xm1014"
  18.  
  19. #define OLD_W_MODEL "models/w_xm1014.mdl"
  20. #define OLD_EVENT "events/xm1014.sc"
  21. #define WEAPON_SECRETCODE 1982
  22.  
  23. #define DRAW_TIME 1.0
  24. #define DAMAGE 52
  25. #define FIRE_DAMAGE 500
  26. #define BPAMMO 56
  27.  
  28. #define CHARGE_COND_AMMO 4
  29. #define MAX_SPECIAL_AMMO 7
  30. #define SPECIALSHOOT_DELAY 0.35
  31. #define FIRE_SPEED 750
  32. #define FIRE_CLASSNAME "balrog11_fire"
  33. #define SYSTEM_CLASSNAME "balrog11_firesystem"
  34.  
  35. // OFFSET
  36. const PDATA_SAFE = 2
  37. const OFFSET_LINUX_WEAPONS = 4
  38. const OFFSET_WEAPONOWNER = 41
  39. const m_flNextAttack = 83
  40. const m_flNextPrimaryAttack = 46
  41. const m_flNextSecondaryAttack = 47
  42.  
  43. // Weapon bitsums
  44. const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90)
  45. const SECONDARY_WEAPONS_BIT_SUM = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)
  46.  
  47. new const WeaponSounds[5][] =
  48. {
  49. "weapons/balrog11-1.wav",
  50. "weapons/balrog11-2.wav",
  51. "weapons/balrog11_draw.wav",
  52. "weapons/balrog11_insert.wav",
  53. "weapons/balrog11_charge.wav"
  54. }
  55.  
  56. new const WeaponResources[4][] =
  57. {
  58. "sprites/flame_puff01.spr",
  59. "sprites/weapon_balrog11.txt",
  60. "sprites/640hud3_2.spr",
  61. "sprites/640hud89_2.spr"
  62. }
  63.  
  64. enum
  65. {
  66. B11_ANIM_IDLE = 0,
  67. B11_ANIM_SHOOT,
  68. B11_ANIM_SHOOT_SPECIAL,
  69. B11_ANIM_INSERT,
  70. B11_ANIM_AFTER_RELOAD,
  71. B11_ANIM_START_RELOAD,
  72. B11_ANIM_DRAW
  73. }
  74.  
  75. new g_balrog11
  76. new g_had_balrog11[33], g_holding_attack[33], g_Shoot_Count[33], g_SpecialAmmo[33]
  77. new g_old_weapon[33], g_event_balrog11, g_Msg_StatusIcon, g_smokepuff_id, g_ham_bot, g_MaxPlayers
  78.  
  79. public plugin_init()
  80. {
  81. register_plugin(PLUGIN, VERSION, AUTHOR)
  82.  
  83. register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
  84.  
  85. register_forward(FM_Think, "fw_Think")
  86. register_forward(FM_Touch, "fw_Touch")
  87. register_forward(FM_CmdStart, "fw_CmdStart")
  88. register_forward(FM_SetModel, "fw_SetModel")
  89. register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
  90. register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
  91.  
  92. RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack")
  93. RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack")
  94.  
  95. RegisterHam(Ham_Item_AddToPlayer, weapon_balrog11, "fw_Item_AddToPlayer_Post", 1)
  96. RegisterHam(Ham_Item_PostFrame, weapon_balrog11, "fw_Item_PostFrame")
  97. RegisterHam(Ham_Item_Deploy, weapon_balrog11, "fw_Item_Deploy_Post", 1)
  98.  
  99. g_Msg_StatusIcon = get_user_msgid("StatusIcon")
  100. g_MaxPlayers = get_maxplayers()
  101.  
  102. //register_clcmd("admin_get_balrog11", "Get_Balrog11", ADMIN_BAN)
  103. register_clcmd("weapon_balrog11", "hook_weapon")
  104. }
  105.  
  106. public plugin_precache()
  107. {
  108. engfunc(EngFunc_PrecacheModel, V_MODEL)
  109. engfunc(EngFunc_PrecacheModel, P_MODEL)
  110. engfunc(EngFunc_PrecacheModel, W_MODEL)
  111.  
  112. new i
  113. for(i = 0; i < sizeof(WeaponSounds); i++)
  114. engfunc(EngFunc_PrecacheSound, WeaponSounds[i])
  115. for(i = 0; i < sizeof(WeaponResources); i++)
  116. {
  117. if(i == 1) engfunc(EngFunc_PrecacheGeneric, WeaponResources[i])
  118. else engfunc(EngFunc_PrecacheModel, WeaponResources[i])
  119. }
  120.  
  121. register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
  122. g_smokepuff_id = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
  123.  
  124. g_balrog11 = zp_register_extra_item("Balrog-XI", 25, ZP_TEAM_HUMAN)
  125. }
  126.  
  127. public client_putinserver(id)
  128. {
  129. if(!g_ham_bot && is_user_bot(id))
  130. {
  131. g_ham_bot = 1
  132. set_task(0.1, "do_register", id)
  133. }
  134. }
  135.  
  136. public do_register(id)
  137. {
  138. RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack")
  139. }
  140.  
  141. public fw_PrecacheEvent_Post(type, const name[])
  142. {
  143. if(equal(OLD_EVENT, name))
  144. g_event_balrog11 = get_orig_retval()
  145. }
  146.  
  147. public zp_extra_item_selected(id, itemid)
  148. {
  149. if(itemid == g_balrog11) Get_Balrog11(id)
  150. }
  151.  
  152. public zp_user_infected_post(id) Remove_Balrog11(id)
  153. public zp_round_ended()
  154. {
  155. for(new i = 0; i < g_MaxPlayers; i++)
  156. Remove_Balrog11(i)
  157. }
  158.  
  159. public Get_Balrog11(id)
  160. {
  161. if(!is_user_alive(id))
  162. return
  163.  
  164. drop_weapons(id, 1)
  165. Remove_Balrog11(id)
  166.  
  167. g_had_balrog11[id] = 1
  168. g_old_weapon[id] = 0
  169. g_holding_attack[id] = 0
  170. g_Shoot_Count[id] = 0
  171. g_SpecialAmmo[id] = 0
  172.  
  173. fm_give_item(id, weapon_balrog11)
  174. cs_set_user_bpammo(id, CSW_BALROG11, BPAMMO)
  175.  
  176. update_ammo(id)
  177. update_specialammo(id, g_SpecialAmmo[id], g_SpecialAmmo[id] > 0 ? 1 : 0)
  178. }
  179.  
  180. public Remove_Balrog11(id)
  181. {
  182. if(!is_user_connected(id))
  183. return
  184.  
  185. update_specialammo(id, g_SpecialAmmo[id], 0)
  186.  
  187. g_had_balrog11[id] = 0
  188. g_old_weapon[id] = 0
  189. g_holding_attack[id] = 0
  190. g_Shoot_Count[id] = 0
  191. g_SpecialAmmo[id] = 0
  192. }
  193.  
  194. public hook_weapon(id)
  195. {
  196. engclient_cmd(id, weapon_balrog11)
  197. return PLUGIN_HANDLED
  198. }
  199.  
  200. public Event_CurWeapon(id)
  201. {
  202. if(!is_user_alive(id))
  203. return
  204.  
  205. if(g_had_balrog11[id] && (get_user_weapon(id) == CSW_BALROG11 && g_old_weapon[id] != CSW_BALROG11))
  206. { // Balrog Draw
  207. set_weapon_anim(id, B11_ANIM_DRAW)
  208. set_player_nextattack(id, DRAW_TIME)
  209.  
  210. update_specialammo(id, g_SpecialAmmo[id], g_SpecialAmmo[id] > 0 ? 1 : 0)
  211. } else if(get_user_weapon(id) != CSW_BALROG11 && g_old_weapon[id] == CSW_BALROG11) {
  212. update_specialammo(id, g_SpecialAmmo[id], 0)
  213. }
  214.  
  215. g_old_weapon[id] = get_user_weapon(id)
  216. }
  217.  
  218. public fw_CmdStart(id, uc_handle, seed)
  219. {
  220. if(!is_user_alive(id))
  221. return
  222. if(get_user_weapon(id) != CSW_BALROG11 || !g_had_balrog11[id])
  223. return
  224.  
  225. static NewButton; NewButton = get_uc(uc_handle, UC_Buttons)
  226. static OldButton; OldButton = pev(id, pev_oldbuttons)
  227.  
  228. if(NewButton & IN_ATTACK)
  229. {
  230. if(!g_holding_attack[id]) g_holding_attack[id] = 1
  231. } else if(NewButton & IN_ATTACK2) {
  232. SpecialShoot_Handle(id)
  233. } else {
  234. if(OldButton & IN_ATTACK)
  235. {
  236. if(g_holding_attack[id])
  237. {
  238. g_holding_attack[id] = 0
  239. g_Shoot_Count[id] = 0
  240. }
  241. }
  242. }
  243. }
  244.  
  245. public fw_SetModel(entity, model[])
  246. {
  247. if(!pev_valid(entity))
  248. return FMRES_IGNORED
  249.  
  250. static Classname[64]
  251. pev(entity, pev_classname, Classname, sizeof(Classname))
  252.  
  253. if(!equal(Classname, "weaponbox"))
  254. return FMRES_IGNORED
  255.  
  256. static id
  257. id = pev(entity, pev_owner)
  258.  
  259. if(equal(model, OLD_W_MODEL))
  260. {
  261. static weapon
  262. weapon = fm_get_user_weapon_entity(entity, CSW_BALROG11)
  263.  
  264. if(!pev_valid(weapon))
  265. return FMRES_IGNORED
  266.  
  267. if(g_had_balrog11[id])
  268. {
  269. set_pev(weapon, pev_impulse, WEAPON_SECRETCODE)
  270. set_pev(weapon, pev_iuser4, g_SpecialAmmo[id])
  271. engfunc(EngFunc_SetModel, entity, W_MODEL)
  272.  
  273. Remove_Balrog11(id)
  274.  
  275. return FMRES_SUPERCEDE
  276. }
  277. }
  278.  
  279. return FMRES_IGNORED;
  280. }
  281.  
  282. public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
  283. {
  284. if(!is_user_alive(id) || !is_user_connected(id))
  285. return FMRES_IGNORED
  286. if(get_user_weapon(id) == CSW_BALROG11 && g_had_balrog11[id])
  287. set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001)
  288.  
  289. return FMRES_HANDLED
  290. }
  291.  
  292. public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
  293. {
  294. if (!is_user_connected(invoker))
  295. return FMRES_IGNORED
  296. if(get_user_weapon(invoker) == CSW_BALROG11 && g_had_balrog11[invoker] && eventid == g_event_balrog11)
  297. {
  298. engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
  299.  
  300. if(g_holding_attack[invoker]) g_Shoot_Count[invoker]++
  301. else g_Shoot_Count[invoker] = 0
  302.  
  303. if(g_Shoot_Count[invoker] >= CHARGE_COND_AMMO)
  304. {
  305. g_Shoot_Count[invoker] = 0
  306.  
  307. if(g_SpecialAmmo[invoker] < MAX_SPECIAL_AMMO)
  308. {
  309. update_specialammo(invoker, g_SpecialAmmo[invoker], 0)
  310. g_SpecialAmmo[invoker]++
  311. update_specialammo(invoker, g_SpecialAmmo[invoker], 1)
  312.  
  313. emit_sound(invoker, CHAN_ITEM, WeaponSounds[4], 1.0, ATTN_NORM, 0, PITCH_NORM)
  314. }
  315. }
  316.  
  317. set_weapon_anim(invoker, B11_ANIM_SHOOT)
  318. emit_sound(invoker, CHAN_WEAPON, WeaponSounds[0], 1.0, ATTN_NORM, 0, PITCH_NORM)
  319.  
  320. return FMRES_SUPERCEDE
  321. }
  322.  
  323. return FMRES_HANDLED
  324. }
  325.  
  326. public fw_Think(ent)
  327. {
  328. if(!pev_valid(ent))
  329. return
  330.  
  331. static Classname[32]; pev(ent, pev_classname, Classname, sizeof(Classname))
  332. if(equal(Classname, FIRE_CLASSNAME))
  333. {
  334. static Float:fFrame; pev(ent, pev_frame, fFrame)
  335.  
  336. fFrame += 1.5
  337. fFrame = floatmin(21.0, fFrame)
  338.  
  339. set_pev(ent, pev_frame, fFrame)
  340. set_pev(ent, pev_nextthink, get_gametime() + 0.05)
  341.  
  342. // time remove
  343. static Float:fTimeRemove, Float:Amount
  344. pev(ent, pev_fuser1, fTimeRemove)
  345. pev(ent, pev_renderamt, Amount)
  346.  
  347. if(get_gametime() >= fTimeRemove)
  348. {
  349. Amount -= 10.0
  350. set_pev(ent, pev_renderamt, Amount)
  351.  
  352. if(Amount <= 15.0) engfunc(EngFunc_RemoveEntity, ent)
  353. }
  354. } else if(equal(Classname, SYSTEM_CLASSNAME)) {
  355.  
  356. static Float:Origin[3], Float:Scale
  357.  
  358. pev(ent, pev_origin, Origin)
  359. pev(ent, pev_scale, Scale)
  360.  
  361. Scale += 0.1
  362. Scale = floatmin(1.5, Scale)
  363. set_pev(ent, pev_scale, Scale)
  364.  
  365. Create_Fire(pev(ent, pev_owner), Origin, Scale, 0.0)
  366.  
  367. set_pev(ent, pev_nextthink, get_gametime() + 0.05)
  368.  
  369. // time remove
  370. static Float:fTimeRemove
  371. pev(ent, pev_fuser1, fTimeRemove)
  372. if(get_gametime() >= fTimeRemove) engfunc(EngFunc_RemoveEntity, ent)
  373. }
  374. }
  375.  
  376. public fw_Touch(ent, id)
  377. {
  378. if(!pev_valid(ent))
  379. return
  380.  
  381. static Classname[32]
  382. pev(ent, pev_classname, Classname, sizeof(Classname))
  383.  
  384. if(!equal(Classname, SYSTEM_CLASSNAME))
  385. return
  386.  
  387. if(pev_valid(id))
  388. {
  389. static Classname2[32]
  390. pev(id, pev_classname, Classname2, sizeof(Classname2))
  391.  
  392. if(equal(Classname2, SYSTEM_CLASSNAME) || equal(Classname2, FIRE_CLASSNAME)) return
  393. else if(is_user_alive(id))
  394. {
  395. if(pev(ent, pev_iuser3) == 1 && cs_get_user_team(id) != CS_TEAM_T) ExecuteHamB(Ham_TakeDamage, id, 0, pev(ent, pev_owner), float(FIRE_DAMAGE) / random_float(3.0, 5.0), DMG_BULLET)
  396. else if(pev(ent, pev_iuser3) == 2 && cs_get_user_team(id) != CS_TEAM_CT) ExecuteHamB(Ham_TakeDamage, id, 0,pev(ent, pev_owner), float(FIRE_DAMAGE) / random_float(3.0, 5.0), DMG_BULLET)
  397.  
  398. return
  399. }
  400. }
  401.  
  402. set_pev(ent, pev_movetype, MOVETYPE_NONE)
  403. set_pev(ent, pev_solid, SOLID_NOT)
  404. }
  405.  
  406. public fw_TraceAttack(Ent, Attacker, Float:Damage, Float:Dir[3], ptr, DamageType)
  407. {
  408. if(!is_user_alive(Attacker))
  409. return HAM_IGNORED
  410. if(get_user_weapon(Attacker) != CSW_BALROG11 || !g_had_balrog11[Attacker])
  411. return HAM_IGNORED
  412.  
  413. static Float:flEnd[3], Float:vecPlane[3]
  414.  
  415. get_tr2(ptr, TR_vecEndPos, flEnd)
  416. get_tr2(ptr, TR_vecPlaneNormal, vecPlane)
  417.  
  418. if(!is_user_alive(Ent))
  419. {
  420. make_bullet(Attacker, flEnd)
  421. fake_smoke(Attacker, ptr)
  422. }
  423.  
  424. SetHamParamFloat(3, float(DAMAGE) / random_float(1.5, 2.5))
  425.  
  426. return HAM_HANDLED
  427. }
  428.  
  429. public fw_Item_AddToPlayer_Post(ent, id)
  430. {
  431. if(pev(ent, pev_impulse) == WEAPON_SECRETCODE)
  432. {
  433. g_had_balrog11[id] = 1
  434.  
  435. set_pev(ent, pev_impulse, 0)
  436. g_SpecialAmmo[id] = pev(ent, pev_iuser4)
  437. }
  438.  
  439. message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("WeaponList"), _, id)
  440. write_string((g_had_balrog11[id] == 1 ? "weapon_balrog11" : "weapon_xm1014"))
  441. write_byte(5)
  442. write_byte(32)
  443. write_byte(-1)
  444. write_byte(-1)
  445. write_byte(0)
  446. write_byte(12)
  447. write_byte(CSW_BALROG11)
  448. write_byte(0)
  449. message_end()
  450. }
  451.  
  452. public fw_Item_PostFrame(ent)
  453. {
  454. static id; id = fm_cs_get_weapon_ent_owner(ent)
  455. if (!pev_valid(id))
  456. return
  457.  
  458. if(!g_had_balrog11[id])
  459. return
  460.  
  461. if(get_pdata_int(ent, 55, OFFSET_LINUX_WEAPONS) == 1) set_weapon_anim(id, B11_ANIM_INSERT)
  462. }
  463.  
  464. public fw_Item_Deploy_Post(ent)
  465. {
  466. static id; id = fm_cs_get_weapon_ent_owner(ent)
  467. if (!pev_valid(id))
  468. return
  469.  
  470. if(!g_had_balrog11[id])
  471. return
  472.  
  473. set_pev(id, pev_viewmodel2, V_MODEL)
  474. set_pev(id, pev_weaponmodel2, P_MODEL)
  475. }
  476.  
  477. public update_ammo(id)
  478. {
  479. if(!is_user_alive(id))
  480. return
  481.  
  482. static weapon_ent; weapon_ent = fm_get_user_weapon_entity(id, CSW_BALROG11)
  483. if(!pev_valid(weapon_ent)) return
  484.  
  485. engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, get_user_msgid("CurWeapon"), {0, 0, 0}, id)
  486. write_byte(1)
  487. write_byte(CSW_BALROG11)
  488. write_byte(cs_get_weapon_ammo(weapon_ent))
  489. message_end()
  490.  
  491. message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("AmmoX"), _, id)
  492. write_byte(1)
  493. write_byte(cs_get_user_bpammo(id, CSW_BALROG11))
  494. message_end()
  495. }
  496.  
  497. public update_specialammo(id, Ammo, On)
  498. {
  499. static AmmoSprites[33]
  500. format(AmmoSprites, sizeof(AmmoSprites), "number_%d", Ammo)
  501.  
  502. message_begin(MSG_ONE_UNRELIABLE, g_Msg_StatusIcon, {0,0,0}, id)
  503. write_byte(On)
  504. write_string(AmmoSprites)
  505. write_byte(42) // red
  506. write_byte(212) // green
  507. write_byte(255) // blue
  508. message_end()
  509. }
  510.  
  511. public SpecialShoot_Handle(id)
  512. {
  513. if(get_pdata_float(id, 83, 5) > 0.0)
  514. return
  515. if(g_SpecialAmmo[id] <= 0)
  516. return
  517.  
  518. create_fake_attack(id)
  519.  
  520. // Shoot Handle
  521. set_player_nextattack(id, SPECIALSHOOT_DELAY)
  522. set_weapons_timeidle(id, CSW_BALROG11, SPECIALSHOOT_DELAY)
  523.  
  524. update_specialammo(id, g_SpecialAmmo[id], 0)
  525. g_SpecialAmmo[id]--
  526. update_specialammo(id, g_SpecialAmmo[id], g_SpecialAmmo[id] > 0 ? 1 : 0)
  527.  
  528. set_weapon_anim(id, B11_ANIM_SHOOT_SPECIAL)
  529. emit_sound(id, CHAN_WEAPON, WeaponSounds[1], 1.0, ATTN_NORM, 0, PITCH_NORM)
  530.  
  531. Create_FireSystem(id)
  532. }
  533.  
  534. public create_fake_attack(id)
  535. {
  536. static weapon
  537. weapon = fm_find_ent_by_owner(-1, "weapon_knife", id)
  538.  
  539. if(pev_valid(weapon)) ExecuteHamB(Ham_Weapon_PrimaryAttack, weapon)
  540. }
  541.  
  542. public Create_FireSystem(id)
  543. {
  544. static Float:StartOrigin[3], Float:EndOrigin[5][3]
  545. get_weapon_attachment(id, StartOrigin, 40.0)
  546.  
  547. // Left
  548. get_position(id, 512.0, -140.0, 0.0, EndOrigin[0])
  549. get_position(id, 512.0, -70.0, 0.0, EndOrigin[1])
  550.  
  551. // Center
  552. get_position(id, 512.0, 0.0, 0.0, EndOrigin[2])
  553.  
  554. // Right
  555. get_position(id, 512.0, 70.0, 0.0, EndOrigin[3])
  556. get_position(id, 512.0, 140.0, 0.0, EndOrigin[4])
  557.  
  558. // Create Fire
  559. for(new i = 0; i < 5; i++) Create_System(id, StartOrigin, EndOrigin[i], float(FIRE_SPEED))
  560. }
  561.  
  562. public Create_System(id, Float:StartOrigin[3], Float:EndOrigin[3], Float:Speed)
  563. {
  564. static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_sprite"))
  565.  
  566. // set info for ent
  567. set_pev(Ent, pev_movetype, MOVETYPE_FLY)
  568. set_pev(Ent, pev_rendermode, kRenderTransAdd)
  569. set_pev(Ent, pev_renderamt, 0.0)
  570. set_pev(Ent, pev_fuser1, get_gametime() + 0.75) // time remove
  571. set_pev(Ent, pev_scale, 0.1)
  572. set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
  573.  
  574. set_pev(Ent, pev_classname, SYSTEM_CLASSNAME)
  575. engfunc(EngFunc_SetModel, Ent, WeaponResources[0])
  576. set_pev(Ent, pev_mins, Float:{-16.0, -16.0, -16.0})
  577. set_pev(Ent, pev_maxs, Float:{16.0, 16.0, 16.0})
  578. set_pev(Ent, pev_origin, StartOrigin)
  579. set_pev(Ent, pev_gravity, 0.01)
  580. set_pev(Ent, pev_solid, SOLID_TRIGGER)
  581. set_pev(Ent, pev_owner, id)
  582. static Team;
  583. if(cs_get_user_team(id) == CS_TEAM_T) Team = 1
  584. else if(cs_get_user_team(id) == CS_TEAM_CT) Team = 2
  585. set_pev(Ent, pev_iuser3, Team)
  586. set_pev(Ent, pev_frame, 0.0)
  587.  
  588. static Float:Velocity[3]
  589.  
  590. get_speed_vector(StartOrigin, EndOrigin, Speed, Velocity)
  591. set_pev(Ent, pev_velocity, Velocity)
  592. }
  593.  
  594. public Create_Fire(id, Float:Origin[3], Float:Scale, Float:Frame)
  595. {
  596. static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_sprite"))
  597.  
  598. // set info for ent
  599. set_pev(Ent, pev_movetype, MOVETYPE_FLY)
  600. set_pev(Ent, pev_rendermode, kRenderTransAdd)
  601. set_pev(Ent, pev_renderamt, 255.0)
  602. set_pev(Ent, pev_fuser1, get_gametime() + 0.1) // time remove
  603. set_pev(Ent, pev_scale, Scale)
  604. set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
  605.  
  606. set_pev(Ent, pev_classname, FIRE_CLASSNAME)
  607. engfunc(EngFunc_SetModel, Ent, WeaponResources[0])
  608. set_pev(Ent, pev_mins, Float:{-10.0, -10.0, -10.0})
  609. set_pev(Ent, pev_maxs, Float:{10.0, 10.0, 10.0})
  610. set_pev(Ent, pev_origin, Origin)
  611. set_pev(Ent, pev_gravity, 0.01)
  612. set_pev(Ent, pev_solid, SOLID_TRIGGER)
  613. set_pev(Ent, pev_owner, id)
  614. set_pev(Ent, pev_frame, Frame)
  615. }
  616.  
  617. stock make_bullet(id, Float:Origin[3])
  618. {
  619. // Find target
  620. new decal = random_num(41, 45)
  621. const loop_time = 2
  622.  
  623. static Body, Target
  624. get_user_aiming(id, Target, Body, 999999)
  625.  
  626. if(is_user_connected(Target))
  627. return
  628.  
  629. for(new i = 0; i < loop_time; i++)
  630. {
  631. // Put decal on "world" (a wall)
  632. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  633. write_byte(TE_WORLDDECAL)
  634. engfunc(EngFunc_WriteCoord, Origin[0])
  635. engfunc(EngFunc_WriteCoord, Origin[1])
  636. engfunc(EngFunc_WriteCoord, Origin[2])
  637. write_byte(decal)
  638. message_end()
  639.  
  640. // Show sparcles
  641. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  642. write_byte(TE_GUNSHOTDECAL)
  643. engfunc(EngFunc_WriteCoord, Origin[0])
  644. engfunc(EngFunc_WriteCoord, Origin[1])
  645. engfunc(EngFunc_WriteCoord, Origin[2])
  646. write_short(id)
  647. write_byte(decal)
  648. message_end()
  649. }
  650. }
  651.  
  652. stock fake_smoke(id, trace_result)
  653. {
  654. static Float:vecSrc[3], Float:vecEnd[3], TE_FLAG
  655.  
  656. get_weapon_attachment(id, vecSrc)
  657. global_get(glb_v_forward, vecEnd)
  658.  
  659. xs_vec_mul_scalar(vecEnd, 8192.0, vecEnd)
  660. xs_vec_add(vecSrc, vecEnd, vecEnd)
  661.  
  662. get_tr2(trace_result, TR_vecEndPos, vecSrc)
  663. get_tr2(trace_result, TR_vecPlaneNormal, vecEnd)
  664.  
  665. xs_vec_mul_scalar(vecEnd, 2.5, vecEnd)
  666. xs_vec_add(vecSrc, vecEnd, vecEnd)
  667.  
  668. TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
  669. TE_FLAG |= TE_EXPLFLAG_NOSOUND
  670. TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
  671.  
  672. engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0)
  673. write_byte(TE_EXPLOSION)
  674. engfunc(EngFunc_WriteCoord, vecEnd[0])
  675. engfunc(EngFunc_WriteCoord, vecEnd[1])
  676. engfunc(EngFunc_WriteCoord, vecEnd[2] - 10.0)
  677. write_short(g_smokepuff_id)
  678. write_byte(2)
  679. write_byte(50)
  680. write_byte(TE_FLAG)
  681. message_end()
  682. }
  683.  
  684. stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
  685. {
  686. new Float:vfEnd[3], viEnd[3]
  687. get_user_origin(id, viEnd, 3)
  688. IVecFVec(viEnd, vfEnd)
  689.  
  690. new Float:fOrigin[3], Float:fAngle[3]
  691.  
  692. pev(id, pev_origin, fOrigin)
  693. pev(id, pev_view_ofs, fAngle)
  694.  
  695. xs_vec_add(fOrigin, fAngle, fOrigin)
  696.  
  697. new Float:fAttack[3]
  698.  
  699. xs_vec_sub(vfEnd, fOrigin, fAttack)
  700. xs_vec_sub(vfEnd, fOrigin, fAttack)
  701.  
  702. new Float:fRate
  703.  
  704. fRate = fDis / vector_length(fAttack)
  705. xs_vec_mul_scalar(fAttack, fRate, fAttack)
  706.  
  707. xs_vec_add(fOrigin, fAttack, output)
  708. }
  709.  
  710. stock set_weapon_anim(id, anim)
  711. {
  712. if(!is_user_alive(id))
  713. return
  714.  
  715. set_pev(id, pev_weaponanim, anim)
  716.  
  717. message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, _, id)
  718. write_byte(anim)
  719. write_byte(0)
  720. message_end()
  721. }
  722.  
  723. stock fm_cs_get_weapon_ent_owner(ent)
  724. {
  725. if (pev_valid(ent) != PDATA_SAFE)
  726. return -1
  727.  
  728. return get_pdata_cbase(ent, OFFSET_WEAPONOWNER, OFFSET_LINUX_WEAPONS)
  729. }
  730.  
  731. stock set_player_nextattack(id, Float:nexttime)
  732. {
  733. if(!is_user_alive(id))
  734. return
  735.  
  736. set_pdata_float(id, m_flNextAttack, nexttime, 5)
  737. }
  738.  
  739. stock set_weapons_timeidle(id, WeaponId ,Float:TimeIdle)
  740. {
  741. if(!is_user_alive(id))
  742. return
  743.  
  744. static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
  745. if(!pev_valid(entwpn))
  746. return
  747.  
  748. set_pdata_float(entwpn, 46, TimeIdle, OFFSET_LINUX_WEAPONS)
  749. set_pdata_float(entwpn, 47, TimeIdle, OFFSET_LINUX_WEAPONS)
  750. set_pdata_float(entwpn, 48, TimeIdle + 0.5, OFFSET_LINUX_WEAPONS)
  751. }
  752.  
  753. stock get_position(id,Float:forw, Float:right, Float:up, Float:vStart[])
  754. {
  755. static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
  756.  
  757. pev(id, pev_origin, vOrigin)
  758. pev(id, pev_view_ofs, vUp) //for player
  759. xs_vec_add(vOrigin, vUp, vOrigin)
  760. pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
  761.  
  762. angle_vector(vAngle,ANGLEVECTOR_FORWARD, vForward) //or use EngFunc_AngleVectors
  763. angle_vector(vAngle,ANGLEVECTOR_RIGHT, vRight)
  764. angle_vector(vAngle,ANGLEVECTOR_UP, vUp)
  765.  
  766. vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
  767. vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
  768. vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
  769. }
  770.  
  771. stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
  772. {
  773. new_velocity[0] = origin2[0] - origin1[0]
  774. new_velocity[1] = origin2[1] - origin1[1]
  775. new_velocity[2] = origin2[2] - origin1[2]
  776. new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
  777. new_velocity[0] *= num
  778. new_velocity[1] *= num
  779. new_velocity[2] *= num
  780.  
  781. return 1;
  782. }
  783.  
  784. // Drop primary/secondary weapons
  785. stock drop_weapons(id, dropwhat)
  786. {
  787. // Get user weapons
  788. static weapons[32], num, i, weaponid
  789. num = 0 // reset passed weapons count (bugfix)
  790. get_user_weapons(id, weapons, num)
  791.  
  792. // Loop through them and drop primaries or secondaries
  793. for (i = 0; i < num; i++)
  794. {
  795. // Prevent re-indexing the array
  796. weaponid = weapons[i]
  797.  
  798. if ((dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM)) || (dropwhat == 2 && ((1<<weaponid) & SECONDARY_WEAPONS_BIT_SUM)))
  799. {
  800. // Get weapon entity
  801. static wname[32]
  802. get_weaponname(weaponid, wname, charsmax(wname))
  803.  
  804. // Player drops the weapon and looses his bpammo
  805. engclient_cmd(id, "drop", wname)
  806. cs_set_user_bpammo(id, weaponid, 0)
  807. }
  808. }
  809. }