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.
Last updated
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.
Last updated
tsg ai totem and kill token kit v1
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
mobTotems
- Object List Variable, Global
Objects with label User: Mike are added to this list at declaration.
totemOwners
- Object List Variable, Global
Holds the list of entities that have totems assigned to them.
assignedTotems
- Object List Variable, Global
Holds the list of totems that are currently assigned to entities.
cooldownTotems
- Object List Variable, Global
Holds the list of totems that are on cooldown, which prevents them from being assigned.
totemOwner
- Object Variable, Object
Stores a reference to the entity a totem is assigned to.
Is scoped to the totem owned by that entity.
For each Totem, check if totemOwner
is a valid object
If 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
Clean up totemOwners
list
For each AI Unit, remove from totemOwners
For each assigned Totem, add totemOwner
to totemOwners
For each AI Unit not in totemOwners
...
Assign the first unassigned Totem that is not in cooldownTotems
to the current unit
Assign the current unit as it's Totem's totemOwner
Add the current Totem to assignedTotems
Call checkTotemOwnership
For each assigned Totem, set Totem location to offset from it's owner
Adjust offset with Vector 3 node
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
killTokens
- Object List Variable, Global
Objects that are created to drop from dead units are added to this list when they are created.
activeKillTokens
- Object List Variable, Global
Kill 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, Object
The value that is adjusted to represent how many Kill Tokens a player has acquired.
killTokenValue
- Number Variable, Object
The 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
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
For killTokenValue
iterations...
Add the input Totem's position, plus offset, to v3Queue
Wait 0.1 Seconds
Call gunball
to generate a Kill Token
Check to see if Totem is in activeKillTokens
or if time has run out
If true, remove the Totem from activeKillTokens
and delete it
If false, call resetTokenLoop
with the input number value minus 1
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 increment playerInventory
for current Player, and call tokenPU
* event
* screenshot says 'motePU' instead of 'tokenPU'
Call tokenDrop
when a Player is killed
For 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
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
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
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 entry
Set current Token velocity to random (in ranges) upward and sideways velocity to produce fountain effect
Call resetTokenLoop
for current Token
Captain Punch