using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Colors }
using { /Fortnite.com/UI }
using { /Verse.org/Colors/NamedColors }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/UI }
using { /Verse.org/Simulation/Tags }
using { /UnrealEngine.com/Temporary/SpatialMath }
using {/Verse.org/Assets}
using {/Fortnite.com/Teams}
spawners := class(tag){}
player_profile_data := class:
Power:int = 0
PetsPower:int = 1
Rebirth:int = 1
playerDataUpdate(OldStats:player_profile_data) := player_profile_data{
Power := OldStats.Power
PetsPower := OldStats.PetsPower
Rebirth := OldStats.Rebirth
}
var PlayerProfileDataMap:weak_map(player, player_profile_data) = map{}
PlayerStats := class(creative_device):
var PlayerMap : [agent]spawners = map{}
S2M<localizes>(S:string):message="{S}"
@editable PlayerSpawners : []player_spawner_device = array{}
@editable RefreshRate : float = 0.1
var PowerTextBlock : [agent]?text_block = map{}
var PetPowerTextBlock : [agent]?text_block = map{}
var RebirthTextBlock : [agent]?text_block = map{}
#----------------------------------------------------------------------
@editable ButtonTest : button_device = button_device{}
# Runs when the device is started in a running game
OnBegin<override>()<suspends>:void=
Spawners := GetCreativeObjectsWithTag(spawners{})
for(Obj : Spawners):
if(Spanwers := player_spawner_device[Obj]){
Spanwers.SpawnedEvent.Subscribe(PlayerSpawned)
}
AllPlayers := GetPlayspace().GetPlayers()
for(Player : AllPlayers):
PlayerSpawned(Player)
GetPlayspace().PlayerRemovedEvent().Subscribe(PlayerRemoved)
GetPlayspace().PlayerAddedEvent().Subscribe(PlayerSpawned)
ButtonTest.InteractedWithEvent.Subscribe(IncreseTestBtn)
IncreseTestBtn(Agent:agent):void=
IncresePower(Agent,1)
PlayerSpawned(Agent:agent):void=
Print("Player Spawned")
if(Player := player[Agent]):
if (not PlayerProfileDataMap[Player]):
if (set PlayerProfileDataMap[Player] = player_profile_data{}) {}
AssignUI(Agent)
PlayerRemoved(PlayerLeft : agent):void=
if(Agent := agent[PlayerLeft]):
if(ActualPlayer := agent[PlayerLeft]):
var TempPlayerMap : [agent]spawners = map{}
for(Key -> Value : PlayerMap , Key <> Agent):
set TempPlayerMap = ConcatenateMaps(TempPlayerMap, map{Key => Value})
set PlayerMap = TempPlayerMap
AssignUI(Agent:agent):void=
Print("Assigning UI")
MyCanvas:=MakeCanvas(Agent)
if:
PlayerUI:=GetPlayerUI[player[Agent]]
then:
PlayerUI.AddWidget(MyCanvas)
spawn{RefreshUI(Agent)}
spawn{CheckPlayerIsAliveUI(Agent,MyCanvas)}
RefreshUI(Agent:agent)<suspends>:void=
Print("Starting to Refresh")
if(MyPowerTextBlock := PowerTextBlock[Agent]?,MyPowerPetTextBlock:=PetPowerTextBlock[Agent]?,MyRebirthTextBlock := RebirthTextBlock[Agent]?):
loop:
Sleep(RefreshRate)
if(PlayerObj := player[Agent]):
if(PlayerData := PlayerProfileDataMap[PlayerObj]):
MyPowerTextBlock.SetText(S2M("{PlayerData.Power}"))
MyPowerPetTextBlock.SetText(S2M("{PlayerData.PetsPower}"))
MyRebirthTextBlock.SetText(S2M("{PlayerData.Rebirth - 1}"))
AllPlayers := GetPlayspace().GetPlayers()
var PlayerIsOnMap : logic = false
for(Player : AllPlayers):
if(Agent = Player):
set PlayerIsOnMap = true
if(PlayerIsOnMap = false):
break
CheckPlayerIsAliveUI(Agent:agent, Canvas : canvas)<suspends>:void=
loop:
Sleep(0.1)
AllPlayers := GetPlayspace().GetPlayers()
var PlayerIsOnMap : logic = false
for(Player : AllPlayers):
if(Agent = Player):
set PlayerIsOnMap = true
if(PlayerIsOnMap = false):
if(PlayerUI:=GetPlayerUI[player[Agent]]):
PlayerUI.RemoveWidget(Canvas)
break
MakeCanvas(Agent:agent):canvas=
Print("Making Canvas")
PowerHudImage := texture_block {DefaultImage := UI.PowerUI,DefaultDesiredSize := vector2{X := 350.0, Y := 350.0}}
PowerValue:=text_block{DefaultTextColor:=White}
if(set PowerTextBlock[Agent] = option{PowerValue}){}
PetHudImage := texture_block {DefaultImage := UI.PetsUI,DefaultDesiredSize := vector2{X := 350.0, Y := 350.0}}
PetPowerValue:=text_block{DefaultTextColor:=White}
if(set PetPowerTextBlock[Agent] = option{PetPowerValue}){}
RebirthHudImage := texture_block {DefaultImage := UI.RebirthUI,DefaultDesiredSize := vector2{X := 350.0, Y := 350.0}}
RebirthValue:=text_block{DefaultTextColor:=Black}
if(set RebirthTextBlock[Agent] = option{RebirthValue}){}
MyCanvas:=canvas:
Slots:=array:
canvas_slot:
Anchors := anchors{Minimum := vector2{X := 0.9 , Y := 0.5}, Maximum := vector2{X := 0.9 , Y := 0.5}}
Alignment := vector2{X := 0.5, Y:= 0.5}
SizeToContent := true
Widget:= PowerHudImage
canvas_slot:
Anchors := anchors{Minimum := vector2{X := 0.91 , Y := 0.5}, Maximum := vector2{X := 0.91 , Y := 0.5}}
Alignment := vector2{X := 0.5, Y:= 0.5}
SizeToContent := true
Widget:= PowerValue
canvas_slot:
Anchors := anchors{Minimum := vector2{X := 0.9 , Y := 0.6}, Maximum := vector2{X := 0.9 , Y := 0.6}}
Alignment := vector2{X := 0.5, Y:= 0.5}
SizeToContent := true
Widget:= PetHudImage
canvas_slot:
Anchors := anchors{Minimum := vector2{X := 0.91 , Y := 0.6}, Maximum := vector2{X := 0.91 , Y := 0.6}}
Alignment := vector2{X := 0.5, Y:= 0.5}
SizeToContent := true
Widget:= PetPowerValue
canvas_slot:
Anchors := anchors{Minimum := vector2{X := 0.9 , Y := 0.7}, Maximum := vector2{X := 0.9 , Y := 0.7}}
Alignment := vector2{X := 0.5, Y:= 0.5}
SizeToContent := true
Widget:= RebirthHudImage
canvas_slot:
Anchors := anchors{Minimum := vector2{X := 0.91 , Y := 0.7}, Maximum := vector2{X := 0.91 , Y := 0.7}}
Alignment := vector2{X := 0.5, Y:= 0.5}
SizeToContent := true
Widget:= RebirthValue
return MyCanvas
IncresePower(Agent:agent,AddPower:int):void=
if(PlayerObj := player[Agent]):
if(PlayerData := PlayerProfileDataMap[PlayerObj]):
if:
OldData := PlayerProfileDataMap[PlayerObj]
set PlayerProfileDataMap[PlayerObj] = player_profile_data{
playerDataUpdate<constructor>(OldData)
Power := OldData.Power + AddPower
}
When I enter the session, the data is displayed from the UI, but when I exit and re-enter the same session, the interface with the data stops showing.Please Help !