The Spike

The Spike
The Spike

Enhance any team-based shooter game with a new objective – a bomb defusal mission!

In this lesson, you will learn how to integrate a community content piece with an existing game, using the Last Team Standing framework as an example.

Adding the Spike to Your Game

Import the Spike

  1. In the Community Content window, search for spike.
  2. Find Spike Defuse Asset and click Import

Add the Spike to the Game

  1. In the Core Content window in the section called Community Content, click the Spike Defuse Asset template.
  2. You should see two green icons, a script called SampleGameInterface and a template called Spike Equipment.
  3. Click and drag the Spike Equipment on to the Main Viewport positioning it near a spawn point.
  4. For testing purposes, drag a second copy of the Spike Equipment into the other team’s spawn point as well.

Testing the Spike

Pick Up the Spike

  1. Press = or Play to start the Preview.
  2. Run over the spike. It should automatically equip in your character’s hands, overlapping the gun.
  3. Using left click will not place it yet, because that action is currently bound to the gun.

Change the Spike Action Binding

  1. Open the Spike Equipment in the Hierarchy to select the Spike ability (symbolized by a hand icon).
  2. Open the Properties window to edit the ability properties.
  3. In the Ability section, change the Action Binding property to Secondary Ability to connect it to the right click action.
  4. To apply your change to both of the spikes in the scene, right-click the changed Spike Equipment in the Hierarchy and select Update Template From This
  5. Start a preview, pick up the spike, and test planting it with right click.

You could also change the action that the player uses to plant it in the ability properties. By default it uses the 1hand_melee_rm_combo_opener_vertical_slash. Delete this text to see all the options. The unarmed_pickup animation, for example, will make players crouch down to plant it instead.

Creating Bomb Sites

Right now, you can plant the spike in any location, but the key to a bomb defusal mission is creating specific bomb sites that have to be attacked and defended by the teams.

Create a Bomb Site Trigger

To detect if a player is on a bomb site, we will use the Core object whose purpose is detecting if players are on it, a Trigger.

  1. In Core Content, search trigger and drag the Trigger object onto a the raised platform area of the whitebox map.
  2. Resize the trigger to cover the entire area.
  3. Select the trigger in the Hierarchy and press F2 to rename it to Bomb** Site A

Reference the Bomb Site in the Spike Weapon Script

To keep the player from planting the spike outside of the bomb site, we need to change the script that controls the spike planting ability.

  1. Right click the Spike Equipment template and select Deinstance This Object so that you can change its internal scripts.
  2. Open the Spike ability folder to find the Spike Weapon Script and select it.
  3. Open the Properties window, and scroll down to the Custom section.
  4. Click and drag the Bomb Site A trigger over the Custom section of the Properties window until it lights up in green.
  5. You should see a new BombSiteA property, and a line of code listed below that says local propBombSiteA = script:GetCustomProperty("BombSiteA"):WaitForObject()

This line of code creates a variable that you can use in the script to reference the bomb site.

Check if a Player is on the Bomb Site

  1. Copy the propBombSiteA variable code from the Spike Weapon Script.
  2. Double click the Spike Weapon Script in the Hierarchy to open it.
  3. Paste the variable code in the beginning of the script, anywhere before the OnAbilityCast function.
  4. Copy or type in this code into the OnAbilityCast function, before the end keyword:
local player = ability.owner --the player here is whoever tried to use the spike planting ability
local onBombSite = propBombSiteA:IsOverlapping(player) -- will be true/false depending on if the player is overlapping the trigger
if not onBombSite then
    ability:Interrupt()
endCode language: Lua (lua)
  1. Press CTRL+S to save your script changes.
  2. Right-click the Spike Equipment you deinstanced earlier and choose to “Update Template from this”.
  3. Start a preview, and try to plant the spike both outside and inside of the bomb site.

Add a Second Site

  1. Select Bomb Site A and copy and paste it in the scene.
  2. Move the copied trigger to a different location.
  3. Rename it to Bomb Site B
  4. Drag Bomb Site B onto the properties of the Spike Weapon Script to make a new Custom Property.
  5. Copy and paste the propBombSiteB line into the script
  6. Change the onBombSite line to check for both sites:
local onBombSite = propBombSiteA:IsOverlapping(player) or propBombSiteB:IsOverlapping(player)Code language: Lua (lua)

Restricting Interactions by Team

Our next step is to make sure that only one team can pick up and plant the spike, and only the other can defuse it. From now on we will assume Team 1 is the attackers, the ones who can carry and plant the spike, and Team 2 is the defenders, who can defuse it.

Apply a Team to the Spike Pickup Trigger

  1. Delete the extra Spike Equipment in Team 2’s base.
  2. Select the PickupTrigger object in Spike Equipment and open Properties.
  3. In the Gameplay section, the Team value should be set to 1.
  4. In the Collision section, make sure only Enable Team Collision is checked.
  5. Right click the Spike Equipment and select Update Template From this

Apply a Team to Defusing the Spike

Because the planted spike is actually a different object from the spike equipment, we will need to bring it into the Hierarchy to edit it.

  1. Open the Project Content window, and search for spike to find Spike_Planted.
  2. Drag the Spike_Planted into the Main Viewport.
  3. Select the DisarmTrigger object and open the Properties.
  4. Make sure the Team value to 1
  5. In the Collision section, make sure only Enable Enemy Collision is checked.’
  6. Repeat these steps for the DisarmZoneTrigger.
  7. Right click the Spike_Planted object and select Update Template From this
  8. Delete the Spike_Planted from the scene.

Round Ending Conditions

See How Rounds End

To add new ways that a round can end, it helps to understand how this is already happening in the framework. The script that controls this is called RoundEliminationConditionServer

  1. Open the Project Content window.
  2. In the My Scripts section, find RoundEliminationConditionServer

The Tick() function is a special function that gets called over and over again as long as the game is running. In this case, it is being used to constantly check if the win conditions are met, so that it can end the round.

The most important section is in the second if statement in the Tick() function:

This checks:

  • If our game has team victories (it does)
  • If someone is not dead on both teams.
  • As long someone is not dead on both teams, we don’t need to go any further, and can just start back at the top on the next tick (this what the return keyword does)
  • If there are no players alive on one team, then the team that belongs to the last alive player we checked is the winning team.

Once there is a winning team, then this important line is called: Events.Broadcast("TeamVictory", winningTeam).

This is the line we will use to make Spike detonation and defusal also broadcast different victories.

Announce a Team Victory

To announce the winner from the bomb, we will use the SampleGameInterface script from the Spike template.

  1. From the Spike Defuse Asset template in the Imported Content section of Core Content, click and drag the Sample Game Interface into the Hierarchy.
  2. Double click Sample Game Interface to edit it.

The last two functions connect to the "Spike_Disarmed" event and the "Spike_Detonated". These are the places we will broadcast the team victory event.

In the Spike_Detonated event function, add this line to say that the attackers won.:

Events.Broadcast("TeamVictory", 1)Code language: Lua (lua)

In the Spike_Disarmed event function, add this line to say that the defenders one:

Events.Broadcast("TeamVictory", 2)Code language: Lua (lua)
Post a comment

Leave a Comment

Scroll to Top