Creating a kill counter

In this recipe, we will look at one of the many methods to make a quick kill counter for the player based on the HitInfo taken from raycasted weapons (melee, bullets, and so on) and also using the Grunt entity types as the targets.

Getting ready

  • Open My_Level.cry within the Sandbox

How to do it...

  1. Begin by placing an AreaTrigger entity onto the map to use as the container for the Flow Graph.
  2. In the RollupBar, click on the Entities button.
  3. Under the Triggers section, select AreaTrigger.
  4. Right-click the newly placed AreaTrigger and create a new Flow Graph. Name the Flow Graph as KillCounter.
  5. With the Flow Graph open and the new AreaTrigger selected, add in the following nodes:
    • 2x Game:LocalPlayer
    • Crysis:HitInfo
    • Math:Counter
    • HUD:DisplayDebugMessage
  6. Set Crysis:HitInfo Enable to true (1).
  7. You will also need to place down at least one Grunt within the level. Then with the Grunt selected, go back into the AreaTrigger Flow Graph and right-click Add Selected Entity.
  8. Link the Flow Graph together as follows:
    • Game:LocalPlayer entityId out to Crysis:HitInfo ShooterId in.
    • Crysis:HitInfo TargetId out to entity:Grunt Grunt # in. (This will change to<Input Entity> as these nodes take the entity IDs.)
    • entity:Grunt Dead out to Math:Counter in in.
    • Math:Counter count out to HUD:DisplayDebugMessage Show in AND message in.
    • Second Game:LocalPlayer entityId out to HUD:DisplayDebugMessage Choose Entity in.
  9. The resulting Flow Graph should look like the following:
    How to do it...

How it works...

Using the Crysis:HitInfo node within the Flow Graph checks to see what the player is hitting with any Raycasting weapons such as bullets or melee for example. Each time the player lands a hit on an entity, the TargetId is then triggered in this node. As we are comparing against Grunt type entities, it checks to see if that TargetId died. If the Grunt has died from this event, it forwards a true value in the Boolean only once, which gets counted by the Math:Counter. The total value of the Math Counter is then displayed back to the player showing how many times the player has killed the Grunts.

The number displayed will appear in the upper-left corner of the screen after the successful kills have been made:

How it works...

See also

  • The Rewarding the player for reaching a kill goal recipe
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.151.164