tsg ai totems and kill tokens
Track information about AI units and reference it after death. Example code spawns tokens per enemy type at death location that players can pick up.

Current File
tsg ai totem and kill token kit v1
Boilerplate
This is a subset of the boilerplate code provided by the tsg init
prefab.
If this is being used alongside an install of tsg init
, this code should be deleted.
tsg init
is explained in detail here: tsg init


Totems
Variable Declaration
mobTotems
- Object List Variable, GlobalObjects with label User: Mike are added to this list at declaration.
totemOwners
- Object List Variable, GlobalHolds the list of entities that have totems assigned to them.
assignedTotems
- Object List Variable, GlobalHolds the list of totems that are currently assigned to entities.
cooldownTotems
- Object List Variable, GlobalHolds the list of totems that are on cooldown, which prevents them from being assigned.
totemOwner
- Object Variable, ObjectStores a reference to the entity a totem is assigned to.
Is scoped to the totem owned by that entity.

Poll Totems and Check Totem Owner Status
For each Totem, check if
totemOwner
is a valid objectIf false, that AI is no longer alive/in the simulation
Remove Totem from
assignedTotems
Add Totem to
cooldownTotems
Call
ownerDied
to process the death of the current Totem's owner

Update Totem Ownership
Clean up
totemOwners
listFor each AI Unit, remove from
totemOwners
For each assigned Totem, add
totemOwner
tototemOwners
For each AI Unit not in
totemOwners
...Assign the first unassigned Totem that is not in
cooldownTotems
to the current unitAssign the current unit as it's Totem's
totemOwner
Add the current Totem to
assignedTotems

State Monitoring
Call
checkTotemOwnership
For each assigned Totem, set Totem location to offset from it's owner
Adjust offset with Vector 3 node

Handle Totem Losing Ownership
Call
processOwnerDeath
Wait N Seconds to keep Totem data available
Delete and spawn Totem to reset Totem data
Remove Totem from
cooldownTotems
so that it can be used again

Kill Tokens
Variable Declaration
killTokens
- Object List Variable, GlobalObjects that are created to drop from dead units are added to this list when they are created.
activeKillTokens
- Object List Variable, GlobalKill Tokens that are in play and haven't been picked up are added to this list.
This list is not relevant to Gunball Machine Tokens.
playerInventory
- Number Variable, ObjectThe value that is adjusted to represent how many Kill Tokens a player has acquired.
killTokenValue
- Number Variable, ObjectThe number of Kill Tokens that an unit is configured to drop.
This value defaults to 1 and can be augmented during Totem config or any time between then and the unit's death

Totem Configuration
Toggle event via adjusting hard-coded Branch node
In this example, the Totem owner is examined and the value of
killTokenValue
is set based on their Character Type using a switch case

Distribute Kill Tokens on Owner Death
For
killTokenValue
iterations...Add the input Totem's position, plus offset, to
v3Queue
Wait 0.1 Seconds
Call
gunball
to generate a Kill Token

Handle Kill Token Reset (Recursive Loop)
Check to see if Totem is in
activeKillTokens
or if time has run outIf true, remove the Totem from
activeKillTokens
and delete itIf false, call
resetTokenLoop
with the input number value minus 1

Poll Active Kill Tokens and Player Locations to Handle Token Pick Up
For each active Kill Token...
For each Player (all players)
Get current Player distance from current Kill Token
Check if distance < 8 units
If true, remove Kill Token from
activeKillTokens
, delete it, and incrementplayerInventory
for current Player, and calltokenPU
* event
* screenshot says 'motePU' instead of 'tokenPU'

Handle Players Dropping Kill Tokens on Death
Call
tokenDrop
when a Player is killedFor
playerInventory
* X (where X is a 0-1 scalar to modify the magnitude) iterations...Add the player's location, plus offset, to
v3Queue
Wait 0.1 seconds
Call
gunball
Set current player's
playerInventory
to 0

Gunball Machine
Clean Up Excess Kill Tokens and Prevent Token Pick Up as Weapon
Sometimes the Gunball Machine makes extra Tokens
When tokens fall into the boundary, they are excess that wont get assigned, delete them
Tokens shouldn't be picked up as weapons
On Token pickup, force dropping that Token

Generate Tokens
Preload Gunball Machine at
gameplayInit
Give turret a weapon (Generic Ball or Skull)
On
gunball
For input Iterations...
Wait 0.1 seconds
Give turret a weapon
Wait 0 seconds
Force turret to drop weapon
On Weapon Dropped
Check if dropping unit is Gunball Machine (turret)
If true, add the dropped weapon to killTokens
Wait 0.1 seconds
Call
sendIt
and pass the dropped weapon

Put Generated Kill Tokens into Play
Add current Token to
activeTokens
Set current Token to random rotation
Set current Token position to Index 1 of
v3Queue
Update
v3Queue
to remove that entrySet current Token velocity to random (in ranges) upward and sideways velocity to produce fountain effect
Call
resetTokenLoop
for current Token

Contributors
Captain Punch
Last updated