Advertisement
Guest User

Untitled

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