using { /Fortnite.com/Characters }
using { /Fortnite.com/Devices }
using { /Fortnite.com/Game }
using { /Fortnite.com/UI }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
using { /Verse.org/Assets }
using { /Verse.org/Colors }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/UI }
StringToText(String : string) : message = “{String}”
loadout_vote_selection_device := class(creative_device):
@editable StartTrigger : trigger_device = trigger_device{}
@editable Columns : type{_X : int where _X > 1, _X < 6} = 3
@editable VotingTime : type{ _X : int where _X >= 3, _X <= 30} = 10
@editable Loadouts : []loadout = array{}
@editable UISettings : ui_settings = ui_settings{}
var LoadoutToCurrentVotes : [loadout]int = map{}
var MaxVotes : int = 0
var CurrentVotes : int = 0
var ImageSize : vector2 = vector2{}
var RowsToUse : int = 1
Textures : []texture = array:
<# TexturePath #>
<# TexturePath #>
VoteEndedEvent<private> : event() = event(){}
PlayerSelectionEvent<private> : event(button_selection_result) = event(button_selection_result){}
OnBegin<override>()<suspends> : void =
loop:
StartTrigger.TriggeredEvent.Await()
InitLoadoutSelection(GetPlayspace().GetPlayers())
InitLoadoutSelection<public>(Players : []player)<suspends> : void =
Sleep(0.0)
set RowsToUse = Ceil[1.0 * Loadouts.Length / (1.0 * Columns)] or 4
set ImageSize = (560.0 / (1.0 * RowsToUse)) * vector2{ X := 1.0, Y := 1.0}
set MaxVotes = Players.Length
set CurrentVotes = 0
for (Loadout : Loadouts, set LoadoutToCurrentVotes[Loadout] = 0) {}
for ( Player : Players):
spawn{ PresentSelectionUI(Player) }
VoteEndedEvent.Await()
WinningLoadout := CalculateMostVotedLoadout()
for ( Player : Players):
WinningLoadout.ItemGranter.GrantItem(Player)
PresentSelectionUI<private>(Player : player)<suspends> : void =
if ( PlayerUI := GetPlayerUI[Player]):
var BuyMenuWidget := CreateBuyMenuWidget(Player)
Canvas := canvas:
Slots := array:
canvas_slot:
Widget := BuyMenuWidget
Offsets := margin{ Left := 960.0, Top := 50.0}
Alignment := vector2{ X := 0.5, Y := 0.0}
PlayerUI.AddWidget(Canvas, player_ui_slot{ InputMode := ui_input_mode.All})
await WaitForButtonSelection(BuyMenuWidget:widget)uyMenuWidget:widget)
PlayerUI.RemoveWidget(Canvas)
WaitForButtonSelection<private>(BuyMenuWidget : widget)<suspends> : void =
var SelectionMadeEvent : event() = event(){}
for ( Index->Button : BuyMenuWidget.Buttons, Loadout := Loadouts[Index]):
race:
block:
Button.OnClick().Await()
PlayerSelectionEvent.Signal(button_selection_result{ Player := WidgetMessage.Player, Index := Index })
block:
Sleep(0.1)
SelectionMadeEvent.Await()
CalculateMostVotedLoadout() : loadout =
var GreatestVote : int = 0
var WinningLoadout : loadout = loadout{}
for (Loadout->Vote : LoadoutToCurrentVotes):
if (Vote > GreatestVote):
set GreatestVote = Vote
set WinningLoadout = Loadout
if (Vote = GreatestVote, GetRandomInt(1,2) = 1):
set WinningLoadout = Loadout
return WinningLoadout
GetImageWidget(Index : int) : widget =
if (Texture := Textures[Index]):
return texture_block:
DefaultImage := Texture
DefaultDesiredSize := 0.9 * ImageSize
else:
return color_block:
DefaultColor := UISettings.BackgroundColor
DefaultDesiredSize := 0.9 * ImageSize
MakeTextBlock(Text : string, Color : color, ShadowColor : color, ShadowOffset : vector2) : text_block =
NewTextBlock := text_block:
DefaultText := StringToText(Text)
DefaultTextColor := Color
DefaultShadowColor := ShadowColor
DefaultShadowOffset := option{ ShadowOffset }
NewTextBlock.SetShadowOpacity(1.0)
return NewTextBlock
loadout := class:
@editable Name : string = “Loadout”
@editable ItemGranter : item_granter_device = item_granter_device{}
button_selection_result := struct:
Player : player
Index : int
ui_settings := class:
@editable UseBorder : logic = true
@editable BackgroundColor : color = NamedColors.Black
@editable BorderColor : color = NamedColors.White
@editable TimerTextColor : color = NamedColors.White
@editable TimerTextShadowColor : color = NamedColors.Black
@editable LoadoutTextColor : color = NamedColors.White
@editable LoadoutTextShadowColor : color = NamedColors.Black