toy-ichi
(toy-ichi)
March 27, 2025, 6:36am
1
How to Use GetAgentsInVolume
with a Mutator Zone
I want to use the GetAgentsInVolume
function within a Mutator Zone to detect players who enter the zone and display a shared UI for them.
Could you please explain how to achieve this?
Thank you in advance!
⇒ForExample
@editable
BossBattle_Area : mutator_zone_device = mutator_zone_device{}
OnPlayerEntersArea(Agent : agent):void=
if (Player := player[Agent]):
BossBar.ShowUIForAllPlayers()
Vath
(Vath)
March 28, 2025, 3:25pm
2
Hi toy-ichi, here’s an example of using the GetAgentsInVolume method under the mutator_zone_device{}
get_agents_in_volume_device := class(creative_device):
@editable
BossBattle_Area : mutator_zone_device = mutator_zone_device{}
OnBegin<override>()<suspends>:void=
BossBattle_Area.AgentEntersEvent.Subscribe(OnAgentEntersArea)
BossBattle_Area.AgentExitsEvent.Subscribe(OnAgentExitsArea)
OnAgentEntersArea(AgentToEnter : agent):void=
Agents := BossBattle_Area.GetAgentsInVolume()
for:
Agent : Agents
Player := player[Agent]
do:
if:
PlayerUI := GetPlayerUI[Player]
then:
PlayerUI.AddWidget(BossBar)
OnAgentExitsArea(AgentToExit : agent):void=
if:
Player := player[AgentToExit]
PlayerUI := GetPlayerUI[Player]
then:
PlayerUI.RemoveWidget(BossBar)
With this example, we add our Widget to only Players within the Volume. Then when a respective Player leaves the volume. We will remove the Widget
Adding and removing the widgets can be done in various different ways. It looks like you’re using BossBar.ShowUIForAllPlayers to do that
1 Like
toy-ichi
(toy-ichi)
March 30, 2025, 6:51am
3
Yes! Hello, Vath.
Thank you for teaching me! That really helps!
I tried writing the code as a reference.
Indeed, I was able to display the UI when entering the mutator zone!
I want to display the same UI for all players who enter the mutator zone and also share the updated UI with the agents obtained using GetAgentsInVolume()
.
In that case, which part should I modify?
I would be very happy if we could think about it together!
要約
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/UI }
using { /Fortnite.com/UI }
using { /UnrealEngine.com/Temporary/SpatialMath}
using { /Verse.org/Colors }
using { /Verse.org/Colors/NamedColors }
BossBattle := module:
health_bar := class():
var iTotalHP<private> : float = 10000.0
var iCurrentHP<public>: float = 10000.0
var iBossName<private> : string = "Demon Mutatant"
var MaybeUIPerPlayer : [agent]canvas = map{}
BossBarColorBase<private> : color_block = color_block{
DefaultColor := MakeColorFromHex("000000")
DefaultDesiredSize := vector2{X := 900.0, Y := 40.0} }
var BossBarColorTop<private> : color_block = color_block{}
var Overlay<private> : overlay = overlay{}
@editable
BossEliminatedTrigger : trigger_device = trigger_device{}
HPBarTitleTextBlock<private> : text_block = text_block{DefaultTextColor := MakeColorFromHex("FFFFFF")}
HPTitleText<private><localizes>(HPText : string) : message = "{HPText}"
Init(BossName : string, BossTotalHP : float):void=
set iBossName = BossName
set iTotalHP = BossTotalHP
set iCurrentHP = BossTotalHP
if (Current := Round[iTotalHP], Total := Round[iCurrentHP]):
HPBarTitleTextBlock.SetText(HPTitleText("{iBossName}:{Current}/{Total}"))
TakeDamage(DamageAmount : float):void=
set iCurrentHP -= DamageAmount
if (iCurrentHP < 0.0):
set iCurrentHP = 0.0
HealthPercentage := iCurrentHP / iTotalHP
BarSize := BossBarColorBase.GetDesiredSize()
NewHealthBarWidth := BarSize.X * HealthPercentage
if (Current := Round[iCurrentHP], Total := Round[iTotalHP]):
HPBarTitleTextBlock.SetText(HPTitleText("{iBossName}:{Current}/{Total}"))
UpdateHealthBar(NewHealthBarWidth)
Heal(HealAmount : float):void=
block:
BossEliminationCheck(Player : player):void=
if (iCurrentHP = 0.0):
Print("Boss Eliminated")
RemoveHealthBar(Player)
set iTotalHP = 10000.0
set iCurrentHP = 10000.0
ShowUIForPlayer(Player : player):void=
if (PlayerUI := GetPlayerUI[Player]):
PlayerUI.AddWidget(CreateUI())
RemoveHealthBar(Player : player):void=
Overlay.RemoveWidget(HPBarTitleTextBlock)
Overlay.RemoveWidget(BossBarColorTop)
Overlay.RemoveWidget(BossBarColorBase)
ShowUIToAllPlayers():void=
block:
MyButton : button_device = button_device{}
UpdateHealthBar(NewWidth : float):void=
Overlay.RemoveWidget(HPBarTitleTextBlock)
Overlay.RemoveWidget(BossBarColorTop)
set BossBarColorTop = CreateTopHealthBar(NewWidth)
Overlay.AddWidget(CreateOverlaySlot(BossBarColorTop, horizontal_alignment.Left))
Overlay.AddWidget(CreateOverlaySlot(HPBarTitleTextBlock, horizontal_alignment.Center))
CreateOverlaySlot<private>(TheWidget : widget, HAlignment : horizontal_alignment):overlay_slot=
overlay_slot:
Widget := TheWidget
HorizontalAlignment := HAlignment
CreateTopHealthBar<private>(Width : float):color_block=
ColorBlock := color_block{
DefaultColor := MakeColorFromHex("ff2a00")
DefaultDesiredSize := vector2{X := Width, Y := 40.0} }
set BossBarColorTop = ColorBlock
CreateOverlay<private>() : overlay=
TheOverlay := overlay:
Slots := array:
overlay_slot:
Widget := BossBarColorBase
overlay_slot:
Widget := CreateTopHealthBar(900.0)
overlay_slot:
Widget := HPBarTitleTextBlock
set Overlay = TheOverlay
CreateUI<private>(): canvas=
TheCanvas : canvas = canvas:
Slots := array:
canvas_slot:
Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.9}, Maximum := vector2{X := 0.5, Y := 0.9}}
Offsets := margin{Top := 0.0, Left := 0.0, Right := 0.0, Bottom := 100.0}
Alignment := vector2{X := 0.5, Y := 1.0}
Widget := stack_box:
Orientation := orientation.Vertical
Slots := array:
stack_box_slot:
Widget := CreateOverlay()
return TheCanvas
Boss_Battle := class(creative_device):
@editable
BossMonster : creative_prop = creative_prop{}
@editable
BossPropManip : prop_manipulator_device = prop_manipulator_device{}
#ミューテーターゾーン
@editable
BossBattle_Area : mutator_zone_device = mutator_zone_device{}
@editable
BossBattle_Area_Respawn : mutator_zone_device = mutator_zone_device{}
@editable
BossBattle_Area_Bonus : mutator_zone_device = mutator_zone_device{}
@editable
NextBossFightTimer : timer_device = timer_device{}
@editable
BossFightingTimer : timer_device = timer_device{}
@editable
BossEliminatedTrigger : trigger_device = trigger_device{}
@editable
EliminationGold : item_granter_device = item_granter_device{}
BossBar : health_bar = health_bar{}
OnBegin<override>()<suspends>:void=
BossPropManip.DamagedEvent.Subscribe(OnTheBossDamaged)
BossBar.Init("Demon Mutatant", 10000.0)
BossBattle_Area.AgentEntersEvent.Subscribe(OnAgentsEntersArea)
BossBattle_Area.AgentExitsEvent.Subscribe(OnAgentsLeavesArea)
NextBossFightTimer.SuccessEvent.Subscribe(OnBossFightStart)
BossFightingTimer.SuccessEvent.Subscribe(OnBossBattleTimeFinish)
BossEliminatedTrigger.TriggeredEvent.Subscribe(OnBossEliminated)
OnAgentsEntersArea(AgentToEnter : agent):void=
<# if (Player := player[Agent]):
BossBar.ShowUIForPlayer(Player)
Print("Player Enters Area") #>
Agents := BossBattle_Area.GetAgentsInVolume()
for:
Agent : Agents
Player := player[Agent]
do:
if:
PlayerUI := GetPlayerUI[Player]
then:
BossBar.ShowUIForPlayer(Player)
OnAgentsLeavesArea(Agent : agent):void=
if (Player := player[Agent]):
BossBar.RemoveHealthBar(Player)
OnBossFightStart(Agent : ?agent):void=
BossBattle_Area.Enable()
Print("Boss Fight Start")
OnTheBossDamaged(Agent :agent):void=
BossBar.TakeDamage(10.0)
if (Player := player[Agent]):
if(BossBar.iCurrentHP = 0.0):
BossBar.BossEliminationCheck(Player)
BossEliminatedTrigger.Trigger(Agent)
OnBossEliminated(Agent : ?agent):void=
BossBattle_Area.Disable()
BossBattle_Area_Respawn.Enable()
BossBattle_Area_Bonus.Enable()
BossBattle_Area_Respawn.Disable()
BossBattle_Area_Bonus.Disable()
OnBossBattleTimeFinish(Agent :?agent):void=
BossBattle_Area.Disable()
BossBattle_Area_Respawn.Enable()
BossBattle_Area_Resp
awn.Disable()