Book Image

CryEngine Game Development Blueprints

Book Image

CryEngine Game Development Blueprints

Overview of this book

Table of Contents (22 chapters)
CRYENGINE Game Development Blueprints
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating ammo events


Now that we have a complete weapon and ammo system, we can shoot and cause some damage. However, how do we know when an object has been hit? If we don't know this information, then how can we know if someone is supposed to take damage or if an object is supposed to break? The answer to this problem, like many, is events. We will add a couple of methods to our game's rules that get called when a piece of ammunition hits any object in the game word. From there, it will determine what should happen. Let's get started:

  1. Add an OnAmmoHit() method to the CGasGameRules class and implement it as follows:

    void CGASGameRules::OnAmmoHit( IAmmo* const pAmmo, IEntity*const pVictim )
    {
      if( "Player" == pVictim->GetClass()->GetName() )
      {
        auto pActor = static_cast< CPlayer* >( gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor( pVictim->GetId() ) );
        if( pActor )
          pActor->ApplyDamage( pAmmo->GetPower() );
      }
    }

    When any object in...