Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // button and multiple button
- float TARGET_START_ACTIVATED = 1;
- float TARGET_TOGGLE = 4;
- void() tc_target_wait_active;
- void() tc_target_wait_inactive;
- void() tc_target_recover;
- void() tc_target_activate;
- void() tc_target_deactivate;
- //
- // Move brush functions for activating and deactivating.
- //
- void() tc_target_activate = {
- // Set state to a temp.
- self.state = STATE_TEMP_0;
- // Do not take damage until activated.
- self.takedamage = DAMAGE_NO;
- // Move, wait_active as callback.
- SUB_CalcMove (self.pos1, self.speed, tc_target_wait_active);
- };
- void() tc_target_deactivate = {
- // Set state to a temp.
- self.state = STATE_TEMP_0;
- // Do not take damage until activated.
- self.takedamage = DAMAGE_NO;
- // Move, wait_inactive as callback.
- SUB_CalcMove (self.pos2, self.speed, tc_target_wait_inactive);
- };
- //
- // Think functions for when active and inactive.
- //
- void() tc_target_wait_active = {
- // It is active, and waiting, cash dat damage lawl.
- self.takedamage = DAMAGE_YES;
- // Setup other selfs.
- self.frame = 1;
- if (self.health < 0) {
- // Print message to the player we finished the target round.
- centerprint(self.enemy, "Finished target range round.");
- // Setup the new think.
- self.think = tc_target_recover;
- } else {
- // Adjust state.
- self.state = STATE_ACTIVE;
- // Set activator to self.enemy(is the player.)
- activator = self.enemy;
- SUB_UseTargets();
- }
- };
- void() tc_target_wait_inactive = {
- // Setup other selfs.
- self.frame = 0;
- // Reset health value.
- self.health = self.max_health;
- // Adjust state.
- self.state = STATE_INACTIVE;
- // Set activator to self.enemy(is the player.)
- activator = self.enemy;
- SUB_UseTargets();
- };
- //
- // Target return function, called after its death.
- //
- void() tc_target_recover = {
- // We don't want it to take damage for now.
- self.takedamage = DAMAGE_NO; // can be shot again
- // Reset its state.
- self.state = STATE_INACTIVE;
- // Setup the inactive state think.
- self.think = tc_target_wait_inactive;
- };
- //
- // Target Block function, called when brush hits an entity.
- //
- void() tc_target_blocked = {
- // Can't do shit here, normally does a T_Damage thing.
- };
- //
- // Use function. (Dunno what this does ? lol.)
- //
- void() tc_target_use = {
- // Setup reference to player(activate).
- self.enemy = activator;
- // Activate.
- tc_target_activate();
- };
- //
- // Killed function.
- //
- void() tc_target_killed = {
- // Setup the damage_attacker as self.enemy global.
- self.enemy = damage_attacker;
- // Print message to the player we finished the target round.
- centerprint(self.enemy, "Finished target range round.");
- // Play sound.
- sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
- // Move the target back to begin position.
- tc_target_deactivate();
- };
- //
- // Touched function.
- //
- void() tc_target_touch = {
- // Only reply to players.
- if (other.classname != "player")
- return;
- // Setup enemy, which is other in this context.
- self.enemy = other;
- // Play sound.
- sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
- // Inform client we are starting target practicing range course.
- centerprint(self.enemy, "Starting target range course.");
- // Activate target to wait position.
- tc_target_activate ();
- };
- //
- // Spawn function.
- //
- void() func_tc_target =
- {
- local float gtemp, ftemp;
- // Set direction, ok...
- SetMovedir();
- // Setup model itself.
- setmodel(self, self.model);
- // Setup self values.
- if (!self.health)
- self.health = 2;
- if (!self.speed)
- self.speed = 100;
- if (!self.wait)
- self.wait = 1;
- if (!self.lip)
- self.lip = 8;
- if (!self.dmg)
- self.dmg = 2;
- self.max_health = self.health;
- self.movetype = MOVETYPE_PUSH;
- self.solid = SOLID_BSP;
- // Take damage since we are active now.
- self.takedamage = DAMAGE_YES;
- // Setup function pointers.
- self.blocked = tc_target_blocked;
- self.use = tc_target_use;
- self.th_die = tc_target_killed;
- self.touch = tc_target_touch;
- self.think = tc_target_wait_inactive;
- // Generate front and back position(in use, and waiting for use.)
- self.pos1 = self.origin;
- self.pos2 = self.pos1 + self.movedir*(fabs(self.movedir*self.size) + self.lip);
- // Position accordingly and setup state accordingly to if activated or not.
- if (self.spawnflags & TARGET_START_ACTIVATED) {
- // Setup brush origin to active state. (Pos1.)
- setorigin (self, self.pos1);
- // Setup active state.
- self.state = STATE_ACTIVE;
- // Take damage since we are active now.
- self.takedamage = DAMAGE_YES;
- // Setup active function pointer.
- self.think = tc_target_wait_active;
- } else {
- // Setup brush origin to inactive state. (Pos2.)
- setorigin (self, self.pos2);
- // Setup inactive state.
- self.state = STATE_INACTIVE;
- // Take no damage since we are inactive now.
- self.takedamage = DAMAGE_NO;
- // Setup active function pointer.
- self.think = tc_target_wait_inactive;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment