I'm writing a murder election system

I’m writing a murder selection system, but I’m confused because I think it only takes the first “Agent” instead of checking them all…

Please see if someone can help me…

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 }

SeleccionAsesino := class(creative_device):

    var PlayerMap : [player]SeleccionAsesino = map{}
    MakeAgentName<localizes> (Agent:agent):message= "{Agent}"
    ConvertirTexto<localizes> (:[]float):message= "{TemporalAleatorio}"

    var TemporalAleatorio : []float = array{}
    var TemporalAsesino : float = 0.0
    var Temporal : float = 0.0
    var MurderGanador  : int = -1
    var SheriffGanador : int = -1

    @editable var MinimoAleatorio : float = 0.0
    @editable var MaximoAleatorio : float = 100.0

    @editable  ItemGranterAsesino : item_granter_device = item_granter_device{}
    @editable  ItemGranterSheriff : item_granter_device = item_granter_device{}
    @editable  ItemGranterInocente : item_granter_device = item_granter_device{}

    @editable  TriggerActivador : trigger_device = trigger_device{}

    OnBegin< override>()<suspends>:void=
        Print("Carga el OnBegin a la espera del activador")
        TriggerActivador.TriggeredEvent.Subscribe(ComenzarVotacion)

    ComenzarVotacion(Agent : ?agent):void=
        Print("Comienza el calculo\nEmpezamos obteniendo los numeros aleatorios para cada jugador para murder")
        MurdeElegidor(Agent)
        SheriffElegidor(Agent)
                            
    
    SheriffElegidor(Agent : ?agent):void=
        AllPlayers := GetPlayspace().GetPlayers()
        for (EliminationGamePlayer : AllPlayers):
            if (FortCharacter := EliminationGamePlayer.GetFortCharacter[]):
                if(SheriffGanador = -1): #selecciono al ganador para el sheriff
                    Print("Seleccion del Sheriff")
    
                    set TemporalAleatorio += array:
                        temp : float = GetRandomFloat(MinimoAleatorio, MaximoAleatorio)  #obtengo un numero para cada Sheriff:

                    Sel_Sheriff(TemporalAleatorio)

                    if(SheriffGanador = MurderGanador):  #casteo que no vuelva a salir el murder  
                        Print("parece ser QUE SON IGUIALESSSSSSSSSSS")       
                        Sel_Sheriff(TemporalAleatorio)
                    
                    else if(SheriffGanador <> MurderGanador):                        
                        if(Player := AllPlayers[SheriffGanador]): #Selecciono al ganador para el sheriff y le otorgo lo que  seaaaaaaaaaa
                            #if (CastAgent := agent[Agent?]): #cASTEA EL AGENTE Y LO CONVIERTE EN ?AGENT
                                ItemGranterSheriff.GrantItem(Player)
                                Print("Llego hasta el if para darle las pistolas al sheriff")
                    if(SheriffGanador >= 0 and MurderGanador >= 0): 
                        Print("Selecion de inocentes")
                                    
    MurdeElegidor(Agent : ?agent):void=
        AllPlayers := GetPlayspace().GetPlayers()
        for (EliminationGamePlayer : AllPlayers):
            if (FortCharacter := EliminationGamePlayer.GetFortCharacter[]):
                
                if(MurderGanador = -1 ):   #Casteo si el murder ha sido ya seleccionado   
                    
                    set TemporalAleatorio += array:
                        temp : float = GetRandomFloat(MinimoAleatorio, MaximoAleatorio)  #obtengo un numero para cada murder:

                    Print("Numero generado: {temp} \nPara:") 
                    ObtenerNombres(Agent) 
                    Sel_Asesino(TemporalAleatorio) 
                    Print("{MurderGanador}")

                    if(Player := AllPlayers[MurderGanador]): #Selecciono al ganador para el murder
                        #if (CastAgent := agent[Agent?]): #cASTEA EL AGENTE Y LO CONVIERTE EN ?AGENT
                            ItemGranterAsesino.GrantItem(Player)   

    ObtenerNombres(Agent:?agent):void=
        if (CastAgent := agent[Agent?]): # Funcion para convertir Agent? en "Agent"
            Username : message = MakeAgentName(CastAgent)
            Print(Username)  
            
  
    Sel_Asesino(Float : []float): void =
        Print("Selecion del asesino dependiendo del los numeros")

        var PosicionMayor : int = 0
        var PosicionActual : int = 0
        set TemporalAsesino = 0.0
        set PosicionActual = 0
        set Temporal = 0.0
        
        Values := for (X : Float):
            Print("Paso por el for de asesino para comprobar cual tiene el numero mayor")
            Print("El valor de X cuando entro en el for:{X}")
            Print("El valor de TemporalAsesino cuando entro en el for:{TemporalAsesino}")
            
            

            if(X >= TemporalAsesino):       # Compruebo cual es el numero mas alto
                Print("Entro aqui en el if")
                Print("El valor de X cuando entro en if:{X}")
                Print("El valor de X cuando entro en if:{X}")
                set PosicionMayor = PosicionActual
                set TemporalAsesino = X
                set Temporal = TemporalAsesino
                Print("Temporal en Sel_Asesino: {Temporal}")
                Print("MurderGanador en Sel_Asesino: {MurderGanador}")
             
            Print("El valor de TemporalAsesino cuando ssalgo del IF:{TemporalAsesino}")
            PosicionActual + 1
            X + 1.0
            
        set MurderGanador = PosicionMayor   
        Print("MurderGanador en Sel_Asesino al final: {MurderGanador}")   
            
    Sel_Sheriff(Float : []float): void =
                Print("Selecion del SHERIFF dependiendo del los numeros")

        var PosicionMayor : int = 0
        var PosicionActual : int = 0
        set TemporalAsesino = 0.0
        set PosicionActual = 0
        set Temporal = 0.0
        
        Values := for (X : Float):
            Print("Paso por el for de SHERIFF para comprobar cual tiene el numero mayor")
            Print("El valor de X cuando entro en el for:{X}")
            Print("El valor de TemporalAsesino cuando entro en el for:{TemporalAsesino}")
            
            

            if(X >= TemporalAsesino):       # Compruebo cual es el numero mas alto
                Print("Entro aqui en el if")
                Print("El valor de X cuando entro en if:{X}")
                Print("El valor de X cuando entro en if:{X}")
                set PosicionMayor = PosicionActual
                set TemporalAsesino = X
                set Temporal = TemporalAsesino
                Print("Temporal en Sel_Asesino: {Temporal}")
                Print("SheriffGanador en Sel_Asesino: {SheriffGanador}")
             
            Print("El valor de TemporalAsesino cuando ssalgo del IF:{TemporalAsesino}")
            PosicionActual + 1
            X + 1.0
            
        set SheriffGanador = PosicionMayor   
        Print("SheriffGanador en Sel_Sheriff al final: {SheriffGanador}")  

            
            

        




Moved to the Verse forum, I’ll try to get someone to take a look.

@Fali_005 Can you give more details? What are you wanting to happen and what is it currently doing? I like to use Prints and playtest with a bunch of folks to figure out the behavior and debug.

1 Like

Thank you very much for your help, I solved the problem :slight_smile:
I could ask you a quick question since you mentioned “Prints”…
How do you see the prints with more players? On a board?

You can find more details here in troubleshooting your code: Modify and Run Your First Verse Program | Unreal Editor for Fortnite Documentation | Epic Developer Community. Set up a playtest with multiple people and you can print out the values you’re calculating and actions you’re doing to see what’s going on in the code!