Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using { /Fortnite.com/Devices }
- using { /Verse.org/Simulation }
- using { /UnrealEngine.com/Temporary/Diagnostics }
- ################################# SORTING ALGORITHM ###################################################
- MergeSort<public>(Array:[]t, Compare(L:t, R:t)<decides><transacts>:t where t:type)<transacts>:[]t=
- Length:int = Array.Length
- if:
- Length > 1
- Mid:int = Floor(Length / 2)
- Left:[]t = Array.Slice[0, Mid]
- Right:[]t = Array.Slice[Mid]
- then:
- LeftSorted:[]t = MergeSort(Left, Compare)
- RightSorted:[]t = MergeSort(Right, Compare)
- Merge(LeftSorted, RightSorted, Compare)
- else:
- Array
- Merge(Left:[]t, Right:[]t, Compare(L:t, R:t)<decides><transacts>:t where t:type)<transacts>:[]t=
- var LeftIndex:int = 0
- var RightIndex:int = 0
- var MergedArray:[]t = array{}
- loop:
- if (LeftElement := Left[LeftIndex], RightElement := Right[RightIndex]):
- if (Compare[LeftElement, RightElement]):
- set MergedArray += array{LeftElement}
- set LeftIndex += 1
- else:
- set MergedArray += array{RightElement}
- set RightIndex += 1
- else:
- if (LeftIndex >= Left.Length):
- option{set MergedArray += Right.Slice[RightIndex]}
- else:
- option{set MergedArray += Left.Slice[LeftIndex]}
- break
- MergedArray
- ################################### VERSE DEVICE #############################################################################################
- player_leaderboards_example := class(creative_device):
- @editable
- PlayerReferences:[]player_reference_device = array{}
- @editable
- Leaderboards:[]billboard_device = array{}
- @editable
- RaceManager:race_manager_device = race_manager_device{}
- @editable
- PlacementRequiredForWin:int = 1
- @editable
- PointsPerPlace:[]int = array{5, 3, 1}
- var CurrentFinishOrder:int = 0
- OnBegin<override>()<suspends>:void=
- Players := GetPlayspace().GetPlayers()
- InitializeAllPlayerStats(Players)
- UpdateStatsBillboards(Players, Leaderboards)
- UpdatePlayerReferences(Players, PlayerReferences)
- for:
- Player:Players
- do:
- spawn{WaitForPlayerToFinishRace(Player)}
- WaitForPlayerToFinishRace(Player:agent)<suspends>:void=
- race:
- loop:
- FinishingPlayer := RaceManager.RaceCompletedEvent.Await()
- if:
- FinishingPlayer = Player
- then:
- RecordPlayerFinish(Player)
- break
- loop:
- LeavingPlayer := GetPlayspace().PlayerRemovedEvent().Await()
- if:
- LeavingPlayer = Player
- then:
- break
- RecordPlayerFinish(Player:agent):void=
- PlayerFinishOrder:int = CurrentFinishOrder
- set CurrentFinishOrder += 1
- if:
- PointsToAward := PointsPerPlace[PlayerFinishOrder]
- then:
- AddPoints(Player, PointsToAward)
- if:
- PlayerFinishOrder < PlacementRequiredForWin
- then:
- AddWin(Player, 1)
- ################################################# HANDLES THE PLAYER STATS AND DATA #################################################################
- GetPlayerStats<public>(Agent:agent)<decides><transacts>:player_stats_table=
- var PlayerStats:player_stats_table = player_stats_table{}
- if:
- Player := player[Agent]
- PlayerStatsTable := PlayerStatsMap[Player]
- set PlayerStats = MakePlayerStatsTable(PlayerStatsTable)
- PlayerStats
- InitializeAllPlayerStats<public>(Players:[]player):void =
- for (Player : Players):
- InitializePlayerStat(Player)
- InitializePlayerStat<public>(Player:player):void=
- if:
- not PlayerStatsMap[Player]
- set PlayerStatsMap[Player] = player_stats_table{}
- else:
- Print("Unable to initialize player stats")
- AddPoints<public>(Agent:agent, NewPoints:int):void=
- if:
- Player := player[Agent]
- PlayerStatsTable := PlayerStatsMap[Player]
- CurrentPoints := PlayerStatsTable.Points
- set PlayerStatsMap[Player] = player_stats_table:
- MakePlayerStatsTable<constructor>(PlayerStatsTable)
- Points := CurrentPoints + NewPoints
- else:
- Print("Unable to record player points")
- AddWin<public>(Agent:agent, NewWins:int):void=
- if:
- Player := player[Agent]
- PlayerStatsTable := PlayerStatsMap[Player]
- CurrentWins := PlayerStatsTable.Wins
- set PlayerStatsMap[Player] = player_stats_table:
- MakePlayerStatsTable<constructor>(PlayerStatsTable)
- Wins := CurrentWins + NewWins
- else:
- Print("Unable to record player Wins")
- ######################################## HANDLES UPDATES AND DATA DISPLAY ########################################################################################
- StatsMessage<localizes>(CurrentPlayer:message, Points:message, Wins:message):message=
- "{CurrentPlayer}:\n{Points}\n{Wins}"
- PlayerText<localizes>(CurrentPlayer:agent):message = "Player {CurrentPlayer}"
- PointsText<localizes>(Points:int):message = "Total Points {Points}"
- WinsText<localizes>(Wins:int):message = "{Wins} Total Wins"
- UpdateStatsBillboard<public>(Player:agent, StatsBillboard:billboard_device):void=
- if:
- CurrentPlayerStats := GetPlayerStats[Player]
- then:
- PlayerStatsText := StatsMessage(
- PlayerText(Player),
- PointsText(CurrentPlayerStats.Points),
- WinsText(CurrentPlayerStats.Wins))
- StatsBillboard.SetText(PlayerStatsText)
- UpdateStatsBillboards<public>(Players:[]agent, StatsBillboards:[]billboard_device):void=
- var PlayerAndStatsArray:[]player_and_stats =
- for:
- Agent:Players
- Player := player[Agent]
- PlayerStats := GetPlayerStats[Player]
- do:
- player_and_stats:
- Player := Player
- StatsTable := PlayerStats
- SortedPlayersAndStats := MergeSort(PlayerAndStatsArray ,MorePointsComparison)
- for:
- PlayerIndex -> PlayerAndStats : SortedPlayersAndStats
- StatsBillboard := StatsBillboards[PlayerIndex]
- do:
- UpdateStatsBillboard(PlayerAndStats.Player, StatsBillboard)
- UpdatePlayerReferences<public>(Players:[]player, PlayerReferences:[]player_reference_device):void=
- var PlayerAndStatsArray:[]player_and_stats =
- for:
- Agent:Players
- Player := player[Agent]
- PlayerStats := GetPlayerStats[Player]
- do:
- player_and_stats:
- Player := Player
- StatsTable := PlayerStats
- SortedPlayersAndStats := MergeSort(PlayerAndStatsArray,MorePointsComparison)
- for:
- PlayerIndex -> PlayerAndStats : SortedPlayersAndStats
- PlayerReference := PlayerReferences[PlayerIndex]
- do:
- PlayerReference.Register(PlayerAndStats.Player)
- ################################################### STATISTICS DATA TABLE ###################################################################
- player_and_stats<public> := struct:
- Player<public>:player
- StatsTable<public>:player_stats_table
- player_stats_table<public>:= class<final><persistable>:
- Version<public>:int = 0
- Points<public>:int = 0
- Wins<public>:int = 0
- MorePointsComparison<public>(Left:player_and_stats, Right:player_and_stats)<decides><transacts>:player_and_stats=
- Left.StatsTable.Points > Right.StatsTable.Points
- Left
- LessPointsComparison<public>(Left:player_and_stats, Right:player_and_stats)<decides><transacts>:player_and_stats=
- Left.StatsTable.Points < Right.StatsTable.Points
- Left
- MoreWinsComparison<public>(Left:player_and_stats, Right:player_and_stats)<decides><transacts>:player_and_stats=
- Left.StatsTable.Points > Right.StatsTable.Points
- Left
- LessWinsComparison<public>(Left:player_and_stats, Right:player_and_stats)<decides><transacts>:player_and_stats=
- Left.StatsTable.Points < Right.StatsTable.Points
- Left
- SlowerLapTimeComparison(Left:player_and_stats, Right:player_and_stats)<decides><transacts>:player_and_stats=
- Left.StatsTable.Points > Right.StatsTable.Points
- Left
- FasterLapTimeComparison(Left:player_and_stats, Right:player_and_stats)<decides><transacts>:player_and_stats=
- Left.StatsTable.Points < Right.StatsTable.Points
- Left
- MakePlayerStatsTable<constructor>(OldTable:player_stats_table)<transacts> := player_stats_table:
- Version := OldTable.Version
- Points := OldTable.Points
- Wins := OldTable.Wins
- var PlayerStatsMap:weak_map(player, player_stats_table) = map{}
Advertisement
Add Comment
Please, Sign In to add comment