burc_2004

_zm_weap_staff_lightning.gsc

Oct 22nd, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.42 KB | None | 0 0
  1. #include maps/mp/animscripts/shared;
  2. #include maps/mp/zombies/_zm_score;
  3. #include maps/mp/zombies/_zm_powerups;
  4. #include maps/mp/zombies/_zm_audio;
  5. #include maps/mp/zombies/_zm_spawner;
  6. #include maps/mp/zm_tomb_utility;
  7. #include maps/mp/zombies/_zm_net;
  8. #include maps/mp/zombies/_zm_utility;
  9. #include maps/mp/_utility;
  10. #include common_scripts/utility;
  11.  
  12. init()
  13. {
  14.     level._effect[ "lightning_miss" ] = loadfx( "weapon/zmb_staff/fx_zmb_staff_elec_ug_impact_miss" );
  15.     level._effect[ "lightning_arc" ] = loadfx( "weapon/zmb_staff/fx_zmb_staff_elec_trail_bolt_cheap" );
  16.     level._effect[ "lightning_impact" ] = loadfx( "weapon/zmb_staff/fx_zmb_staff_elec_ug_impact_hit_torso" );
  17.     level._effect[ "tesla_shock_eyes" ] = loadfx( "maps/zombie/fx_zombie_tesla_shock_eyes" );
  18.     registerclientfield( "actor", "lightning_impact_fx", 14000, 1, "int" );
  19.     registerclientfield( "scriptmover", "lightning_miss_fx", 14000, 1, "int" );
  20.     registerclientfield( "actor", "lightning_arc_fx", 14000, 1, "int" );
  21.     set_zombie_var( "tesla_head_gib_chance", 50 );
  22.     onplayerconnect_callback( ::onplayerconnect );
  23.     maps/mp/zombies/_zm_spawner::register_zombie_damage_callback( ::staff_lightning_zombie_damage_response );
  24.     maps/mp/zombies/_zm_spawner::register_zombie_death_event_callback( ::staff_lightning_death_event );
  25. }
  26.  
  27. precache()
  28. {
  29.     precacheitem( "staff_lightning_melee_zm" );
  30. }
  31.  
  32. onplayerconnect()
  33. {
  34.     self thread onplayerspawned();
  35. }
  36.  
  37. onplayerspawned()
  38. {
  39.     self endon( "disconnect" );
  40.     self thread watch_staff_lightning_fired();
  41.     self thread watch_staff_usage();
  42. }
  43.  
  44. watch_staff_lightning_fired()
  45. {
  46.     self endon( "disconnect" );
  47.     while ( 1 )
  48.     {
  49.         self waittill( "missile_fire", e_projectile, str_weapon );
  50.         if ( str_weapon == "staff_lightning_upgraded2_zm" || str_weapon == "staff_lightning_upgraded3_zm" )
  51.         {
  52.             fire_angles = vectorToAngle( self getweaponforwarddir() );
  53.             fire_origin = self getweaponmuzzlepoint();
  54.             self thread staff_lightning_position_source( fire_origin, fire_angles, str_weapon );
  55.         }
  56.     }
  57. }
  58.  
  59. lightning_ball_wait( n_lifetime_after_move )
  60. {
  61.     level endon( "lightning_ball_created" );
  62.     self waittill( "movedone" );
  63.     wait n_lifetime_after_move;
  64.     return 1;
  65. }
  66.  
  67. staff_lightning_position_source( v_detonate, v_angles, str_weapon )
  68. {
  69.     self endon( "disconnect" );
  70.     level notify( "lightning_ball_created" );
  71.     if ( !isDefined( v_angles ) )
  72.     {
  73.         v_angles = ( 0, 0, 1 );
  74.     }
  75.     e_ball_fx = spawn( "script_model", v_detonate + ( anglesToForward( v_angles ) * 100 ) );
  76.     e_ball_fx.angles = v_angles;
  77.     e_ball_fx.str_weapon = str_weapon;
  78.     e_ball_fx setmodel( "tag_origin" );
  79.     e_ball_fx.n_range = get_lightning_blast_range( self.chargeshotlevel );
  80.     e_ball_fx.n_damage_per_sec = get_lightning_ball_damage_per_sec( self.chargeshotlevel );
  81.     e_ball_fx setclientfield( "lightning_miss_fx", 1 );
  82.     n_shot_range = staff_lightning_get_shot_range( self.chargeshotlevel );
  83.     v_end = v_detonate + ( anglesToForward( v_angles ) * n_shot_range );
  84.     trace = bullettrace( v_detonate, v_end, 0, undefined );
  85.     if ( trace[ "fraction" ] != 1 )
  86.     {
  87.         v_end = trace[ "position" ];
  88.     }
  89.     staff_lightning_ball_speed = n_shot_range / 8;
  90.     n_dist = distance( e_ball_fx.origin, v_end );
  91.     n_max_movetime_s = n_shot_range / staff_lightning_ball_speed;
  92.     n_movetime_s = n_dist / staff_lightning_ball_speed;
  93.     n_leftover_time = n_max_movetime_s - n_movetime_s;
  94.     e_ball_fx thread staff_lightning_ball_kill_zombies( self );
  95. /#
  96.     e_ball_fx thread puzzle_debug_position( "X", ( 175, 0, 255 ) );
  97. #/
  98.     e_ball_fx moveto( v_end, n_movetime_s );
  99.     finished_playing = e_ball_fx lightning_ball_wait( n_leftover_time );
  100.     e_ball_fx notify( "stop_killing" );
  101.     e_ball_fx notify( "stop_debug_position" );
  102.     if ( is_true( finished_playing ) )
  103.     {
  104.         wait 3;
  105.     }
  106.     if ( isDefined( e_ball_fx ) )
  107.     {
  108.         e_ball_fx delete();
  109.     }
  110. }
  111.  
  112. staff_lightning_ball_kill_zombies( e_attacker )
  113. {
  114.     self endon( "death" );
  115.     self endon( "stop_killing" );
  116.     while ( 1 )
  117.     {
  118.         a_zombies = staff_lightning_get_valid_targets( e_attacker, self.origin );
  119.         while ( isDefined( a_zombies ) )
  120.         {
  121.             _a173 = a_zombies;
  122.             _k173 = getFirstArrayKey( _a173 );
  123.             while ( isDefined( _k173 ) )
  124.             {
  125.                 zombie = _a173[ _k173 ];
  126.                 if ( staff_lightning_is_target_valid( zombie ) )
  127.                 {
  128.                     e_attacker thread staff_lightning_arc_fx( self, zombie );
  129.                     wait 0,2;
  130.                 }
  131.                 _k173 = getNextArrayKey( _a173, _k173 );
  132.             }
  133.         }
  134.         wait 0,5;
  135.     }
  136. }
  137.  
  138. staff_lightning_get_valid_targets( player, v_source )
  139. {
  140.     player endon( "disconnect" );
  141.     a_enemies = [];
  142.     a_zombies = getaiarray( level.zombie_team );
  143.     a_zombies = get_array_of_closest( v_source, a_zombies, undefined, undefined, self.n_range );
  144.     while ( isDefined( a_zombies ) )
  145.     {
  146.         _a200 = a_zombies;
  147.         _k200 = getFirstArrayKey( _a200 );
  148.         while ( isDefined( _k200 ) )
  149.         {
  150.             ai_zombie = _a200[ _k200 ];
  151.             if ( staff_lightning_is_target_valid( ai_zombie ) )
  152.             {
  153.                 a_enemies[ a_enemies.size ] = ai_zombie;
  154.             }
  155.             _k200 = getNextArrayKey( _a200, _k200 );
  156.         }
  157.     }
  158.     return a_enemies;
  159. }
  160.  
  161. staff_lightning_get_shot_range( n_charge )
  162. {
  163.     switch( n_charge )
  164.     {
  165.         case 3:
  166.             return 1200;
  167.         default:
  168.             return 800;
  169.     }
  170. }
  171.  
  172. get_lightning_blast_range( n_charge )
  173. {
  174.     switch( n_charge )
  175.     {
  176.         case 1:
  177.             n_range = 200;
  178.             break;
  179.         case 2:
  180.             n_range = 150;
  181.             break;
  182.         case 3:
  183.         default:
  184.             n_range = 250;
  185.             break;
  186.     }
  187.     return n_range;
  188. }
  189.  
  190. get_lightning_ball_damage_per_sec( n_charge )
  191. {
  192.     if ( !isDefined( n_charge ) )
  193.     {
  194.         return 2500;
  195.     }
  196.     switch( n_charge )
  197.     {
  198.         case 3:
  199.             return 3500;
  200.         default:
  201.             return 2500;
  202.     }
  203. }
  204.  
  205. staff_lightning_is_target_valid( ai_zombie )
  206. {
  207.     if ( !isDefined( ai_zombie ) )
  208.     {
  209.         return 0;
  210.     }
  211.     if ( is_true( ai_zombie.is_being_zapped ) )
  212.     {
  213.         return 0;
  214.     }
  215.     if ( is_true( ai_zombie.is_mechz ) )
  216.     {
  217.         return 0;
  218.     }
  219.     return 1;
  220. }
  221.  
  222. staff_lightning_ball_damage_over_time( e_source, e_target, e_attacker )
  223. {
  224.     e_attacker endon( "disconnect" );
  225.     e_target setclientfield( "lightning_impact_fx", 1 );
  226.     e_target thread maps/mp/zombies/_zm_audio::do_zombies_playvocals( "electrocute", e_target.animname );
  227.     n_range_sq = e_source.n_range * e_source.n_range;
  228.     e_target.is_being_zapped = 1;
  229.     e_target setclientfield( "lightning_arc_fx", 1 );
  230.     wait 0,5;
  231.     if ( isDefined( e_source ) )
  232.     {
  233.         if ( !isDefined( e_source.n_damage_per_sec ) )
  234.         {
  235.             e_source.n_damage_per_sec = get_lightning_ball_damage_per_sec( e_attacker.chargeshotlevel );
  236.         }
  237.         n_damage_per_pulse = e_source.n_damage_per_sec * 1;
  238.     }
  239.     while ( isDefined( e_source ) && isalive( e_target ) )
  240.     {
  241.         e_target thread stun_zombie();
  242.         wait 1;
  243.         if ( !isDefined( e_source ) || !isalive( e_target ) )
  244.         {
  245.         }
  246.         else
  247.         {
  248.             n_dist_sq = distancesquared( e_source.origin, e_target.origin );
  249.             if ( n_dist_sq > n_range_sq )
  250.             {
  251.             }
  252.             else if ( isalive( e_target ) && isDefined( e_source ) )
  253.             {
  254.                 instakill_on = e_attacker maps/mp/zombies/_zm_powerups::is_insta_kill_active();
  255.                 if ( n_damage_per_pulse < e_target.health && !instakill_on )
  256.                 {
  257.                     e_target do_damage_network_safe( e_attacker, n_damage_per_pulse, e_source.str_weapon, "MOD_RIFLE_BULLET" );
  258.                 }
  259.                 else
  260.                 {
  261.                     e_target thread zombie_shock_eyes();
  262.                     e_target thread staff_lightning_kill_zombie( e_attacker, e_source.str_weapon );
  263.                 }
  264.             }
  265.             else
  266.             {
  267.             }
  268.         }
  269.     }
  270.     if ( isDefined( e_target ) )
  271.     {
  272.         e_target.is_being_zapped = 0;
  273.         e_target setclientfield( "lightning_arc_fx", 0 );
  274.     }
  275. }
  276.  
  277. staff_lightning_arc_fx( e_source, ai_zombie )
  278. {
  279.     self endon( "disconnect" );
  280.     if ( !isDefined( ai_zombie ) )
  281.     {
  282.         return;
  283.     }
  284.     if ( !bullet_trace_throttled( e_source.origin, ai_zombie.origin + vectorScale( ( 0, 0, 1 ), 20 ), ai_zombie ) )
  285.     {
  286.         return;
  287.     }
  288.     if ( isDefined( e_source ) && isDefined( ai_zombie ) && isalive( ai_zombie ) )
  289.     {
  290.         level thread staff_lightning_ball_damage_over_time( e_source, ai_zombie, self );
  291.     }
  292. }
  293.  
  294. staff_lightning_kill_zombie( player, str_weapon )
  295. {
  296.     player endon( "disconnect" );
  297.     if ( !isalive( self ) )
  298.     {
  299.         return;
  300.     }
  301.     if ( is_true( self.has_legs ) )
  302.     {
  303.         if ( !self hasanimstatefromasd( "zm_death_tesla" ) )
  304.         {
  305.             return;
  306.         }
  307.         self.deathanim = "zm_death_tesla";
  308.     }
  309.     else
  310.     {
  311.         if ( !self hasanimstatefromasd( "zm_death_tesla_crawl" ) )
  312.         {
  313.             return;
  314.         }
  315.         self.deathanim = "zm_death_tesla_crawl";
  316.     }
  317.     if ( is_true( self.is_traversing ) )
  318.     {
  319.         self.deathanim = undefined;
  320.     }
  321.     self do_damage_network_safe( player, self.health, str_weapon, "MOD_RIFLE_BULLET" );
  322.     player maps/mp/zombies/_zm_score::player_add_points( "death", "", "" );
  323. }
  324.  
  325. staff_lightning_death_fx()
  326. {
  327.     if ( isDefined( self ) )
  328.     {
  329.         self setclientfield( "lightning_impact_fx", 1 );
  330.         self thread maps/mp/zombies/_zm_audio::do_zombies_playvocals( "electrocute", self.animname );
  331.         self thread zombie_shock_eyes();
  332.     }
  333. }
  334.  
  335. zombie_shock_eyes_network_safe( fx, entity, tag )
  336. {
  337.     if ( network_entity_valid( entity ) )
  338.     {
  339.         if ( !is_true( self.head_gibbed ) )
  340.         {
  341.             playfxontag( fx, entity, tag );
  342.         }
  343.     }
  344. }
  345.  
  346. zombie_shock_eyes()
  347. {
  348.     if ( isDefined( self.head_gibbed ) && self.head_gibbed )
  349.     {
  350.         return;
  351.     }
  352.     maps/mp/zombies/_zm_net::network_safe_init( "shock_eyes", 2 );
  353.     maps/mp/zombies/_zm_net::network_choke_action( "shock_eyes", ::zombie_shock_eyes_network_safe, level._effect[ "tesla_shock_eyes" ], self, "J_Eyeball_LE" );
  354. }
  355.  
  356. staff_lightning_zombie_damage_response( mod, hit_location, hit_origin, player, amount )
  357. {
  358.     if ( self is_staff_lightning_damage() && self.damagemod != "MOD_RIFLE_BULLET" )
  359.     {
  360.         self thread stun_zombie();
  361.     }
  362.     return 0;
  363. }
  364.  
  365. is_staff_lightning_damage()
  366. {
  367.     if ( isDefined( self.damageweapon ) && self.damageweapon != "staff_lightning_zm" && self.damageweapon == "staff_lightning_upgraded_zm" )
  368.     {
  369.         return !is_true( self.set_beacon_damage );
  370.     }
  371. }
  372.  
  373. staff_lightning_death_event()
  374. {
  375.     if ( is_staff_lightning_damage() && self.damagemod != "MOD_MELEE" )
  376.     {
  377.         if ( is_true( self.is_mechz ) )
  378.         {
  379.             return;
  380.         }
  381.         self thread maps/mp/zombies/_zm_audio::do_zombies_playvocals( "death", self.animname );
  382.         self thread zombie_eye_glow_stop();
  383.         if ( is_true( self.has_legs ) )
  384.         {
  385.             if ( !self hasanimstatefromasd( "zm_death_tesla" ) )
  386.             {
  387.                 return;
  388.             }
  389.             self.deathanim = "zm_death_tesla";
  390.         }
  391.         else
  392.         {
  393.             if ( !self hasanimstatefromasd( "zm_death_tesla_crawl" ) )
  394.             {
  395.                 return;
  396.             }
  397.             self.deathanim = "zm_death_tesla_crawl";
  398.         }
  399.         if ( is_true( self.is_traversing ) )
  400.         {
  401.             self.deathanim = undefined;
  402.         }
  403.         tag = "J_SpineUpper";
  404.         self setclientfield( "lightning_impact_fx", 1 );
  405.         self thread maps/mp/zombies/_zm_audio::do_zombies_playvocals( "electrocute", self.animname );
  406.         self thread zombie_shock_eyes();
  407.         if ( isDefined( self.deathanim ) )
  408.         {
  409.             self waittillmatch( "death_anim" );
  410.             return "die";
  411.         }
  412.         self do_damage_network_safe( self.attacker, self.health, self.damageweapon, "MOD_RIFLE_BULLET" );
  413.     }
  414. }
  415.  
  416. stun_zombie()
  417. {
  418.     self endon( "death" );
  419.     if ( is_true( self.is_mechz ) )
  420.     {
  421.         return;
  422.     }
  423.     if ( is_true( self.is_electrocuted ) )
  424.     {
  425.         return;
  426.     }
  427.     if ( !isDefined( self.ai_state ) || self.ai_state != "find_flesh" )
  428.     {
  429.         return;
  430.     }
  431.     self.forcemovementscriptstate = 1;
  432.     self.ignoreall = 1;
  433.     self.is_electrocuted = 1;
  434.     tag = "J_SpineUpper";
  435.     network_safe_play_fx_on_tag( "lightning_impact", 2, level._effect[ "lightning_impact" ], self, tag );
  436.     if ( is_true( self.has_legs ) )
  437.     {
  438.         self animscripted( self.origin, self.angles, "zm_electric_stun" );
  439.     }
  440.     self maps/mp/animscripts/shared::donotetracks( "stunned" );
  441.     self.forcemovementscriptstate = 0;
  442.     self.ignoreall = 0;
  443.     self.is_electrocuted = 0;
  444. }
Advertisement
Add Comment
Please, Sign In to add comment