Advertisement
Guest User

Untitled

a guest
May 21st, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. #using scripts\shared\ai_shared;
  4. #using scripts\zm\_zm_attackables;
  5. #using scripts\zm\_zm_spawner;
  6.  
  7.  
  8. // EXAMPLE
  9. // #precache( "model",  "p7_zm_vending_revive" );
  10. // attack_thing = create_attackable( "test", "p7_zm_vending_revive", ( 0, 0, 0 ), ( 0, 0, 0 ), 10, 50, 1000, 1, "attackable_symbo_test", &attackable_callback );
  11. // zm_spawner::add_custom_zombie_spawn_logic( &attack_stuff );
  12.  
  13.  
  14.  
  15. function attack_stuff()
  16. {
  17.     self endon( "death" );
  18.  
  19.     while ( isDefined( self ) && isAlive( self ) )
  20.     {
  21.         b_attribute_active = self ai::get_behavior_attribute( "use_attackable" );
  22.        
  23.         if ( !IS_TRUE( b_attribute_active ) )
  24.             ai::set_behavior_attribute( "use_attackable", true );
  25.        
  26.         WAIT_SERVER_FRAME;
  27.     }
  28. }
  29.  
  30. /*
  31. entity create_attackable( <str_targetname>, <str_model_name>, <v_origin>, <v_angles>, <n_number_of_attack_spots>, <n_distance_to_attack_point>, <n_attackable_max_health>, <b_attackable_active>, <str_script_bundle_name>, [ptr_function_to_thread] )
  32. [MANDATORY] <str_targetname> The targetname assigned to the model
  33. [MANDATORY] <str_model_name> The model to be spawned
  34. [MANDATORY] <v_origin> The origin to spawn model at
  35. [MANDATORY] <v_angles> The angles to spawn model using
  36. [MANDATORY] <n_number_of_attack_spots> The number of points spaced around the model that are created. Zombies will go to these to attack
  37. [MANDATORY] <n_distance_to_attack_point> The distance the attack spots will be placed away from the model
  38. [MANDATORY] <n_attackable_max_health> The max health the model attackable is set to
  39. [MANDATORY] <b_attackable_active> Decides if the model should start "active" or not
  40. [MANDATORY] <str_script_bundle_name> The script bundle attackable asset to be assigned ( created in APE )
  41. [OPTIONAL] [ptr_function_to_thread] The function to thread on the model for handling it being attacked or destroyed
  42. CATEGORY:
  43. CLIENT/SERVER: Server
  44. SUMMARY: Creates and returns a attackable model with attack spots spawned around it
  45. EXAMPLE: attack_thing = create_attackable( "test", "p7_zm_vending_revive", ( 0, 0, 0 ), ( 0, 0, 0 ), 10, 50, 1000, 1, "attackable_symbo_test", &attackable_callback );
  46. */
  47. function create_attackable( str_targetname, str_model_name, v_origin, v_angles, n_number_of_attack_spots, n_distance_to_attack_point, n_attackable_max_health, b_attackable_active, str_script_bundle_name, ptr_function_to_thread )
  48. {
  49.     DEFAULT( level.attackables, [] );
  50.  
  51.     e_model = spawn( "script_model", v_origin );
  52.     e_model.angles = v_angles;
  53.     e_model setModel( str_model_name );
  54.     e_model.targetname = str_targetname;
  55.     e_model enableLinkTo();
  56.    
  57.     a_slots = [];
  58.  
  59.     f_incriment = 360 / n_number_of_attack_spots;
  60.     f_offset = randomFloat( f_incriment );
  61.    
  62.     for ( i = 0; i < n_number_of_attack_spots; i++ )
  63.     {
  64.         f_new_angle = f_offset + ( f_incriment * i );
  65.  
  66.         n_forward_velocity = ( cos( f_new_angle ) * n_distance_to_attack_point, sin( f_new_angle ) * n_distance_to_attack_point, 0 );
  67.  
  68.         e_origin = spawn( "script_origin", v_origin + n_forward_velocity );
  69.         e_origin.targetname = str_targetname + "_slots";
  70.         e_origin.angles = vectorToAngles( e_model.origin - e_origin.origin );
  71.        
  72.         v_ground_trace = playerPhysicsTrace( e_origin.origin + ( 0, 0, 50 ), e_origin.origin - ( 0, 0, 50 ) ); // groundTrace( e_origin.origin, e_origin.origin - ( 0, 0, 50 ), 1 );
  73.         n_z_distance = v_ground_trace[ 2 ] - e_model.origin[ 2 ];
  74.        
  75.         if ( n_z_distance > 20 || n_z_distance < -20 )
  76.         {
  77.             e_origin delete();
  78.             continue;
  79.         }
  80.        
  81.         e_origin linkTo( e_model );
  82.         a_slots[ a_slots.size ] = e_origin;
  83.     }
  84.    
  85.     e_model.target = str_targetname + "_slots";
  86.     e_model.bundle = struct::get_script_bundle( "attackables", level.attackables[ 0 ].scriptbundlename );
  87.     e_model.is_active = b_attackable_active;
  88.     e_model.health = n_attackable_max_health;
  89.  
  90.     e_model.slot = a_slots;
  91.  
  92.     if ( isDefined( ptr_function_to_thread ) )
  93.         e_model thread [ [ ptr_function_to_thread ] ]();
  94.  
  95.     ARRAY_ADD( level.attackables, e_model );
  96.  
  97.     return e_model;
  98. }
  99.  
  100. /*
  101. entity delete_attackable()
  102. CATEGORY:
  103. CLIENT/SERVER: Server
  104. SUMMARY: Fully deletes an attackable model and will delete the attack spots attached to it
  105. EXAMPLE: attack_thing delete_attackable();
  106. */
  107. function delete_attackable()
  108. {
  109.     if ( isDefined( self.slot ) && isArray( self.slot ) && self.slot.size > 0 )
  110.     {
  111.         for ( i = 0; i < self.slot; i++ )
  112.             self.slot[ i ] delete();
  113.        
  114.     }
  115.    
  116.     arrayRemoveValue( level.attackables, self );
  117.     self delete();
  118. }
  119.  
  120. function attackable_callback()
  121. {
  122.     self endon( "entityshutdown" );
  123.     while ( isDefined( self ) )
  124.     {
  125.         str_notify_caught = self util::waittill_any_return( "attackable_damaged", "attackable_deactivated" );
  126.  
  127.         if ( str_notify_caught == "attackable_damaged" )
  128.         {
  129.             // SOMEONE HIT ME!!!!!! DO YOU CODE
  130.             iPrintLnBold( "^1HEALTH REMAINING : " + self.health );
  131.         }
  132.         if ( str_notify_caught == "attackable_deactivated" )
  133.         {
  134.             self zm_attackables::deactivate();
  135.             iPrintLnBold( "^1ATTACKABLE DEACTIVATED" );
  136.             self delete_attackable();
  137.         }
  138.     }
  139. }
  140.  
  141. function activate_attackables( a_attackables )
  142. {
  143.     for ( i = 0; i < a_attackables.size; i++ )
  144.     {
  145.         a_attackables[ i ].health = 1000;
  146.      a_attackables[ i ] zm_attackables::activate();
  147.      a_attackables[ i ] thread symbos_attackable_stuff();
  148.     }
  149. }
  150.  
  151. function symbos_attackable_stuff()
  152. {
  153.     self endon( "entityshutdown" );
  154.     while ( isDefined( self ) )
  155.     {
  156.         str_notify_caught = self util::waittill_any_return( "attackable_damaged", "attackable_deactivated" );
  157.        
  158.         if ( str_notify_caught == "attackable_damaged" )
  159.         {
  160.             // SOMEONE HIT ME!!!!!! DO YOU CODE
  161.             iPrintLnBold( "HEALTH REMAINING : " + self.health );
  162.         }
  163.         if ( str_notify_caught == "attackable_deactivated" )
  164.         {
  165.             self zm_attackables::deactivate();
  166.             iPrintLnBold( "ATTACKABLE DEACTIVATED" );
  167.         }
  168.        
  169.     }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement