MasamuneDate

Amx Apache

May 28th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 29.74 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <cstrike>
  4. #include <fun>
  5. #include <engine>
  6. #include <fakemeta>
  7. #include <codmod>
  8. #include <colorchat>
  9. #include <hamsandwich>
  10.  
  11. #define TASK_ROCKET 6740100
  12. #define TASK_BOMB 6760200
  13. #define VERSION "1.2.2"
  14.  
  15. new const nazwa[] = "Black Ops Comander";
  16. new const opis[] = "Say /mount to create Apache, and say /unmount di disasamble, Nightvision for Stealth Mode. You have 2 Apache";
  17. new const bronie = 1<<CSW_FLASHBANG | 1<<CSW_HEGRENADE | 1<<CSW_SMOKEGRENADE;
  18. new const zdrowie = 0;
  19. new const kondycja = 0;
  20. new const inteligencja = 0;
  21. new const wytrzymalosc = 50;
  22.  
  23. new bool:ma_klase[33];
  24. new ilosc_uzyc[33];
  25.  
  26. new apaches[33], camera[33], apache_speed[33], grabbed[33]
  27. new smoke, boom, laserbeam
  28. new maxplayers, maxentities
  29. new bool:wait_rocket[33], bool:wait_bomb[33], bool:wait_stealth[33], stealth[33]
  30. new gmsgNVGToggle
  31. new g_apacheactive = 0
  32.  
  33. new active,health,maxspeed2,stealthamt,stealthspeed,stealthregen,bulletdmg,bulletspeed;
  34. new rocketspeed,distance,height,beams,cost,ff,c_ilosc_uzyc;
  35.  
  36. public plugin_init()
  37. {
  38.     register_plugin(nazwa, VERSION, "SeeK")
  39.     cod_register_class(nazwa, opis, bronie, zdrowie, kondycja, inteligencja, wytrzymalosc);
  40.    
  41.     register_clcmd("say /mount", "create_apache")
  42.     register_clcmd("say /unmount", "destroy_apache")
  43.    
  44.     register_clcmd("drop", "stop_apache")
  45.     register_clcmd("nightvision", "stealth_mode")
  46.    
  47.     active =           register_cvar("apache_active", "1")
  48.     health =           register_cvar("apache_health", "300")
  49.     maxspeed2 =         register_cvar("apache_maxspeed", "500")
  50.     stealthamt =       register_cvar("apache_stealth_amount", "100")
  51.     stealthspeed =    register_cvar("apache_stealth_maxspeed", "350")
  52.     stealthregen =    register_cvar("apache_stealth_regen", "10")
  53.     bulletdmg =        register_cvar("apache_bulletdmg", "10")
  54.     bulletspeed =     register_cvar("apache_bulletspeed", "2000")
  55.     rocketspeed =     register_cvar("apache_rocketspeed", "1000")
  56.     distance =         register_cvar("apache_dist", "70")
  57.     height =           register_cvar("apache_height", "20")
  58.     beams =            register_cvar("apache_beams", "0")
  59.     cost =             register_cvar("apache_cost", "0")
  60.     ff =              register_cvar("apache_ff", "0")
  61.     c_ilosc_uzyc =  register_cvar("apache_max_use", "1")
  62.    
  63.     register_event("DeathMsg", "death_event", "a")
  64.     register_event("ResetHUD", "resethud_event", "be") //bad
  65.     register_event("CurWeapon", "check_weapon", "be", "1=1")
  66.     register_logevent("new_round", 2, "0=World triggered", "1=Round_Start")
  67.     register_event("TextMsg", "game_restart", "a", "1=4", "2&#Game_C", "2&#Game_w")
  68.     register_event("SendAudio", "round_end", "a", "2=%!MRAD_terwin", "2=%!MRAD_ctwin", "2=%!MRAD_rounddraw")
  69.     register_forward(FM_EmitSound,"emitsound",0)
  70.    
  71.     maxplayers = get_maxplayers() + 1
  72.     maxentities = get_global_int(GL_maxEntities)
  73.    
  74.     gmsgNVGToggle = get_user_msgid("NVGToggle")
  75. }
  76.  
  77. public cod_class_enabled(id)
  78. {
  79.     ma_klase[id] = true
  80.    
  81.     return COD_CONTINUE;
  82. }
  83.  
  84. public cod_class_disabled(id)
  85.     ma_klase[id] = false
  86.    
  87. public client_connect(id)
  88. {      
  89.     if(task_exists(54545454+id))
  90.     {
  91.         remove_task(54545454+id)
  92.     }
  93.     ilosc_uzyc[id] = c_ilosc_uzyc
  94.     apaches[id] = 0
  95.     camera[id] = 0
  96.     grabbed[id] = 0
  97.     wait_rocket[id] = false
  98.     wait_bomb[id] = false
  99.     wait_stealth[id] = false
  100.     stealth[id] = false
  101. }
  102.  
  103. public client_disconnect(id)
  104. {
  105.     if(task_exists(54545454+id))
  106.     {
  107.         remove_task(54545454+id)
  108.     }
  109.     if(apaches[id] > 0)
  110.     {
  111.         emit_sound(apaches[id], CHAN_VOICE, "vox/_period.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  112.         remove_entity(apaches[id])
  113.         apaches[id] = 0
  114.     }
  115.     if(camera[id] > 0)
  116.     {
  117.         remove_entity(camera[id])
  118.         camera[id] = 0
  119.     }
  120.     grabbed[id] = 0
  121.     wait_rocket[id] = false
  122.     wait_bomb[id] = false
  123.     wait_stealth[id] = false
  124.     stealth[id] = false
  125. }
  126.  
  127. public new_round()
  128. {
  129.     for(new i = 1; i < 33; ++i)
  130.         ilosc_uzyc[i] = c_ilosc_uzyc
  131.        
  132.     new ent
  133.     while((ent = find_ent_by_class(ent,"apache_bullet")) != 0)
  134.         remove_entity(ent)
  135.    
  136.     ent = find_ent_by_class(-1, "apache_rocket")
  137.     new tempent
  138.     while(ent > 0)
  139.     {
  140.         tempent = find_ent_by_class(ent, "apache_rocket")
  141.         emit_sound(ent, CHAN_WEAPON, "vox/_period.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  142.         //emit_sound(ent, CHAN_VOICE, "vox/_period.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  143.         remove_entity(ent)
  144.         ent = tempent
  145.     }
  146.     set_task(0.1, "set_speed", 875457545)
  147. }
  148.  
  149. public round_end()
  150. {
  151.     set_task(4.0, "disable_sound", 212454212)
  152. }
  153.  
  154. public game_restart()
  155. {
  156.     set_task(0.5, "disable_sound", 787454241)
  157. }
  158.  
  159. public disable_sound()
  160. {
  161.     new players[32], inum, player
  162.     get_players(players, inum, "a")
  163.     for(new i = 0 ; i < inum ; i++)
  164.     {
  165.         player = players[i]
  166.         if(apaches[player] > 0)
  167.         {
  168.             emit_sound(apaches[player], CHAN_VOICE, "vox/_period.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  169.         }
  170.     }
  171. }
  172.  
  173. public death_event()
  174. {
  175.     g_apacheactive = get_pcvar_num(active)
  176.     new id = read_data(2)
  177.    
  178.     if(task_exists(54545454+id))
  179.     {
  180.         remove_task(54545454+id)
  181.     }
  182.     if(apaches[id] > 0)
  183.     {
  184.         emit_sound(apaches[id], CHAN_VOICE, "vox/_period.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  185.         remove_entity(apaches[id])
  186.         apaches[id] = 0
  187.     }
  188.     if(camera[id] > 0)
  189.     {
  190.         attach_view(id, id)
  191.         remove_entity(camera[id])
  192.         camera[id] = 0
  193.     }
  194.     for(new i = 1 ; i < maxplayers ; i++)
  195.     {
  196.         if(grabbed[i] == id)
  197.         {
  198.             grabbed[i] = 0
  199.         }
  200.     }
  201.     grabbed[id] = 0
  202.     wait_rocket[id] = false
  203.     wait_bomb[id] = false
  204.     wait_stealth[id] = false
  205.     stealth[id] = false
  206.     client_cmd(id, "-left")
  207.     client_cmd(id, "-right")
  208.     message_begin(MSG_ONE, gmsgNVGToggle, {0,0,0}, id)
  209.     write_byte(0)
  210.     message_end()
  211. }
  212.  
  213. public resethud_event(id)
  214. {  
  215.     g_apacheactive = get_pcvar_num(active)
  216.     if(task_exists(54545454+id))
  217.     {
  218.         remove_task(54545454+id)
  219.     }
  220.     if(apaches[id] > 0)
  221.     {
  222.         new Float:apachecost = get_pcvar_float(cost)
  223.         new Float:apachehealth = get_pcvar_float(health)
  224.         new Float:apachecurhealth = entity_get_float(apaches[id], EV_FL_health) - 5000
  225.         new payback = floatround((apachecost * apachecurhealth) / apachehealth)
  226.         cs_set_user_money(id, cs_get_user_money(id) + payback, 1)
  227.         emit_sound(apaches[id], CHAN_VOICE, "vox/_period.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  228.         remove_entity(apaches[id])
  229.         apaches[id] = 0
  230.     }
  231.     if(camera[id] > 0)
  232.     {
  233.         attach_view(id, id)
  234.         remove_entity(camera[id])
  235.         camera[id] = 0
  236.     }
  237.     grabbed[id] = 0
  238.     wait_rocket[id] = false
  239.     wait_bomb[id] = false
  240.     wait_stealth[id] = false
  241.     stealth[id] = false
  242.     client_cmd(id, "-left")
  243.     client_cmd(id, "-right")
  244.     message_begin(MSG_ONE, gmsgNVGToggle, {0,0,0}, id)
  245.     write_byte(0)
  246.     message_end()
  247. }
  248.  
  249. public check_weapon(id)
  250. {
  251.        
  252.     if(apaches[id] > 0)
  253.     {
  254.         client_cmd(id, "weapon_knife")
  255.         set_user_maxspeed(id, -1.0)
  256.     }
  257. }
  258.  
  259. public set_speed(id)
  260. {
  261.        
  262.     new players[32], inum, player
  263.     get_players(players, inum, "a")
  264.     for(new i = 0 ; i < inum ; i++)
  265.     {
  266.         player = players[i]
  267.         if(apaches[player] > 0)
  268.         {
  269.             set_user_maxspeed(player, -1.0)
  270.         }
  271.     }
  272. }
  273.  
  274.  
  275. public create_apache(id,level,cid)
  276. {
  277.     if(!ma_klase[id])
  278.         return PLUGIN_CONTINUE;
  279.    
  280.    
  281.     if(ilosc_uzyc[id] == 0)
  282.     {
  283.         console_print(id, "You can create only 2 helicopter per round.")
  284.         client_print(id, print_center, "You can create only 2 helicopter per round.")
  285.         return PLUGIN_HANDLED
  286.     }
  287.        
  288.     if(get_pcvar_num(active) == 0)
  289.     {
  290.         console_print(id, "WARNING! AMX APACHE IS NOT TURN ON!")
  291.         return PLUGIN_HANDLED
  292.     }
  293.    
  294.     if(apaches[id] > 0)
  295.     {
  296.         console_print(id, "You just control the helicopter.")
  297.         client_print(id, print_center, "You just control the helicopter.")
  298.         return PLUGIN_HANDLED
  299.     }
  300.    
  301.     if(!is_user_alive(id))
  302.     {
  303.         console_print(id, "You can not use a helicopter when you are dead.")
  304.         client_print(id, print_center, "You can not use a helicopter when you are dead.")
  305.         return PLUGIN_HANDLED
  306.     }
  307.    
  308.     new apachecost = get_pcvar_num(cost)
  309.     new usermoney = cs_get_user_money(id)
  310.     if(usermoney < apachecost)
  311.     {
  312.         console_print(id, "You do not have enough money (you need $%i )", apachecost)
  313.         client_print(id, print_center, "You do not have enough money (you need $%i )", apachecost)
  314.         return PLUGIN_HANDLED
  315.     }
  316.     cs_set_user_money(id, usermoney - apachecost, 1)
  317.    
  318.     ilosc_uzyc[id]--;
  319.     set_user_rendering(id, kRenderFxNone, 0, 0, 0, kRenderTransAlpha, 0);
  320.    
  321.     new Float:origin[3]
  322.     new Float:angles[3]
  323.     entity_get_vector(id, EV_VEC_origin, origin)
  324.     entity_get_vector(id, EV_VEC_v_angle, angles)
  325.    
  326.     apaches[id] = create_entity("info_target")
  327.     if(apaches[id] > 0)
  328.     {
  329.         entity_set_string(apaches[id], EV_SZ_classname, "amx_apache")
  330.         entity_set_model(apaches[id], "models/rc_apache_final.mdl")
  331.        
  332.         entity_set_size(apaches[id], Float:{-12.0,-12.0,-6.0}, Float:{12.0,12.0,6.0})
  333.        
  334.         entity_set_origin(apaches[id], origin)
  335.         entity_set_vector(apaches[id], EV_VEC_angles, angles)
  336.        
  337.         entity_set_int(apaches[id], EV_INT_solid, 2)
  338.         entity_set_int(apaches[id], EV_INT_movetype, 5)
  339.         entity_set_edict(apaches[id], EV_ENT_owner, id)
  340.         entity_set_int(apaches[id], EV_INT_sequence, 1)
  341.         entity_set_float(apaches[id], EV_FL_takedamage, DAMAGE_AIM)
  342.         entity_set_float(apaches[id], EV_FL_health, get_pcvar_float(health) + 5000.0)
  343.        
  344.         apache_speed[id] = 50
  345.        
  346.         new Float:velocity[3]
  347.         VelocityByAim(id, apache_speed[id], velocity)
  348.         entity_set_vector(apaches[id], EV_VEC_velocity, velocity)
  349.        
  350.         emit_sound(apaches[id], CHAN_VOICE, "apache/ap_rotor2.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  351.     }
  352.    
  353.     camera[id] = create_entity("info_target")
  354.     if(camera[id] > 0)
  355.     {
  356.         entity_set_string(camera[id], EV_SZ_classname, "camera")
  357.         entity_set_int(camera[id], EV_INT_solid, SOLID_NOT)
  358.         entity_set_int(camera[id], EV_INT_movetype, MOVETYPE_NOCLIP)
  359.         entity_set_size(camera[id], Float:{0,0,0}, Float:{0,0,0})
  360.         entity_set_model(camera[id], "models/rpgrocket.mdl")
  361.         set_rendering(camera[id], kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, 0)
  362.        
  363.         entity_set_origin(camera[id], origin)
  364.         entity_set_vector(camera[id], EV_VEC_angles, angles)
  365.        
  366.         attach_view(id, camera[id])
  367.     }
  368.    
  369.     engclient_cmd(id, "weapon_knife")
  370.     set_user_maxspeed(id, -1.0)
  371.    
  372.     if(task_exists(54545454+id))
  373.     {
  374.         remove_task(54545454+id)
  375.     }
  376.    
  377.     grabbed[id] = 0
  378.     wait_rocket[id] = false
  379.     wait_bomb[id] = false
  380.     wait_stealth[id] = false
  381.     stealth[id] = false
  382.    
  383.     return PLUGIN_HANDLED
  384. }
  385.  
  386. public destroy_apache(id,level,cid)
  387. {
  388.     if(!ma_klase[id])
  389.         return PLUGIN_CONTINUE;
  390.        
  391.     if (!cmd_access(id,level,cid,1))
  392.     {
  393.         return PLUGIN_HANDLED
  394.     }
  395.    
  396.     if(apaches[id] > 0)
  397.     {
  398.         attach_view(id, id)
  399.         emit_sound(apaches[id], CHAN_VOICE, "vox/_period.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  400.         remove_entity(apaches[id])
  401.         apaches[id] = 0
  402.         set_user_maxspeed(id, 250.0)
  403.     }
  404.     if(camera[id] > 0)
  405.     {
  406.         attach_view(id, id)
  407.         remove_entity(camera[id])
  408.         camera[id] = 0
  409.     }
  410.    
  411.     if(task_exists(54545454+id))
  412.     {
  413.         remove_task(54545454+id)
  414.     }
  415.    
  416.     grabbed[id] = 0
  417.     wait_rocket[id] = false
  418.     wait_bomb[id] = false
  419.     wait_stealth[id] = false
  420.     stealth[id] = false
  421.     client_cmd(id, "-left")
  422.     client_cmd(id, "-right")
  423.    
  424.     message_begin(MSG_ONE, gmsgNVGToggle, {0,0,0}, id)
  425.     write_byte(0)
  426.     message_end()
  427.     set_user_rendering(id, kRenderFxNone, 0, 0, 0, kRenderTransAlpha, 255);
  428.    
  429.     return PLUGIN_HANDLED
  430. }
  431.  
  432. public stop_apache(id)
  433. {  
  434.     if(!ma_klase[id])
  435.         return PLUGIN_CONTINUE;
  436.     if(apaches[id] > 0)
  437.     {
  438.         if(apache_speed[id] <= 30 && apache_speed[id] >= -30)
  439.         {
  440.             apache_speed[id] = 0
  441.         }
  442.         return PLUGIN_HANDLED
  443.     }
  444.    
  445.     return PLUGIN_CONTINUE
  446. }
  447.  
  448. public stealth_mode(id)
  449. {  
  450.     if(!ma_klase[id])
  451.         return PLUGIN_CONTINUE;
  452.     if(apaches[id] > 0)
  453.     {
  454.         if(!wait_stealth[id])
  455.         {
  456.             if(!stealth[id])
  457.             {
  458.                 stealth[id] = true
  459.                 emit_sound(apaches[id], CHAN_VOICE, "apache/ap_rotor2.wav", 0.1, ATTN_NORM, 0, PITCH_NORM)
  460.                 set_rendering(apaches[id], kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, get_pcvar_num(stealthamt))
  461.                 message_begin(MSG_ONE, gmsgNVGToggle, {0,0,0}, id)
  462.                 write_byte(1)
  463.                 message_end()
  464.             }
  465.             else
  466.             {
  467.                 stealth[id] = false
  468.                 emit_sound(apaches[id], CHAN_VOICE, "apache/ap_rotor2.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  469.                 set_rendering(apaches[id])
  470.                 message_begin(MSG_ONE, gmsgNVGToggle, {0,0,0}, id)
  471.                 write_byte(0)
  472.                 message_end()
  473.                 wait_stealth[id] = true
  474.                 new ids[1]
  475.                 ids[0] = id
  476.                 set_task(get_pcvar_float(stealthregen), "reset_stealth", 54545454+id, ids, 1)
  477.             }
  478.         }
  479.         return PLUGIN_HANDLED
  480.     }
  481.    
  482.     return PLUGIN_CONTINUE
  483. }
  484.  
  485. public client_PreThink(id)
  486. {
  487.     if(!ma_klase[id])
  488.         return PLUGIN_CONTINUE;
  489.        
  490.     if(!(apaches[id] > 0))
  491.     {
  492.         set_user_rendering(id, kRenderFxNone, 0, 0, 0, kRenderTransAlpha, 255);
  493.     }
  494.     if(g_apacheactive == 0)
  495.     {
  496.         return PLUGIN_CONTINUE
  497.     }
  498.    
  499.     if(is_user_alive(id) && apaches[id] > 0 && camera[id] > 0)
  500.     {
  501.         new Float:forigin[3], Float:dist_origin[3], Float:camera_origin[3]
  502.         new button, oldbutton
  503.         new apacheId = apaches[id]
  504.         new maxspeed
  505.         new Float:frame
  506.         new apache_maxspeed = get_pcvar_num(maxspeed2)
  507.         new apache_stealth_maxspeed = get_pcvar_num(stealthspeed)
  508.         new Float:angles[3], Float:velocity[3]
  509.         new Float:apache_height = get_pcvar_float(height)
  510.         new apache_bulletspeed = get_pcvar_num(bulletspeed)
  511.         new apache_rocketspeed = get_pcvar_num(rocketspeed)
  512.         new classname[32]
  513.         new Float:aim_origin[3], Float:end_origin[3]
  514.         new apache_beams = get_pcvar_num(beams)
  515.         if(entity_get_float(apacheId, EV_FL_health) < 5000)
  516.         {
  517.             new Float:explosion[3]
  518.             entity_get_vector(apacheId, EV_VEC_origin, explosion)
  519.             message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  520.             write_byte(3)
  521.             write_coord(floatround(explosion[0]))
  522.             write_coord(floatround(explosion[1]))
  523.             write_coord(floatround(explosion[2]))
  524.             write_short(boom)
  525.             write_byte(50)
  526.             write_byte(15)
  527.             write_byte(0)
  528.             message_end()
  529.            
  530.             HL_RadiusDamage(explosion,0,75.0,150.0)
  531.             /*radius_damage(explosion,75,200)*/
  532.            
  533.             attach_view(id, id)
  534.             if(camera[id] > 0)
  535.             {
  536.                 remove_entity(camera[id])
  537.                 camera[id] = 0
  538.             }
  539.             emit_sound(apacheId, CHAN_VOICE, "vox/_period.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  540.             remove_entity(apacheId)
  541.             apaches[id] = 0
  542.             set_user_maxspeed(id, 250.0)
  543.             if(task_exists(54545454+id))
  544.             {
  545.                 remove_task(54545454+id)
  546.             }
  547.             wait_rocket[id] = false
  548.             wait_stealth[id] = false
  549.             stealth[id] = false
  550.             client_cmd(id, "-left")
  551.             client_cmd(id, "-right")
  552.             message_begin(MSG_ONE, gmsgNVGToggle, {0,0,0}, id)
  553.             write_byte(0)
  554.             message_end()
  555.             return PLUGIN_CONTINUE
  556.         }
  557.        
  558.         frame = entity_get_float(apacheId, EV_FL_frame)
  559.         if(frame < 0.0 || frame > 254.0)
  560.         {
  561.             entity_set_float(apacheId, EV_FL_frame, 0.0)
  562.         }
  563.         else
  564.         {
  565.             entity_set_float(apacheId, EV_FL_frame, frame + 1.0)
  566.         }
  567.        
  568.         entity_get_vector(apacheId, EV_VEC_origin, forigin)
  569.         button = get_user_button(id)
  570.         if(button & IN_FORWARD)
  571.         {
  572.             apache_speed[id] += 5
  573.         }
  574.         if(button & IN_BACK)
  575.         {
  576.             apache_speed[id] -= 5
  577.         }
  578.         if(!stealth[id])
  579.         {
  580.             maxspeed = apache_maxspeed
  581.         }
  582.         else
  583.         {
  584.             maxspeed = apache_stealth_maxspeed
  585.         }
  586.         if(apache_speed[id] > maxspeed)
  587.         {
  588.             apache_speed[id] = maxspeed
  589.         }
  590.         if(apache_speed[id] < - 80)
  591.         {
  592.             apache_speed[id] = - 80
  593.         }
  594.        
  595.         entity_get_vector(apacheId, EV_VEC_origin, forigin)
  596.         entity_get_vector(id, EV_VEC_v_angle, angles)
  597.         angles[0] = - angles[0]
  598.         VelocityByAim(id, apache_speed[id], velocity)
  599.         entity_set_vector(apacheId, EV_VEC_angles, angles)
  600.         entity_set_vector(apacheId, EV_VEC_velocity, velocity)
  601.        
  602.         oldbutton = get_user_oldbutton(id)
  603.         if(button & IN_JUMP)
  604.         {
  605.             forigin[2] += 2.0
  606.             if(PointContents(forigin) != CONTENTS_SOLID)
  607.             {
  608.                 entity_set_origin(apacheId, forigin)
  609.             }
  610.         }
  611.         if(button & IN_DUCK)
  612.         {
  613.             forigin[2] -= 2.0
  614.             if(PointContents(forigin) != CONTENTS_SOLID)
  615.             {
  616.                 entity_set_origin(apacheId, forigin)
  617.             }
  618.         }
  619.        
  620.         if(PointContents(forigin) == CONTENTS_SOLID)
  621.         {
  622.             forigin[2] += 10.0
  623.             if(PointContents(forigin) == CONTENTS_SOLID)
  624.             {
  625.                 forigin[2] -= 60.0
  626.             }
  627.             entity_set_origin(apacheId, forigin)
  628.         }
  629.        
  630.         VelocityByAim(id, get_pcvar_num(distance), dist_origin)
  631.         camera_origin[0] = forigin[0] - dist_origin[0]
  632.         camera_origin[1] = forigin[1] - dist_origin[1]
  633.         camera_origin[2] = forigin[2] + apache_height
  634.         entity_set_origin(camera[id], camera_origin)
  635.         angles[0] = - angles[0]
  636.         entity_set_vector(camera[id], EV_VEC_angles, angles)
  637.        
  638.         if(button & IN_ATTACK && !(oldbutton & IN_ATTACK) && get_num_ents() < (maxentities - 50))
  639.         {
  640.             emit_sound(apacheId, CHAN_WEAPON, "weapons/m249-1.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  641.            
  642.             new ent = create_entity("info_target")
  643.             if(ent > 0)
  644.             {
  645.                 entity_set_string(ent, EV_SZ_classname, "apache_bullet")
  646.                 entity_set_model(ent, "models/shell.mdl")
  647.                
  648.                 entity_set_size(ent, Float:{-1.0,-1.0,-1.0}, Float:{1.0,1.0,1.0})
  649.                
  650.                 entity_set_origin(ent, forigin)
  651.                 entity_set_vector(ent, EV_VEC_angles, angles)
  652.                
  653.                 entity_set_int(ent, EV_INT_solid, 1)
  654.                 entity_set_int(ent, EV_INT_movetype, 5)
  655.                 entity_set_edict(ent, EV_ENT_owner, id)
  656.                
  657.                 VelocityByAim(id, apache_bulletspeed, velocity)
  658.                 entity_set_vector(ent, EV_VEC_velocity, velocity)
  659.                
  660.                 message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  661.                 write_byte(22)
  662.                 write_short(ent)
  663.                 write_short(smoke)
  664.                 write_byte(25)
  665.                 write_byte(1)
  666.                 write_byte(255)
  667.                 write_byte(255)
  668.                 write_byte(255)
  669.                 write_byte(128)
  670.                 message_end()
  671.             }
  672.         }
  673.         if(button & IN_ATTACK2 && !wait_rocket[id] && get_num_ents() < (maxentities - 50))
  674.         {
  675.             new ent = create_entity("info_target")
  676.             if(ent > 0)
  677.             {
  678.                 entity_set_string(ent, EV_SZ_classname, "apache_rocket")
  679.                 entity_set_model(ent, "models/rpgrocket.mdl")
  680.                
  681.                 entity_set_size(ent, Float:{-1.0,-1.0,-1.0}, Float:{1.0,1.0,1.0})
  682.                
  683.                 entity_set_origin(ent, forigin)
  684.                 entity_set_vector(ent, EV_VEC_angles, angles)
  685.                
  686.                 entity_set_int(ent, EV_INT_effects, 64)
  687.                 entity_set_int(ent, EV_INT_solid, 1)
  688.                 entity_set_int(ent, EV_INT_movetype, 5)
  689.                 entity_set_edict(ent, EV_ENT_owner, id)
  690.                
  691.                 VelocityByAim(id, apache_rocketspeed, velocity)
  692.                 entity_set_vector(ent, EV_VEC_velocity, velocity)
  693.                
  694.                 message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  695.                 write_byte(22)
  696.                 write_short(ent)
  697.                 write_short(smoke)
  698.                 write_byte(40)
  699.                 write_byte(4)
  700.                 write_byte(255)
  701.                 write_byte(0)
  702.                 write_byte(0)
  703.                 write_byte(128)
  704.                 message_end()
  705.                
  706.                 emit_sound(ent, CHAN_WEAPON, "weapons/rocketfire1.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  707.                 //emit_sound(ent, CHAN_VOICE, "weapons/rocket1.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  708.             }
  709.             wait_rocket[id] = true
  710.             set_task(2.0, "reset_rocket", id+TASK_ROCKET)
  711.         }
  712.         if(button & IN_RELOAD && !wait_bomb[id] && grabbed[id] == 0 && get_num_ents() < (maxentities - 50))
  713.         {
  714.             new ent = create_entity("info_target")
  715.             if(ent > 0)
  716.             {
  717.                 entity_set_string(ent, EV_SZ_classname, "apache_bomb")
  718.                 entity_set_model(ent, "models/rpgrocket.mdl")
  719.                
  720.                 entity_set_size(ent, Float:{-1.0,-1.0,-1.0}, Float:{1.0,1.0,1.0})
  721.                
  722.                 entity_set_origin(ent, forigin)
  723.                 entity_set_vector(ent, EV_VEC_angles, angles)
  724.                
  725.                 entity_set_int(ent, EV_INT_solid, 1)
  726.                 entity_set_int(ent, EV_INT_movetype, 6)
  727.                 entity_set_edict(ent, EV_ENT_owner, id)
  728.             }
  729.             wait_bomb[id] = true
  730.             set_task(4.0, "reset_bomb", id+TASK_BOMB)
  731.         }
  732.         if(button & IN_USE && !(oldbutton & IN_USE))
  733.         {
  734.             if(grabbed[id] == 0)
  735.             {
  736.                 new Float:ent_origin[3]
  737.                 new ent = find_ent_in_sphere(-1, forigin, 60.0)
  738.                 while(ent > 0 && grabbed[id] == 0)
  739.                 {
  740.                     classname[0] = '^0'
  741.                     entity_get_string(ent, EV_SZ_classname, classname, 31)
  742.                     if(equal(classname, "player") || equal(classname, "grenade") || equal(classname, "weaponbox") || equal(classname, "armoury_entity") || equal(classname, "hostage_entity"))
  743.                     {
  744.                         entity_get_vector(ent, EV_VEC_origin, ent_origin)
  745.                         if(ent_origin[2] < forigin[2])
  746.                         {
  747.                             grabbed[id] = ent
  748.                             if(equal(classname, "hostage_entity"))
  749.                             {
  750.                                 entity_set_int(apacheId, EV_INT_solid, 3)
  751.                             }
  752.                         }
  753.                     }
  754.                     ent = find_ent_in_sphere(ent, forigin, 60.0)
  755.                 }
  756.             }
  757.             else
  758.             {
  759.                 classname[0] = '^0'
  760.                 if(is_valid_ent(grabbed[id])) {
  761.                     entity_get_string(grabbed[id], EV_SZ_classname, classname, 31)
  762.                     if(!equal(classname, "player"))
  763.                     {
  764.                         entity_set_vector(grabbed[id], EV_VEC_velocity, Float:{0,0,-20})
  765.                     }
  766.                 }
  767.                 grabbed[id] = 0
  768.                 entity_set_int(apacheId, EV_INT_solid, 2)
  769.             }
  770.         }
  771.         if(button & IN_MOVELEFT)
  772.         {
  773.             client_cmd(id, "+left")
  774.         }
  775.         else if(oldbutton & IN_MOVELEFT)
  776.         {
  777.             client_cmd(id, "-left")
  778.         }
  779.         if(button & IN_MOVERIGHT)
  780.         {
  781.             client_cmd(id, "+right")
  782.         }
  783.         else if(oldbutton & IN_MOVERIGHT)
  784.         {
  785.             client_cmd(id, "-right")
  786.         }
  787.         if(apache_beams == 1)
  788.         {
  789.             VelocityByAim(id, 9999, velocity)
  790.             end_origin[0] = forigin[0] + velocity[0]
  791.             end_origin[1] = forigin[1] + velocity[1]
  792.             end_origin[2] = forigin[2] + velocity[2]
  793.             trace_line(0, forigin, end_origin, aim_origin)
  794.             message_begin(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, {0,0,0}, id)
  795.             write_byte(1)
  796.             write_short(apacheId)
  797.             write_coord(floatround(aim_origin[0]))
  798.             write_coord(floatround(aim_origin[1]))
  799.             write_coord(floatround(aim_origin[2]))
  800.             write_short(laserbeam)
  801.             write_byte(1)
  802.             write_byte(1)
  803.             write_byte(1)
  804.             write_byte(8)
  805.             write_byte(0)
  806.             write_byte(255)
  807.             write_byte(0)
  808.             write_byte(0)
  809.             write_byte(128)
  810.             write_byte(0)
  811.             message_end()
  812.         }
  813.         if(grabbed[id] > 0 && is_valid_ent(grabbed[id]))
  814.         {
  815.             new Float:direction[3], Float:moveto[3], Float:grabbedorigin[3], Float:length
  816.             VelocityByAim(id, 9999, velocity)
  817.             end_origin[0] = forigin[0] + velocity[0]
  818.             end_origin[1] = forigin[1] + velocity[1]
  819.             end_origin[2] = forigin[2] + velocity[2]
  820.             trace_line(0, forigin, end_origin, aim_origin)
  821.            
  822.             entity_get_vector(grabbed[id], EV_VEC_origin, grabbedorigin)
  823.            
  824.             direction[0] = aim_origin[0] - forigin[0]
  825.             direction[1] = aim_origin[1] - forigin[1]
  826.             direction[2] = aim_origin[2] - forigin[2]
  827.            
  828.             length = vector_distance(aim_origin,forigin)
  829.             if (!length) length = 1.0
  830.            
  831.             moveto[0] = forigin[0] + direction[0] / length
  832.             moveto[1] = forigin[1] + direction[1] / length
  833.             classname[0] = '^0'
  834.             entity_get_string(grabbed[id], EV_SZ_classname, classname, 31)
  835.             if(equal(classname, "player"))
  836.             {
  837.                 moveto[2] = (forigin[2] + direction[2] / length) - 45.0
  838.                 velocity[0] = (moveto[0] - grabbedorigin[0]) * 5
  839.                 velocity[1] = (moveto[1] - grabbedorigin[1]) * 5
  840.                 velocity[2] = (moveto[2] - grabbedorigin[2]) * 5
  841.             }
  842.             else
  843.             {
  844.                 moveto[2] = (forigin[2] + direction[2] / length) - 15.0
  845.                 velocity[0] = (moveto[0] - grabbedorigin[0]) * 10
  846.                 velocity[1] = (moveto[1] - grabbedorigin[1]) * 10
  847.                 velocity[2] = (moveto[2] - grabbedorigin[2]) * 10
  848.             }
  849.            
  850.             entity_set_vector(grabbed[id], EV_VEC_velocity, velocity)
  851.         }
  852.         set_hudmessage(255, 255, 255, -2.0, 0.76, 0, 1.0, 0.01, 0.1, 0.2, 4)
  853.         show_hudmessage(id, " [APACHE] Speed: %i, Health: %i", apache_speed[id], floatround(entity_get_float(apaches[id], EV_FL_health) - 5000))
  854.     }
  855.    
  856.     return PLUGIN_CONTINUE
  857. }
  858.  
  859. public reset_rocket(id)
  860. {  
  861.     wait_rocket[id-TASK_ROCKET] = false
  862. }
  863.  
  864. public reset_bomb(id)
  865. {  
  866.     wait_bomb[id-TASK_BOMB] = false
  867. }
  868.  
  869. public reset_stealth(ids[])
  870. {
  871.     wait_stealth[ids[0]] = false
  872. }
  873.  
  874. public pfn_touch(entity1, entity2)
  875. {
  876.     if(g_apacheactive == 0)
  877.     {
  878.         return PLUGIN_CONTINUE
  879.     }
  880.    
  881.     if(entity1 > 0 && is_valid_ent(entity1))
  882.     {
  883.         new classname[32]
  884.         entity_get_string(entity1, EV_SZ_classname, classname, 31)
  885.         new classname2[32]
  886.         if(entity2 > 0 && is_valid_ent(entity2))
  887.         {
  888.             entity_get_string(entity2, EV_SZ_classname, classname2, 31)
  889.         }
  890.        
  891.         new attacker = entity_get_edict(entity1, EV_ENT_owner)
  892.        
  893.         if(!ma_klase[attacker])
  894.             return PLUGIN_CONTINUE;
  895.        
  896.         if((equal(classname, "apache_rocket") || equal(classname, "apache_bomb")) && (entity2 == 0 || equal(classname2, "player") || equal(classname2, "amx_apache") || equal(classname2, "apache_rocket") || equal(classname2, "func_breakable") || equal(classname2, "func_pushable")))
  897.         {
  898.             if(entity2 > 0)
  899.             {
  900.                 if(attacker == entity_get_edict(entity2, EV_ENT_owner))
  901.                 {
  902.                     return PLUGIN_CONTINUE
  903.                 }
  904.             }
  905.            
  906.             new Float:explosion[3]
  907.             entity_get_vector(entity1, EV_VEC_origin, explosion)
  908.            
  909.             if(!stealth[attacker])
  910.             {
  911.                 /*radius_damage(explosion,200,300)*/
  912.                 HL_RadiusDamage(explosion,0,100.0,120.0)
  913.             }
  914.             else
  915.             {
  916.                 /*radius_damage(explosion,120,300)*/
  917.                 HL_RadiusDamage(explosion,0,120.0,80.0)
  918.             }
  919.            
  920.             message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  921.             write_byte(3)
  922.             write_coord(floatround(explosion[0]))
  923.             write_coord(floatround(explosion[1]))
  924.             write_coord(floatround(explosion[2]))
  925.             write_short(boom)
  926.             write_byte(50)
  927.             write_byte(15)
  928.             write_byte(0)
  929.             message_end()
  930.            
  931.             emit_sound(entity1, CHAN_WEAPON, "vox/_period.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  932.             //emit_sound(entity1, CHAN_VOICE, "vox/_period.wav", 0.8, ATTN_NORM, 0, PITCH_NORM)
  933.            
  934.             remove_entity(entity1)
  935.         }
  936.         if(equal(classname, "apache_bullet"))
  937.         {
  938.             if(equal(classname2, "player") || equal(classname2, "amx_apache") || equal(classname2, "func_breakable") || equal(classname2, "func_pushable"))
  939.             {
  940.                 if(entity2 > 0)
  941.                 {
  942.                     if(attacker == entity_get_edict(entity2, EV_ENT_owner))
  943.                     {
  944.                         return PLUGIN_CONTINUE
  945.                     }
  946.                     if(equal(classname2, "func_breakable") || equal(classname2, "func_pushable"))
  947.                     {
  948.                         force_use(entity2, attacker)
  949.                     }
  950.                     else
  951.                     {
  952.                         new Float:origin[3]
  953.                         entity_get_vector(entity2, EV_VEC_origin, origin)
  954.                         cod_inflict_damage( attacker, entity2, get_pcvar_float(bulletdmg) + 5.0, 1.0, CSW_KNIFE, (1<<24))
  955.                     }
  956.                 }
  957.             }
  958.            
  959.             remove_entity(entity1)
  960.         }
  961.         if(equal(classname, "amx_apache"))
  962.         {
  963.             if(equal(classname2, "player") || equal(classname2, "amx_apache") || equal(classname2, "func_breakable") || equal(classname2, "func_pushable"))
  964.             {
  965.                
  966.                 if(equal(classname2, "player") || equal(classname2, "amx_apache"))
  967.                 {
  968.                     new friendlyfire = get_pcvar_num(ff);
  969.                     if((friendlyfire == 1 || friendlyfire == 0 && get_user_team(attacker) != get_user_team(entity2)))
  970.                     {
  971.                         new Float:origin[3]
  972.                         entity_get_vector(entity2, EV_VEC_origin, origin)
  973.                         if(equal(classname2, "player") && get_user_health(entity2) == 1)
  974.                         {
  975.                             client_print(entity2, print_center, "NEVER STAND IN THE ROTORS AGAIN!")
  976.                         }
  977.                         cod_inflict_damage( attacker, entity2, 1.0, 1.0, entity2, (1<<24))
  978.                     }
  979.                 }
  980.                 else if(equal(classname2, "func_breakable") || equal(classname2, "func_pushable"))
  981.                 {
  982.                     force_use(entity2, attacker)
  983.                 }
  984.             }
  985.         }
  986.     }
  987.    
  988.     return PLUGIN_CONTINUE
  989. }
  990.  
  991. public emitsound(entity, const sample[])
  992. {
  993.     if(equal(sample, "common/wpn_denyselect.wav"))
  994.     {
  995.         return FMRES_SUPERCEDE
  996.     }
  997.     return FMRES_IGNORED
  998. }
  999.  
  1000. public plugin_precache()
  1001. {
  1002.     laserbeam = precache_model("sprites/laserbeam.spr")
  1003.     smoke = precache_model("sprites/smoke.spr")
  1004.     boom = precache_model("sprites/zerogxplode.spr")
  1005.    
  1006.     precache_model("models/rc_apache_final.mdl")
  1007.     precache_model("models/rpgrocket.mdl")
  1008.     precache_model("models/shell.mdl")
  1009.    
  1010.     precache_sound("vox/_period.wav")
  1011.     precache_sound("weapons/rocketfire1.wav")
  1012.     precache_sound("weapons/rocket1.wav")
  1013.     precache_sound("weapons/m249-1.wav")
  1014.     precache_sound("apache/ap_rotor2.wav")
  1015. }
  1016.  
  1017. public get_num_ents()
  1018. {
  1019.     new i, count;
  1020.     for(i=1;i<maxentities;i++)
  1021.     {
  1022.         if(is_valid_ent(i))
  1023.             count++
  1024.     }
  1025.     return count;
  1026. }
  1027.  
  1028. ///////////////// THANKS AVALANCHE!! ///////////////////
  1029.  
  1030. public HL_RadiusDamage( Float:vecSrc[3], /*pevAttacker,*/ pevInflictor, Float:flDamage, Float:flRadius/*, iClassIgnore, bitsDamageType*/ )
  1031. {
  1032.     new pEntity;
  1033.     new tr;
  1034.     new Float:flAdjustedDamage, Float:falloff;
  1035.     new Float:vecSpot[3];
  1036.    
  1037.     // NEW
  1038.     new Float:vecAbsMin[3], Float:vecAbsMax[3], Float:vecAdjust[3],
  1039.     Float:vecEndPos[3], Float:flFraction, iWaterLevel, i;
  1040.    
  1041.     if( flRadius )
  1042.         falloff = flDamage / flRadius;
  1043.     else
  1044.         falloff = 1.0;
  1045.    
  1046.     new bInWater = (engfunc( EngFunc_PointContents, vecSrc ) == CONTENTS_WATER);
  1047.    
  1048.     vecSrc[2] += 1;// in case grenade is lying on the ground
  1049.    
  1050.     // iterate on all entities in the vicinity.
  1051.     while ((pEntity = engfunc( EngFunc_FindEntityInSphere, pEntity, vecSrc, flRadius )) != 0)
  1052.     {
  1053.         if ( pev( pEntity, pev_takedamage ) != DAMAGE_NO )
  1054.         {
  1055.             iWaterLevel = pev( pEntity, pev_waterlevel ); // NEW
  1056.            
  1057.             // blasts don't travel into or out of water
  1058.             if (bInWater && iWaterLevel == 0)
  1059.                 continue;
  1060.             if (!bInWater && iWaterLevel == 3)
  1061.                 continue;
  1062.            
  1063.             // OLD: vecSpot = pEntity->BodyTarget( vecSrc ); -- NEW:
  1064.             pev( pEntity, pev_absmin, vecAbsMin );
  1065.             pev( pEntity, pev_absmax, vecAbsMax );
  1066.             for( i = 0; i < 3; i++ ) vecSpot[i] = ( vecAbsMin[i] + vecAbsMax[i] ) * 0.5;
  1067.            
  1068.             engfunc( EngFunc_TraceLine, vecSrc, vecSpot, DONT_IGNORE_MONSTERS, pevInflictor, tr );
  1069.            
  1070.             get_tr2( tr, TR_flFraction, flFraction ); // NEW
  1071.             get_tr2( tr, TR_vecEndPos, vecEndPos ); // NEW
  1072.            
  1073.             if ( flFraction == 1.0 || get_tr2( tr, TR_pHit ) == pEntity )
  1074.                 {// the explosion can 'see' this entity, so hurt them!
  1075.             if ( get_tr2( tr, TraceResult:TR_StartSolid ) )
  1076.             {
  1077.                 // if we're stuck inside them, fixup the position and distance
  1078.                 vecEndPos =  vecSrc;
  1079.                 flFraction = 0.0;
  1080.             }
  1081.            
  1082.             // decrease damage for an ent that's farther from the bomb.
  1083.            
  1084.             // OLD: flAdjustedDamage = ( vecSrc - tr.vecEndPos ).Length() * falloff; -- NEW:
  1085.             for( i = 0; i < 3; i++ ) vecAdjust[i] = vecSrc[i] - vecEndPos[i];
  1086.             flAdjustedDamage = floatsqroot(vecAdjust[0]*vecAdjust[0] + vecAdjust[1]*vecAdjust[1] + vecAdjust[2]*vecAdjust[2]) * falloff;
  1087.            
  1088.             flAdjustedDamage = flDamage - flAdjustedDamage;
  1089.            
  1090.             if ( flAdjustedDamage < 0.0 )
  1091.             {
  1092.                 flAdjustedDamage = 0.0;
  1093.             }
  1094.            
  1095.             // ALERT( at_console, "hit %s\n", STRING( pEntity->pev->classname ) );
  1096.             take_damage( pEntity, pevInflictor, flAdjustedDamage ); // NEW
  1097.         }
  1098.     }
  1099. }
  1100. }
  1101.  
  1102. public take_damage( victim, attacker, Float:damage )
  1103. {
  1104.     if(!ma_klase[attacker])
  1105.         return;
  1106.        
  1107.     cod_inflict_damage( attacker, victim, damage, 1.0, victim, (1<<24))
  1108. }
Advertisement
Add Comment
Please, Sign In to add comment