using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/Diagnostics }
Voting_System := class(creative_device):
@editable VoteSystemDevice : popup_dialog_device = popup_dialog_device{} # your pop up
@editable RoundStartDevice : round_settings_device = round_settings_device{} # a trigger for starting the round
@editable Map1TeleportDevice : teleporter_device = teleporter_device{} #Moves player to area
@editable Map2TeleportDevice : teleporter_device = teleporter_device{} #Moves player to area
@editable Map3TeleportDevice : teleporter_device = teleporter_device{} #Move player to area
@editable Map4TeleportDevice : teleporter_device = teleporter_device{} #Move player to area
@editable Map5TeleportDevice : teleporter_device = teleporter_device{} #Move player to area
@editable TimeToVoteDevice : timer_device = timer_device{} #Time for players to vote
@editable WinningMapUI : hud_message_device = hud_message_device{}
var VotesForMap1 : int = 0 #Counter for Map 1
var VotesForMap2 : int = 0 #Counter for Map 2
var VotesForMap3 : int = 0 #Counter for Map 3
var VotesForMap4 : int = 0 #Counter for Map 4
var VotesForMap5 : int = 0 #Counter for Map 5
@editable var Map1Name : string = "" #Coral Cove
@editable var Map2Name : string = "" #Beach Blast
@editable var Map3Name : string = "" #Bay Park
@editable var Map4Name : string = "" #Pirate Paradise
@editable var Map5Name : string = "" #Pool Party
OnBegin<override>()<suspends>:void=
RoundStartDevice.RoundBeginEvent.Subscribe(OnRoundStart) #Listening for round to start
VoteSystemDevice.RespondingButtonEvent.Subscribe(OnButtonVote) #Listening for button responces
TimeToVoteDevice.SuccessEvent.Subscribe(OnTimerSuccess) #Listening for timer to finish
Map1TeleportDevice.Disable() #disable map 1 teleporter
Map2TeleportDevice.Disable() #disable map 2 teleporter
Map3TeleportDevice.Disable() #disable map 3 teleporter
Map4TeleportDevice.Disable() #disable map 4 teleporter
Map5TeleportDevice.Disable() #disable map 5 teleporter
OnRoundStart():void=
VoteSystemDevice.Show() #Show the vote UI
TimeToVoteDevice.Start() #start the timer
OnTimerSuccess(Agent :? agent):void= #Timer finish event
VoteSystemDevice.Hide() # hides the vote UI
CalculateWinner(Map1_Votes : int, Map2_Votes : int, Map3_Votes : int, Map4_Votes : int, Map5_Votes : int):void=
# ... (the rest of the function body that handles 5 maps, as I provided in the previous message) ...
OnButtonVote(Agent : agent, Number : int):void= #Setting the vote value to the int values
if(Number = 0):
set VotesForMap1 += 1
if(Number = 1):
set VotesForMap2 += 1
if(Number = 2):
set VotesForMap3 += 1
if(Number = 3):
set VotesForMap4 += 1
if(Number = 4):
set VotesForMap5 += 1
# Place this entire function inside your voting system class, replacing your current CalculateWinner
CalculateWinner(Map1_Votes : int, Map2_Votes : int, Map3_Votes : int, Map4_Votes : int, Map5_Votes : int):void=
# THIS IS THE ACTUAL START OF THE FUNCTION BODY, CORRECTLY INDENTED:
Print("Summer Scramble: Calculating winner (Strict Pastebin-style extension for 5 maps)...")
var MaxVoted : int = Map1_Votes # set most voted to map 1 to start
Print("Initial MaxVoted (Map1): {MaxVoted}")
# Map 2 comparison (original flawed pattern)
if(Map2_Votes >= MaxVoted):
set MaxVoted = Map2_Votes
else if(Map2_Votes <> MaxVoted): # This means Map2_Votes < MaxVoted
RandomValue1 := GetRandomInt(1,2)
if(RandomValue1 = 1):
Print("Map2 vs MaxVoted: RandomValue1 was 1, MaxVoted unchanged from this path.")
else if(RandomValue1 = 2):
set MaxVoted = Map2_Votes
Print("Map2 vs MaxVoted: RandomValue1 was 2, MaxVoted set to Map2_Votes ({Map2_Votes}).")
Print("After Map 2, MaxVoted is: {MaxVoted}")
# Map 3 comparison (original flawed pattern)
if(Map3_Votes >= MaxVoted):
set MaxVoted = Map3_Votes
else if(Map3_Votes <> MaxVoted):
RandomValue2 := GetRandomInt(1,2)
if(RandomValue2 = 1):
Print("Map3 vs MaxVoted: RandomValue2 was 1, MaxVoted unchanged from this path.")
else if(RandomValue2 = 2):
set MaxVoted = Map3_Votes
Print("Map3 vs MaxVoted: RandomValue2 was 2, MaxVoted set to Map3_Votes ({Map3_Votes}).")
Print("After Map 3, MaxVoted is: {MaxVoted}")
# ADDED FOR MAP 4 (Following the exact same flawed pattern)
if(Map4_Votes >= MaxVoted):
set MaxVoted = Map4_Votes
else if(Map4_Votes <> MaxVoted):
RandomValue3 := GetRandomInt(1,2)
if(RandomValue3 = 1):
Print("Map4 vs MaxVoted: RandomValue3 was 1, MaxVoted unchanged from this path.")
else if(RandomValue3 = 2):
set MaxVoted = Map4_Votes
Print("Map4 vs MaxVoted: RandomValue3 was 2, MaxVoted set to Map4_Votes ({Map4_Votes}).")
Print("After Map 4, MaxVoted is: {MaxVoted}")
# ADDED FOR MAP 5 (Following the exact same flawed pattern)
if(Map5_Votes >= MaxVoted):
set MaxVoted = Map5_Votes
else if(Map5_Votes <> MaxVoted):
RandomValue4 := GetRandomInt(1,2)
if(RandomValue4 = 1):
Print("Map5 vs MaxVoted: RandomValue4 was 1, MaxVoted unchanged from this path.")
else if(RandomValue4 = 2):
set MaxVoted = Map5_Votes
Print("Map5 vs MaxVoted: RandomValue4 was 2, MaxVoted set to Map5_Votes ({Map5_Votes}).")
Print("Final MaxVoted from sequential flawed logic: {MaxVoted}")
# Announce winner and teleport
var WinnerAnnounced : logic = false
if(MaxVoted = Map1_Votes and Map1Name <> ""):
WinningMapUI.SetText(TextForUI("The Summer Scramble winner is {Map1Name}! Let's Go!"))
WinningMapUI.Show()
Map1TeleportDevice.Enable()
TeleportAllPlayersToDevice(Map1TeleportDevice)
set WinnerAnnounced = true
Print("Winner declared: {Map1Name}")
elif(MaxVoted = Map2_Votes and Map2Name <> ""):
WinningMapUI.SetText(TextForUI("The Summer Scramble winner is {Map2Name}! Surf's Up!"))
WinningMapUI.Show()
Map2TeleportDevice.Enable()
TeleportAllPlayersToDevice(Map2TeleportDevice)
set WinnerAnnounced = true
Print("Winner declared: {Map2Name}")
elif(MaxVoted = Map3_Votes and Map3Name <> ""):
WinningMapUI.SetText(TextForUI("The Summer Scramble winner is {Map3Name}! Party Time!"))
WinningMapUI.Show()
Map3TeleportDevice.Enable()
TeleportAllPlayersToDevice(Map3TeleportDevice)
set WinnerAnnounced = true
Print("Winner declared: {Map3Name}")
elif(MaxVoted = Map4_Votes and Map4Name <> ""):
WinningMapUI.SetText(TextForUI("The Summer Scramble winner is {Map4Name}! Adventure Awaits!"))
WinningMapUI.Show()
Map4TeleportDevice.Enable()
TeleportAllPlayersToDevice(Map4TeleportDevice)
set WinnerAnnounced = true
Print("Winner declared: {Map4Name}")
elif(MaxVoted = Map5_Votes and Map5Name <> ""):
WinningMapUI.SetText(TextForUI("The Summer Scramble winner is {Map5Name}! Make a Splash!"))
WinningMapUI.Show()
Map5TeleportDevice.Enable()
TeleportAllPlayersToDevice(Map5TeleportDevice)
set WinnerAnnounced = true
Print("Winner declared: {Map5Name}")
if(WinnerAnnounced = false):
Print("Summer Scramble: No clear winner from specific map checks or MaxVoted ({MaxVoted}) is problematic. Trying default.")
var FallbackWinnerName : string = ""
var FallbackTeleporter : ?teleporter_device = false
TempMapNames := array{Map1Name, Map2Name, Map3Name, Map4Name, Map5Name}
TempTeleporters := array{Map1TeleportDevice, Map2TeleportDevice, Map3TeleportDevice, Map4TeleportDevice, Map5TeleportDevice}
ValidIndices : []int = array{}
for (Index := 0..TempMapNames.Length - 1):
if(TempMapNames[Index] <> ""):
set ValidIndices += array{Index}
if(ValidIndices.Length > 0):
RandomIndex := GetRandomInt(0, ValidIndices.Length - 1)
TrueWinnerIndex := ValidIndices[RandomIndex]
set FallbackWinnerName = TempMapNames[TrueWinnerIndex]
set FallbackTeleporter = option{TempTeleporters[TrueWinnerIndex]}
WinningMapUI.SetText(TextForUI("It's a wild Summer Scramble! Random pick: {FallbackWinnerName}!"))
WinningMapUI.Show()
Print("Fallback winner: {FallbackWinnerName}")
if(Teleporter := FallbackTeleporter?):
Teleporter.Enable()
TeleportAllPlayersToDevice(Teleporter)
else:
WinningMapUI.SetText(TextForUI("Oh no! Map voting had a glitch!"))
WinningMapUI.Show()
Print("Summer Scramble: CRITICAL - No winner AND no fallback configured maps.")