Ways to stop a recurring loop

In the previous recipe we created a swap between two Bots called Gremlin and Zombie. We can perform this swap all day and all night. Being able to jump back and forth forever might be a good dynamic in some games, but you might want to build in a way to prevent the swapping at a certain point, perhaps when a quest goal is reached or a mission objective achieved. It would be good to show how to interrupt the possession sequence. In this recipe we'll try out two methods, a New Action | Switch | Switch action and a New Action | Misc | AND Gate.

Ways to stop a recurring loop

If Zombie shoots the gate shown here and dawn has arrived, the possession mechanism we set up in the previous recipe will stop. Instead a sliding gate (provisioned by a prefab) will open and Gremlin will start shooting at Zombie. There's our reason to use an AND Gate as both events must occur first. The problem is, as soon as the level begins it is dawn, we want to limit things so they player has to wait through the night (the day is much briefer than a real one). This is a good reason to use the Switch action.

Getting ready

Open the scene Packt_04_GremlinZombieStart.UDK. This continues from the previous recipe. In Kismet, two Integer Variables we'll call on have been added to the Globals section: GateOpen and DawnSet. Also, this game has been set to work best in Play On PC mode [ Getting ready ] as a Console Command has been added that sends the player back to start the level again if they get killed. This means that the View | World Properties | Game Type | Default Game Type (as well as the GameType for PIE) has been set to UTGame.

Getting ready

How to do it...

  1. Our goal is that the actor Packt.Prefabs.SlidingGate will open under two conditions. One is that it has been damaged by the Zombie incarnation of the player (not Gremlin) and the other is that Dawn has come. Right-click in Kismet and choose New Action | Misc | AND Gate.
    How to do it...
  2. This simple action has no properties but lets us flow actions through it only when all the incoming connections have been met. We need to provision a check for whether it is Dawn and a limitation and check on the damage applied to the gate. If we run a check from the Dawn output of the Matinee ChangeMaterials (or its Log Dawn) into the AND Gate we're halfway there. The problem is, the Event Track Dawn in the Matinee fires almost immediately when the level loads. What we'll do is add a New Action | Switch | Switch action in between, as shown in the next screenshot. The Switch action has a property called Link Count. Set this to 2. The Link 1 nub of the Switch now has a friend called Link 2. We're going to ignore Link 1 completely, and instead connect to the AND Gate through Link 2.
    How to do it...

    We can add to this the following set up. All the nodes here should be familiar from previous lessons. Try out the Using Take Damage to produce explosions recipe if not.

    How to do it...
  3. The Take Damage event should have its Max Trigger Count set to 0, so it can be used as much as we need, and the property Min Damage Amount set to 1 and its Damage Threshold set to 1 so it's easy to fire off this effect. Add an entry to the Damage Types channels so [0] is UTDmgType_LinkBeam and [1] is UTDmgType_LinkGun, since the LinkGun is the weapon the player has access to in this map.
  4. The main thing in this sequence is the Object Variable InterpActor_12 representing the SlidingGate prefab is attached to the Take Damage event when the player spawns, so whenever damage occurs it sends off the second input to the AND Gate. The damage may occur frequently, while Dawn only needs to come once, then both conditions will have been met. The order in which they occur isn't important.
  5. At present nothing happens when the AND Gate is fired. Let's set up a result. Right-click and choose New Action | Event | Activate Remote Event. For this, enter the Event Name, type GateShot. Hook up the Out nub of the AND Gate to the In nub of the Activate Remote Event GateShot. There is already a Remote Event that matches this action. It is embedded in the Sub-Sequence Prefabs | SlidingGate_Seq that comes with the Packt.Prefabs.SlidingGate asset.
  6. In the Sequences window, expand the Sub-Sequences to show SlidingGate_Seq and click on it.
    How to do it...
  7. The Matinee is just a transform of one side of the gate, and there's a sound to go with it. After that, a New Action | Set Variable | Int sets a Named Variable GateOpen to 1.
    How to do it...
  8. Here, after the Level Loaded event, the Named Variable GateOpen is set by another Set Variable | Int to 0. Then a Compare Int checks it, with a rapid loop, to see when the value it has actually does change to 1.
  9. This will only happen when the AND Gate is opened and the Matinee plays for the Prefab SlidingGate.
  10. What we can add is some aggression from the Bot Gremlin. If he's alive, he'll start to fire, and if he's not around, he'll spawn, then run towards the player and start to fire. This result, shown in the previous screenshot, is set up in a way we've covered several times before in this chapter. It can be compressed into a Sub-Sequence itself, called something like GremlinAttack.
  11. Why is it Gremlin who starts firing? At the time of the AND Gate firing, as things are now, it could well be the player is Gremlin, which wouldn't work. So we need to add a method to get around this.
    How to do it...
  12. The highlighted Gate action (hold G and click) forces the AND Gate to only work if it is Zombie who damages the sliding gate. This is set up by the Trigger_0 Used event closing the Gate, and the Trigger_2 Used event opening the Gate.
  13. The result is that, after Dawn has finally come and Sliding Gate has been damaged, and opens, a well placed Toggle lets us Turn Off the events Trigger_0 Used and Trigger_2 Used. These simply stop the PossessPawn actions from occurring, so the recurring loop for this can no longer occur.
  14. An example scene is include Packt_04_Zombie_DEMO.UDK. Note that for this scene it is best to use Play on PC mode [ How to do it... ] not PIE.
..................Content has been hidden....................

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