Guest User

Untitled

a guest
Jan 4th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.23 KB | None | 0 0
  1. // button and multiple button
  2. float TARGET_START_ACTIVATED = 1;
  3. float TARGET_TOGGLE = 4;
  4.  
  5. void() tc_target_wait_active;
  6. void() tc_target_wait_inactive;
  7. void() tc_target_recover;
  8. void() tc_target_activate;
  9. void() tc_target_deactivate;
  10.  
  11. //
  12. // Move brush functions for activating and deactivating.
  13. //
  14. void() tc_target_activate = {
  15.     // Set state to a temp.
  16.     self.state = STATE_TEMP_0;
  17.  
  18.     // Do not take damage until activated.
  19.     self.takedamage = DAMAGE_NO;
  20.  
  21.     // Move, wait_active as callback.
  22.     SUB_CalcMove (self.pos1, self.speed, tc_target_wait_active);
  23. };
  24. void() tc_target_deactivate = {
  25.     // Set state to a temp.
  26.     self.state = STATE_TEMP_0;
  27.  
  28.     // Do not take damage until activated.
  29.     self.takedamage = DAMAGE_NO;
  30.  
  31.     // Move, wait_inactive as callback.
  32.     SUB_CalcMove (self.pos2, self.speed, tc_target_wait_inactive);
  33. };
  34.  
  35.  
  36. //
  37. // Think functions for when active and inactive.
  38. //
  39. void() tc_target_wait_active = {
  40.     // It is active, and waiting, cash dat damage lawl.
  41.     self.takedamage = DAMAGE_YES;
  42.  
  43.     // Setup other selfs.
  44.     self.frame = 1;
  45.  
  46.     if (self.health < 0) {
  47.         // Print message to the player we finished the target round.
  48.         centerprint(self.enemy, "Finished target range round.");
  49.  
  50.         // Setup the new think.
  51.         self.think = tc_target_recover;
  52.     } else {
  53.         // Adjust state.
  54.         self.state = STATE_ACTIVE;
  55.  
  56.         // Set activator to self.enemy(is the player.)
  57.         activator = self.enemy;
  58.         SUB_UseTargets();
  59.     }
  60. };
  61. void() tc_target_wait_inactive = {
  62.     // Setup other selfs.
  63.     self.frame = 0;
  64.  
  65.     // Reset health value.
  66.     self.health = self.max_health;
  67.  
  68.     // Adjust state.
  69.     self.state = STATE_INACTIVE;
  70.  
  71.     // Set activator to self.enemy(is the player.)
  72.     activator = self.enemy;
  73.     SUB_UseTargets();
  74. };
  75.  
  76. //
  77. // Target return function, called after its death.
  78. //
  79. void() tc_target_recover = {
  80.     // We don't want it to take damage for now.
  81.     self.takedamage = DAMAGE_NO;    // can be shot again
  82.  
  83.     // Reset its state.
  84.     self.state = STATE_INACTIVE;
  85.  
  86.     // Setup the inactive state think.
  87.     self.think = tc_target_wait_inactive;
  88. };
  89.  
  90. //
  91. // Target Block function, called when brush hits an entity.
  92. //
  93. void() tc_target_blocked = {
  94.     // Can't do shit here, normally does a T_Damage thing.
  95. };
  96.  
  97. //
  98. // Use function. (Dunno what this does ? lol.)
  99. //
  100. void() tc_target_use = {
  101.     // Setup reference to player(activate).
  102.     self.enemy = activator;
  103.  
  104.     // Activate.
  105.     tc_target_activate();
  106. };
  107.  
  108. //
  109. // Killed function.
  110. //
  111. void() tc_target_killed = {
  112.     // Setup the damage_attacker as self.enemy global.
  113.     self.enemy = damage_attacker;
  114.  
  115.     // Print message to the player we finished the target round.
  116.     centerprint(self.enemy, "Finished target range round.");
  117.  
  118.     // Play sound.
  119.     sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  120.  
  121.     // Move the target back to begin position.
  122.     tc_target_deactivate();
  123. };
  124.  
  125. //
  126. // Touched function.
  127. //
  128. void() tc_target_touch = {
  129.     // Only reply to players.
  130.     if (other.classname != "player")
  131.         return;
  132.  
  133.     // Setup enemy, which is other in this context.
  134.     self.enemy = other;
  135.  
  136.     // Play sound.
  137.     sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  138.  
  139.     // Inform client we are starting target practicing range course.
  140.     centerprint(self.enemy, "Starting target range course.");
  141.  
  142.     // Activate target to wait position.
  143.     tc_target_activate ();
  144. };
  145.  
  146.  
  147. //
  148. // Spawn function.
  149. //
  150. void() func_tc_target =
  151. {
  152. local float     gtemp, ftemp;
  153.  
  154.     // Set direction, ok...
  155.     SetMovedir();
  156.  
  157.     // Setup model itself.
  158.     setmodel(self, self.model);
  159.  
  160.     // Setup self values.
  161.     if (!self.health)
  162.         self.health = 2;
  163.     if (!self.speed)
  164.         self.speed = 100;
  165.     if (!self.wait)
  166.         self.wait = 1;
  167.     if (!self.lip)
  168.         self.lip = 8;
  169.     if (!self.dmg)
  170.         self.dmg = 2;
  171.     self.max_health = self.health;
  172.     self.movetype = MOVETYPE_PUSH;
  173.     self.solid = SOLID_BSP;
  174.  
  175.     // Take damage since we are active now.
  176.     self.takedamage = DAMAGE_YES;
  177.  
  178.     // Setup function pointers.
  179.     self.blocked = tc_target_blocked;
  180.     self.use = tc_target_use;
  181.     self.th_die = tc_target_killed;
  182.     self.touch = tc_target_touch;
  183.     self.think = tc_target_wait_inactive;
  184.  
  185.     // Generate front and back position(in use, and waiting for use.)
  186.     self.pos1 = self.origin;
  187.     self.pos2 = self.pos1 + self.movedir*(fabs(self.movedir*self.size) + self.lip);
  188.  
  189.     // Position accordingly and setup state accordingly to if activated or not.
  190.     if (self.spawnflags & TARGET_START_ACTIVATED) {
  191.         // Setup brush origin to active state. (Pos1.)
  192.         setorigin (self, self.pos1);
  193.  
  194.         // Setup active state.
  195.         self.state = STATE_ACTIVE;
  196.  
  197.         // Take damage since we are active now.
  198.         self.takedamage = DAMAGE_YES;
  199.  
  200.         // Setup active function pointer.
  201.         self.think = tc_target_wait_active;
  202.     } else {
  203.         // Setup brush origin to inactive state. (Pos2.)
  204.         setorigin (self, self.pos2);
  205.  
  206.         // Setup inactive state.
  207.         self.state = STATE_INACTIVE;
  208.  
  209.         // Take no damage since we are inactive now.
  210.         self.takedamage = DAMAGE_NO;
  211.  
  212.         // Setup active function pointer.
  213.         self.think = tc_target_wait_inactive;
  214.     }
  215. };
Advertisement
Add Comment
Please, Sign In to add comment