⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trigger.cpp

📁 this keik game source
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			if ( !num )
				{
				break;
				}

			ent = G_GetEntity( num );
		
	      if ( !ent->deadflag && !( ent->flags & FL_GODMODE ) )
		      {
	         ent->Damage( this, attacker, dmg, ent->worldorigin, vec_zero, vec_zero, 0, 0, MOD_CRUSH, -1, -1, 1.0f );
		      }
			}
		while ( 1 );
		}
	}
//
//==============================
// DamageTargets
//==============================
//

void TriggerDamageTargets::DamageTargets
	(
	Event *ev
	)

	{
	Entity	*other;
	Entity	*ent;
	const char		*name;
	int		num;

	other = ev->GetEntity( 1 );

	if ( triggerActivated )
		{
		//
		// Entity triggered itself.  Prevent an infinite loop
		//
		ev->Error( "Entity targeting itself--Targetname '%s'", TargetName() );
		return;
		}

	triggerActivated = true;
	activator = other;
	
   //
   // print the message
   //
	if ( message.length() && other && other->isClient() )
		{
		gi.centerprintf( other->edict, "jcx jcy string \"%s\"", message.c_str() );
		if ( Noise().length() )
			{
			other->sound( Noise(), 1, CHAN_VOICE, ATTN_NORM );
			}
		}
		
   //
   // damage the targets
   //
	name = Target();
	if ( name && strcmp( name, "" ) )
		{
		num = 0;
		do
			{
			num = G_FindTarget( num, name );
			if ( !num )
				{
				break;
				}

			ent = G_GetEntity( num );
		
	      if ( !ent->deadflag && !( ent->flags & FL_GODMODE ) )
		      {
            if (damage)
		         ent->Damage( this, other, damage, ent->worldorigin, vec_zero, vec_zero, 0, 0, MOD_CRUSH, -1, -1, 1.0f );
            else
               ent->Damage( this, other, ent->health+1, ent->worldorigin, vec_zero, vec_zero, 0, 0, MOD_CRUSH, -1, -1, 1.0f );
		      }
			}
		while ( 1 );
		}

	triggerActivated = false;
	}


/*****************************************************************************/
/*SINED trigger_damagetargetsfixed (0.5 0.5 0.5) (-8 -8 -8) (8 8 8) SOLID x NOT_PLAYERS NOT_MONSTERS PROJECTILES

"damage" amount of damage to cause. If no damage is specified, objects\
are damaged by the current health+1

"key"          The item needed to activate this. (default nothing)

if a trigger_damagetargetsfixed is shot at and the SOLID flag is set,\
the damage is passed on to the targets

If NOT_PLAYERS is set, the trigger does not hurt players
If NOT_MONSTERS is set, the trigger does not hurt monsters
If PROJECTILES is set, the trigger will hurt projectiles (rockets, grenades, etc.)

/*****************************************************************************/

CLASS_DECLARATION( TriggerDamageTargets, TriggerFixedDamageTargets, "trigger_damagetargetsfixed" );

ResponseDef TriggerFixedDamageTargets::Responses[] =
	{
		{ &EV_Touch,	NULL },
		{ NULL, NULL }
	};

/*****************************************************************************/
/*SINED trigger_particles (0.3 0.1 0.6) (-8 -8 -8) (8 8 8)  x NOSOUND NOT_PLAYERS MONSTERS PROJECTILES RANDSTYLE BRIGHT 

spawn some particles when triggered

"count" number of particles to spawn ( default 10 )
"noise" sound to play when triggered ( defaults to random spark sounds )
"angles" specifies direction to spawn particles
"key"   The item needed to activate this. (default nothing)
"particlestyle" style of particles ( default 122 (sparks) )
sample styles (121 blood, 120 gunsmoke, 123 orangeglow, 124 blueyellow, 125 debris trail, 128 oil, 129 waterspray)

If NOSOUND is set, no sound will be played
If NOT_PLAYERS is set, the trigger does not respond to players
If MONSTERS is set, the trigger will respond to monsters
If PROJECTILES is set, the trigger will respond to projectiles (rockets, grenades, etc.)
If RANDSTYLE is set, the particles will be set to random colors in the particlestyle
if BRIGHT is set, particles will be drawn extra bright
/*****************************************************************************/

CLASS_DECLARATION( Trigger, TriggerParticles, "trigger_particles" );

Event EV_TriggerParticles_SetDirection( "setdirection" );

ResponseDef TriggerParticles::Responses[] =
	{
	   { &EV_Trigger_Effect,						( Response )TriggerParticles::SpawnParticles },
	   { &EV_TriggerParticles_SetDirection,	( Response )TriggerParticles::SetDirection },
		{ &EV_Touch,	NULL },
		{ NULL, NULL }
	};

void TriggerParticles::SpawnParticles
	(
	Event *ev
	)

	{
   if ( !(spawnflags & 2) )
      {
      if (Noise().length())
         sound( Noise() );
      else
         RandomGlobalSound( str("sparks") );
      }

   if ( particlestyle == 122 )
      SpawnTempDlight( worldorigin, 1, 1, 0, 100, 0.9, 1 );

   Particles( worldorigin, dir, count, particlestyle, flags );
	}

void TriggerParticles::SetDirection
   (
   Event *ev
   )

   {
   const char  *target;
   int         num;
   Entity      *end;

   // Set the end position if there is a target set.
   target = Target();
   if ( target && strlen( target ) )
      {
      if ( num = G_FindTarget( 0, target ) )
         {
         end = G_GetEntity( num );
         assert( end );
         dir = end->worldorigin - worldorigin;
         dir.normalize();
         }
      }
   else 
      dir = Vector( 0, 0, 0 );
   }

TriggerParticles::TriggerParticles
   (
   )
	
   {
   const char *target;
   target = Target();

   if ( target && strlen( target ) )
      PostEvent( EV_TriggerParticles_SetDirection, 0 );
   else
      dir = G_GetMovedir();

	SetNoise( G_GetSpawnArg( "noise", "" ) );
	count     	= G_GetIntArg( "count", 10 );
	particlestyle	= G_GetIntArg( "particlestyle", 122 );
   
   if ( spawnflags & 32 )
      flags |= PARTICLE_RANDOM;
   if ( spawnflags & 64 )
      flags |= PARTICLE_OVERBRIGHT;
	}

/*****************************************************************************/
/*SINED trigger_randomparticles (0.3 0.1 0.6) (-8 -8 -8) (8 8 8) START_ON NOSOUND NOT_PLAYERS MONSTERS PROJECTILES RANDSTYLE BRIGHT 

START_ON start the effect on

spawn some particles randomly
triggering the object 

"count" number of particles to spawn ( default 10 )
"noise" sound to play when triggered ( default none )
"mindelay" minimum delay between particle triggers (default 3)
"maxdelay" maximum delay between particle triggers (default 10)
"key"      The item needed to activate this. (default nothing)
"particlestyle" style of particles ( default 122 (sparks) )
sample styles (121 blood, 120 gunsmoke, 123 orangeglow, 124 blueyellow, 125 debris trail )

If NOSOUND is set, no sound will be played
If NOT_PLAYERS is set, the trigger does not respond to players
If MONSTERS is set, the trigger will respond to monsters
If PROJECTILES is set, the trigger will respond to projectiles (rockets, grenades, etc.)
If RANDSTYLE is set, the particles will be set to random colors in the particlestyle
if BRIGHT is set, particles will be drawn extra bright
/*****************************************************************************/

Event EV_RandomTriggerParticles_SpawnParticles( "spawnparticles" );

CLASS_DECLARATION( TriggerParticles, RandomTriggerParticles, "trigger_randomparticles" );

ResponseDef RandomTriggerParticles::Responses[] =
	{
	   { &EV_RandomTriggerParticles_SpawnParticles, ( Response )RandomTriggerParticles::RandomParticles },
	   { &EV_Trigger_Effect,						      ( Response )RandomTriggerParticles::ToggleParticles },
		{ &EV_Touch,	NULL },
		{ NULL, NULL }
	};

void RandomTriggerParticles::RandomParticles
	(
	Event *ev
	)

	{
   SpawnParticles( NULL );
   if (state)
      ScheduleParticles();
	}

void RandomTriggerParticles::ToggleParticles
	(
	Event *ev
	)

	{
   state ^= 1;
   if (state)
      ScheduleParticles();
   else
     	CancelEventsOfType( EV_RandomTriggerParticles_SpawnParticles );
	}

void RandomTriggerParticles::ScheduleParticles
	(
   void
	)

	{
   if (state)
      PostEvent( EV_RandomTriggerParticles_SpawnParticles, mindelay + G_Random( maxdelay-mindelay ) );
	}


RandomTriggerParticles::RandomTriggerParticles()
	{
   state = 0;
   if (spawnflags & 1)
      state = 1;
   ScheduleParticles();
	mindelay  	= G_GetFloatArg( "mindelay", 3 );
	maxdelay    = G_GetFloatArg( "maxdelay", 10 );
   }


/*****************************************************************************/
/*SINED trigger_thread (.5 .5 .5) ? notouch x NOT_PLAYERS MONSTERS PROJECTILES

Variable sized trigger. After firing cnt times, removes itself.  

"thread" name of thread to trigger.  This can be in a different script file as well\
by using the '::' notation.

You must set the key "target" to the name of another object in the 
level that has a matching name

"cnt" how many times it can be triggered ( default 1 )
"targetname".  If "health" is set, the trigger must be killed to activate.

if "killtarget" is set, any objects that have a matching "target" will be
removed when the trigger is fired.

if "angle" is set, the trigger will only fire when someone is facing the 
direction of the angle.  Use "360" for an angle of 0.

"key" The item needed to activate this. (default nothing)

If NOT_PLAYERS is set, the trigger does not respond to players
If MONSTERS is set, the trigger will respond to monsters
If PROJECTILES is set, the trigger will respond to projectiles (rockets, grenades, etc.)

set "message" to text string

/*****************************************************************************/

CLASS_DECLARATION( Trigger, TriggerThread, "trigger_thread" );

ResponseDef TriggerThread::Responses[] =
	{
		{ NULL, NULL }
	};

TriggerThread::TriggerThread()
	{
   if ( count == -1 )
      count = 1;
   if ( !thread.length() )
      {
      warning( "TriggerThread", "thread string not defined.\n" );
      }
	}

/*****************************************************************************/
/*SINED trigger_camerause (0.5 0.5 0.5) ? VISIBLE x NOT_PLAYERS MONSTERS

Activates 'targeted' camera when 'used'
If activated, toggles through cameras
"key"          The item needed to activate this. (default nothing)
"thread" name of thread to trigger.  This can be in a different script file as well\
by using the '::' notation.

If NOT_PLAYERS is set, the trigger does not respond to players
If MONSTERS is set, the trigger will respond to monsters

/*****************************************************************************/

CLASS_DECLARATION( TriggerUse, TriggerCameraUse, "trigger_camerause" );

ResponseDef TriggerCameraUse::Responses[] =
	{
	   { &EV_Use,		( Response )TriggerCameraUse::TriggerCamera },
		{ &EV_Touch,	NULL },
		{ NULL, NULL }
	};

void TriggerCameraUse::TriggerCamera
	(
	Event *ev
	)
	{
   str    camthread;
	Entity *other;

	other = ev->GetEntity( 1 );
   if ( other->isClient() )
      {
      int num;
      Player * client;
      Entity * ent;
      Camera * cam;

      client = ( Player * )other;
      if ( client->ViewMode() == CAMERA_VIEW )
         {
         str nextcam;
         cam = client->CurrentCamera();

         // It's possible to get out of the camera
         if ( !cam )
            return;

         nextcam = cam->NextCamera();
         if ( nextcam.length() )
            {
            num = G_FindTarget( 0, nextcam.c_str() );

            if ( num )
               {
               ent = (Entity *) G_GetEntity( num );
               if ( ent && ent->isSubclassOf( Camera ) )
                  {
                  cam = (Camera *)ent;
                  camthread = cam->Thread();
                  client->SetCamera( cam );
                  }
               }
            }
         }
      else
         {
         num = G_FindTarget( 0, Target() );
         if ( num )
            {
            ent = (Entity *) G_GetEntity( num );
            if ( ent && ent->isSubclassOf( Camera ) )
               {
               cam = (Camera *)ent;
               camthread = cam->Thread();
               client->SetCamera( cam );
               }
            else
               {
               warning( "TriggerCamera", "%s is not a camera", Target() );
               }
            }

         }
      if ( camthread.length() > 1 )
         {
         if ( !ExecuteThread( camthread ) )
            {
            warning( "TriggerCamera", "Null game script" );
            }
         }
      }
	}

/*****************************************************************************/
/*SINED trigger_mutate (0.5 0.5 0.5) ? x x NOT_PLAYERS NOT_MONSTERS
mutates whatever triggers it.

"key"          The item needed to activate this. (default nothing)

If NOT_PLAYERS is set, the trigger does not activate on players
If NOT_MONSTERS is set, the trigger does not activate on monsters

/*****************************************************************************/

CLASS_DECLARATION( TriggerUse, TriggerMutate, "trigger_mutate" );

ResponseDef TriggerMutate::Responses[] =
	{
		{ &EV_Trigger_Effect,		   ( Response )TriggerMutate::Mutate },
	   { &EV_Touch,						( Response )Trigger::TriggerStuff },
		{ NULL, NULL }
	};

TriggerMutate::TriggerMutate()
	{
	respondto = spawnflags ^ ( TRIGGER_PLAYERS | TRIGGER_MONSTERS );
	}

void TriggerMutate::Mutate
	(
	Event *ev
	)

	{
   Event *event;
	Entity

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -