-
-
Save ZeroYaHero/17463e55a8f0a9be01fcd9c55fe1a8e0 to your computer and use it in GitHub Desktop.
UEFN + Verse Skill Check Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using { /Fortnite.com/Devices } | |
| using { /Verse.org/Simulation } | |
| using { /UnrealEngine.com/Temporary/Diagnostics } | |
| using { /UnrealEngine.com/Temporary/UI } | |
| using { /Fortnite.com/UI } | |
| using { /Verse.org/Colors } | |
| using { /UnrealEngine.com/Temporary/SpatialMath } | |
| using { /Verse.org/Random } | |
| using { /Verse.org/Assets } | |
| Skill_Check_Assets<public> := module: | |
| Tex2d<public> := module{} | |
| skill_check_ui := class(): | |
| Canvas : canvas | |
| CursorPusher : color_block | |
| Critical : texture_block | |
| CriticalPusher : color_block | |
| Hitbox : texture_block | |
| HitboxPusher : color_block | |
| InteractButton : button_quiet | |
| ExitButton : button_quiet | |
| skill_check_trigger := class<concrete><unique>(): | |
| # Manager | |
| var Manager : ?skill_check_device = false | |
| # Customizable properities | |
| @editable ButtonDevice : button_device = button_device{} | |
| @editable Saving : ProgressCondition = ProgressCondition.Reset | |
| @editable PassiveProgress : float = 2.0 | |
| @editable HitScore : float = 8.0 | |
| @editable CriticalScore : float = 15.0 | |
| @editable MissPenalty : float = 0.0 | |
| # Events | |
| Failed : event() = event(){} | |
| Success : event() = event(){} | |
| Finished : event() = event(){} | |
| # Progress variables | |
| var UniversalProgress : float = 0.0 | |
| var PlayerProgress : [player]float = map{} | |
| var ProgressGetter : ?type{_(:player):float} = false | |
| var ProgressSetter : ?type{_(:float, :player):void} = false | |
| # Waits for the the main interaction device to get a player signature, then it prompts them with a skill_check_ui | |
| Listen()<suspends>:void = | |
| Print("Setting up a Skill Check") | |
| Setup() | |
| if(GetProgress := ProgressGetter?, SetProgress := ProgressSetter?): | |
| race: | |
| loop: | |
| Print("Listening for Skill Check Interaction") | |
| Agent := ButtonDevice.InteractedWithEvent.Await() | |
| if(Player := player[Agent], PlayerUI := GetPlayerUI[Player], Device := Manager?, Elements := Device.UIPerPlayer[Player]): | |
| PlayerUI.AddWidget(Elements.Canvas, player_ui_slot{InputMode := ui_input_mode.All}) | |
| race: | |
| block: | |
| SetProgress(Prompt(Device, Elements, GetProgress(Player), Player), Player) | |
| PlayerUI.RemoveWidget(Elements.Canvas) | |
| Sleep(2.0) | |
| block: | |
| Success.Await() | |
| Print("Success") | |
| PlayerUI.RemoveWidget(Elements.Canvas) | |
| Print("Removed widget") | |
| Finished.Signal() | |
| ButtonDevice.Disable() | |
| block: | |
| Finished.Await() | |
| Print("Unsubscribing") | |
| return | |
| # Prompts the user with a skill check ui | |
| Prompt(Device : skill_check_device, Elements : skill_check_ui, CurrentProgress : float, Player : player)<suspends>:float = | |
| var SpeedIndex : int = 0 | |
| var Direction : float = 1.0 | |
| var Progress : float = CurrentProgress | |
| defer: | |
| Elements.CursorPusher.SetDesiredSize(vector2{}) | |
| Elements.CriticalPusher.SetDesiredSize(vector2{}) | |
| Elements.Critical.SetDesiredSize(vector2{}) | |
| Elements.Hitbox.SetDesiredSize(vector2{}) | |
| spawn { GenerateHitboxes(Elements) } | |
| race: | |
| sync: | |
| # Move + Bounce Cursor | |
| loop: | |
| if(CursorSpeed := Device.Speeds[SpeedIndex]): | |
| CursorPushSize := Elements.CursorPusher.GetDesiredSize() | |
| NextSize := CursorPushSize.X + (Direction * CursorSpeed) | |
| if(Limit := ((Device.TrackSize.X / 2.0) - Device.TrackBuffer <= NextSize) or ((-(Device.TrackSize.X / 2.0) - Device.CursorSize.X) + Device.TrackBuffer >= NextSize)): | |
| Elements.CursorPusher.SetDesiredSize(vector2{X := Limit, Y := CursorPushSize.Y}) | |
| set Direction *= -1.0 | |
| Elements.CursorPusher.SetDesiredSize(vector2{X := CursorPushSize.X + (Direction * CursorSpeed), Y := CursorPushSize.Y}) | |
| Sleep(0.0) | |
| # Update the progress variable every 1 second, adding the passive progress. (ALSO WILL UPDATE PROGRESS BAR UI) | |
| loop: | |
| Sleep(1.0) | |
| if(Progress >= 100.0): | |
| Print("Progress finished") | |
| Success.Signal() | |
| set Progress += PassiveProgress | |
| Print("Current Progress: {Progress}") | |
| # Await Button Press, determines if its a critical hit, valid hit, or a miss | |
| loop: | |
| Elements.InteractButton.OnClick().Await() | |
| CursorPushSize := Elements.CursorPusher.GetDesiredSize().X + Device.CursorSize.X / 2.0 | |
| CriticalPushSize := Elements.CriticalPusher.GetDesiredSize().X + Device.CriticalSize.X / 2.0 | |
| HitboxSize := Elements.Hitbox.GetDesiredSize() | |
| HitboxPushSize := Elements.HitboxPusher.GetDesiredSize() | |
| if(IsAlmostEqual[CursorPushSize, CriticalPushSize, Device.CriticalTolerance]): # If the click was in the critical area, count as a critical | |
| if(SpeedIndex < Device.Speeds.Length - 2): | |
| set SpeedIndex += 2 | |
| else if(SpeedIndex < Device.Speeds.Length - 1): | |
| set SpeedIndex += 1 | |
| set Progress += CriticalScore | |
| Device.CritMSG.Show(Player) | |
| else if(IsAlmostEqual[CursorPushSize, HitboxPushSize.X, Device.HitboxTolerance] or IsAlmostEqual[CursorPushSize, (HitboxPushSize.X + HitboxSize.X), Device.HitboxTolerance] or ((CursorPushSize > HitboxPushSize.X) and (CursorPushSize < (HitboxPushSize.X + HitboxSize.X)))): | |
| if(SpeedIndex < Device.Speeds.Length - 1): | |
| set SpeedIndex += 1 | |
| set Progress += HitScore | |
| Device.HitMSG.Show(Player) | |
| else: | |
| if(SpeedIndex > 0): | |
| set SpeedIndex -= 1 | |
| set Progress += MissPenalty | |
| Device.MissMSG.Show(Player) | |
| GenerateHitboxes(Elements) | |
| block: | |
| Elements.ExitButton.OnClick().Await() | |
| block: | |
| Failed.Await() | |
| block: | |
| Finished.Await() | |
| return Progress | |
| # Procedurally generates new hitboxes for the skill check | |
| GenerateHitboxes(Elements : skill_check_ui)<suspends>:void = | |
| if(Device := Manager?): | |
| # Hides/resets all widgets | |
| Elements.InteractButton.SetEnabled(false) | |
| Elements.Critical.SetDesiredSize(vector2{}) | |
| Elements.Hitbox.SetDesiredSize(vector2{}) | |
| Sleep(Device.WaitTime) | |
| # Generates new skill check hit points | |
| HitboxSizeX := GetRandomFloat(Device.HitboxMinMax.X, Device.HitboxMinMax.Y) | |
| HitboxPusherSizeX := GetRandomFloat(-(Device.TrackSize.X / 2.0) + Device.TrackBuffer, ((Device.TrackSize.X / 2.0) - Device.TrackBuffer) - HitboxSizeX) | |
| CriticalPusherSizeX := GetRandomFloat(-(Device.TrackSize.X / 2.0) + Device.TrackBuffer, (Device.TrackSize.X / 2.0 - Device.TrackBuffer)) | |
| # Shows them | |
| Elements.HitboxPusher.SetDesiredSize(vector2{X := HitboxPusherSizeX}) | |
| Elements.Hitbox.SetDesiredSize(vector2{X := HitboxSizeX, Y := Device.HitboxHeight}) | |
| Elements.CriticalPusher.SetDesiredSize(vector2{X := CriticalPusherSizeX}) | |
| Elements.Critical.SetDesiredSize(Device.CriticalSize) | |
| # Sets the button back to be enabled | |
| Elements.InteractButton.SetEnabled(true) | |
| Setup():void = | |
| case(Saving): | |
| ProgressCondition.Reset => | |
| Print("Reset") | |
| set ProgressGetter = option{GetResetProgress} | |
| set ProgressSetter = option{SetResetProgress} | |
| ProgressCondition.PerPlayer => | |
| Print("Per player") | |
| set ProgressGetter = option{GetPlayerProgress} | |
| set ProgressSetter = option{SetPlayerProgress} | |
| ProgressCondition.Universal => | |
| Print("Universal") | |
| set ProgressGetter = option{GetUniversalProgress} | |
| set ProgressSetter = option{SetUniversalProgress} | |
| SetResetProgress(Progress: float, Player : player):void = | |
| Print("Resetting progress") | |
| return | |
| SetUniversalProgress(Progress : float, Player : player):void = | |
| Print("Updating the progress for this task universally") | |
| set UniversalProgress = Progress | |
| SetPlayerProgress(Progress : float, Player : player):void = | |
| Print("Updating the progress for this task for the player who last instigated") | |
| if { Progress < 100.0, set PlayerProgress[Player] = Progress } | |
| GetResetProgress(Player : player):float = | |
| return 0.0 | |
| GetUniversalProgress(Player : player):float = | |
| return UniversalProgress | |
| GetPlayerProgress(Player : player):float = | |
| if(CurrentProgress := PlayerProgress[Player]): | |
| return CurrentProgress | |
| else: | |
| return 0.0 | |
| skill_check_device := class(creative_device): | |
| # SkillChecks | |
| @editable SkillCheckTasks : []skill_check_trigger = array{} | |
| # Logic | |
| @editable HitboxMinMax : vector2 = vector2{X := 70.0, Y := 110.0} | |
| @editable Speeds : []float = array{6.0, 7.0, 8.0, 9.0, 10.0, 15.0} | |
| @editable CriticalTolerance : float = 18.0 | |
| @editable HitboxTolerance : float = 8.0 | |
| @editable WaitTime : float = 1.0 | |
| # UI Elements | |
| @editable TrackSize : vector2 = vector2{X := 470.4, Y := 43.2} | |
| @editable TrackBuffer : float = 30.0 | |
| @editable CriticalSize : vector2 = vector2{X := 48.75, Y := 247.0} | |
| @editable CursorSize : vector2 = vector2{X := 39.0, Y := 156.25} | |
| @editable HitboxHeight : float = 112.5 | |
| @editable SkillCheckAnchor : vector2 = vector2{X := 0.5, Y := 0.6} | |
| @editable ProgressBarAnchor : vector2 = vector2{} | |
| @editable InteractButtonSize : vector2 = vector2{X := 150.0, Y := 30.0} | |
| @editable InteractButtonAnchor : vector2 = vector2{X := 0.5, Y := 0.7} | |
| @editable ExitButtonSize : vector2 = vector2{X := 125.0, Y := 30.0} | |
| @editable ExitButtonAnchor : vector2 = vector2{X := 0.5, Y := 0.75} | |
| # HUD Message Devices | |
| @editable HitMSG : hud_message_device = hud_message_device{} | |
| @editable CritMSG : hud_message_device = hud_message_device{} | |
| @editable MissMSG : hud_message_device = hud_message_device{} | |
| # Variables | |
| var UIPerPlayer : [player]skill_check_ui = map{} | |
| OnBegin<override>()<suspends>:void= | |
| for(Task : SkillCheckTasks): | |
| set Task.Manager = option{Self} | |
| spawn { Task.Listen() } | |
| GenerateUIElements(Player : player):void = | |
| Print("Generating UI") | |
| if(PlayerUI := GetPlayerUI[Player]): | |
| # Static elements | |
| BottomTrack := texture_block{DefaultImage := Skill_Check_Assets.Tex2d.track, DefaultDesiredSize := TrackSize} # What the skillcheck goes between | |
| # Cursor movements | |
| CursorPusher := color_block{DefaultOpacity := 0.0, DefaultDesiredSize := vector2{}} # The color_block that changes size to give the illusion of cursor moving | |
| Cursor := texture_block{DefaultImage := Skill_Check_Assets.Tex2d.wrench, DefaultDesiredSize := CursorSize} # The cursor that shows the alignment | |
| CursorStackBox := stack_box: # The stack_box to make it possible | |
| Orientation := orientation.Horizontal | |
| Slots := array: | |
| stack_box_slot: | |
| Widget := CursorPusher | |
| stack_box_slot: | |
| Widget := Cursor | |
| # Critical movement | |
| Critical := texture_block{DefaultImage := Skill_Check_Assets.Tex2d.gear_crit, DefaultDesiredSize := CriticalSize} # The randomly generated spot that gives a critical hit/boost | |
| CriticalPusher := color_block{DefaultOpacity := 0.0, DefaultDesiredSize := vector2{}} | |
| CriticalStackBox := stack_box: | |
| Orientation := orientation.Horizontal | |
| Slots := array: | |
| stack_box_slot: | |
| Widget := CriticalPusher | |
| stack_box_slot: | |
| Widget := Critical | |
| # Hitbox movement | |
| Hitbox := texture_block{DefaultImage := Skill_Check_Assets.Tex2d.hit_box, DefaultDesiredSize := vector2{Y := HitboxHeight}} | |
| HitboxPusher := color_block{DefaultOpacity := 0.0, DefaultDesiredSize := vector2{}} | |
| HitboxStackBox := stack_box: | |
| Orientation := orientation.Horizontal | |
| Slots := array: | |
| stack_box_slot: | |
| Widget := HitboxPusher | |
| stack_box_slot: | |
| Widget := Hitbox | |
| # Interact Button | |
| InteractButton := button_quiet{DefaultText := ToMessage("Press")} | |
| InteractButtonOverlay := overlay: | |
| Slots := array: | |
| overlay_slot: | |
| Widget := color_block{DefaultOpacity := 0.0, DefaultDesiredSize := InteractButtonSize} | |
| overlay_slot: | |
| HorizontalAlignment := horizontal_alignment.Fill | |
| VerticalAlignment := vertical_alignment.Fill | |
| Widget := InteractButton | |
| # Exit Button | |
| ExitButton := button_quiet{DefaultText := ToMessage("Exit")} | |
| ExitButtonOverlay := overlay: | |
| Slots := array: | |
| overlay_slot: | |
| Widget := color_block{DefaultOpacity := 0.0, DefaultDesiredSize := ExitButtonSize} | |
| overlay_slot: | |
| HorizontalAlignment := horizontal_alignment.Fill | |
| VerticalAlignment := vertical_alignment.Fill | |
| Widget := ExitButton | |
| # Canvas for it all (ZOrder, Anchors, Alignment) | |
| Canvas : canvas = | |
| canvas: | |
| Slots := array: | |
| canvas_slot: | |
| Widget := BottomTrack | |
| Anchors := anchors{Minimum := SkillCheckAnchor, Maximum := SkillCheckAnchor} | |
| Alignment := vector2{X := 0.5, Y := 0.5} | |
| ZOrder := 1 | |
| canvas_slot: | |
| Widget := HitboxStackBox | |
| Anchors := anchors{Minimum := SkillCheckAnchor, Maximum := SkillCheckAnchor} | |
| Alignment := vector2{X := 0.0, Y := 0.5} | |
| ZOrder := 2 | |
| canvas_slot: | |
| Widget := CriticalStackBox | |
| Anchors := anchors{Minimum := SkillCheckAnchor, Maximum := SkillCheckAnchor} | |
| Alignment := vector2{X := 0.0, Y := 0.5} | |
| ZOrder := 3 | |
| canvas_slot: | |
| Widget := CursorStackBox | |
| Anchors := anchors{Minimum := SkillCheckAnchor, Maximum := SkillCheckAnchor} | |
| Alignment := vector2{X := 0.0, Y := 0.5} | |
| ZOrder := 4 | |
| canvas_slot: | |
| Widget := InteractButtonOverlay | |
| Anchors := anchors{Minimum := InteractButtonAnchor, Maximum := InteractButtonAnchor} | |
| Alignment := vector2{X := 0.5, Y := 0.5} | |
| ZOrder := 5 | |
| canvas_slot: | |
| Widget := ExitButtonOverlay | |
| Anchors := anchors{Minimum := ExitButtonAnchor, Maximum := ExitButtonAnchor} | |
| Alignment := vector2{X := 0.5, Y := 0.5} | |
| ZOrder := 5 | |
| if { set UIPerPlayer[Player] = skill_check_ui{Canvas := Canvas, CursorPusher := CursorPusher, Critical := Critical, CriticalPusher := CriticalPusher, Hitbox := Hitbox, HitboxPusher := HitboxPusher, InteractButton := InteractButton, ExitButton := ExitButton} } | |
| # Generates a skill check task on the fly with some simple parameters | |
| ProceduralSkillCheck(Agent : agent, Reward : type{_(:agent):void}, ?Passive : float = 2.0, ?Hit : float = 8.0, ?Critical : float = 15.0, ?Miss : float = 0.0)<suspends>:void = | |
| if(Player := player[Agent], Elements := UIPerPlayer[Player], PlayerUI := GetPlayerUI[Player]): | |
| PlayerUI.AddWidget(Elements.Canvas, player_ui_slot{InputMode := ui_input_mode.All}) | |
| SkillCheck := skill_check_trigger{Manager := option{Self}, PassiveProgress := Passive, HitScore := Hit, CriticalScore := Critical, MissPenalty := Miss} | |
| race: | |
| SkillCheck.Prompt(Self, Elements, 0.0, Player) | |
| block: | |
| SkillCheck.Success.Await() | |
| SkillCheck.Finished.Signal() | |
| PlayerUI.RemoveWidget(Elements.Canvas) | |
| Reward(Agent) | |
| ToMessage<localizes>(String : string):message = "{String}" | |
| ProgressCondition := enum{Reset, PerPlayer, Universal} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment