Guest User

Untitled

a guest
Nov 9th, 2024
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. using { /Fortnite.com/Devices }
  2. using { /Fortnite.com/UI }
  3. using { /UnrealEngine.com/Temporary/Diagnostics }
  4. using { /UnrealEngine.com/Temporary/UI }
  5. using { /Verse.org/Colors/NamedColors }
  6. using { /Verse.org/Simulation }
  7.  
  8. Item_Counter_Device := class(creative_device):
  9.  
  10. var Bool: logic = false
  11.  
  12. UpdateValue<localizes>(Str:string):message="{Str}"
  13.  
  14. #Create an array of player spawners to loop through and initialize the map.
  15. @editable
  16. SpawnerArray : []player_spawner_device = array{}
  17.  
  18. @editable
  19. ButtonCounter : conditional_button_device = conditional_button_device{}
  20.  
  21. @editable
  22. ToggleButton: button_device = button_device {}
  23.  
  24. #Map with an agent object reference as the key and the HUD (a text block) as the value!
  25. var AgentTextMap : [agent] ?text_block = map{}
  26.  
  27. TextBlockWidget: text_block= text_block {DefaultTextColor:= Red}
  28.  
  29. var OverlayPanel: overlay = overlay{}
  30.  
  31. OnBegin<override>()<suspends>:void=
  32. for(SpawnerDevice:SpawnerArray):
  33. SpawnerDevice.SpawnedEvent.Subscribe(PlayerSpawned)
  34. ToggleButton.InteractedWithEvent.Subscribe(ToggleViz)
  35.  
  36. PlayerSpawned(Agent:agent):void=
  37. Print("A player has spawned.", ?Duration:=10.0)
  38. # Querying a map with its key to see if it has a value. If no value (text block), it fails and moves to else.
  39. if( TextBlock:text_block = AgentTextMap[Agent]?){}
  40.  
  41. # Otherwise, begin HUD initialization and creation process.
  42. # This calls InitializeUI, which in turn calls both UpdateUI and MakeHUD.
  43. else:
  44. InitializeUI(Agent)
  45.  
  46. InitializeUI(Agent:agent):void=
  47. set OverlayPanel = MakeHUD(Agent)
  48. if:
  49. #Cast from agent to player, so we can get the player's UI.
  50. InPlayer:= player[Agent]
  51. PlayerUI:= GetPlayerUI[InPlayer]
  52. then:
  53. PlayerUI.AddWidget(OverlayPanel)
  54. #Calling to an async function that repeatedly checks in with the Conditional Button.
  55. spawn{UpdateUI(Agent)}
  56.  
  57. UpdateUI(Agent:agent)<suspends>:void=
  58.  
  59. if(TextBlock := AgentTextMap[Agent]?):
  60. loop:
  61. Sleep(1.0)
  62. CurrentCount := ButtonCounter.GetItemCount(Agent,0)
  63. TextBlock.SetText(UpdateValue("Item Count: {CurrentCount}"))
  64.  
  65.  
  66. # Creates the HUD
  67. MakeHUD(Agent:agent):overlay=
  68.  
  69. # Add player with UI (HUD) to the map.
  70. if(set AgentTextMap[Agent] = option{TextBlockWidget}){}
  71.  
  72. MyOverlay:=overlay:
  73. Slots:=array:
  74. overlay_slot:
  75. Widget:=TextBlockWidget
  76. HorizontalAlignment :=horizontal_alignment.Center
  77. VerticalAlignment := vertical_alignment.Top
  78. Padding:=margin{Top:=100.0}
  79.  
  80. Print("UI created for player and map updated.")
  81. return MyOverlay
  82.  
  83. ToggleViz(Agent: agent): void =
  84. if (Bool = false):
  85. set Bool = true
  86. OverlayPanel.SetVisibility(widget_visibility.Hidden)
  87. else:
  88. set Bool = false
  89. OverlayPanel.SetVisibility(widget_visibility.Visible)
Add Comment
Please, Sign In to add comment