using { /Fortnite.com/UI }
using { /Fortnite.com/Devices }
using { /Fortnite.com/Game }
using { /Verse.org/Simulation }
custom_player_ui := class(creative_device):
@editable
PlayerSpawner : player_spawner_device = player_spawner_device{}
@editable
Button1 : button_widget = button_widget{X := 100, Y := 200}
@editable
Button2 : button_widget = button_widget{X := 300, Y := 200}
@editable
Button3 : button_widget = button_widget{X := 500, Y := 200}
@editable
Trigger1 : trigger_device = trigger_device{}
@editable
Trigger2 : trigger_device = trigger_device{}
@editable
Trigger3 : trigger_device = trigger_device{}
var Votes1 : int = 0
var Votes2 : int = 0
var Votes3 : int = 0
var VotingTime : float = 10.0
var PlayerVotes : [player]int = map{}
OnBegin<override>()<suspends>:
PlayerSpawner.PlayerSpawnedEvent.Subscribe(OnPlayerSpawned)
Button1.PressedEvent.Subscribe(OnButton1Pressed)
Button2.PressedEvent.Subscribe(OnButton2Pressed)
Button3.PressedEvent.Subscribe(OnButton3Pressed)
spawn StartVotingTimer()
UpdateButtonLabels()
OnPlayerSpawned(Agent : agent):
pass
OnButton1Pressed():
if Player := GetCurrentPlayer[]:
if PlayerVotes[Player] == 0:
set Votes1 += 1
set PlayerVotes[Player] = 1
UpdateButtonLabels()
OnButton2Pressed():
if Player := GetCurrentPlayer[]:
if PlayerVotes[Player] == 0:
set Votes2 += 1
set PlayerVotes[Player] = 2
UpdateButtonLabels()
OnButton3Pressed():
if Player := GetCurrentPlayer[]:
if PlayerVotes[Player] == 0:
set Votes3 += 1
set PlayerVotes[Player] = 3
UpdateButtonLabels()
StartVotingTimer()<suspends>:
Sleep(VotingTime)
TriggerMostVotedButton()
TriggerMostVotedButton():
if Votes1 >= Votes2 and Votes1 >= Votes3:
Trigger1.Trigger()
BroadcastMessage("Button 1 Wins with {Votes1} Votes")
elif Votes2 >= Votes1 and Votes2 >= Votes3:
Trigger2.Trigger()
BroadcastMessage("Button 2 Wins with {Votes2} Votes")
else:
Trigger3.Trigger()
BroadcastMessage("Button 3 Wins with {Votes3} Votes")
ResetVotes()
BroadcastMessage(Message : string):
AllPlayers := GetPlayspace().GetPlayers()
for Player : AllPlayers:
if HUD := Player.GetPlayerHUD[]:
HUD.DisplayMessage(Message)
ResetVotes():
set Votes1 = 0
set Votes2 = 0
set Votes3 = 0
set PlayerVotes = map{}
UpdateButtonLabels()
spawn StartVotingTimer()
UpdateButtonLabels():
Button1.SetText("Button 1: {Votes1} Votes")
Button2.SetText("Button 2: {Votes2} Votes")
Button3.SetText("Button 3: {Votes3} Votes")
GetCurrentPlayer():?player:
if Agent := GetLocalPlayerAgent[]:
return player[Agent]
return false