Skip to content

Instantly share code, notes, and snippets.

@LionGet
Last active October 19, 2023 22:17
Show Gist options
  • Save LionGet/5f008f943aba3ab09b5b16def4ed9d28 to your computer and use it in GitHub Desktop.
Save LionGet/5f008f943aba3ab09b5b16def4ed9d28 to your computer and use it in GitHub Desktop.
Trap Mechanic
using { /Fortnite.com/Devices }
using { /Fortnite.com/Game }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/SpatialMath }
trap_device := class(creative_device):
# Put all of your spawners in this array which maps fort_char to custom class
@editable Spawners : []player_spawner_device = array{}
# Trigger is the trap
@editable TrapZone : mutator_zone_device = mutator_zone_device{}
# See class at bottom which stores values we need per player
var Gamers:[fort_character]game_player=map{}
# Set this value to how many crouches you want before player is released
@editable CrouchesToRelease:int=5
# Set this to the damage per second you want the player to take while in the trap
@editable DamagePerSecond:float=5.0
# Player Initialization
OnBegin<override>()<suspends>:void=
TrapZone.AgentEntersEvent.Subscribe(TrapPlayer)
for (Spawner:Spawners):
Spawner.SpawnedEvent.Subscribe(OnPlayerSpawn)
OnPlayerSpawn(Agent:agent):void=
if (FortChar:=Agent.GetFortCharacter[]):
PlayerInit(FortChar)
PlayerInit(FortChar:fort_character):void=
if (Existing:=Gamers[FortChar]){}
else:
Gamer:=game_player{FortChar:=FortChar}
if (set Gamers[FortChar]=Gamer){}
Print("Info: Gamer Mapped")
FortChar.CrouchedEvent().Subscribe(OnPlayerCrouched)
FortChar.SprintedEvent().Subscribe(OnPlayerSprint)
FortChar.JumpedEvent().Subscribe(OnPlayerJump)
# When a player crouches, if they are in a trap, set crouch count +1
OnPlayerCrouched(FortChar:fort_character,IsCrouching:logic):void=
if (Gamer:=Gamers[FortChar], IsInTrap:int=Gamer.IsInTrap):
if (IsInTrap=1, IsCrouching=true):
set Gamer.CrouchCount += 1
Print("{Gamer.CrouchCount}/5 crouches")
OnPlayerSprint(FortChar:fort_character,IsSprinting:logic):void=
if (IsSprinting=true):
Print("Player is sprinting")
Print("Player is not sprinting")
OnPlayerJump(FortChar:fort_character):void=
Print("Player is Jumping")
# Trap mechanic = when player steps on trigger put them in stasis, spawn release check
TrapPlayer(Agent:agent):void=
if (PlayerAgent := Agent, FortChar := PlayerAgent.GetFortCharacter[]):
FortChar.PutInStasis(stasis_args{AllowTurning := true, AllowFalling := false, AllowEmotes := false})
if (Gamer:=Gamers[FortChar]):
set Gamer.IsInTrap = 1
Print("You've been trapped! Crouch 5x to Escape.")
spawn{ReleaseCheck(FortChar)}
spawn{DamageGamer(FortChar)}
# Deals damage to the character every second while they're trapped
DamageGamer(FortChar:fort_character)<suspends>:void=
loop:
Sleep(1.0)
FortChar.Damage(damage_args{Amount := DamagePerSecond})
if (Gamer:=Gamers[FortChar]):
if(Gamer.IsInTrap=0):
break
# Loop that checks for the players crouch count to exceed the crouches required to be released
ReleaseCheck(FortChar:fort_character)<suspends>:void=
loop:
Sleep(0.0)
if (Gamer:=Gamers[FortChar]):
if(Gamer.CrouchCount >= CrouchesToRelease):
FortChar.ReleaseFromStasis()
set Gamer.CrouchCount = 0
set Gamer.IsInTrap = 0
break
# Custom class for the gamers
game_player := class():
FortChar:fort_character
var CrouchCount:int=0
var IsInTrap:int=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment