• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Math - Random Integer not working

Status
Not open for further replies.
I have a map , which is here, and I have a trigger which detects if the unit "Random" is selected, so it will pick a random integer between 1 and 5, and will make the corresponding race. However, it always picks number four.

This is the trigger in JASS.
JASS:
function Trig_RacePicked_Func007C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTrainedUnit()) == 'h002' ) ) then
        return false
    endif
    return true
endfunction

function Trig_RacePicked_Func008C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTrainedUnit()) == 'h005' ) ) then
        return false
    endif
    return true
endfunction

function Trig_RacePicked_Func009C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTrainedUnit()) == 'h006' ) ) then
        return false
    endif
    return true
endfunction

function Trig_RacePicked_Func010C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTrainedUnit()) == 'h007' ) ) then
        return false
    endif
    return true
endfunction

function Trig_RacePicked_Func011C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTrainedUnit()) == 'h008' ) ) then
        return false
    endif
    return true
endfunction

function Trig_RacePicked_Func012Func004C takes nothing returns boolean
    if ( not ( udg_Roll5 == 1 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RacePicked_Func012Func005C takes nothing returns boolean
    if ( not ( udg_Roll5 == 2 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RacePicked_Func012Func006C takes nothing returns boolean
    if ( not ( udg_Roll5 == 3 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RacePicked_Func012Func007C takes nothing returns boolean
    if ( not ( udg_Roll5 == 4 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RacePicked_Func012Func008C takes nothing returns boolean
    if ( not ( udg_Roll5 == 5 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RacePicked_Func012C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTrainedUnit()) == 'h004' ) ) then
        return false
    endif
    return true
endfunction

function Trig_RacePicked_Actions takes nothing returns nothing
    call AdjustPlayerStateBJ( 100, Player(0), PLAYER_STATE_RESOURCE_GOLD )
    call PlaySoundBJ( gg_snd_HeroPicked )
    call TriggerSleepAction( 2 )
    call RemoveUnit( gg_unit_h003_0003 )
    call TriggerExecute( gg_trg_SpawnIni )
    call DisableTrigger( GetTriggeringTrigger() )
    if ( Trig_RacePicked_Func007C() ) then
        set udg_BuilderType = 1
        call AdjustPlayerStateBJ( 10, Player(0), PLAYER_STATE_RESOURCE_GOLD )
        set udg_Lives = ( udg_Lives + 25 )
        return
    else
    endif
    if ( Trig_RacePicked_Func008C() ) then
        set udg_BuilderType = 2
        return
    else
    endif
    if ( Trig_RacePicked_Func009C() ) then
        set udg_BuilderType = 3
        return
    else
    endif
    if ( Trig_RacePicked_Func010C() ) then
        set udg_BuilderType = 4
        return
    else
    endif
    if ( Trig_RacePicked_Func011C() ) then
        set udg_BuilderType = 5
        return
    else
    endif
    if ( Trig_RacePicked_Func012C() ) then
        call AdjustPlayerStateBJ( 10, Player(0), PLAYER_STATE_RESOURCE_GOLD )
        call RemoveUnit( GetTrainedUnit() )
        set udg_Roll5 = GetRandomInt(1, 5)
        if ( Trig_RacePicked_Func012Func004C() ) then
            set udg_Temp_Point = GetUnitLoc(gg_unit_h003_0003)
            call CreateNUnitsAtLoc( 1, 'h002', Player(0), udg_Temp_Point, bj_UNIT_FACING )
            set udg_BuilderType = 1
            call AdjustPlayerStateBJ( 10, Player(0), PLAYER_STATE_RESOURCE_GOLD )
            set udg_Lives = ( udg_Lives + 25 )
            call RemoveLocation (udg_Temp_Point)
            call DisplayTextToForce( GetPlayersAll(), ( ( "You have chosen " + GetUnitName(GetLastCreatedUnit()) ) + " as your race!" ) )
            return
        else
        endif
        if ( Trig_RacePicked_Func012Func005C() ) then
            set udg_Temp_Point = GetUnitLoc(gg_unit_h003_0003)
            call CreateNUnitsAtLoc( 1, 'h005', Player(0), udg_Temp_Point, bj_UNIT_FACING )
            set udg_BuilderType = 2
            call RemoveLocation (udg_Temp_Point)
            call DisplayTextToForce( GetPlayersAll(), ( ( "You have chosen " + GetUnitName(GetLastCreatedUnit()) ) + " as your race!" ) )
            return
        else
        endif
        if ( Trig_RacePicked_Func012Func006C() ) then
            set udg_Temp_Point = GetUnitLoc(gg_unit_h003_0003)
            call CreateNUnitsAtLoc( 1, 'h006', Player(0), udg_Temp_Point, bj_UNIT_FACING )
            set udg_BuilderType = 3
            call RemoveLocation (udg_Temp_Point)
            call DisplayTextToForce( GetPlayersAll(), ( ( "You have chosen " + GetUnitName(GetLastCreatedUnit()) ) + " as your race!" ) )
            return
        else
        endif
        if ( Trig_RacePicked_Func012Func007C() ) then
            set udg_Temp_Point = GetUnitLoc(gg_unit_h003_0003)
            call CreateNUnitsAtLoc( 1, 'h007', Player(0), udg_Temp_Point, bj_UNIT_FACING )
            set udg_BuilderType = 4
            call RemoveLocation (udg_Temp_Point)
            call DisplayTextToForce( GetPlayersAll(), ( ( "You have chosen " + GetUnitName(GetLastCreatedUnit()) ) + " as your race!" ) )
            return
        else
        endif
        if ( Trig_RacePicked_Func012Func008C() ) then
            set udg_Temp_Point = GetUnitLoc(gg_unit_h003_0003)
            call CreateNUnitsAtLoc( 1, 'h008', Player(0), udg_Temp_Point, bj_UNIT_FACING )
            set udg_BuilderType = 5
            call RemoveLocation (udg_Temp_Point)
            call DisplayTextToForce( GetPlayersAll(), ( ( "You have chosen " + GetUnitName(GetLastCreatedUnit()) ) + " as your race!" ) )
            return
        else
        endif
    else
        call DisplayTextToForce( GetPlayersAll(), ( ( "You have chosen " + GetUnitName(GetTrainedUnit()) ) + " as your race!" ) )
    endif
endfunction

//===========================================================================
function InitTrig_RacePicked takes nothing returns nothing
    set gg_trg_RacePicked = CreateTrigger(  )
    call TriggerRegisterUnitEvent( gg_trg_RacePicked, gg_unit_h003_0003, EVENT_UNIT_TRAIN_FINISH )
    call TriggerAddAction( gg_trg_RacePicked, function Trig_RacePicked_Actions )
endfunction


In a nutshell...

The random integer is not working
 
Status
Not open for further replies.
Top