Rank System

mail@pastecode.io avatar
unknown
plain_text
2 months ago
5.9 kB
39
Indexable
Never
using { /Fortnite.com/AI}
using { /Fortnite.com/Characters}
using { /Fortnite.com/Devices }
using { /Fortnite.com/Playspaces}
using { /Fortnite.com/UI}
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath}
using { /UnrealEngine.com/Temporary/UI}
using { /Verse.org/Colors}
using { /Verse.org/Random}
using { /Verse.org/Simulation}
using { /Verse.org/Simulation/Tags} 


spawner := class(tag){}

   
verse_device := class(creative_device):
    
    TargetCounterMessage <localizes>(Msg: string, Agent: agent): message = "{Agent}'s Kill Counter:  {Msg}"

    NextGoalMessage <localizes>(Msg: string): message = "Goal for next ranking:  {Msg}"
    
    #creates a map to track players coming and going
    var PlayerMap:[player]verse_device = map {}
    
    @editable
    MyTracker : tracker_device = tracker_device{}

    @editable
    MyHUD_Apprentice : hud_message_device = hud_message_device {}
    
    @editable
    MyHUD_Pro : hud_message_device = hud_message_device {}

      
           
    OnBegin<override>()<suspends>:void=
        SetSpawners()
        GetPlayspace().PlayerRemovedEvent().Subscribe(OnPlayerRemoveEvent)
        
    
    SetSpawners(): void=   
        Spawners:= GetCreativeObjectsWithTag(spawner{})
       
        for (Objects: Spawners):
            if (Spawner := player_spawner_device[Objects]):
                Spawner.SpawnedEvent.Subscribe(OnPlayerAdded)
    
    TargetCounter(Player: player, TextBlock: text_block, Agent: agent)<suspends>:void=
        loop:
            Sleep(0.1)
            if (AgentStats:= PlayerMap[Player]):
                TextBlock.SetText(TargetCounterMessage("{MyTracker.GetValue(Player)}", Agent))
                
    RankingMonitor(Player:player, TextBlock: text_block, Agent: agent)<suspends>: void=
        loop:
            Sleep(0.1)
            if(MyTracker.GetValue(Player) >= 5):
                if(PlayerUI := GetPlayerUI[Player]):
                    MyHUD_Apprentice.Show(Agent)
                    TextBlock.SetText(NextGoalMessage("10"))
                    break 
        loop: 
            Sleep(0.1)
            if(MyTracker.GetValue(Player) >= 10):
                if(PlayerUI := GetPlayerUI[Player]):
                    MyHUD_Pro.Show(Agent)
                    TextBlock.SetText(NextGoalMessage("15"))
                    break 
    
    # display initialization                
    OnPlayerAdded(NewPlayer: agent): void =
        if (PlayerX := player[NewPlayer]):
            if (PlayerExists:= PlayerMap[NewPlayer]):   #does nothing if player exists
                
            else:
                if(set PlayerMap[PlayerX] = verse_device{}):
                    if(PlayerUI := GetPlayerUI[PlayerX]):
                        
                        var TargetDisplay: text_block = text_block{DefaultTextColor :=NamedColors.Gold}
                       

                        if(MyTracker.GetValue(PlayerX) < 5):
                            MyOverlay1 : overlay = overlay:
                                Slots := array:
                                    overlay_slot:
                                        Widget := TargetDisplay
                                        HorizontalAlignment := horizontal_alignment.Center 
                                        VerticalAlignment := vertical_alignment.Top
                                        Padding := margin{Left:=0.0, Top:=50.0 , Right:=0.0 , Bottom:=0.0 }
                            PlayerUI.AddWidget(MyOverlay1)
                            

                        if(MyTracker.GetValue(PlayerX) >= 5):
                            MyHUD_Apprentice.Show(NewPlayer)
                            MyOverlay1 : overlay = overlay:
                                Slots := array:
                                    overlay_slot:
                                        Widget := TargetDisplay
                                        HorizontalAlignment := horizontal_alignment.Center 
                                        VerticalAlignment := vertical_alignment.Top
                                        Padding := margin{Left:=0.0, Top:=50.0 , Right:=0.0 , Bottom:=0.0 }
                            
                            PlayerUI.AddWidget(MyOverlay1)
                            if (MyTracker.GetValue(PlayerX) >= 10):
                                MyHUD_Pro.Show(NewPlayer)
                                

                        var GoalandRankDisplay: text_block = text_block{DefaultTextColor :=NamedColors.Gold}  

                        MyOverlay2 : overlay = overlay:
                            Slots := array:
                                overlay_slot:
                                    Widget := GoalandRankDisplay
                                    HorizontalAlignment := horizontal_alignment.Center 
                                    VerticalAlignment := vertical_alignment.Top
                                    Padding := margin{Left:=0.0, Top:=0.0 , Right:=0.0 , Bottom:=0.0 }
                        
                        PlayerUI.AddWidget(MyOverlay2)
                        
                        #starts async function to monitor kills
                        spawn{TargetCounter(PlayerX,TargetDisplay, NewPlayer)}
                        
                        #starts async function to monitor score for rankings
                        spawn{RankingMonitor(PlayerX, GoalandRankDisplay, NewPlayer)}

    #removes player from map upon leaving game.
    OnPlayerRemoveEvent(PlayerLeaving:player): void =
        if (ActualPlayer := PlayerMap[PlayerLeaving]):
            var TempPlayerMap:[player]verse_device = map{}
            for (Key-> Value: PlayerMap, Key <> PlayerLeaving):
                set TempPlayerMap = ConcatenateMaps(TempPlayerMap, map{Key=>Value})
            
            set PlayerMap = TempPlayerMap    
Leave a Comment