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
In the Community Content window, search for spike.
Find Spike Defuse Asset and click Import
Add the Spike to the Game
In the Core Content window in the section called Community Content, click the Spike Defuse Asset template.
You should see two green icons, a script called SampleGameInterface and a template called Spike Equipment.
Click and drag the Spike Equipment on to the Main Viewport positioning it near a spawn point.
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
Press = or Play to start the Preview.
Run over the spike. It should automatically equip in your character’s hands, overlapping the gun.
Using left click will not place it yet, because that action is currently bound to the gun.
Change the Spike Action Binding
Open the Spike Equipment in the Hierarchy to select the Spike ability (symbolized by a hand icon).
Open the Properties window to edit the ability properties.
In the Ability section, change the Action Binding property to Secondary Ability to connect it to the right click action.
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
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.
In Core Content, search trigger and drag the Trigger object onto a the raised platform area of the whitebox map.
Resize the trigger to cover the entire area.
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.
Right click the Spike Equipment template and select Deinstance This Object so that you can change its internal scripts.
Open the Spike ability folder to find the Spike Weapon Script and select it.
Open the Properties window, and scroll down to the Custom section.
Click and drag the Bomb Site A trigger over the Custom section of the Properties window until it lights up in green.
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
Copy the propBombSiteA variable code from the Spike Weapon Script.
Double click the Spike Weapon Script in the Hierarchy to open it.
Paste the variable code in the beginning of the script, anywhere before the OnAbilityCast function.
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 abilitylocal onBombSite = propBombSiteA:IsOverlapping(player) -- will be true/false depending on if the player is overlapping the triggerifnot onBombSite then
Start a preview, and try to plant the spike both outside and inside of the bomb site.
Add a Second Site
Select Bomb Site A and copy and paste it in the scene.
Move the copied trigger to a different location.
Rename it to Bomb Site B
Drag Bomb Site B onto the properties of the Spike Weapon Script to make a new Custom Property.
Copy and paste the propBombSiteB line into the script
Change the onBombSite line to check for both sites:
local onBombSite = propBombSiteA:IsOverlapping(player) or propBombSiteB:IsOverlapping(player)
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
Delete the extra Spike Equipment in Team 2’s base.
Select the PickupTrigger object in Spike Equipment and open Properties.
In the Gameplay section, the Team value should be set to 1.
In the Collision section, make sure only Enable Team Collision is checked.
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.
Open the Project Content window, and search for spike to find Spike_Planted.
Drag the Spike_Planted into the Main Viewport.
Select the DisarmTrigger object and open the Properties.
Make sure the Team value to 1
In the Collision section, make sure only Enable Enemy Collision is checked.’
Repeat these steps for the DisarmZoneTrigger.
Right clock the Spike_Planted object and select Update Template From this
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
Open the Project Content window.
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:
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.
From the Spike Defuse Asset template in the Imported Content section of Core Content, click and drag the Sample Game Interface into the Hierarchy.
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.:
In the Spike_Defused event function, add this line to say that the defenders one: