Advertisement
macquid123560

Top Jailbreak | Days | Speargun

Mar 23rd, 2016
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 20.89 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <engine>
  3. #include <fakemeta>
  4. #include <fakemeta_util>
  5. #include <hamsandwich>
  6. #include <cstrike>
  7. #include <fun>
  8.  
  9. #define PLUGIN "Spear Gun"
  10. #define VERSION "1.0"
  11. #define AUTHOR "m4m3ts"
  12.  
  13. native is_day();
  14. native get_running_day_speargun();
  15.  
  16. native is_lr_active();
  17. native is_user_lr( index );
  18.  
  19. const PDATA_SAFE = 2
  20. const OFFSET_LINUX_WEAPONS = 4
  21. const OFFSET_WEAPONOWNER = 41
  22. const m_flNextAttack = 83
  23. const m_szAnimExtention = 492
  24.  
  25. new const v_model[] = "models/Top/JB/Days/v_speargun.mdl"
  26. new const p_model[] = "models/Top/JB/Days/p_speargun.mdl"
  27. new const w_model[] = "models/Top/JB/Days/w_speargun.mdl"
  28. new const ARROW_MODEL[] = "models/Top/JB/Days/spear.mdl"
  29. new const GRENADE_EXPLOSION[] = "sprites/fexplo.spr"
  30. new const speargun_wall[] = "weapons/speargun_metal21.wav"
  31. new const speargun_hit[] = "weapons/speargun_stone11.wav"
  32. new const sound[3][] =
  33. {
  34.     "weapons/speargun-11.wav",
  35.     "weapons/speargun_clipin1.wav",
  36.     "weapons/speargun_draw1.wav"
  37. }
  38.  
  39.  
  40. new const sprite[3][] =
  41. {
  42.     "sprites/weapon_speargun.txt",
  43.     "sprites/640hud103.spr",
  44.     "sprites/640hud400.spr"
  45. }
  46.  
  47. enum
  48. {
  49.     IDLE = 0,
  50.     SHOOT,
  51.     RELOAD,
  52.     DRAW,
  53.     DRAW_EMPTY,
  54.     IDLE_EMPTY
  55. }
  56.  
  57. new sExplo, g_MaxPlayers, Ent, g_ready, g_rightclick
  58. new g_had_speargun[33], g_speargun_ammo[33]
  59. new g_old_weapon[33], g_smokepuff_id, m_iBlood[2]
  60. new sTrail, cvar_dmg1_spear, cvar_dmg2_spear, cvar_ammo_spear
  61.  
  62. const PRIMARY_WEAPONS_BIT_SUM =
  63. (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<<
  64. 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)
  65.  
  66. public plugin_init()
  67. {
  68.     register_plugin(PLUGIN, VERSION, AUTHOR)
  69.     register_cvar("spear_version", "m4m3ts", FCVAR_SERVER|FCVAR_SPONLY)
  70.     register_forward(FM_CmdStart, "fw_CmdStart")
  71.     register_message(get_user_msgid("DeathMsg"), "message_DeathMsg")
  72.     register_forward(FM_SetModel, "fw_SetModel")
  73.     register_touch("spear_arrow", "*", "fw_touch2")
  74.     register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
  75.     register_forward(FM_TraceLine,"fw_traceline",1)
  76.     RegisterHam(Ham_Weapon_WeaponIdle, "weapon_galil", "fw_speargunidleanim", 1)
  77.     RegisterHam(Ham_Killed, "player", "fw_PlayerKilled")
  78.     RegisterHam(Ham_Item_AddToPlayer, "weapon_galil", "fw_AddToPlayer_Post", 1)
  79.     register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
  80.    
  81.     cvar_dmg1_spear = register_cvar("zp_dmg1_spear", "400.0")
  82.     cvar_dmg2_spear = register_cvar("zp_dmg2_spear", "600.0")
  83.     cvar_ammo_spear = register_cvar("zp_spear_ammo", "40")
  84.  
  85.     register_clcmd("weapon_speargun", "hook_weapon")
  86.     register_clcmd("say /speargun", "get_speargun")
  87.    
  88.     g_MaxPlayers = get_maxplayers()
  89. }
  90.  
  91.  
  92. public plugin_precache()
  93. {
  94.     precache_model(v_model)
  95.     precache_model(p_model)
  96.     precache_model(w_model)
  97.     precache_model(ARROW_MODEL)
  98.     precache_sound(speargun_wall)
  99.     precache_sound(speargun_hit)
  100.    
  101.     for(new i = 0; i < sizeof(sound); i++)
  102.         precache_sound(sound[i])
  103.        
  104.     for(new i = 1; i < sizeof(sprite); i++)
  105.         precache_model(sprite[i])
  106.    
  107.     g_smokepuff_id = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
  108.     m_iBlood[0] = precache_model("sprites/blood.spr")
  109.     m_iBlood[1] = precache_model("sprites/bloodspray.spr")
  110.     sExplo = precache_model(GRENADE_EXPLOSION)
  111.     sTrail = precache_model("sprites/Top/flame.spr")
  112. }
  113.  
  114. public fw_PlayerKilled(id)
  115. {
  116.     remove_speargun(id)
  117. }
  118.  
  119. public hook_weapon(id)
  120. {
  121.     engclient_cmd(id, "weapon_galil")
  122.     return
  123. }
  124.  
  125. public _give_speargun( plugin, params )
  126. {
  127.     new client = get_param( 1 );
  128.    
  129.     if( is_day() && get_running_day_speargun() || is_lr_active() && is_user_lr( client ) )
  130.         get_speargun( client )
  131. }
  132.  
  133. public plugin_natives()
  134. {
  135.     register_native( "give_speargun", "_give_speargun" );
  136.     register_native( "remove_speargun", "remove_speargun_native" );
  137. }
  138.  
  139. public remove_speargun_native( plugin, params )
  140.     return remove_speargun( get_param( 1 ) );
  141.  
  142.  
  143.  
  144. public get_speargun(id)
  145. {
  146.     if(!is_user_alive(id))
  147.         return
  148.     drop_weapons(id, 1)
  149.     g_had_speargun[id] = 1
  150.     g_ready = 0
  151.     g_rightclick = 0
  152.     g_speargun_ammo[id] = get_pcvar_num(cvar_ammo_spear)
  153.    
  154.     fm_give_item(id, "weapon_galil")
  155.     update_ammo(id)
  156.    
  157.     static weapon_ent; weapon_ent = fm_find_ent_by_owner(-1, "weapon_galil", id)
  158.     if(pev_valid(weapon_ent)) cs_set_weapon_ammo(weapon_ent, 1)
  159. }
  160.  
  161. public message_DeathMsg(msg_id, msg_dest, id)
  162. {
  163.     static szTruncatedWeapon[33], iAttacker, iVictim
  164.        
  165.     get_msg_arg_string(4, szTruncatedWeapon, charsmax(szTruncatedWeapon))
  166.        
  167.     iAttacker = get_msg_arg_int(1)
  168.     iVictim = get_msg_arg_int(2)
  169.        
  170.     if(!is_user_connected(iAttacker) || iAttacker == iVictim) return PLUGIN_CONTINUE
  171.        
  172.     if(get_user_weapon(iAttacker) == CSW_GALIL)
  173.     {
  174.         if(g_had_speargun[iAttacker])
  175.             set_msg_arg_string(4, "Spear Gun")
  176.     }
  177.                
  178.     return PLUGIN_CONTINUE
  179. }
  180.  
  181. public remove_speargun(id)
  182. {
  183.     g_had_speargun[id] = 0
  184.     g_speargun_ammo[id] = 0
  185. }
  186.    
  187. public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
  188. {
  189.     if(!is_user_alive(id) || !is_user_connected(id))
  190.         return FMRES_IGNORED   
  191.     if(get_user_weapon(id) == CSW_GALIL && g_had_speargun[id])
  192.         set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001)
  193.    
  194.     return FMRES_HANDLED
  195. }
  196.  
  197. public Event_CurWeapon(id)
  198. {
  199.     if(!is_user_alive(id))
  200.         return
  201.        
  202.     if(get_user_weapon(id) == CSW_GALIL && g_had_speargun[id])
  203.     {
  204.         set_pev(id, pev_viewmodel2, v_model)
  205.         set_pev(id, pev_weaponmodel2, p_model)
  206.         remove_task(id)
  207.         if(g_old_weapon[id] != CSW_GALIL && g_speargun_ammo[id] >= 1) set_weapon_anim(id, DRAW)
  208.         if(g_old_weapon[id] != CSW_GALIL && g_speargun_ammo[id] == 0) set_weapon_anim(id, DRAW_EMPTY)
  209.         update_ammo(id)
  210.     }
  211.    
  212.     g_old_weapon[id] = get_user_weapon(id)
  213. }
  214.  
  215. public fw_speargunidleanim(Weapon)
  216. {
  217.     new id = get_pdata_cbase(Weapon, 41, 4)
  218.  
  219.     if(!is_user_alive(id) || !g_had_speargun[id] || get_user_weapon(id) != CSW_GALIL)
  220.         return HAM_IGNORED;
  221.  
  222.     if(g_speargun_ammo[id] >= 1)
  223.         return HAM_SUPERCEDE;
  224.    
  225.     if(g_speargun_ammo[id] == 0 && get_pdata_float(Weapon, 48, 4) <= 0.25)
  226.     {
  227.         set_weapon_anim(id, IDLE_EMPTY)
  228.         set_pdata_float(Weapon, 48, 20.0, 4)
  229.         return HAM_SUPERCEDE;
  230.     }
  231.  
  232.     return HAM_IGNORED;
  233. }
  234.  
  235. public fw_CmdStart(id, uc_handle, seed)
  236. {
  237.     if(!is_user_alive(id) || !is_user_connected(id))
  238.         return
  239.     if(get_user_weapon(id) != CSW_GALIL || !g_had_speargun[id])
  240.         return
  241.    
  242.     static ent; ent = fm_get_user_weapon_entity(id, CSW_GALIL)
  243.     if(!pev_valid(ent))
  244.         return
  245.    
  246.     static CurButton
  247.     CurButton = get_uc(uc_handle, UC_Buttons)
  248.    
  249.     if(CurButton & IN_ATTACK && get_pdata_float(id, 83, 5) <= 0.0)
  250.     {
  251.         if(get_pdata_float(ent, 46, OFFSET_LINUX_WEAPONS) > 0.0 || get_pdata_float(ent, 47, OFFSET_LINUX_WEAPONS) > 0.0)
  252.             return
  253.            
  254.         CurButton &= ~IN_ATTACK
  255.         set_uc(uc_handle, UC_Buttons, CurButton)
  256.        
  257.         if(g_speargun_ammo[id] == 0)
  258.             return
  259.         if(get_pdata_float(id, 83, 5) <= 0.0)
  260.         {
  261.             FireArrow_Charge(id)
  262.             g_ready = 1
  263.             update_ammo(id)
  264.             set_weapons_timeidle(id, CSW_GALIL, 2.2)
  265.             set_player_nextattackx(id, 2.2)
  266.             if(g_speargun_ammo[id] >= 1)
  267.             {
  268.                 set_weapon_anim(id, SHOOT)
  269.                 emit_sound(id, CHAN_WEAPON, sound[0], 1.0, ATTN_NORM, 0, PITCH_NORM)
  270.                 set_task(1.0, "reloadspear", id)
  271.             }
  272.             else
  273.             {
  274.                 set_weapon_anim(id, SHOOT)
  275.                 emit_sound(id, CHAN_WEAPON, sound[0], 1.0, ATTN_NORM, 0, PITCH_NORM)
  276.             }
  277.         }
  278.     }
  279.     /*else if(CurButton & IN_ATTACK2)
  280.     {
  281.         if(g_ready)
  282.         {
  283.             CurButton &= ~IN_ATTACK2
  284.             set_uc(uc_handle, UC_Buttons, CurButton)
  285.        
  286.             remove_task(Ent)
  287.             g_rightclick = 1
  288.             explode(Ent)
  289.         }
  290.     }*/
  291. }
  292.  
  293.  
  294. public reloadspear(id)
  295. {
  296.     if(get_user_weapon(id) != CSW_GALIL || !g_had_speargun[id])
  297.         return
  298.    
  299.     set_weapon_anim(id, RELOAD)
  300. }
  301.  
  302. public FireArrow_Charge(id)
  303. {
  304.     static Float:StartOrigin[3], Float:TargetOrigin[3], Float:angles[3], Float:angles_fix[3]
  305.     get_position(id, 50.0, 0.0, 5.0, StartOrigin)
  306.  
  307.     pev(id,pev_v_angle,angles)
  308.     Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  309.     if(!pev_valid(Ent)) return
  310.     angles_fix[0] = 360.0 - angles[0]
  311.     angles_fix[1] = angles[1]
  312.     angles_fix[2] = angles[2]
  313.     set_pev(Ent, pev_movetype, MOVETYPE_TOSS)
  314.     set_pev(Ent, pev_owner, id)
  315.    
  316.     entity_set_string(Ent, EV_SZ_classname, "spear_arrow")
  317.     engfunc(EngFunc_SetModel, Ent, ARROW_MODEL)
  318.     set_pev(Ent, pev_mins,{ -0.1, -0.1, -0.1 })
  319.     set_pev(Ent, pev_maxs,{ 0.1, 0.1, 0.1 })
  320.     set_pev(Ent, pev_origin, StartOrigin)
  321.     set_pev(Ent, pev_angles, angles_fix)
  322.     set_pev(Ent, pev_gravity, 0.01)
  323.     set_pev(Ent, pev_solid, SOLID_TRIGGER)
  324.     set_pev(Ent, pev_frame, 0.0)
  325.    
  326.     static Float:Velocity[3]
  327.     fm_get_aim_origin(id, TargetOrigin)
  328.     get_speed_vector(StartOrigin, TargetOrigin, 1500.0, Velocity)
  329.     set_pev(Ent, pev_velocity, Velocity)
  330.    
  331.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  332.     write_byte(TE_BEAMFOLLOW) // Temporary entity ID
  333.     write_short(Ent) // Entity
  334.     write_short(sTrail) // Sprite index
  335.     write_byte(13) // Life
  336.     write_byte(7) // Line width
  337.     write_byte(random_num(1,255))
  338.     write_byte(random_num(100,255))
  339.     write_byte(random_num(100,255))
  340.     write_byte(random_num(100,255)) // Alpha
  341.     message_end()
  342. }
  343.  
  344. public fw_touch2(Ent, Id)
  345. {
  346.     // If ent is valid
  347.     if(!pev_valid(Ent))
  348.         return
  349.     if(pev(Ent, pev_movetype) == MOVETYPE_NONE)
  350.         return
  351.        
  352.     static Owner; Owner = pev(Ent, pev_owner)
  353.    
  354.     static classnameptd[32]
  355.     pev(Id, pev_classname, classnameptd, 31)
  356.     if (equali(classnameptd, "func_breakable")) ExecuteHamB( Ham_TakeDamage, Id, 0, 0, 300.0, DMG_GENERIC )
  357.    
  358.     // Get it's origin
  359.     new Float:originF[3]
  360.     pev(Ent, pev_origin, originF)
  361.     // Alive...
  362.    
  363.     if(is_user_alive(Id))
  364.     {
  365.         set_pev(Ent, pev_movetype, MOVETYPE_FOLLOW)
  366.         set_pev(Ent, pev_solid, SOLID_NOT)
  367.         set_pev(Ent, pev_aiment, Id)
  368.         create_blood(originF)
  369.         create_blood(originF)
  370.         set_task(1.0, "explode", Ent)
  371.         engfunc(EngFunc_EmitSound, Ent, CHAN_WEAPON, speargun_hit, 1.0, ATTN_STATIC, 0, PITCH_NORM)
  372.        
  373.         static Float:MyOrigin[3]
  374.         pev(Owner, pev_origin, MyOrigin)
  375.        
  376.         new CsTeams:team = cs_get_user_team( Owner );
  377.        
  378.         if( !( team == CS_TEAM_CT && team == cs_get_user_team( Id ) ) )
  379.             hook_ent2(Id, MyOrigin, 500.0, 2)
  380.     }
  381.    
  382.     else if(!is_user_alive(Id))
  383.     {
  384.         engfunc(EngFunc_EmitSound, Ent, CHAN_WEAPON, speargun_wall, 1.0, ATTN_STATIC, 0, PITCH_NORM)
  385.         set_pev(Ent, pev_movetype, MOVETYPE_NONE)
  386.         set_pev(Ent, pev_solid, SOLID_NOT)
  387.         make_bullet(Owner, originF)
  388.         fake_smokes(Owner, originF)
  389.         set_task(1.0, "explode", Ent)
  390.     }
  391. }
  392.  
  393. public explode(Ent)
  394. {
  395.     new Float:originZ[3], Float:originX[3]
  396.     pev(Ent, pev_origin, originX)
  397.     entity_get_vector(Ent, EV_VEC_origin, originZ)
  398.     // Draw explosion
  399.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  400.     write_byte(TE_EXPLOSION) // Temporary entity ID
  401.     engfunc(EngFunc_WriteCoord, originX[0]) // engfunc because float
  402.     engfunc(EngFunc_WriteCoord, originX[1])
  403.     engfunc(EngFunc_WriteCoord, originX[2]+30.0)
  404.     write_short(sExplo) // Sprite index
  405.     write_byte(20) // Scale
  406.     write_byte(200) // Framerate
  407.     write_byte(0) // Flags
  408.     message_end()
  409.    
  410.     engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, originZ, 0)
  411.     write_byte(TE_PARTICLEBURST) // TE id
  412.     engfunc(EngFunc_WriteCoord, originZ[0]) // x
  413.     engfunc(EngFunc_WriteCoord, originZ[1]) // y
  414.     engfunc(EngFunc_WriteCoord, originZ[2]) // z
  415.     write_short(30) // radius
  416.     write_byte(0) // color
  417.     write_byte(1) // duration (will be randomized a bit)
  418.     message_end()
  419.    
  420.     Damage_spear(Ent)
  421.            
  422.     remove_entity(Ent)
  423.    
  424.     g_ready = 0
  425. }
  426.  
  427. public Damage_spear(Ent)
  428. {
  429.     static Owner; Owner = pev(Ent, pev_owner)
  430.     static Attacker
  431.    
  432.     if( !is_user_connected( Owner ) )
  433.         return;
  434.    
  435.     if(!is_user_alive(Owner))
  436.     {
  437.         Attacker = 0
  438.         return
  439.     } else Attacker = Owner
  440.    
  441.     new CsTeams:team = cs_get_user_team( Attacker );
  442.    
  443.     for(new i = 1; i <= g_MaxPlayers; i++)
  444.     {
  445.         if(!is_user_alive(i))
  446.             continue
  447.         if(entity_range(i, Ent) > 100.0)
  448.             continue
  449.  
  450.         if( get_user_godmode( i ) )
  451.             continue;
  452.        
  453.         if( team == CS_TEAM_CT && team == cs_get_user_team( i ) )
  454.             continue;
  455.        
  456.         if(!g_rightclick) ExecuteHamB(Ham_TakeDamage, i, 0, Attacker, get_pcvar_float(cvar_dmg1_spear), DMG_BULLET)
  457.         else ExecuteHamB(Ham_TakeDamage, i, 0, Attacker, get_pcvar_float(cvar_dmg2_spear), DMG_BULLET)
  458.  
  459.         static Float:v_Velocity[3], Float:ori_Velocity[3]
  460.         pev(i, pev_velocity, ori_Velocity)
  461.         v_Velocity[0] = ori_Velocity[0]
  462.         v_Velocity[1] = ori_Velocity[1]
  463.         v_Velocity[2] = 230.0
  464.         entity_set_vector(i, EV_VEC_velocity, v_Velocity)
  465.         g_rightclick = 0
  466.     }
  467.    
  468.     for(new i = 1; i <= g_MaxPlayers; i++)
  469.     {
  470.         if(!is_user_alive(i))
  471.             continue
  472.         if(entity_range(i, Ent) > 200.0)
  473.             continue
  474.         if(!g_had_speargun[i])
  475.             continue
  476.         if(i != Owner)
  477.             continue
  478.         if( get_user_godmode( i ) )
  479.             continue;
  480.            
  481.         if( team == CS_TEAM_CT && team == cs_get_user_team( i ) )
  482.             continue;
  483.        
  484.         static Float:v_Velocity[3], Float:ori_Velocity[3]
  485.         pev(i, pev_velocity, ori_Velocity)
  486.         v_Velocity[0] = ori_Velocity[0]
  487.         v_Velocity[1] = ori_Velocity[1]
  488.         v_Velocity[2] = 250.0
  489.         entity_set_vector(i, EV_VEC_velocity, v_Velocity)
  490.     }
  491. }
  492.  
  493. public fw_SetModel(entity, model[])
  494. {
  495.     if(!pev_valid(entity))
  496.         return FMRES_IGNORED
  497.    
  498.     static Classname[64]
  499.     pev(entity, pev_classname, Classname, sizeof(Classname))
  500.    
  501.     if(!equal(Classname, "weaponbox"))
  502.         return FMRES_IGNORED
  503.    
  504.     static id
  505.     id = pev(entity, pev_owner)
  506.    
  507.     if(equal(model, "models/w_galil.mdl"))
  508.     {
  509.         static weapon
  510.         weapon = fm_get_user_weapon_entity(entity, CSW_GALIL)
  511.        
  512.         if(!pev_valid(weapon))
  513.             return FMRES_IGNORED
  514.        
  515.         if(g_had_speargun[id])
  516.         {
  517.             set_pev(weapon, pev_impulse, 19391)
  518.             set_pev(weapon, pev_iuser4, g_speargun_ammo[id])
  519.             engfunc(EngFunc_SetModel, entity, w_model)
  520.            
  521.             g_had_speargun[id] = 0
  522.             g_speargun_ammo[id] = 0
  523.            
  524.             return FMRES_SUPERCEDE
  525.         }
  526.     }
  527.  
  528.     return FMRES_IGNORED;
  529. }
  530.  
  531. public fw_AddToPlayer_Post(ent, id)
  532. {
  533.     if(pev(ent, pev_impulse) == 19391)
  534.     {
  535.         g_had_speargun[id] = 1
  536.         g_speargun_ammo[id] = pev(ent, pev_iuser4)
  537.        
  538.         set_pev(ent, pev_impulse, 0)
  539.     }          
  540.    
  541.     message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("WeaponList"), _, id)
  542.     write_string((g_had_speargun[id] == 1 ? "weapon_speargun" : "weapon_galil"))
  543.     write_byte(1)
  544.     write_byte(90)
  545.     write_byte(-1)
  546.     write_byte(-1)
  547.     write_byte(0)
  548.     write_byte(17)
  549.     write_byte(CSW_GALIL)
  550.     write_byte(0)
  551.     message_end()
  552. }
  553.  
  554. public update_ammo(id)
  555. {
  556.     if(!is_user_alive(id))
  557.         return
  558.    
  559.     static weapon_ent; weapon_ent = fm_find_ent_by_owner(-1, "weapon_galil", id)
  560.     if(pev_valid(weapon_ent)) cs_set_weapon_ammo(weapon_ent, 1)
  561.    
  562.     cs_set_user_bpammo(id, CSW_GALIL, 0)
  563.    
  564.     engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, get_user_msgid("CurWeapon"), {0, 0, 0}, id)
  565.     write_byte(1)
  566.     write_byte(CSW_GALIL)
  567.     write_byte(-1)
  568.     message_end()
  569.    
  570.     message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("AmmoX"), _, id)
  571.     write_byte(1)
  572.     write_byte(g_speargun_ammo[id])
  573.     message_end()
  574. }
  575.  
  576. public fw_traceline(Float:v1[3],Float:v2[3],noMonsters,id,ptr)
  577. {
  578.     if(!is_user_alive(id))
  579.         return HAM_IGNORED 
  580.     if(get_user_weapon(id) != CSW_GALIL || !g_had_speargun[id])
  581.         return HAM_IGNORED
  582.  
  583.     // get crosshair aim
  584.     static Float:aim[3];
  585.     get_aim(id,v1,aim);
  586.    
  587.     // do another trace to this spot
  588.     new trace = create_tr2();
  589.     engfunc(EngFunc_TraceLine,v1,aim,noMonsters,id,trace);
  590.    
  591.     // copy ints
  592.     set_tr2(ptr,TR_AllSolid,get_tr2(trace,TR_AllSolid));
  593.     set_tr2(ptr,TR_StartSolid,get_tr2(trace,TR_StartSolid));
  594.     set_tr2(ptr,TR_InOpen,get_tr2(trace,TR_InOpen));
  595.     set_tr2(ptr,TR_InWater,get_tr2(trace,TR_InWater));
  596.     set_tr2(ptr,TR_pHit,get_tr2(trace,TR_pHit));
  597.     set_tr2(ptr,TR_iHitgroup,get_tr2(trace,TR_iHitgroup));
  598.  
  599.     // copy floats
  600.     get_tr2(trace,TR_flFraction,aim[0]);
  601.     set_tr2(ptr,TR_flFraction,aim[0]);
  602.     get_tr2(trace,TR_flPlaneDist,aim[0]);
  603.     set_tr2(ptr,TR_flPlaneDist,aim[0]);
  604.    
  605.     // copy vecs
  606.     get_tr2(trace,TR_vecEndPos,aim);
  607.     set_tr2(ptr,TR_vecEndPos,aim);
  608.     get_tr2(trace,TR_vecPlaneNormal,aim);
  609.     set_tr2(ptr,TR_vecPlaneNormal,aim);
  610.  
  611.     // get rid of new trace
  612.     free_tr2(trace);
  613.  
  614.     return FMRES_IGNORED;
  615. }
  616.  
  617. get_aim(id,Float:source[3],Float:ret[3])
  618. {
  619.     static Float:vAngle[3], Float:pAngle[3], Float:dir[3], Float:temp[3];
  620.  
  621.     // get aiming direction from forward global based on view angle and punch angle
  622.     pev(id,pev_v_angle,vAngle);
  623.     pev(id,pev_punchangle,pAngle);
  624.     xs_vec_add(vAngle,pAngle,temp);
  625.     engfunc(EngFunc_MakeVectors,temp);
  626.     global_get(glb_v_forward,dir);
  627.    
  628.     /* vecEnd = vecSrc + vecDir * flDistance; */
  629.     xs_vec_mul_scalar(dir,8192.0,temp);
  630.     xs_vec_add(source,temp,ret);
  631. }
  632.  
  633. stock make_bullet(id, Float:Origin[3])
  634. {
  635.     // Find target
  636.     new decal = random_num(41, 45)
  637.     const loop_time = 2
  638.    
  639.     static Body, Target
  640.     get_user_aiming(id, Target, Body, 999999)
  641.    
  642.     if(is_user_connected(Target))
  643.         return
  644.    
  645.     for(new i = 0; i < loop_time; i++)
  646.     {
  647.         // Put decal on "world" (a wall)
  648.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  649.         write_byte(TE_WORLDDECAL)
  650.         engfunc(EngFunc_WriteCoord, Origin[0])
  651.         engfunc(EngFunc_WriteCoord, Origin[1])
  652.         engfunc(EngFunc_WriteCoord, Origin[2])
  653.         write_byte(decal)
  654.         message_end()
  655.     }
  656. }
  657.  
  658. public fake_smokes(id, Float:Origin[3])
  659. {
  660.     static TE_FLAG
  661.    
  662.     TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
  663.     TE_FLAG |= TE_EXPLFLAG_NOSOUND
  664.     TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
  665.    
  666.     engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, Origin, 0)
  667.     write_byte(TE_EXPLOSION)
  668.     engfunc(EngFunc_WriteCoord, Origin[0])
  669.     engfunc(EngFunc_WriteCoord, Origin[1])
  670.     engfunc(EngFunc_WriteCoord, Origin[2] - 10.0)
  671.     write_short(g_smokepuff_id)
  672.     write_byte(2)
  673.     write_byte(80)
  674.     write_byte(TE_FLAG)
  675.     message_end()
  676. }
  677.  
  678. stock set_weapon_anim(id, anim)
  679. {
  680.     if(!is_user_alive(id))
  681.         return
  682.    
  683.     set_pev(id, pev_weaponanim, anim)
  684.    
  685.     message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
  686.     write_byte(anim)
  687.     write_byte(pev(id, pev_body))
  688.     message_end()
  689. }
  690.  
  691. stock create_blood(const Float:origin[3])
  692. {
  693.     // Show some blood :)
  694.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  695.     write_byte(TE_BLOODSPRITE)
  696.     engfunc(EngFunc_WriteCoord, origin[0])
  697.     engfunc(EngFunc_WriteCoord, origin[1])
  698.     engfunc(EngFunc_WriteCoord, origin[2])
  699.     write_short(m_iBlood[1])
  700.     write_short(m_iBlood[0])
  701.     write_byte(75)
  702.     write_byte(8)
  703.     message_end()
  704. }
  705.  
  706. stock drop_weapons(id, dropwhat)
  707. {
  708.     static weapons[32], num, i, weaponid
  709.     num = 0
  710.     get_user_weapons(id, weapons, num)
  711.      
  712.     for (i = 0; i < num; i++)
  713.     {
  714.         weaponid = weapons[i]
  715.          
  716.         if (dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM))
  717.         {
  718.             static wname[32]
  719.             get_weaponname(weaponid, wname, sizeof wname - 1)
  720.             engclient_cmd(id, "drop", wname)
  721.         }
  722.     }
  723. }
  724.  
  725. stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
  726. {
  727.     new_velocity[0] = origin2[0] - origin1[0]
  728.     new_velocity[1] = origin2[1] - origin1[1]
  729.     new_velocity[2] = origin2[2] - origin1[2]
  730.     static Float:num; num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
  731.     new_velocity[0] *= num
  732.     new_velocity[1] *= num
  733.     new_velocity[2] *= num
  734.    
  735.     return 1;
  736. }
  737.  
  738. stock get_position(id,Float:forw, Float:right, Float:up, Float:vStart[])
  739. {
  740.     static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
  741.    
  742.     pev(id, pev_origin, vOrigin)
  743.     pev(id, pev_view_ofs, vUp) //for player
  744.     xs_vec_add(vOrigin, vUp, vOrigin)
  745.     pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
  746.    
  747.     angle_vector(vAngle, ANGLEVECTOR_FORWARD, vForward) //or use EngFunc_AngleVectors
  748.     angle_vector(vAngle, ANGLEVECTOR_RIGHT, vRight)
  749.     angle_vector(vAngle, ANGLEVECTOR_UP, vUp)
  750.    
  751.     vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
  752.     vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
  753.     vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
  754. }
  755.  
  756. stock hook_ent2(ent, Float:VicOrigin[3], Float:speed, type)
  757. {
  758.     if( get_user_godmode( ent ) )
  759.         return;
  760.    
  761.     static Float:fl_Velocity[3]
  762.     static Float:EntOrigin[3]
  763.    
  764.     pev(ent, pev_origin, EntOrigin)
  765.     static Float:distance_f
  766.     distance_f = 100.0
  767.    
  768.     new Float:fl_Time = distance_f / speed
  769.    
  770.     if(type == 1)
  771.     {
  772.         fl_Velocity[0] = ((VicOrigin[0] - EntOrigin[0]) / fl_Time) * 1.5
  773.         fl_Velocity[1] = ((VicOrigin[1] - EntOrigin[1]) / fl_Time) * 1.5
  774.         fl_Velocity[2] = (VicOrigin[2] - EntOrigin[2]) / fl_Time       
  775.         } else if(type == 2) {
  776.         fl_Velocity[0] = ((EntOrigin[0] - VicOrigin[0]) / fl_Time) * 1.5
  777.         fl_Velocity[1] = ((EntOrigin[1] - VicOrigin[1]) / fl_Time) * 1.5
  778.         fl_Velocity[2] = (EntOrigin[2] - VicOrigin[2]) / fl_Time
  779.     }
  780.    
  781.     entity_set_vector(ent, EV_VEC_velocity, fl_Velocity)
  782. }
  783.  
  784. stock set_weapons_timeidle(id, WeaponId ,Float:TimeIdle)
  785. {
  786.     if(!is_user_alive(id))
  787.         return
  788.        
  789.     static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
  790.     if(!pev_valid(entwpn))
  791.         return
  792.        
  793.     set_pdata_float(entwpn, 46, TimeIdle, OFFSET_LINUX_WEAPONS)
  794.     set_pdata_float(entwpn, 47, TimeIdle, OFFSET_LINUX_WEAPONS)
  795.     set_pdata_float(entwpn, 48, TimeIdle + 0.5, OFFSET_LINUX_WEAPONS)
  796. }
  797.  
  798. stock set_player_nextattackx(id, Float:nexttime)
  799. {
  800.     if(!is_user_alive(id))
  801.         return
  802.        
  803.     set_pdata_float(id, m_flNextAttack, nexttime, 5)
  804. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement