Page 1 of 1

minigun

Posted: 01 Aug 2019, 18:16
by czirimbolo
I can't destroy any entities by this weapon, can someone help me?
  1. #include <zombie_escape>
  2. #include <engine>
  3. #include <fakemeta_util>
  4. #include <cstrike>
  5. #include <xs>
  6. #include <fun>
  7.  
  8. #define MODEL_V "models/addons/v_m134_vulcan.mdl"
  9. #define MODEL_P "models/addons/p_m134_vulcan.mdl"
  10. #define MODEL_W "models/addons/w_m134_vulcan.mdl"
  11.  
  12. #define MUZZLEFLASH "sprites/addons/m134_vulcan_muzzle2.spr"
  13. #define MUZZLEFLASH2 "sprites/addons/m134_vulcan_muzzle1.spr"
  14.  
  15. #define DAMAGE 80
  16. #define CLIP 100
  17. #define BPAMMO 200
  18.  
  19. #define SPEED_A 0.04
  20. #define SPEED_B 0.02
  21. #define TIME_RELOAD 5.0
  22.  
  23. #define CSW_M134V CSW_M249
  24. #define weapon_m134v "weapon_m249"
  25. #define WEAPON_ANIMEXT "m249"
  26.  
  27. new const WeaponSounds[11][] =
  28. {
  29.     "weapons/m134ex-1.wav",
  30.     "weapons/m134_clipoff.wav",
  31.     "weapons/m134_clipon.wav",
  32.     "weapons/m134ex_spin.wav",
  33.     "weapons/m134hero_draw.wav",
  34.     "weapons/m134hero_fire_after_overheat.wav",
  35.     "weapons/m134hero_overheat_end.wav",
  36.     "weapons/m134hero_overload.wav",
  37.     "weapons/m134hero_spindown.wav",
  38.     "weapons/m134hero_spinup.wav",
  39.     "weapons/steam.wav"
  40. }
  41.  
  42. new const WeaponResources[3][] =
  43. {
  44.     "sprites/weapon_m134_vulcan.txt",
  45.     "sprites/addons/m134_vulcan_weapon1.spr",
  46.     "sprites/addons/m134_vulcan_ammo1.spr"
  47. }
  48.  
  49. new const Steam[] = "sprites/addons/m134_vulcan_steam1.spr"
  50. new const Shell1[] = "models/addons/s_m134_vulcan_piston.mdl"
  51. new const Shell2[] = "models/addons/s_m134_vulcan_shell.mdl"
  52.  
  53. enum
  54. {
  55.     ANIME_IDLE = 0,
  56.     ANIME_DRAW,
  57.     ANIME_RELOAD,
  58.     ANIME_FIRE_START,
  59.     ANIME_FIRE_LOOP,
  60.     ANIME_FIRE_END,
  61.     ANIME_NANI1,
  62.     ANIME_NANI2,
  63.     ANIME_OH_DRAW,
  64.     ANIME_OH_START,
  65.     ANIME_OH_IDLE,
  66.     ANIME_OH_END,
  67.     ANIME_SFIRE_START,
  68.     ANIME_SFIRE_LOOP,
  69.     ANIME_SFIRE_END
  70. }
  71.  
  72. enum
  73. {
  74.     M134_ATTACK_NOT = 0,
  75.     M134_ATTACK_BEGIN,
  76.     M134_ATTACK_LOOP,
  77.     M134_ATTACK_END
  78. }
  79.  
  80. #define TASK_ATTACK 1972
  81. #define TASK_OVERHEAT 1973
  82.  
  83. #define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
  84. #define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
  85. #define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))
  86.  
  87. 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)
  88. const SECONDARY_WEAPONS_BIT_SUM = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)
  89. new g_Had_M134V, g_Clip[33], g_M134State[33], Float:g_SpeedControl[33], Float:g_AttackDelay[33], g_RapidMode
  90. new g_Event_M134V, m_iBlood[2], g_OverHeat, g_Fired, g_ShellID1, g_ShellID2
  91. new g_MsgWeaponList, g_MsgCurWeapon, g_SteamID, Float:SteamTime[33], FiringTime[33], g_InTempingAttack
  92. new g_Muzzleflash_Ent, g_Muzzleflash
  93. new g_Muzzleflash_Ent2, g_Muzzleflash2
  94. new g_IsConnected, g_IsAlive, g_PlayerWeapon[33]
  95.  
  96. public plugin_init(){
  97.     Register_SafetyFunc()
  98.     register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
  99.     register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
  100.     register_forward(FM_CmdStart, "fw_CmdStart")
  101.     register_forward(FM_EmitSound, "fw_EmitSound")
  102.     register_forward(FM_TraceLine, "fw_TraceLine")
  103.     register_forward(FM_TraceHull, "fw_TraceHull")
  104.     register_forward(FM_SetModel, "fw_SetModel")   
  105.     register_forward(FM_AddToFullPack, "fw_AddToFullPack_post", 1)
  106.     register_forward(FM_CheckVisibility, "fw_CheckVisibility")
  107.    
  108.     RegisterHam(Ham_Item_Deploy, weapon_m134v, "fw_Item_Deploy_Post", 1)   
  109.     RegisterHam(Ham_Item_AddToPlayer, weapon_m134v, "fw_Item_AddToPlayer_Post", 1)
  110.     RegisterHam(Ham_Weapon_WeaponIdle, weapon_m134v, "fw_Weapon_WeaponIdle_Post", 1)
  111.     RegisterHam(Ham_Item_PostFrame, weapon_m134v, "fw_Item_PostFrame") 
  112.     RegisterHam(Ham_Weapon_Reload, weapon_m134v, "fw_Weapon_Reload")
  113.     RegisterHam(Ham_Weapon_Reload, weapon_m134v, "fw_Weapon_Reload_Post", 1)   
  114.     RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
  115.     RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")
  116.  
  117.     g_MsgCurWeapon = get_user_msgid("CurWeapon")
  118.     g_MsgWeaponList = get_user_msgid("WeaponList")
  119.    
  120. }
  121. public plugin_precache(){
  122.     precache_model(MODEL_V)
  123.     precache_model(MODEL_P)
  124.     precache_model(MODEL_W)
  125.     for(new i = 0; i < sizeof(WeaponSounds); i++)precache_sound(WeaponSounds[i])
  126.    
  127.     precache_generic(WeaponResources[0])
  128.     precache_model(WeaponResources[1])
  129.     precache_model(WeaponResources[2])
  130.     g_SteamID = precache_model(Steam)
  131.     m_iBlood[0] = precache_model("sprites/blood.spr")
  132.     m_iBlood[1] = precache_model("sprites/bloodspray.spr")
  133.     register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
  134.     g_ShellID1 = precache_model(Shell1)
  135.     g_ShellID2 = precache_model(Shell2)
  136.    
  137.     g_Muzzleflash_Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  138.    
  139.     precache_model(MUZZLEFLASH)
  140.     engfunc(EngFunc_SetModel, g_Muzzleflash_Ent, MUZZLEFLASH)
  141.     set_pev(g_Muzzleflash_Ent, pev_scale, 0.2)
  142.    
  143.     set_pev(g_Muzzleflash_Ent, pev_rendermode, kRenderTransTexture)
  144.     set_pev(g_Muzzleflash_Ent, pev_renderamt, 0.0)
  145.  
  146.     g_Muzzleflash_Ent2 = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  147.    
  148.     precache_model(MUZZLEFLASH2)
  149.     engfunc(EngFunc_SetModel, g_Muzzleflash_Ent2, MUZZLEFLASH2)
  150.     set_pev(g_Muzzleflash_Ent2, pev_scale, 0.2)
  151.    
  152.     set_pev(g_Muzzleflash_Ent2, pev_rendermode, kRenderTransTexture)
  153.     set_pev(g_Muzzleflash_Ent2, pev_renderamt, 0.0)
  154. }
  155. public fw_PrecacheEvent_Post(type, const name[]){
  156.     if(equal("events/m249.sc", name)) g_Event_M134V = get_orig_retval()    
  157. }
  158. public Hook_Weapon(id){
  159.     engclient_cmd(id, weapon_m134v)
  160.     return PLUGIN_HANDLED
  161. }
  162. public client_putinserver(id){
  163.     Safety_Connected(id)
  164. }
  165. public client_disconnected(id){
  166.     Safety_Disconnected(id)
  167. }
  168. public plugin_natives ()
  169. {
  170.     register_native("Get_M134V", "native_Get_M134V", 1)
  171. }
  172. public native_Get_M134V(id)
  173. {
  174.     Get_M134V(id)
  175. }
  176.  
  177. stock drop_weapons(id, dropwhat){
  178.     static weapons[32], num, i, weaponid
  179.     num = 0
  180.     get_user_weapons(id, weapons, num)
  181.     for (i = 0; i < num; i++){
  182.         weaponid = weapons[i]
  183.         if ((dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM)) || (dropwhat == 2 && ((1<<weaponid) & SECONDARY_WEAPONS_BIT_SUM))){
  184.             static wname[32]; get_weaponname(weaponid, wname, charsmax(wname))
  185.             engclient_cmd(id, "drop", wname)
  186.         }
  187.     }
  188. }
  189. public Get_M134V(id){
  190.     remove_task(id+TASK_OVERHEAT)
  191.    
  192.     drop_weapons(id, 1)
  193.    
  194.     UnSet_BitVar(g_InTempingAttack, id)
  195.     UnSet_BitVar(g_Fired, id)
  196.     UnSet_BitVar(g_OverHeat, id)
  197.     UnSet_BitVar(g_RapidMode, id)
  198.     g_M134State[id] = M134_ATTACK_NOT
  199.     FiringTime[id] = 0
  200.    
  201.     Set_BitVar(g_Had_M134V, id)
  202.     give_item(id, weapon_m134v)
  203.    
  204.     static Ent; Ent = fm_get_user_weapon_entity(id, CSW_M134V)
  205.     if(!pev_valid(Ent)) return
  206.    
  207.     cs_set_weapon_ammo(Ent, CLIP)
  208.     cs_set_user_bpammo(id, CSW_M134V, BPAMMO)
  209.    
  210.     message_begin(MSG_ONE_UNRELIABLE, g_MsgCurWeapon, _, id)
  211.     write_byte(1)
  212.     write_byte(CSW_M134V)
  213.     write_byte(CLIP)
  214.     message_end()
  215. }
  216. public Remove_M134V(id){
  217.     UnSet_BitVar(g_InTempingAttack, id)
  218.     UnSet_BitVar(g_Had_M134V, id)
  219.     UnSet_BitVar(g_OverHeat, id)
  220.     UnSet_BitVar(g_RapidMode, id)
  221.    
  222.     remove_task(id+TASK_OVERHEAT)
  223. }
  224. public fw_AddToFullPack_post(esState, iE, iEnt, iHost, iHostFlags, iPlayer, pSet){
  225.     if(iEnt == g_Muzzleflash_Ent){
  226.         if(Get_BitVar(g_Muzzleflash, iHost)){
  227.             set_es(esState, ES_Frame, float(random_num(0, 2)))
  228.                
  229.             set_es(esState, ES_RenderMode, kRenderTransAdd)
  230.             set_es(esState, ES_RenderAmt, 255.0)
  231.            
  232.             UnSet_BitVar(g_Muzzleflash, iHost)
  233.         }  
  234.         set_es(esState, ES_Skin, iHost)
  235.         set_es(esState, ES_Body, 1)
  236.         set_es(esState, ES_AimEnt, iHost)
  237.         set_es(esState, ES_MoveType, MOVETYPE_FOLLOW)
  238.     }
  239.     if(iEnt == g_Muzzleflash_Ent2){
  240.         if(Get_BitVar(g_Muzzleflash2, iHost)){
  241.             set_es(esState, ES_Frame, float(random_num(0, 2)))
  242.                
  243.             set_es(esState, ES_RenderMode, kRenderTransAdd)
  244.             set_es(esState, ES_RenderAmt, 255.0)
  245.            
  246.             UnSet_BitVar(g_Muzzleflash2, iHost)
  247.         }
  248.            
  249.         set_es(esState, ES_Skin, iHost)
  250.         set_es(esState, ES_Body, 1)
  251.         set_es(esState, ES_AimEnt, iHost)
  252.         set_es(esState, ES_MoveType, MOVETYPE_FOLLOW)
  253.     }
  254. }
  255. public fw_CheckVisibility(iEntity, pSet){
  256.     if(iEntity == g_Muzzleflash_Ent){
  257.         forward_return(FMV_CELL, 1)
  258.         return FMRES_SUPERCEDE
  259.     }
  260.     else if(iEntity == g_Muzzleflash_Ent2) {
  261.         forward_return(FMV_CELL, 1)
  262.         return FMRES_SUPERCEDE
  263.     }
  264.     return FMRES_IGNORED
  265. }
  266. public fw_EmitSound(id, channel, const sample[], Float:volume, Float:attn, flags, pitch){
  267.     if(!is_connected(id))return FMRES_IGNORED
  268.     if(!Get_BitVar(g_InTempingAttack, id))return FMRES_IGNORED
  269.        
  270.     if(sample[8] == 'k' && sample[9] == 'n' && sample[10] == 'i'){
  271.         if(sample[14] == 's' && sample[15] == 'l' && sample[16] == 'a')return FMRES_SUPERCEDE
  272.         if (sample[14] == 'h' && sample[15] == 'i' && sample[16] == 't'){
  273.             if (sample[17] == 'w')  return FMRES_SUPERCEDE
  274.             else  return FMRES_SUPERCEDE
  275.         }
  276.         if (sample[14] == 's' && sample[15] == 't' && sample[16] == 'a')return FMRES_SUPERCEDE;
  277.     }
  278.     return FMRES_IGNORED
  279. }
  280. public fw_TraceLine(Float:vector_start[3], Float:vector_end[3], ignored_monster, id, handle){
  281.     if(!is_alive(id))return FMRES_IGNORED  
  282.     if(!Get_BitVar(g_InTempingAttack, id))return FMRES_IGNORED
  283.    
  284.     static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
  285.    
  286.     pev(id, pev_origin, fOrigin)
  287.     pev(id, pev_view_ofs, view_ofs)
  288.     xs_vec_add(fOrigin, view_ofs, vecStart)
  289.     pev(id, pev_v_angle, v_angle)
  290.    
  291.     engfunc(EngFunc_MakeVectors, v_angle)
  292.     get_global_vector(GL_v_forward, v_forward)
  293.  
  294.     xs_vec_mul_scalar(v_forward, 0.0, v_forward)
  295.     xs_vec_add(vecStart, v_forward, vecEnd)
  296.    
  297.     engfunc(EngFunc_TraceLine, vecStart, vecEnd, ignored_monster, id, handle)
  298.    
  299.     return FMRES_SUPERCEDE
  300. }
  301. public fw_TraceHull(Float:vector_start[3], Float:vector_end[3], ignored_monster, hull, id, handle){
  302.     if(!is_alive(id))return FMRES_IGNORED  
  303.     if(!Get_BitVar(g_InTempingAttack, id))return FMRES_IGNORED
  304.    
  305.     static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
  306.    
  307.     pev(id, pev_origin, fOrigin)
  308.     pev(id, pev_view_ofs, view_ofs)
  309.     xs_vec_add(fOrigin, view_ofs, vecStart)
  310.     pev(id, pev_v_angle, v_angle)
  311.    
  312.     engfunc(EngFunc_MakeVectors, v_angle)
  313.     get_global_vector(GL_v_forward, v_forward)
  314.    
  315.     xs_vec_mul_scalar(v_forward, 0.0, v_forward)
  316.     xs_vec_add(vecStart, v_forward, vecEnd)
  317.    
  318.     engfunc(EngFunc_TraceHull, vecStart, vecEnd, ignored_monster, hull, id, handle)
  319.    
  320.     return FMRES_SUPERCEDE
  321. }
  322. public fw_UpdateClientData_Post(id, sendweapons, cd_handle){
  323.     if(!is_alive(id))return FMRES_IGNORED  
  324.     if(get_player_weapon(id) == CSW_M134V && Get_BitVar(g_Had_M134V, id))set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001)
  325.     return FMRES_HANDLED
  326. }
  327. public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2){
  328.     if (!is_connected(invoker))return FMRES_IGNORED
  329.     if(get_player_weapon(invoker) != CSW_M134V || !Get_BitVar(g_Had_M134V, invoker))return FMRES_IGNORED
  330.        
  331.     if(eventid == g_Event_M134V){
  332.         engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
  333.         return FMRES_SUPERCEDE
  334.     }
  335.     return FMRES_IGNORED
  336. }
  337. public fw_CmdStart(id, uc_handle, seed){
  338.     if(!is_alive(id))return
  339.     if(get_player_weapon(id) != CSW_M134V || !Get_BitVar(g_Had_M134V, id))return
  340.    
  341.     static NewButton; NewButton = get_uc(uc_handle, UC_Buttons)
  342.     static Ent; Ent = fm_get_user_weapon_entity(id, CSW_M134V)
  343.    
  344.     if(!pev_valid(Ent))return
  345.        
  346.     if(NewButton & IN_ATTACK){
  347.         NewButton &= ~IN_ATTACK
  348.         set_uc(uc_handle, UC_Buttons, NewButton)
  349.  
  350.         if(get_pdata_float(id, 83, 5) > 0.0)return
  351.         if(Get_BitVar(g_OverHeat, id))return
  352.         if(cs_get_weapon_ammo(Ent) <= 0){
  353.             if(get_pdata_int(Ent, 54))return
  354.             set_pdata_int(Ent, 54, 1, 4)
  355.             ExecuteHamB(Ham_Weapon_Reload, Ent)
  356.             return
  357.         }
  358.         if(g_M134State[id] == M134_ATTACK_NOT){
  359.             g_M134State[id] = M134_ATTACK_BEGIN
  360.            
  361.             FiringTime[id] = 0
  362.             UnSet_BitVar(g_Fired, id)
  363.             UnSet_BitVar(g_RapidMode, id)
  364.         }
  365.         else if(g_M134State[id] == M134_ATTACK_BEGIN){
  366.             if(pev(id, pev_weaponanim) != ANIME_FIRE_END) Set_WeaponAnim(id, ANIME_FIRE_START)
  367.  
  368.             emit_sound(Ent, CHAN_WEAPON, WeaponSounds[9], 1.0, 0.52, 0, 94 + random_num(0, 15))
  369.            
  370.             Set_WeaponIdleTime(id, CSW_M134V, 0.2)
  371.             Set_PlayerNextAttack(id, 0.2)
  372.            
  373.             if(!task_exists(id+TASK_ATTACK)) set_task(0.15, "Task_ChangeState_Loop", id+TASK_ATTACK)
  374.         }
  375.         else if(g_M134State[id] == M134_ATTACK_LOOP) {
  376.             if(cs_get_weapon_ammo(Ent) > 0){
  377.                 if(!Get_BitVar(g_RapidMode, id)) Set_WeaponAnim(id, ANIME_FIRE_LOOP)
  378.                 else Set_WeaponAnim(id, ANIME_SFIRE_LOOP)
  379.                
  380.                 Set_WeaponIdleTime(id, CSW_M134V, 0.5)
  381.                 Set_PlayerNextAttack(id, 0.5)
  382.             }
  383.             else{
  384.                 g_M134State[id] = M134_ATTACK_END
  385.                 Set_WeaponAnim(id, ANIME_FIRE_END)
  386.                
  387.                 emit_sound(Ent, CHAN_WEAPON, WeaponSounds[8], 1.0, 0.52, 0, 94 + random_num(0, 15))
  388.                
  389.                 Set_WeaponIdleTime(id, CSW_M134V, 2.0)
  390.                 Set_PlayerNextAttack(id, 0.25)
  391.                
  392.                 remove_task(id+TASK_ATTACK)
  393.                 g_M134State[id] = M134_ATTACK_NOT  
  394.             }
  395.         }
  396.     }
  397.     else if(NewButton & IN_ATTACK2) {
  398.         NewButton &= ~IN_ATTACK2
  399.         set_uc(uc_handle, UC_Buttons, NewButton)
  400.  
  401.         if(get_pdata_float(id, 83, 5) > 0.0) return
  402.         if(Get_BitVar(g_OverHeat, id))return
  403.         if(cs_get_weapon_ammo(Ent) <= 0){
  404.             if(get_pdata_int(Ent, 54))return
  405.        
  406.             set_pdata_int(Ent, 54, 1, 4)
  407.             ExecuteHamB(Ham_Weapon_Reload, Ent)
  408.             return
  409.         }
  410.         if(g_M134State[id] == M134_ATTACK_NOT){
  411.             Set_BitVar(g_RapidMode, id)
  412.            
  413.             FiringTime[id] = 0
  414.             UnSet_BitVar(g_Fired, id)
  415.             g_M134State[id] = M134_ATTACK_BEGIN
  416.         }
  417.         else if(g_M134State[id] == M134_ATTACK_BEGIN) {
  418.             if(pev(id, pev_weaponanim) != ANIME_FIRE_END) Set_WeaponAnim(id, ANIME_SFIRE_START)
  419.  
  420.             emit_sound(Ent, CHAN_WEAPON, WeaponSounds[9], 1.0, 0.52, 0, 94 + random_num(0, 15))
  421.            
  422.             Set_WeaponIdleTime(id, CSW_M134V, 0.2)
  423.             Set_PlayerNextAttack(id, 0.2)
  424.            
  425.             if(!task_exists(id+TASK_ATTACK)) set_task(0.15, "Task_ChangeState_Loop", id+TASK_ATTACK)
  426.         }
  427.         else if(g_M134State[id] == M134_ATTACK_LOOP) {
  428.             if(cs_get_weapon_ammo(Ent) > 0){
  429.                 if(!Get_BitVar(g_RapidMode, id)) Set_WeaponAnim(id, ANIME_FIRE_LOOP)
  430.                 else Set_WeaponAnim(id, ANIME_SFIRE_LOOP)
  431.                
  432.                 Set_WeaponIdleTime(id, CSW_M134V, 0.5)
  433.                 Set_PlayerNextAttack(id, 0.5)
  434.             }
  435.             else {
  436.                 g_M134State[id] = M134_ATTACK_END
  437.                 emit_sound(Ent, CHAN_WEAPON, WeaponSounds[8], 1.0, 0.52, 0, 94 + random_num(0, 15))
  438.                
  439.                 Overheat_Begin(id)
  440.                
  441.                 remove_task(id+TASK_ATTACK)
  442.                 g_M134State[id] = M134_ATTACK_NOT  
  443.             }
  444.         }
  445.     }
  446.     else {
  447.         if(g_M134State[id] == M134_ATTACK_LOOP) {
  448.             g_M134State[id] = M134_ATTACK_END
  449.            
  450.             emit_sound(Ent, CHAN_WEAPON, WeaponSounds[8], 1.0, 0.52, 0, 94 + random_num(0, 15))
  451.            
  452.             Set_WeaponIdleTime(id, CSW_M134V, 2.0)
  453.             Set_PlayerNextAttack(id, 0.25)
  454.            
  455.             if(!Get_BitVar(g_RapidMode, id)) Set_WeaponAnim(id, ANIME_FIRE_END)
  456.             else Overheat_Begin(id)
  457.            
  458.             remove_task(id+TASK_ATTACK)
  459.             g_M134State[id] = M134_ATTACK_NOT
  460.         }
  461.     }
  462.    
  463.     if(NewButton & IN_RELOAD){
  464.         if(get_pdata_int(Ent, 54))return
  465.         if(Get_BitVar(g_OverHeat, id))return
  466.         if(cs_get_weapon_ammo(Ent) >= CLIP)return
  467.         if(get_pdata_float(id, 83, 5) > 0.0 || get_pdata_float(Ent, 46, 4) > 0.0 || get_pdata_float(Ent, 47, 4) > 0.0)return
  468.            
  469.         set_pdata_int(Ent, 54, 1, 4)
  470.         ExecuteHamB(Ham_Weapon_Reload, Ent)
  471.     }
  472. }
  473. public Overheat_Begin(id){
  474.     if(Get_BitVar(g_Fired, id)){
  475.         if(FiringTime[id] > 0){
  476.             Set_BitVar(g_OverHeat, id)
  477.            
  478.             SteamTime[id] = get_gametime() + 1.0
  479.            
  480.             Set_WeaponIdleTime(id, CSW_M134V, 2.0 + 1.0)
  481.             Set_PlayerNextAttack(id, float(FiringTime[id]) + 1.0)
  482.            
  483.             Set_WeaponAnim(id, ANIME_OH_START)
  484.            
  485.             remove_task(id+TASK_OVERHEAT)
  486.             set_task(float(FiringTime[id]) + 1.0, "Overheat_End", id+TASK_OVERHEAT)
  487.         }
  488.         else {
  489.             Set_WeaponIdleTime(id, CSW_M134V, 2.0)
  490.             Set_PlayerNextAttack(id, 0.25)
  491.            
  492.             Set_WeaponAnim(id, ANIME_SFIRE_END)
  493.         }
  494.     }
  495.     else {
  496.         Set_WeaponIdleTime(id, CSW_M134V, 2.0)
  497.         Set_PlayerNextAttack(id, 0.25)
  498.        
  499.         Set_WeaponAnim(id, ANIME_SFIRE_END)
  500.     }
  501. }
  502. public Overheat_End(id){
  503.     id -= TASK_OVERHEAT
  504.    
  505.     if(!is_alive(id))return
  506.        
  507.     UnSet_BitVar(g_OverHeat, id)
  508.    
  509.     if(get_player_weapon(id) != CSW_M134V || !Get_BitVar(g_Had_M134V, id))return
  510.        
  511.     Set_WeaponAnim(id, ANIME_OH_END)
  512.  
  513.     Set_WeaponIdleTime(id, CSW_M134V, 2.0)
  514.     Set_PlayerNextAttack(id, 2.0)
  515. }
  516. public client_PostThink(id){
  517.     if(!is_alive(id))return
  518.     if(get_player_weapon(id) != CSW_M134V || !Get_BitVar(g_Had_M134V, id))return
  519.     if(Get_BitVar(g_OverHeat, id)){
  520.         if(get_gametime() - 1.0 > SteamTime[id]){
  521.             static Float:Origin[3]
  522.             get_position(id, 20.0, 0.0, 0.0, Origin)
  523.            
  524.             message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  525.             write_byte(TE_SPRITE)
  526.             engfunc(EngFunc_WriteCoord, Origin[0])
  527.             engfunc(EngFunc_WriteCoord, Origin[1])
  528.             engfunc(EngFunc_WriteCoord, Origin[2])
  529.             write_short(g_SteamID)
  530.             write_byte(1)
  531.             write_byte(250)
  532.             message_end()
  533.            
  534.             emit_sound(id, CHAN_WEAPON, WeaponSounds[10], 1.0, 0.52, 0, 94 + random_num(0, 15))
  535.            
  536.             SteamTime[id] = get_gametime()
  537.         }
  538.     }
  539.     if(g_M134State[id] != M134_ATTACK_LOOP)return  
  540.        
  541.     static Float:DerSpeed; DerSpeed = Get_BitVar(g_RapidMode, id) ? SPEED_B : SPEED_A
  542.    
  543.     if(get_gametime() - DerSpeed > g_SpeedControl[id]){
  544.         static Ent; Ent = fm_get_user_weapon_entity(id, CSW_M134V)
  545.         if(!pev_valid(Ent)) return
  546.  
  547.         if(cs_get_weapon_ammo(Ent) > 0){
  548.             Set_BitVar(g_Fired, id)
  549.            
  550.             // Shake Screen
  551.             static Float:PunchAngles[3]
  552.             PunchAngles[0] = random_float(-1.5, 1.5)
  553.             PunchAngles[1] = random_float(-1.5, 1.5)
  554.            
  555.             set_pev(id, pev_punchangle, PunchAngles)
  556.            
  557.             Set_BitVar(g_Muzzleflash, id)
  558.             Set_BitVar(g_Muzzleflash2, id)
  559.            
  560.             Create_Vodan(id)
  561.             emit_sound(Ent, CHAN_WEAPON, WeaponSounds[0], 1.0, 0.52, 0, 94 + random_num(0, 15))
  562.            
  563.             static Float:Origin[3], Float:Target[3]
  564.             pev(id, pev_origin, Origin); Origin[2] += 16.0
  565.             get_position(id, 4096.0, 0.0, 0.0, Target)
  566.            
  567.             if(get_gametime() - 1.0 > SteamTime[id]){
  568.                 FiringTime[id]++
  569.                 SteamTime[id] = get_gametime()
  570.             }
  571.            
  572.             Create_FakeAttack(id)
  573.            
  574.             static Trace; Trace = create_tr2()
  575.             engfunc(EngFunc_TraceLine, Origin, Target, DONT_IGNORE_MONSTERS, id, Trace)
  576.             static Hit; Hit = get_tr2(Trace, TR_pHit)
  577.            
  578.             if(is_alive(Hit)){
  579.                 do_attack(id, Hit, 0, float(DAMAGE))
  580.             }
  581.             else {
  582.                 static ptr; ptr = create_tr2()
  583.                 engfunc(EngFunc_TraceLine, Origin, Target, DONT_IGNORE_MONSTERS, id, ptr)
  584.  
  585.                 static Float:EndPos[3]
  586.                 get_tr2(ptr, TR_vecEndPos, EndPos)
  587.                 static Float:WallVector[3];get_tr2(ptr,TR_vecPlaneNormal,WallVector)
  588.                
  589.                 make_bullet(id, EndPos)
  590.                
  591.                 engfunc(EngFunc_MessageBegin,MSG_PVS,SVC_TEMPENTITY,EndPos,0);
  592.                 write_byte(TE_STREAK_SPLASH)
  593.                 engfunc(EngFunc_WriteCoord,EndPos[0]);
  594.                 engfunc(EngFunc_WriteCoord,EndPos[1]);
  595.                 engfunc(EngFunc_WriteCoord,EndPos[2]);
  596.                 engfunc(EngFunc_WriteCoord,WallVector[0]*random_float(25.0,30.0));
  597.                 engfunc(EngFunc_WriteCoord,WallVector[1]*random_float(25.0,30.0));
  598.                 engfunc(EngFunc_WriteCoord,WallVector[2]*random_float(25.0,30.0));
  599.                 write_byte(111)
  600.                 write_short(12)
  601.                 write_short(3)
  602.                 write_short(75)
  603.                 message_end()
  604.                
  605.                 free_tr2(ptr)
  606.             }
  607.            
  608.             free_tr2(Trace)
  609.         }
  610.         else {
  611.             g_M134State[id] = M134_ATTACK_END
  612.             if(!Get_BitVar(g_RapidMode, id)) Set_WeaponAnim(id, ANIME_FIRE_END)
  613.             else Set_WeaponAnim(id, ANIME_SFIRE_END)
  614.            
  615.             Set_WeaponIdleTime(id, CSW_M134V, 2.0)
  616.             Set_PlayerNextAttack(id, 0.25)
  617.            
  618.             remove_task(id+TASK_ATTACK)
  619.             g_M134State[id] = M134_ATTACK_NOT
  620.         }
  621.        
  622.         g_SpeedControl[id] = get_gametime()
  623.     }
  624.    
  625.     static Float:DerTime; DerTime = Get_BitVar(g_RapidMode, id) ? 0.1 : 0.25
  626.     if(get_gametime() -  DerTime > g_AttackDelay[id]){
  627.         static Ent; Ent = fm_get_user_weapon_entity(id, CSW_M134V)
  628.         if(!pev_valid(Ent)) return
  629.        
  630.         if(cs_get_weapon_ammo(Ent) > 0) {
  631.             cs_set_weapon_ammo(Ent, cs_get_weapon_ammo(Ent) - 1)
  632.             if(cs_get_weapon_ammo(Ent) <= 0 && Get_BitVar(g_RapidMode, id))
  633.                 set_task(0.1, "Overheat_Begin", id)
  634.         }
  635.        
  636.         g_AttackDelay[id] = get_gametime()
  637.     }
  638. }
  639. public Create_Vodan(id){
  640.     Eject_Shell2(id, g_ShellID1, 0)
  641.     Eject_Shell2(id, g_ShellID2, 1)
  642. }
  643. public Task_ChangeState_Loop(id){
  644.     id -= TASK_ATTACK
  645.    
  646.     if(!is_alive(id))return
  647.     if(get_player_weapon(id) != CSW_M134V || !Get_BitVar(g_Had_M134V, id))return
  648.     if(g_M134State[id] != M134_ATTACK_BEGIN)return
  649.        
  650.     g_M134State[id] = M134_ATTACK_LOOP
  651. }
  652. public fw_Item_Deploy_Post(Ent){
  653.     if(pev_valid(Ent) != 2)return
  654.     static Id; Id = get_pdata_cbase(Ent, 41, 4)
  655.     if(get_pdata_cbase(Id, 373) != Ent)return
  656.     if(!Get_BitVar(g_Had_M134V, Id))return
  657.    
  658.     set_pev(Id, pev_viewmodel2, MODEL_V)
  659.     set_pev(Id, pev_weaponmodel2, MODEL_P)
  660.  
  661.     if(!Get_BitVar(g_OverHeat, Id)) Set_WeaponAnim(Id, ANIME_DRAW)
  662.     else Set_WeaponAnim(Id, ANIME_OH_DRAW)
  663.    
  664.     set_pdata_string(Id, (492) * 4, WEAPON_ANIMEXT, -1 , 20)
  665. }
  666. public fw_Item_AddToPlayer_Post(Ent, id){
  667.     if(!pev_valid(Ent))return HAM_IGNORED
  668.        
  669.     if(pev(Ent, pev_impulse) == 123123645489){
  670.         Set_BitVar(g_Had_M134V, id)
  671.         set_pev(Ent, pev_impulse, 0)
  672.     }
  673.    
  674.     if(Get_BitVar(g_Had_M134V, id)){
  675.         message_begin(MSG_ONE_UNRELIABLE, g_MsgWeaponList, _, id)
  676.         write_string("weapon_m134_vulcan")
  677.         write_byte(3)
  678.         write_byte(200)
  679.         write_byte(-1)
  680.         write_byte(-1)
  681.         write_byte(0)
  682.         write_byte(4)
  683.         write_byte(CSW_M134V)
  684.         write_byte(0)
  685.         message_end()
  686.     }
  687.     return HAM_HANDLED 
  688. }
  689. public fw_SetModel(entity, model[]){
  690.     if(!pev_valid(entity))return FMRES_IGNORED
  691.    
  692.     static Classname[32]
  693.     pev(entity, pev_classname, Classname, sizeof(Classname))
  694.    
  695.     if(!equal(Classname, "weaponbox"))return FMRES_IGNORED
  696.    
  697.     static iOwner
  698.     iOwner = pev(entity, pev_owner)
  699.    
  700.     if(equal(model, "models/w_m249.mdl")){
  701.         static weapon; weapon = find_ent_by_owner(-1, weapon_m134v, entity)
  702.        
  703.         if(!pev_valid(weapon))return FMRES_IGNORED;
  704.        
  705.         if(Get_BitVar(g_Had_M134V, iOwner)){
  706.             set_pev(weapon, pev_impulse, 123123645489)
  707.            
  708.             engfunc(EngFunc_SetModel, entity, MODEL_W)
  709.            
  710.             Remove_M134V(iOwner)
  711.            
  712.             return FMRES_SUPERCEDE
  713.         }
  714.     }
  715.  
  716.     return FMRES_IGNORED;
  717. }
  718. public fw_Item_PostFrame(ent){
  719.     static id; id = pev(ent, pev_owner)
  720.     if(!is_user_alive(id))return HAM_IGNORED
  721.     if(!Get_BitVar(g_Had_M134V, id))return HAM_IGNORED 
  722.    
  723.     static Float:flNextAttack; flNextAttack = get_pdata_float(id, 83, 5)
  724.     static bpammo; bpammo = cs_get_user_bpammo(id, CSW_M134V)
  725.    
  726.     static iClip; iClip = get_pdata_int(ent, 51, 4)
  727.     static fInReload; fInReload = get_pdata_int(ent, 54, 4)
  728.    
  729.     if(fInReload && flNextAttack <= 0.0){
  730.         static temp1
  731.         temp1 = min(CLIP - iClip, bpammo)
  732.  
  733.         set_pdata_int(ent, 51, iClip + temp1, 4)
  734.         cs_set_user_bpammo(id, CSW_M134V, bpammo - temp1)      
  735.        
  736.         set_pdata_int(ent, 54, 0, 4)
  737.         fInReload = 0
  738.     }      
  739.    
  740.     return HAM_IGNORED
  741. }
  742. public fw_Weapon_Reload(ent){
  743.     static id; id = pev(ent, pev_owner)
  744.     if(!is_user_alive(id))return HAM_IGNORED
  745.     if(!Get_BitVar(g_Had_M134V, id))return HAM_IGNORED 
  746.     if(Get_BitVar(g_OverHeat, id))return HAM_SUPERCEDE
  747.    
  748.     g_Clip[id] = -1
  749.        
  750.     static BPAmmo; BPAmmo = cs_get_user_bpammo(id, CSW_M134V)
  751.     static iClip; iClip = get_pdata_int(ent, 51, 4)
  752.        
  753.     if(BPAmmo <= 0)return HAM_SUPERCEDE
  754.     if(iClip >= CLIP)return HAM_SUPERCEDE      
  755.            
  756.     g_Clip[id] = iClip 
  757.    
  758.     return HAM_HANDLED
  759. }
  760. public fw_Weapon_Reload_Post(ent){
  761.     static id; id = pev(ent, pev_owner)
  762.     if(!is_user_alive(id))return HAM_IGNORED
  763.     if(!Get_BitVar(g_Had_M134V, id))return HAM_IGNORED 
  764.     if(Get_BitVar(g_OverHeat, id))return HAM_SUPERCEDE
  765.    
  766.     if((get_pdata_int(ent, 54, 4) == 1)){
  767.         if(g_Clip[id] == -1)return HAM_IGNORED
  768.        
  769.         set_pdata_int(ent, 51, g_Clip[id], 4)
  770.         Set_WeaponAnim(id, ANIME_RELOAD)
  771.        
  772.         Set_PlayerNextAttack(id, TIME_RELOAD)
  773.     }
  774.    
  775.     return HAM_HANDLED
  776. }
  777. public fw_Weapon_WeaponIdle_Post( iEnt ){
  778.     if(pev_valid(iEnt) != 2)return
  779.     static Id; Id = get_pdata_cbase(iEnt, 41, 4)
  780.     if(get_pdata_cbase(Id, 373) != iEnt)return
  781.     if(!Get_BitVar(g_Had_M134V, Id))return
  782.        
  783.     if(get_pdata_float(iEnt, 48, 4) <= 0.25){
  784.         if(!Get_BitVar(g_OverHeat, Id)) Set_WeaponAnim(Id, ANIME_IDLE)
  785.         else Set_WeaponAnim(Id, ANIME_OH_IDLE)
  786.         set_pdata_float(iEnt, 48, 20.0, 4)
  787.     }  
  788. }
  789. public fw_TraceAttack_World(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits){
  790.     if(!is_connected(Attacker))return HAM_IGNORED  
  791.     if(get_player_weapon(Attacker) != CSW_M134V || !Get_BitVar(g_Had_M134V, Attacker))return HAM_IGNORED
  792.        
  793.     static Float:flEnd[3], Float:vecPlane[3]
  794.        
  795.     get_tr2(Ptr, TR_vecEndPos, flEnd)
  796.     get_tr2(Ptr, TR_vecPlaneNormal, vecPlane)      
  797.            
  798.     Make_BulletHole(Attacker, flEnd, Damage)
  799.    
  800.     static Float:WallVector[3];get_tr2(Ptr,TR_vecPlaneNormal,WallVector)
  801.            
  802.     engfunc(EngFunc_MessageBegin,MSG_PVS,SVC_TEMPENTITY,flEnd,0);
  803.     write_byte(TE_STREAK_SPLASH)
  804.     engfunc(EngFunc_WriteCoord,flEnd[0]);
  805.     engfunc(EngFunc_WriteCoord,flEnd[1]);
  806.     engfunc(EngFunc_WriteCoord,flEnd[2]);
  807.     engfunc(EngFunc_WriteCoord,WallVector[0]*random_float(25.0,30.0));
  808.     engfunc(EngFunc_WriteCoord,WallVector[1]*random_float(25.0,30.0));
  809.     engfunc(EngFunc_WriteCoord,WallVector[2]*random_float(25.0,30.0));
  810.     write_byte(111)
  811.     write_short(12)
  812.     write_short(3)
  813.     write_short(75)
  814.     message_end()
  815.  
  816.     SetHamParamFloat(3, float(DAMAGE))
  817.    
  818.     return HAM_HANDLED
  819. }
  820. public fw_TraceAttack_Player(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits){
  821.     if(!is_connected(Attacker))return HAM_IGNORED  
  822.     if(get_player_weapon(Attacker) != CSW_M134V || !Get_BitVar(g_Had_M134V, Attacker))return HAM_IGNORED
  823.  
  824.     SetHamParamFloat(3, float(DAMAGE))
  825.    
  826.     return HAM_HANDLED
  827. }
  828. public Create_FakeAttack(id){
  829.     static Ent; Ent = fm_get_user_weapon_entity(id, CSW_KNIFE)
  830.     if(!pev_valid(Ent)) return
  831.    
  832.     Set_BitVar(g_InTempingAttack, id)
  833.     ExecuteHamB(Ham_Weapon_PrimaryAttack, Ent)
  834.     static iAnimDesired,  szAnimation[64]
  835.     formatex(szAnimation, charsmax(szAnimation), (pev(id, pev_flags) & FL_DUCKING) ? "crouch_shoot_%s" : "ref_shoot_%s", WEAPON_ANIMEXT)
  836.     if((iAnimDesired = lookup_sequence(id, szAnimation)) == -1)
  837.         iAnimDesired = 0
  838.     set_pev(id, pev_sequence, iAnimDesired)
  839.     UnSet_BitVar(g_InTempingAttack, id)
  840. }
  841. public Register_SafetyFunc(){
  842.     register_event("CurWeapon", "Safety_CurWeapon", "be", "1=1")
  843.     RegisterHam(Ham_Spawn, "player", "fw_Safety_Spawn_Post", 1)
  844.     RegisterHam(Ham_Killed, "player", "fw_Safety_Killed_Post", 1)
  845. }
  846. public Register_SafetyFuncBot(id){
  847.     RegisterHamFromEntity(Ham_Spawn, id, "fw_Safety_Spawn_Post", 1)
  848.     RegisterHamFromEntity(Ham_Killed, id, "fw_Safety_Killed_Post", 1)
  849. }
  850. public Safety_Connected(id){
  851.     Set_BitVar(g_IsConnected, id)
  852.     UnSet_BitVar(g_IsAlive, id)
  853.    
  854.     g_PlayerWeapon[id] = 0
  855. }
  856. public Safety_Disconnected(id){
  857.     UnSet_BitVar(g_IsConnected, id)
  858.     UnSet_BitVar(g_IsAlive, id)
  859.    
  860.     g_PlayerWeapon[id] = 0
  861. }
  862. public Safety_CurWeapon(id){
  863.     if(!is_alive(id))return
  864.        
  865.     static CSW; CSW = read_data(2)
  866.     if(g_PlayerWeapon[id] != CSW) g_PlayerWeapon[id] = CSW
  867. }
  868. public fw_Safety_Spawn_Post(id){
  869.     if(!is_user_alive(id))return
  870.        
  871.     Set_BitVar(g_IsAlive, id)
  872. }
  873. public fw_Safety_Killed_Post(id){
  874.     UnSet_BitVar(g_IsAlive, id)
  875. }
  876. public is_alive(id){
  877.     if(!(1 <= id <= 32))return 0
  878.     if(!Get_BitVar(g_IsConnected, id))return 0
  879.     if(!Get_BitVar(g_IsAlive, id))return 0
  880.    
  881.     return 1
  882. }
  883. public is_connected(id){
  884.     if(!(1 <= id <= 32))return 0
  885.     if(!Get_BitVar(g_IsConnected, id))return 0
  886.    
  887.     return 1
  888. }
  889. public get_player_weapon(id){
  890.     if(!is_alive(id))return 0
  891.     return g_PlayerWeapon[id]
  892. }
  893. stock Set_WeaponAnim(id, anim){
  894.     set_pev(id, pev_weaponanim, anim)
  895.     message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
  896.     write_byte(anim)
  897.     write_byte(pev(id, pev_body))
  898.     message_end()
  899. }
  900. stock Make_BulletHole(id, Float:Origin[3], Float:Damage){
  901.     static Decal; Decal = random_num(41, 45)
  902.     static LoopTime;
  903.    
  904.     if(Damage > 100.0) LoopTime = 2
  905.     else LoopTime = 1
  906.    
  907.     for(new i = 0; i < LoopTime; i++){
  908.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  909.         write_byte(TE_WORLDDECAL)
  910.         engfunc(EngFunc_WriteCoord, Origin[0])
  911.         engfunc(EngFunc_WriteCoord, Origin[1])
  912.         engfunc(EngFunc_WriteCoord, Origin[2])
  913.         write_byte(Decal)
  914.         message_end()
  915.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  916.         write_byte(TE_GUNSHOTDECAL)
  917.         engfunc(EngFunc_WriteCoord, Origin[0])
  918.         engfunc(EngFunc_WriteCoord, Origin[1])
  919.         engfunc(EngFunc_WriteCoord, Origin[2])
  920.         write_short(id)
  921.         write_byte(Decal)
  922.         message_end()
  923.     }
  924. }
  925. stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0){
  926.     static Float:vfEnd[3], viEnd[3]
  927.     get_user_origin(id, viEnd, 3)  
  928.     IVecFVec(viEnd, vfEnd)
  929.    
  930.     static Float:fOrigin[3], Float:fAngle[3]
  931.    
  932.     pev(id, pev_origin, fOrigin)
  933.     pev(id, pev_view_ofs, fAngle)
  934.    
  935.     xs_vec_add(fOrigin, fAngle, fOrigin)
  936.    
  937.     static Float:fAttack[3]
  938.    
  939.     xs_vec_sub(vfEnd, fOrigin, fAttack)
  940.     xs_vec_sub(vfEnd, fOrigin, fAttack)
  941.    
  942.     static Float:fRate
  943.    
  944.     fRate = fDis / vector_length(fAttack)
  945.     xs_vec_mul_scalar(fAttack, fRate, fAttack)
  946.    
  947.     xs_vec_add(fOrigin, fAttack, output)
  948. }
  949. stock get_position(id,Float:forw, Float:right, Float:up, Float:vStart[]){
  950.     new Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
  951.    
  952.     pev(id, pev_origin, vOrigin)
  953.     pev(id, pev_view_ofs,vUp)
  954.     xs_vec_add(vOrigin,vUp,vOrigin)
  955.     pev(id, pev_v_angle, vAngle)
  956.    
  957.     angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward)
  958.     angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
  959.     angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
  960.    
  961.     vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
  962.     vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
  963.     vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
  964. }
  965. stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3]){
  966.     new_velocity[0] = origin2[0] - origin1[0]
  967.     new_velocity[1] = origin2[1] - origin1[1]
  968.     new_velocity[2] = origin2[2] - origin1[2]
  969.     new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
  970.     new_velocity[0] *= num
  971.     new_velocity[1] *= num
  972.     new_velocity[2] *= num
  973.    
  974.     return 1;
  975. }
  976. stock Set_WeaponIdleTime(id, WeaponId ,Float:TimeIdle){
  977.     static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
  978.     if(!pev_valid(entwpn)) return
  979.        
  980.     set_pdata_float(entwpn, 46, TimeIdle, 4)
  981.     set_pdata_float(entwpn, 47, TimeIdle, 4)
  982.     set_pdata_float(entwpn, 48, TimeIdle + 0.5, 4)
  983. }
  984. stock Set_PlayerNextAttack(id, Float:nexttime){
  985.     set_pdata_float(id, 83, nexttime, 5)
  986. }
  987. stock Get_Position(id,Float:forw, Float:right, Float:up, Float:vStart[]){
  988.     static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
  989.    
  990.     pev(id, pev_origin, vOrigin)
  991.     pev(id, pev_view_ofs,vUp)
  992.     xs_vec_add(vOrigin,vUp,vOrigin)
  993.     pev(id, pev_v_angle, vAngle)
  994.    
  995.     angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward)
  996.     angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
  997.     angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
  998.    
  999.     vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
  1000.     vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
  1001.     vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
  1002. }
  1003. stock is_wall_between_points(Float:start[3], Float:end[3], ignore_ent){
  1004.     static ptr
  1005.     ptr = create_tr2()
  1006.  
  1007.     engfunc(EngFunc_TraceLine, start, end, IGNORE_MONSTERS, ignore_ent, ptr)
  1008.    
  1009.     static Float:EndPos[3]
  1010.     get_tr2(ptr, TR_vecEndPos, EndPos)
  1011.  
  1012.     free_tr2(ptr)
  1013.     return floatround(get_distance_f(end, EndPos))
  1014. }
  1015. do_attack(Attacker, Victim, Inflictor, Float:fDamage){
  1016.     fake_player_trace_attack(Attacker, Victim, fDamage)
  1017.     fake_take_damage(Attacker, Victim, fDamage, Inflictor)
  1018. }
  1019. fake_player_trace_attack(iAttacker, iVictim, &Float:fDamage){
  1020.     static Float:fAngles[3], Float:fDirection[3]
  1021.     pev(iAttacker, pev_angles, fAngles)
  1022.     angle_vector(fAngles, ANGLEVECTOR_FORWARD, fDirection)
  1023.    
  1024.     static Float:fStart[3], Float:fViewOfs[3]
  1025.     pev(iAttacker, pev_origin, fStart)
  1026.     pev(iAttacker, pev_view_ofs, fViewOfs)
  1027.     xs_vec_add(fViewOfs, fStart, fStart)
  1028.    
  1029.     static iAimOrigin[3], Float:fAimOrigin[3]
  1030.     get_user_origin(iAttacker, iAimOrigin, 3)
  1031.     IVecFVec(iAimOrigin, fAimOrigin)
  1032.    
  1033.     static ptr; ptr = create_tr2()
  1034.     engfunc(EngFunc_TraceLine, fStart, fAimOrigin, DONT_IGNORE_MONSTERS, iAttacker, ptr)
  1035.     static pHit; pHit = get_tr2(ptr, TR_pHit)
  1036.     static iHitgroup; iHitgroup = get_tr2(ptr, TR_iHitgroup)
  1037.     static Float:fEndPos[3]; get_tr2(ptr, TR_vecEndPos, fEndPos)
  1038.  
  1039.     static iTarget, iBody
  1040.     get_user_aiming(iAttacker, iTarget, iBody)
  1041.    
  1042.     if (iTarget == iVictim)iHitgroup = iBody
  1043.    
  1044.     else if (pHit != iVictim){
  1045.         static Float:fVicOrigin[3], Float:fVicViewOfs[3], Float:fAimInVictim[3]
  1046.         pev(iVictim, pev_origin, fVicOrigin)
  1047.         pev(iVictim, pev_view_ofs, fVicViewOfs)
  1048.         xs_vec_add(fVicViewOfs, fVicOrigin, fAimInVictim)
  1049.         fAimInVictim[2] = fStart[2]
  1050.         fAimInVictim[2] += get_distance_f(fStart, fAimInVictim) * floattan( fAngles[0] * 2.0, degrees )
  1051.    
  1052.         static iAngleToVictim; iAngleToVictim = get_angle_to_target(iAttacker, fVicOrigin)
  1053.         iAngleToVictim = abs(iAngleToVictim)
  1054.         static Float:fDis; fDis = 2.0 * get_distance_f(fStart, fAimInVictim) * floatsin( float(iAngleToVictim) * 0.5, degrees )
  1055.         static Float:fVicSize[3]
  1056.         pev(iVictim, pev_size , fVicSize)
  1057.         if ( fDis <= fVicSize[0] * 0.5 ){
  1058.             static ptr2; ptr2 = create_tr2()
  1059.             engfunc(EngFunc_TraceLine, fStart, fAimInVictim, DONT_IGNORE_MONSTERS, iAttacker, ptr2)
  1060.             static pHit2; pHit2 = get_tr2(ptr2, TR_pHit)
  1061.             static iHitgroup2; iHitgroup2 = get_tr2(ptr2, TR_iHitgroup)
  1062.            
  1063.             if ( pHit2 == iVictim && (iHitgroup2 != HIT_HEAD || fDis <= fVicSize[0] * 0.25) ){
  1064.                 pHit = iVictim
  1065.                 iHitgroup = iHitgroup2
  1066.                 get_tr2(ptr2, TR_vecEndPos, fEndPos)
  1067.             }
  1068.            
  1069.             free_tr2(ptr2)
  1070.         }
  1071.        
  1072.         if (pHit != iVictim){
  1073.             iHitgroup = HIT_GENERIC
  1074.            
  1075.             new ptr3 = create_tr2()
  1076.             engfunc(EngFunc_TraceLine, fStart, fVicOrigin, DONT_IGNORE_MONSTERS, iAttacker, ptr3)
  1077.             get_tr2(ptr3, TR_vecEndPos, fEndPos)
  1078.            
  1079.             free_tr2(ptr3)
  1080.         }
  1081.     }
  1082.    
  1083.     set_tr2(ptr, TR_pHit, iVictim)
  1084.     set_tr2(ptr, TR_iHitgroup, iHitgroup)
  1085.     set_tr2(ptr, TR_vecEndPos, fEndPos)
  1086.    
  1087.     if(cs_get_user_team(iVictim) != cs_get_user_team(iAttacker)) create_blood(fEndPos)
  1088.    
  1089.     static Float:fMultifDamage
  1090.     switch(iHitgroup){
  1091.         case HIT_HEAD: fMultifDamage  = 4.0
  1092.         case HIT_STOMACH: fMultifDamage  = 1.25
  1093.         case HIT_LEFTLEG: fMultifDamage  = 0.75
  1094.         case HIT_RIGHTLEG: fMultifDamage  = 0.75
  1095.         default: fMultifDamage  = 1.0
  1096.     }
  1097.    
  1098.     fDamage *= fMultifDamage
  1099.    
  1100.     fake_trake_attack(iAttacker, iVictim, fDamage, fDirection, ptr)
  1101.     free_tr2(ptr)
  1102. }
  1103. stock create_blood(const Float:origin[3]){
  1104.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  1105.     write_byte(TE_BLOODSPRITE)
  1106.     engfunc(EngFunc_WriteCoord, origin[0])
  1107.     engfunc(EngFunc_WriteCoord, origin[1])
  1108.     engfunc(EngFunc_WriteCoord, origin[2])
  1109.     write_short(m_iBlood[1])
  1110.     write_short(m_iBlood[0])
  1111.     write_byte(75)
  1112.     write_byte(5)
  1113.     message_end()
  1114. }
  1115. stock fake_trake_attack(iAttacker, iVictim, Float:fDamage, Float:fDirection[3], iTraceHandle, iDamageBit = (DMG_NEVERGIB | DMG_BULLET)){
  1116.     ExecuteHamB(Ham_TraceAttack, iVictim, iAttacker, fDamage, fDirection, iTraceHandle, iDamageBit)
  1117. }
  1118. stock fake_take_damage(iAttacker, iVictim, Float:fDamage, iInflictor = 0, iDamageBit = (DMG_NEVERGIB | DMG_BULLET)){
  1119.     ExecuteHamB(Ham_TakeDamage, iVictim, iInflictor, iAttacker, fDamage, iDamageBit)
  1120. }
  1121. stock get_angle_to_target(id, const Float:fTarget[3], Float:TargetSize = 0.0){
  1122.     new Float:fOrigin[3], iAimOrigin[3], Float:fAimOrigin[3], Float:fV1[3]
  1123.     pev(id, pev_origin, fOrigin)
  1124.     get_user_origin(id, iAimOrigin, 3)
  1125.     IVecFVec(iAimOrigin, fAimOrigin)
  1126.     xs_vec_sub(fAimOrigin, fOrigin, fV1)
  1127.     new Float:fV2[3]
  1128.     xs_vec_sub(fTarget, fOrigin, fV2)
  1129.     new iResult = get_angle_between_vectors(fV1, fV2)
  1130.     if (TargetSize > 0.0){
  1131.         new Float:fTan = TargetSize / get_distance_f(fOrigin, fTarget)
  1132.         new fAngleToTargetSize = floatround( floatatan(fTan, degrees) )
  1133.         iResult -= (iResult > 0) ? fAngleToTargetSize : -fAngleToTargetSize
  1134.     }
  1135.    
  1136.     return iResult
  1137. }
  1138. stock get_angle_between_vectors(const Float:fV1[3], const Float:fV2[3]){
  1139.     new Float:fA1[3], Float:fA2[3]
  1140.     engfunc(EngFunc_VecToAngles, fV1, fA1)
  1141.     engfunc(EngFunc_VecToAngles, fV2, fA2)
  1142.    
  1143.     new iResult = floatround(fA1[1] - fA2[1])
  1144.     iResult = iResult % 360
  1145.     iResult = (iResult > 180) ? (iResult - 360) : iResult
  1146.    
  1147.     return iResult
  1148. }
  1149. stock make_bullet(id, Float:Origin[3]){
  1150.     new decal = random_num(41, 45)
  1151.     const loop_time = 2
  1152.    
  1153.     for(new i = 0; i < loop_time; i++){
  1154.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  1155.         write_byte(TE_WORLDDECAL)
  1156.         engfunc(EngFunc_WriteCoord, Origin[0])
  1157.         engfunc(EngFunc_WriteCoord, Origin[1])
  1158.         engfunc(EngFunc_WriteCoord, Origin[2])
  1159.         write_byte(decal)
  1160.         message_end()
  1161.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  1162.         write_byte(TE_GUNSHOTDECAL)
  1163.         engfunc(EngFunc_WriteCoord, Origin[0])
  1164.         engfunc(EngFunc_WriteCoord, Origin[1])
  1165.         engfunc(EngFunc_WriteCoord, Origin[2])
  1166.         write_short(id)
  1167.         write_byte(decal)
  1168.         message_end()
  1169.     }
  1170. }
  1171. stock Get_SpeedVector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3]){
  1172.     new_velocity[0] = origin2[0] - origin1[0]
  1173.     new_velocity[1] = origin2[1] - origin1[1]
  1174.     new_velocity[2] = origin2[2] - origin1[2]
  1175.     new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
  1176.     new_velocity[0] *= (num * 2.0)
  1177.     new_velocity[1] *= (num * 2.0)
  1178.     new_velocity[2] *= (num / 2.0)
  1179. }  
  1180. stock Eject_Shell(id, Shell_ModelIndex, Float:Time){
  1181.     static Ent; Ent = get_pdata_cbase(id, 373, 5)
  1182.     if(!pev_valid(Ent))return
  1183.  
  1184.         set_pdata_int(Ent, 57, Shell_ModelIndex, 4)
  1185.         set_pdata_float(id, 111, get_gametime() + Time)
  1186. }
  1187. public Eject_Shell2(id, ShellID, Right){
  1188.     static Float:player_origin[3], Float:origin[3], Float:origin2[3], Float:gunorigin[3], Float:oldangles[3], Float:v_forward[3], Float:v_forward2[3], Float:v_up[3], Float:v_up2[3], Float:v_right[3], Float:v_right2[3], Float:viewoffsets[3];
  1189.    
  1190.     pev(id,pev_v_angle, oldangles); pev(id,pev_origin,player_origin); pev(id, pev_view_ofs, viewoffsets);
  1191.  
  1192.     engfunc(EngFunc_MakeVectors, oldangles)
  1193.    
  1194.     global_get(glb_v_forward, v_forward); global_get(glb_v_up, v_up); global_get(glb_v_right, v_right);
  1195.     global_get(glb_v_forward, v_forward2); global_get(glb_v_up, v_up2); global_get(glb_v_right, v_right2);
  1196.    
  1197.     xs_vec_add(player_origin, viewoffsets, gunorigin);
  1198.    
  1199.     if(!Right){
  1200.         xs_vec_mul_scalar(v_forward, 20.0, v_forward); xs_vec_mul_scalar(v_right, -2.5, v_right);
  1201.         xs_vec_mul_scalar(v_up, -1.5, v_up);
  1202.         xs_vec_mul_scalar(v_forward2, 19.9, v_forward2); xs_vec_mul_scalar(v_right2, -2.0, v_right2);
  1203.         xs_vec_mul_scalar(v_up2, -2.0, v_up2);
  1204.     }
  1205.     else {
  1206.         xs_vec_mul_scalar(v_forward, 20.0, v_forward); xs_vec_mul_scalar(v_right, 2.5, v_right);
  1207.         xs_vec_mul_scalar(v_up, -1.5, v_up);
  1208.         xs_vec_mul_scalar(v_forward2, 19.9, v_forward2); xs_vec_mul_scalar(v_right2, 2.0, v_right2);
  1209.         xs_vec_mul_scalar(v_up2, -2.0, v_up2);
  1210.     }
  1211.    
  1212.     xs_vec_add(gunorigin, v_forward, origin);
  1213.     xs_vec_add(gunorigin, v_forward2, origin2);
  1214.     xs_vec_add(origin, v_right, origin);
  1215.     xs_vec_add(origin2, v_right2, origin2);
  1216.     xs_vec_add(origin, v_up, origin);
  1217.     xs_vec_add(origin2, v_up2, origin2);
  1218.  
  1219.     static Float:velocity[3]
  1220.     get_speed_vector(origin2, origin, random_float(140.0, 160.0), velocity)
  1221.  
  1222.     static angle; angle = random_num(0, 360)
  1223.  
  1224.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  1225.     write_byte(TE_MODEL)
  1226.     engfunc(EngFunc_WriteCoord, origin[0])
  1227.     engfunc(EngFunc_WriteCoord, origin[1])
  1228.     engfunc(EngFunc_WriteCoord, origin[2] - 16.0)
  1229.     engfunc(EngFunc_WriteCoord,velocity[0])
  1230.     engfunc(EngFunc_WriteCoord,velocity[1])
  1231.     engfunc(EngFunc_WriteCoord,velocity[2])
  1232.     write_angle(angle)
  1233.     write_short(ShellID)
  1234.     write_byte(1)
  1235.     write_byte(20)
  1236.     message_end()
  1237. }
  1238. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  1239. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1049\\ f0\\ fs16 \n\\ par }
  1240. */

Re: minigun

Posted: 02 Aug 2019, 17:21
by Raheem
Try:
    1. #include <zombie_escape>
    2. #include <engine>
    3. #include <fakemeta_util>
    4. #include <cstrike>
    5. #include <xs>
    6. #include <fun>
    7.  
    8. #define MODEL_V "models/addons/v_m134_vulcan.mdl"
    9. #define MODEL_P "models/addons/p_m134_vulcan.mdl"
    10. #define MODEL_W "models/addons/w_m134_vulcan.mdl"
    11.  
    12. #define MUZZLEFLASH "sprites/addons/m134_vulcan_muzzle2.spr"
    13. #define MUZZLEFLASH2 "sprites/addons/m134_vulcan_muzzle1.spr"
    14.  
    15. #define DAMAGE 80
    16. #define CLIP 100
    17. #define BPAMMO 200
    18.  
    19. #define SPEED_A 0.04
    20. #define SPEED_B 0.02
    21. #define TIME_RELOAD 5.0
    22.  
    23. #define CSW_M134V CSW_M249
    24. #define weapon_m134v "weapon_m249"
    25. #define WEAPON_ANIMEXT "m249"
    26.  
    27. new const WeaponSounds[11][] =
    28. {
    29.     "weapons/m134ex-1.wav",
    30.     "weapons/m134_clipoff.wav",
    31.     "weapons/m134_clipon.wav",
    32.     "weapons/m134ex_spin.wav",
    33.     "weapons/m134hero_draw.wav",
    34.     "weapons/m134hero_fire_after_overheat.wav",
    35.     "weapons/m134hero_overheat_end.wav",
    36.     "weapons/m134hero_overload.wav",
    37.     "weapons/m134hero_spindown.wav",
    38.     "weapons/m134hero_spinup.wav",
    39.     "weapons/steam.wav"
    40. }
    41.  
    42. new const WeaponResources[3][] =
    43. {
    44.     "sprites/weapon_m134_vulcan.txt",
    45.     "sprites/addons/m134_vulcan_weapon1.spr",
    46.     "sprites/addons/m134_vulcan_ammo1.spr"
    47. }
    48.  
    49. new const Steam[] = "sprites/addons/m134_vulcan_steam1.spr"
    50. new const Shell1[] = "models/addons/s_m134_vulcan_piston.mdl"
    51. new const Shell2[] = "models/addons/s_m134_vulcan_shell.mdl"
    52.  
    53. enum
    54. {
    55.     ANIME_IDLE = 0,
    56.     ANIME_DRAW,
    57.     ANIME_RELOAD,
    58.     ANIME_FIRE_START,
    59.     ANIME_FIRE_LOOP,
    60.     ANIME_FIRE_END,
    61.     ANIME_NANI1,
    62.     ANIME_NANI2,
    63.     ANIME_OH_DRAW,
    64.     ANIME_OH_START,
    65.     ANIME_OH_IDLE,
    66.     ANIME_OH_END,
    67.     ANIME_SFIRE_START,
    68.     ANIME_SFIRE_LOOP,
    69.     ANIME_SFIRE_END
    70. }
    71.  
    72. enum
    73. {
    74.     M134_ATTACK_NOT = 0,
    75.     M134_ATTACK_BEGIN,
    76.     M134_ATTACK_LOOP,
    77.     M134_ATTACK_END
    78. }
    79.  
    80. #define TASK_ATTACK 1972
    81. #define TASK_OVERHEAT 1973
    82.  
    83. #define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
    84. #define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
    85. #define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))
    86.  
    87. 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)
    88. const SECONDARY_WEAPONS_BIT_SUM = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)
    89. new g_Had_M134V, g_Clip[33], g_M134State[33], Float:g_SpeedControl[33], Float:g_AttackDelay[33], g_RapidMode
    90. new g_Event_M134V, m_iBlood[2], g_OverHeat, g_Fired, g_ShellID1, g_ShellID2
    91. new g_MsgWeaponList, g_MsgCurWeapon, g_SteamID, Float:SteamTime[33], FiringTime[33], g_InTempingAttack
    92. new g_Muzzleflash_Ent, g_Muzzleflash
    93. new g_Muzzleflash_Ent2, g_Muzzleflash2
    94. new g_IsConnected, g_IsAlive, g_PlayerWeapon[33]
    95.  
    96. public plugin_init(){
    97.     Register_SafetyFunc()
    98.     register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
    99.     register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
    100.     register_forward(FM_CmdStart, "fw_CmdStart")
    101.     register_forward(FM_EmitSound, "fw_EmitSound")
    102.     register_forward(FM_TraceLine, "fw_TraceLine")
    103.     register_forward(FM_TraceHull, "fw_TraceHull")
    104.     register_forward(FM_SetModel, "fw_SetModel")  
    105.     register_forward(FM_AddToFullPack, "fw_AddToFullPack_post", 1)
    106.     register_forward(FM_CheckVisibility, "fw_CheckVisibility")
    107.    
    108.     RegisterHam(Ham_Item_Deploy, weapon_m134v, "fw_Item_Deploy_Post", 1)  
    109.     RegisterHam(Ham_Item_AddToPlayer, weapon_m134v, "fw_Item_AddToPlayer_Post", 1)
    110.     RegisterHam(Ham_Weapon_WeaponIdle, weapon_m134v, "fw_Weapon_WeaponIdle_Post", 1)
    111.     RegisterHam(Ham_Item_PostFrame, weapon_m134v, "fw_Item_PostFrame")
    112.     RegisterHam(Ham_Weapon_Reload, weapon_m134v, "fw_Weapon_Reload")
    113.     RegisterHam(Ham_Weapon_Reload, weapon_m134v, "fw_Weapon_Reload_Post", 1)  
    114.     RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
    115.     RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")
    116.  
    117.     g_MsgCurWeapon = get_user_msgid("CurWeapon")
    118.     g_MsgWeaponList = get_user_msgid("WeaponList")
    119.    
    120. }
    121. public plugin_precache(){
    122.     precache_model(MODEL_V)
    123.     precache_model(MODEL_P)
    124.     precache_model(MODEL_W)
    125.     for(new i = 0; i < sizeof(WeaponSounds); i++)precache_sound(WeaponSounds[i])
    126.    
    127.     precache_generic(WeaponResources[0])
    128.     precache_model(WeaponResources[1])
    129.     precache_model(WeaponResources[2])
    130.     g_SteamID = precache_model(Steam)
    131.     m_iBlood[0] = precache_model("sprites/blood.spr")
    132.     m_iBlood[1] = precache_model("sprites/bloodspray.spr")
    133.     register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
    134.     g_ShellID1 = precache_model(Shell1)
    135.     g_ShellID2 = precache_model(Shell2)
    136.    
    137.     g_Muzzleflash_Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
    138.    
    139.     precache_model(MUZZLEFLASH)
    140.     engfunc(EngFunc_SetModel, g_Muzzleflash_Ent, MUZZLEFLASH)
    141.     set_pev(g_Muzzleflash_Ent, pev_scale, 0.2)
    142.    
    143.     set_pev(g_Muzzleflash_Ent, pev_rendermode, kRenderTransTexture)
    144.     set_pev(g_Muzzleflash_Ent, pev_renderamt, 0.0)
    145.  
    146.     g_Muzzleflash_Ent2 = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
    147.    
    148.     precache_model(MUZZLEFLASH2)
    149.     engfunc(EngFunc_SetModel, g_Muzzleflash_Ent2, MUZZLEFLASH2)
    150.     set_pev(g_Muzzleflash_Ent2, pev_scale, 0.2)
    151.    
    152.     set_pev(g_Muzzleflash_Ent2, pev_rendermode, kRenderTransTexture)
    153.     set_pev(g_Muzzleflash_Ent2, pev_renderamt, 0.0)
    154. }
    155. public fw_PrecacheEvent_Post(type, const name[]){
    156.     if(equal("events/m249.sc", name)) g_Event_M134V = get_orig_retval()    
    157. }
    158. public Hook_Weapon(id){
    159.     engclient_cmd(id, weapon_m134v)
    160.     return PLUGIN_HANDLED
    161. }
    162. public client_putinserver(id){
    163.     Safety_Connected(id)
    164. }
    165. public client_disconnected(id){
    166.     Safety_Disconnected(id)
    167. }
    168. public plugin_natives ()
    169. {
    170.     register_native("Get_M134V", "native_Get_M134V", 1)
    171. }
    172. public native_Get_M134V(id)
    173. {
    174.     Get_M134V(id)
    175. }
    176.  
    177. stock drop_weapons(id, dropwhat){
    178.     static weapons[32], num, i, weaponid
    179.     num = 0
    180.     get_user_weapons(id, weapons, num)
    181.     for (i = 0; i < num; i++){
    182.         weaponid = weapons[i]
    183.         if ((dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM)) || (dropwhat == 2 && ((1<<weaponid) & SECONDARY_WEAPONS_BIT_SUM))){
    184.             static wname[32]; get_weaponname(weaponid, wname, charsmax(wname))
    185.             engclient_cmd(id, "drop", wname)
    186.         }
    187.     }
    188. }
    189. public Get_M134V(id){
    190.     remove_task(id+TASK_OVERHEAT)
    191.    
    192.     drop_weapons(id, 1)
    193.    
    194.     UnSet_BitVar(g_InTempingAttack, id)
    195.     UnSet_BitVar(g_Fired, id)
    196.     UnSet_BitVar(g_OverHeat, id)
    197.     UnSet_BitVar(g_RapidMode, id)
    198.     g_M134State[id] = M134_ATTACK_NOT
    199.     FiringTime[id] = 0
    200.    
    201.     Set_BitVar(g_Had_M134V, id)
    202.     give_item(id, weapon_m134v)
    203.    
    204.     static Ent; Ent = fm_get_user_weapon_entity(id, CSW_M134V)
    205.     if(!pev_valid(Ent)) return
    206.    
    207.     cs_set_weapon_ammo(Ent, CLIP)
    208.     cs_set_user_bpammo(id, CSW_M134V, BPAMMO)
    209.    
    210.     message_begin(MSG_ONE_UNRELIABLE, g_MsgCurWeapon, _, id)
    211.     write_byte(1)
    212.     write_byte(CSW_M134V)
    213.     write_byte(CLIP)
    214.     message_end()
    215. }
    216. public Remove_M134V(id){
    217.     UnSet_BitVar(g_InTempingAttack, id)
    218.     UnSet_BitVar(g_Had_M134V, id)
    219.     UnSet_BitVar(g_OverHeat, id)
    220.     UnSet_BitVar(g_RapidMode, id)
    221.    
    222.     remove_task(id+TASK_OVERHEAT)
    223. }
    224. public fw_AddToFullPack_post(esState, iE, iEnt, iHost, iHostFlags, iPlayer, pSet){
    225.     if(iEnt == g_Muzzleflash_Ent){
    226.         if(Get_BitVar(g_Muzzleflash, iHost)){
    227.             set_es(esState, ES_Frame, float(random_num(0, 2)))
    228.                
    229.             set_es(esState, ES_RenderMode, kRenderTransAdd)
    230.             set_es(esState, ES_RenderAmt, 255.0)
    231.            
    232.             UnSet_BitVar(g_Muzzleflash, iHost)
    233.         }  
    234.         set_es(esState, ES_Skin, iHost)
    235.         set_es(esState, ES_Body, 1)
    236.         set_es(esState, ES_AimEnt, iHost)
    237.         set_es(esState, ES_MoveType, MOVETYPE_FOLLOW)
    238.     }
    239.     if(iEnt == g_Muzzleflash_Ent2){
    240.         if(Get_BitVar(g_Muzzleflash2, iHost)){
    241.             set_es(esState, ES_Frame, float(random_num(0, 2)))
    242.                
    243.             set_es(esState, ES_RenderMode, kRenderTransAdd)
    244.             set_es(esState, ES_RenderAmt, 255.0)
    245.            
    246.             UnSet_BitVar(g_Muzzleflash2, iHost)
    247.         }
    248.            
    249.         set_es(esState, ES_Skin, iHost)
    250.         set_es(esState, ES_Body, 1)
    251.         set_es(esState, ES_AimEnt, iHost)
    252.         set_es(esState, ES_MoveType, MOVETYPE_FOLLOW)
    253.     }
    254. }
    255. public fw_CheckVisibility(iEntity, pSet){
    256.     if(iEntity == g_Muzzleflash_Ent){
    257.         forward_return(FMV_CELL, 1)
    258.         return FMRES_SUPERCEDE
    259.     }
    260.     else if(iEntity == g_Muzzleflash_Ent2) {
    261.         forward_return(FMV_CELL, 1)
    262.         return FMRES_SUPERCEDE
    263.     }
    264.     return FMRES_IGNORED
    265. }
    266. public fw_EmitSound(id, channel, const sample[], Float:volume, Float:attn, flags, pitch){
    267.     if(!is_connected(id))return FMRES_IGNORED
    268.     if(!Get_BitVar(g_InTempingAttack, id))return FMRES_IGNORED
    269.        
    270.     if(sample[8] == 'k' && sample[9] == 'n' && sample[10] == 'i'){
    271.         if(sample[14] == 's' && sample[15] == 'l' && sample[16] == 'a')return FMRES_SUPERCEDE
    272.         if (sample[14] == 'h' && sample[15] == 'i' && sample[16] == 't'){
    273.             if (sample[17] == 'w')  return FMRES_SUPERCEDE
    274.             else  return FMRES_SUPERCEDE
    275.         }
    276.         if (sample[14] == 's' && sample[15] == 't' && sample[16] == 'a')return FMRES_SUPERCEDE;
    277.     }
    278.     return FMRES_IGNORED
    279. }
    280. public fw_TraceLine(Float:vector_start[3], Float:vector_end[3], ignored_monster, id, handle){
    281.     if(!is_alive(id))return FMRES_IGNORED  
    282.     if(!Get_BitVar(g_InTempingAttack, id))return FMRES_IGNORED
    283.    
    284.     static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
    285.    
    286.     pev(id, pev_origin, fOrigin)
    287.     pev(id, pev_view_ofs, view_ofs)
    288.     xs_vec_add(fOrigin, view_ofs, vecStart)
    289.     pev(id, pev_v_angle, v_angle)
    290.    
    291.     engfunc(EngFunc_MakeVectors, v_angle)
    292.     get_global_vector(GL_v_forward, v_forward)
    293.  
    294.     xs_vec_mul_scalar(v_forward, 0.0, v_forward)
    295.     xs_vec_add(vecStart, v_forward, vecEnd)
    296.    
    297.     engfunc(EngFunc_TraceLine, vecStart, vecEnd, ignored_monster, id, handle)
    298.    
    299.     return FMRES_SUPERCEDE
    300. }
    301. public fw_TraceHull(Float:vector_start[3], Float:vector_end[3], ignored_monster, hull, id, handle){
    302.     if(!is_alive(id))return FMRES_IGNORED  
    303.     if(!Get_BitVar(g_InTempingAttack, id))return FMRES_IGNORED
    304.    
    305.     static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
    306.    
    307.     pev(id, pev_origin, fOrigin)
    308.     pev(id, pev_view_ofs, view_ofs)
    309.     xs_vec_add(fOrigin, view_ofs, vecStart)
    310.     pev(id, pev_v_angle, v_angle)
    311.    
    312.     engfunc(EngFunc_MakeVectors, v_angle)
    313.     get_global_vector(GL_v_forward, v_forward)
    314.    
    315.     xs_vec_mul_scalar(v_forward, 0.0, v_forward)
    316.     xs_vec_add(vecStart, v_forward, vecEnd)
    317.    
    318.     engfunc(EngFunc_TraceHull, vecStart, vecEnd, ignored_monster, hull, id, handle)
    319.    
    320.     return FMRES_SUPERCEDE
    321. }
    322. public fw_UpdateClientData_Post(id, sendweapons, cd_handle){
    323.     if(!is_alive(id))return FMRES_IGNORED  
    324.     if(get_player_weapon(id) == CSW_M134V && Get_BitVar(g_Had_M134V, id))set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001)
    325.     return FMRES_HANDLED
    326. }
    327. public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2){
    328.     if (!is_connected(invoker))return FMRES_IGNORED
    329.     if(get_player_weapon(invoker) != CSW_M134V || !Get_BitVar(g_Had_M134V, invoker))return FMRES_IGNORED
    330.        
    331.     if(eventid == g_Event_M134V){
    332.         engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
    333.         return FMRES_SUPERCEDE
    334.     }
    335.     return FMRES_IGNORED
    336. }
    337. public fw_CmdStart(id, uc_handle, seed){
    338.     if(!is_alive(id))return
    339.     if(get_player_weapon(id) != CSW_M134V || !Get_BitVar(g_Had_M134V, id))return
    340.    
    341.     static NewButton; NewButton = get_uc(uc_handle, UC_Buttons)
    342.     static Ent; Ent = fm_get_user_weapon_entity(id, CSW_M134V)
    343.    
    344.     if(!pev_valid(Ent))return
    345.        
    346.     if(NewButton & IN_ATTACK){
    347.         NewButton &= ~IN_ATTACK
    348.         set_uc(uc_handle, UC_Buttons, NewButton)
    349.  
    350.         if(get_pdata_float(id, 83, 5) > 0.0)return
    351.         if(Get_BitVar(g_OverHeat, id))return
    352.         if(cs_get_weapon_ammo(Ent) <= 0){
    353.             if(get_pdata_int(Ent, 54))return
    354.             set_pdata_int(Ent, 54, 1, 4)
    355.             ExecuteHamB(Ham_Weapon_Reload, Ent)
    356.             return
    357.         }
    358.         if(g_M134State[id] == M134_ATTACK_NOT){
    359.             g_M134State[id] = M134_ATTACK_BEGIN
    360.            
    361.             FiringTime[id] = 0
    362.             UnSet_BitVar(g_Fired, id)
    363.             UnSet_BitVar(g_RapidMode, id)
    364.         }
    365.         else if(g_M134State[id] == M134_ATTACK_BEGIN){
    366.             if(pev(id, pev_weaponanim) != ANIME_FIRE_END) Set_WeaponAnim(id, ANIME_FIRE_START)
    367.  
    368.             emit_sound(Ent, CHAN_WEAPON, WeaponSounds[9], 1.0, 0.52, 0, 94 + random_num(0, 15))
    369.            
    370.             Set_WeaponIdleTime(id, CSW_M134V, 0.2)
    371.             Set_PlayerNextAttack(id, 0.2)
    372.            
    373.             if(!task_exists(id+TASK_ATTACK)) set_task(0.15, "Task_ChangeState_Loop", id+TASK_ATTACK)
    374.         }
    375.         else if(g_M134State[id] == M134_ATTACK_LOOP) {
    376.             if(cs_get_weapon_ammo(Ent) > 0){
    377.                 if(!Get_BitVar(g_RapidMode, id)) Set_WeaponAnim(id, ANIME_FIRE_LOOP)
    378.                 else Set_WeaponAnim(id, ANIME_SFIRE_LOOP)
    379.                
    380.                 Set_WeaponIdleTime(id, CSW_M134V, 0.5)
    381.                 Set_PlayerNextAttack(id, 0.5)
    382.             }
    383.             else{
    384.                 g_M134State[id] = M134_ATTACK_END
    385.                 Set_WeaponAnim(id, ANIME_FIRE_END)
    386.                
    387.                 emit_sound(Ent, CHAN_WEAPON, WeaponSounds[8], 1.0, 0.52, 0, 94 + random_num(0, 15))
    388.                
    389.                 Set_WeaponIdleTime(id, CSW_M134V, 2.0)
    390.                 Set_PlayerNextAttack(id, 0.25)
    391.                
    392.                 remove_task(id+TASK_ATTACK)
    393.                 g_M134State[id] = M134_ATTACK_NOT  
    394.             }
    395.         }
    396.     }
    397.     else if(NewButton & IN_ATTACK2) {
    398.         NewButton &= ~IN_ATTACK2
    399.         set_uc(uc_handle, UC_Buttons, NewButton)
    400.  
    401.         if(get_pdata_float(id, 83, 5) > 0.0) return
    402.         if(Get_BitVar(g_OverHeat, id))return
    403.         if(cs_get_weapon_ammo(Ent) <= 0){
    404.             if(get_pdata_int(Ent, 54))return
    405.        
    406.             set_pdata_int(Ent, 54, 1, 4)
    407.             ExecuteHamB(Ham_Weapon_Reload, Ent)
    408.             return
    409.         }
    410.         if(g_M134State[id] == M134_ATTACK_NOT){
    411.             Set_BitVar(g_RapidMode, id)
    412.            
    413.             FiringTime[id] = 0
    414.             UnSet_BitVar(g_Fired, id)
    415.             g_M134State[id] = M134_ATTACK_BEGIN
    416.         }
    417.         else if(g_M134State[id] == M134_ATTACK_BEGIN) {
    418.             if(pev(id, pev_weaponanim) != ANIME_FIRE_END) Set_WeaponAnim(id, ANIME_SFIRE_START)
    419.  
    420.             emit_sound(Ent, CHAN_WEAPON, WeaponSounds[9], 1.0, 0.52, 0, 94 + random_num(0, 15))
    421.            
    422.             Set_WeaponIdleTime(id, CSW_M134V, 0.2)
    423.             Set_PlayerNextAttack(id, 0.2)
    424.            
    425.             if(!task_exists(id+TASK_ATTACK)) set_task(0.15, "Task_ChangeState_Loop", id+TASK_ATTACK)
    426.         }
    427.         else if(g_M134State[id] == M134_ATTACK_LOOP) {
    428.             if(cs_get_weapon_ammo(Ent) > 0){
    429.                 if(!Get_BitVar(g_RapidMode, id)) Set_WeaponAnim(id, ANIME_FIRE_LOOP)
    430.                 else Set_WeaponAnim(id, ANIME_SFIRE_LOOP)
    431.                
    432.                 Set_WeaponIdleTime(id, CSW_M134V, 0.5)
    433.                 Set_PlayerNextAttack(id, 0.5)
    434.             }
    435.             else {
    436.                 g_M134State[id] = M134_ATTACK_END
    437.                 emit_sound(Ent, CHAN_WEAPON, WeaponSounds[8], 1.0, 0.52, 0, 94 + random_num(0, 15))
    438.                
    439.                 Overheat_Begin(id)
    440.                
    441.                 remove_task(id+TASK_ATTACK)
    442.                 g_M134State[id] = M134_ATTACK_NOT  
    443.             }
    444.         }
    445.     }
    446.     else {
    447.         if(g_M134State[id] == M134_ATTACK_LOOP) {
    448.             g_M134State[id] = M134_ATTACK_END
    449.            
    450.             emit_sound(Ent, CHAN_WEAPON, WeaponSounds[8], 1.0, 0.52, 0, 94 + random_num(0, 15))
    451.            
    452.             Set_WeaponIdleTime(id, CSW_M134V, 2.0)
    453.             Set_PlayerNextAttack(id, 0.25)
    454.            
    455.             if(!Get_BitVar(g_RapidMode, id)) Set_WeaponAnim(id, ANIME_FIRE_END)
    456.             else Overheat_Begin(id)
    457.            
    458.             remove_task(id+TASK_ATTACK)
    459.             g_M134State[id] = M134_ATTACK_NOT
    460.         }
    461.     }
    462.    
    463.     if(NewButton & IN_RELOAD){
    464.         if(get_pdata_int(Ent, 54))return
    465.         if(Get_BitVar(g_OverHeat, id))return
    466.         if(cs_get_weapon_ammo(Ent) >= CLIP)return
    467.         if(get_pdata_float(id, 83, 5) > 0.0 || get_pdata_float(Ent, 46, 4) > 0.0 || get_pdata_float(Ent, 47, 4) > 0.0)return
    468.            
    469.         set_pdata_int(Ent, 54, 1, 4)
    470.         ExecuteHamB(Ham_Weapon_Reload, Ent)
    471.     }
    472. }
    473. public Overheat_Begin(id){
    474.     if(Get_BitVar(g_Fired, id)){
    475.         if(FiringTime[id] > 0){
    476.             Set_BitVar(g_OverHeat, id)
    477.            
    478.             SteamTime[id] = get_gametime() + 1.0
    479.            
    480.             Set_WeaponIdleTime(id, CSW_M134V, 2.0 + 1.0)
    481.             Set_PlayerNextAttack(id, float(FiringTime[id]) + 1.0)
    482.            
    483.             Set_WeaponAnim(id, ANIME_OH_START)
    484.            
    485.             remove_task(id+TASK_OVERHEAT)
    486.             set_task(float(FiringTime[id]) + 1.0, "Overheat_End", id+TASK_OVERHEAT)
    487.         }
    488.         else {
    489.             Set_WeaponIdleTime(id, CSW_M134V, 2.0)
    490.             Set_PlayerNextAttack(id, 0.25)
    491.            
    492.             Set_WeaponAnim(id, ANIME_SFIRE_END)
    493.         }
    494.     }
    495.     else {
    496.         Set_WeaponIdleTime(id, CSW_M134V, 2.0)
    497.         Set_PlayerNextAttack(id, 0.25)
    498.        
    499.         Set_WeaponAnim(id, ANIME_SFIRE_END)
    500.     }
    501. }
    502. public Overheat_End(id){
    503.     id -= TASK_OVERHEAT
    504.    
    505.     if(!is_alive(id))return
    506.        
    507.     UnSet_BitVar(g_OverHeat, id)
    508.    
    509.     if(get_player_weapon(id) != CSW_M134V || !Get_BitVar(g_Had_M134V, id))return
    510.        
    511.     Set_WeaponAnim(id, ANIME_OH_END)
    512.  
    513.     Set_WeaponIdleTime(id, CSW_M134V, 2.0)
    514.     Set_PlayerNextAttack(id, 2.0)
    515. }
    516. public client_PostThink(id){
    517.     if(!is_alive(id))return
    518.     if(get_player_weapon(id) != CSW_M134V || !Get_BitVar(g_Had_M134V, id))return
    519.     if(Get_BitVar(g_OverHeat, id)){
    520.         if(get_gametime() - 1.0 > SteamTime[id]){
    521.             static Float:Origin[3]
    522.             get_position(id, 20.0, 0.0, 0.0, Origin)
    523.            
    524.             message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    525.             write_byte(TE_SPRITE)
    526.             engfunc(EngFunc_WriteCoord, Origin[0])
    527.             engfunc(EngFunc_WriteCoord, Origin[1])
    528.             engfunc(EngFunc_WriteCoord, Origin[2])
    529.             write_short(g_SteamID)
    530.             write_byte(1)
    531.             write_byte(250)
    532.             message_end()
    533.            
    534.             emit_sound(id, CHAN_WEAPON, WeaponSounds[10], 1.0, 0.52, 0, 94 + random_num(0, 15))
    535.            
    536.             SteamTime[id] = get_gametime()
    537.         }
    538.     }
    539.     if(g_M134State[id] != M134_ATTACK_LOOP)return  
    540.        
    541.     static Float:DerSpeed; DerSpeed = Get_BitVar(g_RapidMode, id) ? SPEED_B : SPEED_A
    542.    
    543.     if(get_gametime() - DerSpeed > g_SpeedControl[id]){
    544.         static Ent; Ent = fm_get_user_weapon_entity(id, CSW_M134V)
    545.         if(!pev_valid(Ent)) return
    546.  
    547.         if(cs_get_weapon_ammo(Ent) > 0){
    548.             Set_BitVar(g_Fired, id)
    549.            
    550.             // Shake Screen
    551.             static Float:PunchAngles[3]
    552.             PunchAngles[0] = random_float(-1.5, 1.5)
    553.             PunchAngles[1] = random_float(-1.5, 1.5)
    554.            
    555.             set_pev(id, pev_punchangle, PunchAngles)
    556.            
    557.             Set_BitVar(g_Muzzleflash, id)
    558.             Set_BitVar(g_Muzzleflash2, id)
    559.            
    560.             Create_Vodan(id)
    561.             emit_sound(Ent, CHAN_WEAPON, WeaponSounds[0], 1.0, 0.52, 0, 94 + random_num(0, 15))
    562.            
    563.             static Float:Origin[3], Float:Target[3]
    564.             pev(id, pev_origin, Origin); Origin[2] += 16.0
    565.             get_position(id, 4096.0, 0.0, 0.0, Target)
    566.            
    567.             if(get_gametime() - 1.0 > SteamTime[id]){
    568.                 FiringTime[id]++
    569.                 SteamTime[id] = get_gametime()
    570.             }
    571.            
    572.             Create_FakeAttack(id)
    573.            
    574.             static Trace; Trace = create_tr2()
    575.             engfunc(EngFunc_TraceLine, Origin, Target, DONT_IGNORE_MONSTERS, id, Trace)
    576.             static Hit; Hit = get_tr2(Trace, TR_pHit)
    577.            
    578.             //if(is_alive(Hit)){
    579.                 do_attack(id, Hit, 0, float(DAMAGE))
    580.             //}
    581.            // else {
    582.                 static ptr; ptr = create_tr2()
    583.                 engfunc(EngFunc_TraceLine, Origin, Target, DONT_IGNORE_MONSTERS, id, ptr)
    584.  
    585.                 static Float:EndPos[3]
    586.                 get_tr2(ptr, TR_vecEndPos, EndPos)
    587.                 static Float:WallVector[3];get_tr2(ptr,TR_vecPlaneNormal,WallVector)
    588.                
    589.                 make_bullet(id, EndPos)
    590.                
    591.                 engfunc(EngFunc_MessageBegin,MSG_PVS,SVC_TEMPENTITY,EndPos,0);
    592.                 write_byte(TE_STREAK_SPLASH)
    593.                 engfunc(EngFunc_WriteCoord,EndPos[0]);
    594.                 engfunc(EngFunc_WriteCoord,EndPos[1]);
    595.                 engfunc(EngFunc_WriteCoord,EndPos[2]);
    596.                 engfunc(EngFunc_WriteCoord,WallVector[0]*random_float(25.0,30.0));
    597.                 engfunc(EngFunc_WriteCoord,WallVector[1]*random_float(25.0,30.0));
    598.                 engfunc(EngFunc_WriteCoord,WallVector[2]*random_float(25.0,30.0));
    599.                 write_byte(111)
    600.                 write_short(12)
    601.                 write_short(3)
    602.                 write_short(75)
    603.                 message_end()
    604.                
    605.                 free_tr2(ptr)
    606.             //}
    607.            
    608.             free_tr2(Trace)
    609.         }
    610.         else {
    611.             g_M134State[id] = M134_ATTACK_END
    612.             if(!Get_BitVar(g_RapidMode, id)) Set_WeaponAnim(id, ANIME_FIRE_END)
    613.             else Set_WeaponAnim(id, ANIME_SFIRE_END)
    614.            
    615.             Set_WeaponIdleTime(id, CSW_M134V, 2.0)
    616.             Set_PlayerNextAttack(id, 0.25)
    617.            
    618.             remove_task(id+TASK_ATTACK)
    619.             g_M134State[id] = M134_ATTACK_NOT
    620.         }
    621.        
    622.         g_SpeedControl[id] = get_gametime()
    623.     }
    624.    
    625.     static Float:DerTime; DerTime = Get_BitVar(g_RapidMode, id) ? 0.1 : 0.25
    626.     if(get_gametime() -  DerTime > g_AttackDelay[id]){
    627.         static Ent; Ent = fm_get_user_weapon_entity(id, CSW_M134V)
    628.         if(!pev_valid(Ent)) return
    629.        
    630.         if(cs_get_weapon_ammo(Ent) > 0) {
    631.             cs_set_weapon_ammo(Ent, cs_get_weapon_ammo(Ent) - 1)
    632.             if(cs_get_weapon_ammo(Ent) <= 0 && Get_BitVar(g_RapidMode, id))
    633.                 set_task(0.1, "Overheat_Begin", id)
    634.         }
    635.        
    636.         g_AttackDelay[id] = get_gametime()
    637.     }
    638. }
    639. public Create_Vodan(id){
    640.     Eject_Shell2(id, g_ShellID1, 0)
    641.     Eject_Shell2(id, g_ShellID2, 1)
    642. }
    643. public Task_ChangeState_Loop(id){
    644.     id -= TASK_ATTACK
    645.    
    646.     if(!is_alive(id))return
    647.     if(get_player_weapon(id) != CSW_M134V || !Get_BitVar(g_Had_M134V, id))return
    648.     if(g_M134State[id] != M134_ATTACK_BEGIN)return
    649.        
    650.     g_M134State[id] = M134_ATTACK_LOOP
    651. }
    652. public fw_Item_Deploy_Post(Ent){
    653.     if(pev_valid(Ent) != 2)return
    654.     static Id; Id = get_pdata_cbase(Ent, 41, 4)
    655.     if(get_pdata_cbase(Id, 373) != Ent)return
    656.     if(!Get_BitVar(g_Had_M134V, Id))return
    657.    
    658.     set_pev(Id, pev_viewmodel2, MODEL_V)
    659.     set_pev(Id, pev_weaponmodel2, MODEL_P)
    660.  
    661.     if(!Get_BitVar(g_OverHeat, Id)) Set_WeaponAnim(Id, ANIME_DRAW)
    662.     else Set_WeaponAnim(Id, ANIME_OH_DRAW)
    663.    
    664.     set_pdata_string(Id, (492) * 4, WEAPON_ANIMEXT, -1 , 20)
    665. }
    666. public fw_Item_AddToPlayer_Post(Ent, id){
    667.     if(!pev_valid(Ent))return HAM_IGNORED
    668.        
    669.     if(pev(Ent, pev_impulse) == 123123645489){
    670.         Set_BitVar(g_Had_M134V, id)
    671.         set_pev(Ent, pev_impulse, 0)
    672.     }
    673.    
    674.     if(Get_BitVar(g_Had_M134V, id)){
    675.         message_begin(MSG_ONE_UNRELIABLE, g_MsgWeaponList, _, id)
    676.         write_string("weapon_m134_vulcan")
    677.         write_byte(3)
    678.         write_byte(200)
    679.         write_byte(-1)
    680.         write_byte(-1)
    681.         write_byte(0)
    682.         write_byte(4)
    683.         write_byte(CSW_M134V)
    684.         write_byte(0)
    685.         message_end()
    686.     }
    687.     return HAM_HANDLED
    688. }
    689. public fw_SetModel(entity, model[]){
    690.     if(!pev_valid(entity))return FMRES_IGNORED
    691.    
    692.     static Classname[32]
    693.     pev(entity, pev_classname, Classname, sizeof(Classname))
    694.    
    695.     if(!equal(Classname, "weaponbox"))return FMRES_IGNORED
    696.    
    697.     static iOwner
    698.     iOwner = pev(entity, pev_owner)
    699.    
    700.     if(equal(model, "models/w_m249.mdl")){
    701.         static weapon; weapon = find_ent_by_owner(-1, weapon_m134v, entity)
    702.        
    703.         if(!pev_valid(weapon))return FMRES_IGNORED;
    704.        
    705.         if(Get_BitVar(g_Had_M134V, iOwner)){
    706.             set_pev(weapon, pev_impulse, 123123645489)
    707.            
    708.             engfunc(EngFunc_SetModel, entity, MODEL_W)
    709.            
    710.             Remove_M134V(iOwner)
    711.            
    712.             return FMRES_SUPERCEDE
    713.         }
    714.     }
    715.  
    716.     return FMRES_IGNORED;
    717. }
    718. public fw_Item_PostFrame(ent){
    719.     static id; id = pev(ent, pev_owner)
    720.     if(!is_user_alive(id))return HAM_IGNORED
    721.     if(!Get_BitVar(g_Had_M134V, id))return HAM_IGNORED
    722.    
    723.     static Float:flNextAttack; flNextAttack = get_pdata_float(id, 83, 5)
    724.     static bpammo; bpammo = cs_get_user_bpammo(id, CSW_M134V)
    725.    
    726.     static iClip; iClip = get_pdata_int(ent, 51, 4)
    727.     static fInReload; fInReload = get_pdata_int(ent, 54, 4)
    728.    
    729.     if(fInReload && flNextAttack <= 0.0){
    730.         static temp1
    731.         temp1 = min(CLIP - iClip, bpammo)
    732.  
    733.         set_pdata_int(ent, 51, iClip + temp1, 4)
    734.         cs_set_user_bpammo(id, CSW_M134V, bpammo - temp1)      
    735.        
    736.         set_pdata_int(ent, 54, 0, 4)
    737.         fInReload = 0
    738.     }      
    739.    
    740.     return HAM_IGNORED
    741. }
    742. public fw_Weapon_Reload(ent){
    743.     static id; id = pev(ent, pev_owner)
    744.     if(!is_user_alive(id))return HAM_IGNORED
    745.     if(!Get_BitVar(g_Had_M134V, id))return HAM_IGNORED
    746.     if(Get_BitVar(g_OverHeat, id))return HAM_SUPERCEDE
    747.    
    748.     g_Clip[id] = -1
    749.        
    750.     static BPAmmo; BPAmmo = cs_get_user_bpammo(id, CSW_M134V)
    751.     static iClip; iClip = get_pdata_int(ent, 51, 4)
    752.        
    753.     if(BPAmmo <= 0)return HAM_SUPERCEDE
    754.     if(iClip >= CLIP)return HAM_SUPERCEDE      
    755.            
    756.     g_Clip[id] = iClip
    757.    
    758.     return HAM_HANDLED
    759. }
    760. public fw_Weapon_Reload_Post(ent){
    761.     static id; id = pev(ent, pev_owner)
    762.     if(!is_user_alive(id))return HAM_IGNORED
    763.     if(!Get_BitVar(g_Had_M134V, id))return HAM_IGNORED
    764.     if(Get_BitVar(g_OverHeat, id))return HAM_SUPERCEDE
    765.    
    766.     if((get_pdata_int(ent, 54, 4) == 1)){
    767.         if(g_Clip[id] == -1)return HAM_IGNORED
    768.        
    769.         set_pdata_int(ent, 51, g_Clip[id], 4)
    770.         Set_WeaponAnim(id, ANIME_RELOAD)
    771.        
    772.         Set_PlayerNextAttack(id, TIME_RELOAD)
    773.     }
    774.    
    775.     return HAM_HANDLED
    776. }
    777. public fw_Weapon_WeaponIdle_Post( iEnt ){
    778.     if(pev_valid(iEnt) != 2)return
    779.     static Id; Id = get_pdata_cbase(iEnt, 41, 4)
    780.     if(get_pdata_cbase(Id, 373) != iEnt)return
    781.     if(!Get_BitVar(g_Had_M134V, Id))return
    782.        
    783.     if(get_pdata_float(iEnt, 48, 4) <= 0.25){
    784.         if(!Get_BitVar(g_OverHeat, Id)) Set_WeaponAnim(Id, ANIME_IDLE)
    785.         else Set_WeaponAnim(Id, ANIME_OH_IDLE)
    786.         set_pdata_float(iEnt, 48, 20.0, 4)
    787.     }  
    788. }
    789. public fw_TraceAttack_World(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits){
    790.     if(!is_connected(Attacker))return HAM_IGNORED  
    791.     if(get_player_weapon(Attacker) != CSW_M134V || !Get_BitVar(g_Had_M134V, Attacker))return HAM_IGNORED
    792.        
    793.     static Float:flEnd[3], Float:vecPlane[3]
    794.        
    795.     get_tr2(Ptr, TR_vecEndPos, flEnd)
    796.     get_tr2(Ptr, TR_vecPlaneNormal, vecPlane)      
    797.            
    798.     Make_BulletHole(Attacker, flEnd, Damage)
    799.    
    800.     static Float:WallVector[3];get_tr2(Ptr,TR_vecPlaneNormal,WallVector)
    801.            
    802.     engfunc(EngFunc_MessageBegin,MSG_PVS,SVC_TEMPENTITY,flEnd,0);
    803.     write_byte(TE_STREAK_SPLASH)
    804.     engfunc(EngFunc_WriteCoord,flEnd[0]);
    805.     engfunc(EngFunc_WriteCoord,flEnd[1]);
    806.     engfunc(EngFunc_WriteCoord,flEnd[2]);
    807.     engfunc(EngFunc_WriteCoord,WallVector[0]*random_float(25.0,30.0));
    808.     engfunc(EngFunc_WriteCoord,WallVector[1]*random_float(25.0,30.0));
    809.     engfunc(EngFunc_WriteCoord,WallVector[2]*random_float(25.0,30.0));
    810.     write_byte(111)
    811.     write_short(12)
    812.     write_short(3)
    813.     write_short(75)
    814.     message_end()
    815.  
    816.     SetHamParamFloat(3, float(DAMAGE))
    817.    
    818.     return HAM_HANDLED
    819. }
    820. public fw_TraceAttack_Player(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits){
    821.     if(!is_connected(Attacker))return HAM_IGNORED  
    822.     if(get_player_weapon(Attacker) != CSW_M134V || !Get_BitVar(g_Had_M134V, Attacker))return HAM_IGNORED
    823.  
    824.     SetHamParamFloat(3, float(DAMAGE))
    825.    
    826.     return HAM_HANDLED
    827. }
    828. public Create_FakeAttack(id){
    829.     static Ent; Ent = fm_get_user_weapon_entity(id, CSW_KNIFE)
    830.     if(!pev_valid(Ent)) return
    831.    
    832.     Set_BitVar(g_InTempingAttack, id)
    833.     ExecuteHamB(Ham_Weapon_PrimaryAttack, Ent)
    834.     static iAnimDesired,  szAnimation[64]
    835.     formatex(szAnimation, charsmax(szAnimation), (pev(id, pev_flags) & FL_DUCKING) ? "crouch_shoot_%s" : "ref_shoot_%s", WEAPON_ANIMEXT)
    836.     if((iAnimDesired = lookup_sequence(id, szAnimation)) == -1)
    837.         iAnimDesired = 0
    838.     set_pev(id, pev_sequence, iAnimDesired)
    839.     UnSet_BitVar(g_InTempingAttack, id)
    840. }
    841. public Register_SafetyFunc(){
    842.     register_event("CurWeapon", "Safety_CurWeapon", "be", "1=1")
    843.     RegisterHam(Ham_Spawn, "player", "fw_Safety_Spawn_Post", 1)
    844.     RegisterHam(Ham_Killed, "player", "fw_Safety_Killed_Post", 1)
    845. }
    846. public Register_SafetyFuncBot(id){
    847.     RegisterHamFromEntity(Ham_Spawn, id, "fw_Safety_Spawn_Post", 1)
    848.     RegisterHamFromEntity(Ham_Killed, id, "fw_Safety_Killed_Post", 1)
    849. }
    850. public Safety_Connected(id){
    851.     Set_BitVar(g_IsConnected, id)
    852.     UnSet_BitVar(g_IsAlive, id)
    853.    
    854.     g_PlayerWeapon[id] = 0
    855. }
    856. public Safety_Disconnected(id){
    857.     UnSet_BitVar(g_IsConnected, id)
    858.     UnSet_BitVar(g_IsAlive, id)
    859.    
    860.     g_PlayerWeapon[id] = 0
    861. }
    862. public Safety_CurWeapon(id){
    863.     if(!is_alive(id))return
    864.        
    865.     static CSW; CSW = read_data(2)
    866.     if(g_PlayerWeapon[id] != CSW) g_PlayerWeapon[id] = CSW
    867. }
    868. public fw_Safety_Spawn_Post(id){
    869.     if(!is_user_alive(id))return
    870.        
    871.     Set_BitVar(g_IsAlive, id)
    872. }
    873. public fw_Safety_Killed_Post(id){
    874.     UnSet_BitVar(g_IsAlive, id)
    875. }
    876. public is_alive(id){
    877.     if(!(1 <= id <= 32))return 0
    878.     if(!Get_BitVar(g_IsConnected, id))return 0
    879.     if(!Get_BitVar(g_IsAlive, id))return 0
    880.    
    881.     return 1
    882. }
    883. public is_connected(id){
    884.     if(!(1 <= id <= 32))return 0
    885.     if(!Get_BitVar(g_IsConnected, id))return 0
    886.    
    887.     return 1
    888. }
    889. public get_player_weapon(id){
    890.     if(!is_alive(id))return 0
    891.     return g_PlayerWeapon[id]
    892. }
    893. stock Set_WeaponAnim(id, anim){
    894.     set_pev(id, pev_weaponanim, anim)
    895.     message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
    896.     write_byte(anim)
    897.     write_byte(pev(id, pev_body))
    898.     message_end()
    899. }
    900. stock Make_BulletHole(id, Float:Origin[3], Float:Damage){
    901.     static Decal; Decal = random_num(41, 45)
    902.     static LoopTime;
    903.    
    904.     if(Damage > 100.0) LoopTime = 2
    905.     else LoopTime = 1
    906.    
    907.     for(new i = 0; i < LoopTime; i++){
    908.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    909.         write_byte(TE_WORLDDECAL)
    910.         engfunc(EngFunc_WriteCoord, Origin[0])
    911.         engfunc(EngFunc_WriteCoord, Origin[1])
    912.         engfunc(EngFunc_WriteCoord, Origin[2])
    913.         write_byte(Decal)
    914.         message_end()
    915.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    916.         write_byte(TE_GUNSHOTDECAL)
    917.         engfunc(EngFunc_WriteCoord, Origin[0])
    918.         engfunc(EngFunc_WriteCoord, Origin[1])
    919.         engfunc(EngFunc_WriteCoord, Origin[2])
    920.         write_short(id)
    921.         write_byte(Decal)
    922.         message_end()
    923.     }
    924. }
    925. stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0){
    926.     static Float:vfEnd[3], viEnd[3]
    927.     get_user_origin(id, viEnd, 3)  
    928.     IVecFVec(viEnd, vfEnd)
    929.    
    930.     static Float:fOrigin[3], Float:fAngle[3]
    931.    
    932.     pev(id, pev_origin, fOrigin)
    933.     pev(id, pev_view_ofs, fAngle)
    934.    
    935.     xs_vec_add(fOrigin, fAngle, fOrigin)
    936.    
    937.     static Float:fAttack[3]
    938.    
    939.     xs_vec_sub(vfEnd, fOrigin, fAttack)
    940.     xs_vec_sub(vfEnd, fOrigin, fAttack)
    941.    
    942.     static Float:fRate
    943.    
    944.     fRate = fDis / vector_length(fAttack)
    945.     xs_vec_mul_scalar(fAttack, fRate, fAttack)
    946.    
    947.     xs_vec_add(fOrigin, fAttack, output)
    948. }
    949. stock get_position(id,Float:forw, Float:right, Float:up, Float:vStart[]){
    950.     new Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
    951.    
    952.     pev(id, pev_origin, vOrigin)
    953.     pev(id, pev_view_ofs,vUp)
    954.     xs_vec_add(vOrigin,vUp,vOrigin)
    955.     pev(id, pev_v_angle, vAngle)
    956.    
    957.     angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward)
    958.     angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
    959.     angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
    960.    
    961.     vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
    962.     vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
    963.     vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
    964. }
    965. stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3]){
    966.     new_velocity[0] = origin2[0] - origin1[0]
    967.     new_velocity[1] = origin2[1] - origin1[1]
    968.     new_velocity[2] = origin2[2] - origin1[2]
    969.     new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
    970.     new_velocity[0] *= num
    971.     new_velocity[1] *= num
    972.     new_velocity[2] *= num
    973.    
    974.     return 1;
    975. }
    976. stock Set_WeaponIdleTime(id, WeaponId ,Float:TimeIdle){
    977.     static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
    978.     if(!pev_valid(entwpn)) return
    979.        
    980.     set_pdata_float(entwpn, 46, TimeIdle, 4)
    981.     set_pdata_float(entwpn, 47, TimeIdle, 4)
    982.     set_pdata_float(entwpn, 48, TimeIdle + 0.5, 4)
    983. }
    984. stock Set_PlayerNextAttack(id, Float:nexttime){
    985.     set_pdata_float(id, 83, nexttime, 5)
    986. }
    987. stock Get_Position(id,Float:forw, Float:right, Float:up, Float:vStart[]){
    988.     static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
    989.    
    990.     pev(id, pev_origin, vOrigin)
    991.     pev(id, pev_view_ofs,vUp)
    992.     xs_vec_add(vOrigin,vUp,vOrigin)
    993.     pev(id, pev_v_angle, vAngle)
    994.    
    995.     angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward)
    996.     angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
    997.     angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
    998.    
    999.     vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
    1000.     vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
    1001.     vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
    1002. }
    1003. stock is_wall_between_points(Float:start[3], Float:end[3], ignore_ent){
    1004.     static ptr
    1005.     ptr = create_tr2()
    1006.  
    1007.     engfunc(EngFunc_TraceLine, start, end, IGNORE_MONSTERS, ignore_ent, ptr)
    1008.    
    1009.     static Float:EndPos[3]
    1010.     get_tr2(ptr, TR_vecEndPos, EndPos)
    1011.  
    1012.     free_tr2(ptr)
    1013.     return floatround(get_distance_f(end, EndPos))
    1014. }
    1015. do_attack(Attacker, Victim, Inflictor, Float:fDamage){
    1016.     fake_player_trace_attack(Attacker, Victim, fDamage)
    1017.     fake_take_damage(Attacker, Victim, fDamage, Inflictor)
    1018. }
    1019. fake_player_trace_attack(iAttacker, iVictim, &Float:fDamage){
    1020.     static Float:fAngles[3], Float:fDirection[3]
    1021.     pev(iAttacker, pev_angles, fAngles)
    1022.     angle_vector(fAngles, ANGLEVECTOR_FORWARD, fDirection)
    1023.    
    1024.     static Float:fStart[3], Float:fViewOfs[3]
    1025.     pev(iAttacker, pev_origin, fStart)
    1026.     pev(iAttacker, pev_view_ofs, fViewOfs)
    1027.     xs_vec_add(fViewOfs, fStart, fStart)
    1028.    
    1029.     static iAimOrigin[3], Float:fAimOrigin[3]
    1030.     get_user_origin(iAttacker, iAimOrigin, 3)
    1031.     IVecFVec(iAimOrigin, fAimOrigin)
    1032.    
    1033.     static ptr; ptr = create_tr2()
    1034.     engfunc(EngFunc_TraceLine, fStart, fAimOrigin, DONT_IGNORE_MONSTERS, iAttacker, ptr)
    1035.     static pHit; pHit = get_tr2(ptr, TR_pHit)
    1036.     static iHitgroup; iHitgroup = get_tr2(ptr, TR_iHitgroup)
    1037.     static Float:fEndPos[3]; get_tr2(ptr, TR_vecEndPos, fEndPos)
    1038.  
    1039.     static iTarget, iBody
    1040.     get_user_aiming(iAttacker, iTarget, iBody)
    1041.    
    1042.     if (iTarget == iVictim)iHitgroup = iBody
    1043.    
    1044.     else if (pHit != iVictim){
    1045.         static Float:fVicOrigin[3], Float:fVicViewOfs[3], Float:fAimInVictim[3]
    1046.         pev(iVictim, pev_origin, fVicOrigin)
    1047.         pev(iVictim, pev_view_ofs, fVicViewOfs)
    1048.         xs_vec_add(fVicViewOfs, fVicOrigin, fAimInVictim)
    1049.         fAimInVictim[2] = fStart[2]
    1050.         fAimInVictim[2] += get_distance_f(fStart, fAimInVictim) * floattan( fAngles[0] * 2.0, degrees )
    1051.    
    1052.         static iAngleToVictim; iAngleToVictim = get_angle_to_target(iAttacker, fVicOrigin)
    1053.         iAngleToVictim = abs(iAngleToVictim)
    1054.         static Float:fDis; fDis = 2.0 * get_distance_f(fStart, fAimInVictim) * floatsin( float(iAngleToVictim) * 0.5, degrees )
    1055.         static Float:fVicSize[3]
    1056.         pev(iVictim, pev_size , fVicSize)
    1057.         if ( fDis <= fVicSize[0] * 0.5 ){
    1058.             static ptr2; ptr2 = create_tr2()
    1059.             engfunc(EngFunc_TraceLine, fStart, fAimInVictim, DONT_IGNORE_MONSTERS, iAttacker, ptr2)
    1060.             static pHit2; pHit2 = get_tr2(ptr2, TR_pHit)
    1061.             static iHitgroup2; iHitgroup2 = get_tr2(ptr2, TR_iHitgroup)
    1062.            
    1063.             if ( pHit2 == iVictim && (iHitgroup2 != HIT_HEAD || fDis <= fVicSize[0] * 0.25) ){
    1064.                 pHit = iVictim
    1065.                 iHitgroup = iHitgroup2
    1066.                 get_tr2(ptr2, TR_vecEndPos, fEndPos)
    1067.             }
    1068.            
    1069.             free_tr2(ptr2)
    1070.         }
    1071.        
    1072.         if (pHit != iVictim){
    1073.             iHitgroup = HIT_GENERIC
    1074.            
    1075.             new ptr3 = create_tr2()
    1076.             engfunc(EngFunc_TraceLine, fStart, fVicOrigin, DONT_IGNORE_MONSTERS, iAttacker, ptr3)
    1077.             get_tr2(ptr3, TR_vecEndPos, fEndPos)
    1078.            
    1079.             free_tr2(ptr3)
    1080.         }
    1081.     }
    1082.    
    1083.     set_tr2(ptr, TR_pHit, iVictim)
    1084.     set_tr2(ptr, TR_iHitgroup, iHitgroup)
    1085.     set_tr2(ptr, TR_vecEndPos, fEndPos)
    1086.    
    1087.     if(cs_get_user_team(iVictim) != cs_get_user_team(iAttacker)) create_blood(fEndPos)
    1088.    
    1089.     static Float:fMultifDamage
    1090.     switch(iHitgroup){
    1091.         case HIT_HEAD: fMultifDamage  = 4.0
    1092.         case HIT_STOMACH: fMultifDamage  = 1.25
    1093.         case HIT_LEFTLEG: fMultifDamage  = 0.75
    1094.         case HIT_RIGHTLEG: fMultifDamage  = 0.75
    1095.         default: fMultifDamage  = 1.0
    1096.     }
    1097.    
    1098.     fDamage *= fMultifDamage
    1099.    
    1100.     fake_trake_attack(iAttacker, iVictim, fDamage, fDirection, ptr)
    1101.     free_tr2(ptr)
    1102. }
    1103. stock create_blood(const Float:origin[3]){
    1104.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    1105.     write_byte(TE_BLOODSPRITE)
    1106.     engfunc(EngFunc_WriteCoord, origin[0])
    1107.     engfunc(EngFunc_WriteCoord, origin[1])
    1108.     engfunc(EngFunc_WriteCoord, origin[2])
    1109.     write_short(m_iBlood[1])
    1110.     write_short(m_iBlood[0])
    1111.     write_byte(75)
    1112.     write_byte(5)
    1113.     message_end()
    1114. }
    1115. stock fake_trake_attack(iAttacker, iVictim, Float:fDamage, Float:fDirection[3], iTraceHandle, iDamageBit = (DMG_NEVERGIB | DMG_BULLET)){
    1116.     ExecuteHamB(Ham_TraceAttack, iVictim, iAttacker, fDamage, fDirection, iTraceHandle, iDamageBit)
    1117. }
    1118. stock fake_take_damage(iAttacker, iVictim, Float:fDamage, iInflictor = 0, iDamageBit = (DMG_NEVERGIB | DMG_BULLET)){
    1119.     ExecuteHamB(Ham_TakeDamage, iVictim, iInflictor, iAttacker, fDamage, iDamageBit)
    1120. }
    1121. stock get_angle_to_target(id, const Float:fTarget[3], Float:TargetSize = 0.0){
    1122.     new Float:fOrigin[3], iAimOrigin[3], Float:fAimOrigin[3], Float:fV1[3]
    1123.     pev(id, pev_origin, fOrigin)
    1124.     get_user_origin(id, iAimOrigin, 3)
    1125.     IVecFVec(iAimOrigin, fAimOrigin)
    1126.     xs_vec_sub(fAimOrigin, fOrigin, fV1)
    1127.     new Float:fV2[3]
    1128.     xs_vec_sub(fTarget, fOrigin, fV2)
    1129.     new iResult = get_angle_between_vectors(fV1, fV2)
    1130.     if (TargetSize > 0.0){
    1131.         new Float:fTan = TargetSize / get_distance_f(fOrigin, fTarget)
    1132.         new fAngleToTargetSize = floatround( floatatan(fTan, degrees) )
    1133.         iResult -= (iResult > 0) ? fAngleToTargetSize : -fAngleToTargetSize
    1134.     }
    1135.    
    1136.     return iResult
    1137. }
    1138. stock get_angle_between_vectors(const Float:fV1[3], const Float:fV2[3]){
    1139.     new Float:fA1[3], Float:fA2[3]
    1140.     engfunc(EngFunc_VecToAngles, fV1, fA1)
    1141.     engfunc(EngFunc_VecToAngles, fV2, fA2)
    1142.    
    1143.     new iResult = floatround(fA1[1] - fA2[1])
    1144.     iResult = iResult % 360
    1145.     iResult = (iResult > 180) ? (iResult - 360) : iResult
    1146.    
    1147.     return iResult
    1148. }
    1149. stock make_bullet(id, Float:Origin[3]){
    1150.     new decal = random_num(41, 45)
    1151.     const loop_time = 2
    1152.    
    1153.     for(new i = 0; i < loop_time; i++){
    1154.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    1155.         write_byte(TE_WORLDDECAL)
    1156.         engfunc(EngFunc_WriteCoord, Origin[0])
    1157.         engfunc(EngFunc_WriteCoord, Origin[1])
    1158.         engfunc(EngFunc_WriteCoord, Origin[2])
    1159.         write_byte(decal)
    1160.         message_end()
    1161.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    1162.         write_byte(TE_GUNSHOTDECAL)
    1163.         engfunc(EngFunc_WriteCoord, Origin[0])
    1164.         engfunc(EngFunc_WriteCoord, Origin[1])
    1165.         engfunc(EngFunc_WriteCoord, Origin[2])
    1166.         write_short(id)
    1167.         write_byte(decal)
    1168.         message_end()
    1169.     }
    1170. }
    1171. stock Get_SpeedVector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3]){
    1172.     new_velocity[0] = origin2[0] - origin1[0]
    1173.     new_velocity[1] = origin2[1] - origin1[1]
    1174.     new_velocity[2] = origin2[2] - origin1[2]
    1175.     new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
    1176.     new_velocity[0] *= (num * 2.0)
    1177.     new_velocity[1] *= (num * 2.0)
    1178.     new_velocity[2] *= (num / 2.0)
    1179. }  
    1180. stock Eject_Shell(id, Shell_ModelIndex, Float:Time){
    1181.     static Ent; Ent = get_pdata_cbase(id, 373, 5)
    1182.     if(!pev_valid(Ent))return
    1183.  
    1184.         set_pdata_int(Ent, 57, Shell_ModelIndex, 4)
    1185.         set_pdata_float(id, 111, get_gametime() + Time)
    1186. }
    1187. public Eject_Shell2(id, ShellID, Right){
    1188.     static Float:player_origin[3], Float:origin[3], Float:origin2[3], Float:gunorigin[3], Float:oldangles[3], Float:v_forward[3], Float:v_forward2[3], Float:v_up[3], Float:v_up2[3], Float:v_right[3], Float:v_right2[3], Float:viewoffsets[3];
    1189.    
    1190.     pev(id,pev_v_angle, oldangles); pev(id,pev_origin,player_origin); pev(id, pev_view_ofs, viewoffsets);
    1191.  
    1192.     engfunc(EngFunc_MakeVectors, oldangles)
    1193.    
    1194.     global_get(glb_v_forward, v_forward); global_get(glb_v_up, v_up); global_get(glb_v_right, v_right);
    1195.     global_get(glb_v_forward, v_forward2); global_get(glb_v_up, v_up2); global_get(glb_v_right, v_right2);
    1196.    
    1197.     xs_vec_add(player_origin, viewoffsets, gunorigin);
    1198.    
    1199.     if(!Right){
    1200.         xs_vec_mul_scalar(v_forward, 20.0, v_forward); xs_vec_mul_scalar(v_right, -2.5, v_right);
    1201.         xs_vec_mul_scalar(v_up, -1.5, v_up);
    1202.         xs_vec_mul_scalar(v_forward2, 19.9, v_forward2); xs_vec_mul_scalar(v_right2, -2.0, v_right2);
    1203.         xs_vec_mul_scalar(v_up2, -2.0, v_up2);
    1204.     }
    1205.     else {
    1206.         xs_vec_mul_scalar(v_forward, 20.0, v_forward); xs_vec_mul_scalar(v_right, 2.5, v_right);
    1207.         xs_vec_mul_scalar(v_up, -1.5, v_up);
    1208.         xs_vec_mul_scalar(v_forward2, 19.9, v_forward2); xs_vec_mul_scalar(v_right2, 2.0, v_right2);
    1209.         xs_vec_mul_scalar(v_up2, -2.0, v_up2);
    1210.     }
    1211.    
    1212.     xs_vec_add(gunorigin, v_forward, origin);
    1213.     xs_vec_add(gunorigin, v_forward2, origin2);
    1214.     xs_vec_add(origin, v_right, origin);
    1215.     xs_vec_add(origin2, v_right2, origin2);
    1216.     xs_vec_add(origin, v_up, origin);
    1217.     xs_vec_add(origin2, v_up2, origin2);
    1218.  
    1219.     static Float:velocity[3]
    1220.     get_speed_vector(origin2, origin, random_float(140.0, 160.0), velocity)
    1221.  
    1222.     static angle; angle = random_num(0, 360)
    1223.  
    1224.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    1225.     write_byte(TE_MODEL)
    1226.     engfunc(EngFunc_WriteCoord, origin[0])
    1227.     engfunc(EngFunc_WriteCoord, origin[1])
    1228.     engfunc(EngFunc_WriteCoord, origin[2] - 16.0)
    1229.     engfunc(EngFunc_WriteCoord,velocity[0])
    1230.     engfunc(EngFunc_WriteCoord,velocity[1])
    1231.     engfunc(EngFunc_WriteCoord,velocity[2])
    1232.     write_angle(angle)
    1233.     write_short(ShellID)
    1234.     write_byte(1)
    1235.     write_byte(20)
    1236.     message_end()
    1237. }