-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ranked.verse
243 lines (178 loc) · 8.55 KB
/
Ranked.verse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
--RANK SYSTEM SCRIPT--
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Characters }
using {/Verse.org/Simulation/Tags}
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /UnrealEngine.com/Temporary/UI }
using { /Verse.org/Assets }
using { /Verse.org/Colors }
using { /Fortnite.com/UI }
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
RankProgressBar := class():
ProgressBarColorBase< private> : color_block = color_block{
DefaultColor := MakeColorFromHex("000000")
DefaultDesiredSize := vector2{X:= 250.0, Y := 40.0}}
var ProgressBarColorTop< private> : color_block = color_block{}
var Overlay : overlay = overlay{}
PBarTitleTextBlock< private> : text_block = text_block{DefaultTextColor := MakeColorFromHex("FFFFFF")}
HPTitleText< private>< localizes>(HPText : string) : message = "{HPText}"
Init(Current : int, Goal : int):void=
PBarTitleTextBlock.SetText(HPTitleText("{Current}/{Goal}"))
#############################
UpdateWidthAndText(iCurrent : int, Goal : int):void=
var NewCurrent : float = iCurrent * 1.0
var NewGoal : float = Goal * 1.0
RankPercentage := NewCurrent / NewGoal
BarSize := ProgressBarColorBase.GetDesiredSize()
NewHealthBarWidth := BarSize.X * RankPercentage
if (Current := float[NewGoal], Total := float[NewGoal]):
PBarTitleTextBlock.SetText(HPTitleText("{iCurrent}/{Goal}"))
UpdateHealthBar(NewHealthBarWidth)
ShowUIForPlayer(Player : player):void=
if (PlayerUI := GetPlayerUI[Player]):
if (Fortchar := Player.GetFortCharacter[]):
if (Instigator : agent = Fortchar.GetAgent[]):
PlayerUI.AddWidget(CreateUI(Instigator))
UpdateHealthBar(NewWidth : float):void=
Overlay.RemoveWidget(PBarTitleTextBlock)
Overlay.RemoveWidget(ProgressBarColorTop)
set ProgressBarColorTop = CreateTopHealthBar(NewWidth)
Overlay.AddWidget(CreateOverlaySlot(ProgressBarColorTop, horizontal_alignment.Left))
Overlay.AddWidget(CreateOverlaySlot(PBarTitleTextBlock,horizontal_alignment.Center))
CreateOverlaySlot(TheWidget : widget, HAlignment : horizontal_alignment):overlay_slot=
overlay_slot:
Widget := TheWidget
HorizontalAlignment := HAlignment
CreateTopHealthBar< private>(Width: float):color_block=
ColorBlock := color_block{
DefaultColor := MakeColorFromHex("f5c800")
DefaultDesiredSize := vector2{X:= Width, Y := 40.0}}
set ProgressBarColorTop = ColorBlock
CreateOverlay< private>(Agent : agent) : overlay=
TheOverlay := overlay:
Slots := array:
overlay_slot:
Widget := ProgressBarColorBase
overlay_slot:
Widget := CreateTopHealthBar(1200.0)
overlay_slot:
Widget := PBarTitleTextBlock
set Overlay = TheOverlay
CreateUI< private>(Agent : agent) : canvas=
TheCanvas : canvas = canvas:
Slots := array:
canvas_slot:
Anchors := anchors{Minimum := vector2{X := 0.975, Y := 0.47}, Maximum := vector2{X := 0.975, Y := 0.47}}
Offsets := margin{Top := 0.0, Left := 0.0, Right := 0.0, Bottom := 0.0}
Alignment := vector2{X := 0.975, Y := 0.47}
Widget := stack_box:
Orientation := orientation.Vertical
Slots := array:
stack_box_slot:
Widget := CreateOverlay(Agent)
return TheCanvas
# A Verse-authored creative device that can be placed in a level
AllSpawners := class(tag){}
RankSystem := class(creative_device):
var PlayerMap : [agent]PlayerVariable = map{}
@editable EliminationTracker : tracker_device = tracker_device{}
Bronze1 : texture = Ranks.Bronze_1
Silver1 : texture = Ranks.Silver_1
Gold1 : texture = Ranks.Gold_1
InitSpawners():void =
Spawners := GetCreativeObjectsWithTag(AllSpawners{})
for (Obj : Spawners):
if (Spawner := player_spawner_device[Obj]):
Spawner.SpawnedEvent.Subscribe(OnPlayerSpawned)
# Runs when the device is started in a running game
OnBegin< override>()< suspends>:void=
# TODO: Replace this with your code
Print("RankSystem Started")
InitSpawners()
GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoved)
Sleep(0.3)
AllPlayers := GetPlayspace().GetPlayers()
for (Player : AllPlayers):
Print("Player granted rank")
OnPlayerSpawned(Player)
OnPlayerSpawned(Agent : agent):void =
if (PlayerObj := player[Agent]):
if (PlayerExists := PlayerMap[Agent]):
else:
PV : PlayerVariable = PlayerVariable{AgentOB := Agent}
PV.RankBar.Init(PV.GetCurrentValue(), PV.GetCurrentGoal())
PV.RankBar.ShowUIForPlayer(PlayerObj)
spawn{SetCurrentKills(Agent)}
spawn{RankUpdateLoop(Agent, PlayerObj)}
option:
set PlayerMap[Agent] = PV
SetCurrentKills(Agent : agent)< suspends>:void =
loop:
Sleep(0.01)
if (PV : PlayerVariable = PlayerMap[Agent]):
PV.SetCurrentValue(EliminationTracker.GetValue(Agent))
PV.RankBar.UpdateWidthAndText(PV.GetCurrentValue(), PV.GetCurrentGoal())
RankUpdateLoop(Agent : agent, Player : player)< suspends>:void =
RankTextureBlock : texture_block = texture_block{DefaultImage := Bronze1, DefaultDesiredSize := vector2{X := 210.0, Y := 75.0}}
loop:
Sleep(0.01)
if (EliminationTracker.GetValue(Agent) >= 0):
if (PV : PlayerVariable = PlayerMap[Agent]):
PV.SetCurrentGoal(25)
RankTextureBlock.SetImage(Bronze1)
NewCanvas : canvas = canvas:
Slots := array:
canvas_slot:
Widget := RankTextureBlock
Anchors := anchors{Minimum := vector2{X := 0.97, Y := 0.4}, Maximum := vector2{X := 0.97, Y := 0.4}}
Alignment := vector2{X := 0.97, Y := 0.4}
if (PlayerUI := GetPlayerUI[Player]):
PlayerUI.AddWidget(NewCanvas)
Print("Added Rank Widget")
break
loop:
Sleep(0.01)
if (EliminationTracker.GetValue(Agent) >= 25):
if (PV : PlayerVariable = PlayerMap[Agent]):
PV.SetCurrentGoal(50)
RankTextureBlock.SetImage(Silver1)
break
loop:
Sleep(0.01)
if (EliminationTracker.GetValue(Agent) >= 50):
if (PV : PlayerVariable = PlayerMap[Agent]):
PV.SetCurrentGoal(75)
RankTextureBlock.SetImage(Gold1)
break
OnPlayerRemoved(PlayerLeft : agent):void =
if (Agent := agent[PlayerLeft]):
if (ActualPlayer := PlayerMap[Agent]):
var TempAllPlayerMap : [agent]PlayerVariable = map{}
for (Key -> Value : PlayerMap, Key <> Agent):
set TempAllPlayerMap = ConcatenateMaps(TempAllPlayerMap, map{Key => Value})
set PlayerMap = TempAllPlayerMap
--END OF RANK SYSTEM SCRIPT--
--START OF PLAYER CLASS--
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Fortnite.com/Characters }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /UnrealEngine.com/Temporary/UI }
using { /Verse.org/Assets }
PlayerVariable := class():
AgentOB : agent
RankBar : RankProgressBar = RankProgressBar{}
var CurrentGoal : int = 25
var CurrentValue : int = 0
GetCurrentGoal() : int =
return CurrentGoal
SetCurrentGoal(Change : int) : int =
set CurrentGoal = Change
GetCurrentValue() : int =
return CurrentValue
SetCurrentValue(Change : int) : int =
set CurrentValue = Change
---------------------------------------------