afisakov
You can change this now in User CP.
- Reaction score
- 37
I am working on a trigger that picks a random unit to train, and I need it to not be the same as the last one trained.
the full trigger action
the part that SHOULD solve my problem
note: Trig_Random_Actions()=name of this trigger
What it should do is rerun the trigger, and thus re-random the integer, any time the random integer matches the previous successful result, and that "return" will stop the rest of the trigger from running.
I did not just re-random the integer because then there is a chance it will give same result again and I would be stuck with it.
1) Will this work in guaranteeing second random is different from first
2) are here any problems with this approach I am not seeing (potential glitches, leaks etc.) or just a more elegant/efficient way of doing this?
Thank you in advance for your assistance
the full trigger action
Code:
function Trig_Random_Actions takes nothing returns nothing
local integer Random
local integer i = 1
local integer iEnd = 10
local group TempGroup
set Random = GetRandomInt(1,10)
if Random == udg_prevc then
call Trig_Random_Actions()
return
endif
set TempGroup = GetUnitsOfPlayerAndTypeId(GetTriggerPlayer(), 'hhou')
if (CountUnitsInGroup(TempGroup) == 1 ) then
call IssueTrainOrderByIdBJ( GroupPickRandomUnit(TempGroup), udg_Governors[Random] )
call AdjustPlayerStateBJ( (60/udg_Player_Count) , GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD )
endif
call DestroyGroup( TempGroup )
set TempGroup = null
set udg_prevc=Random
endfunction
note: Trig_Random_Actions()=name of this trigger
Code:
if Random == udg_prevc then
call Trig_Random_Actions()
return
endif
I did not just re-random the integer because then there is a chance it will give same result again and I would be stuck with it.
1) Will this work in guaranteeing second random is different from first
2) are here any problems with this approach I am not seeing (potential glitches, leaks etc.) or just a more elegant/efficient way of doing this?
Thank you in advance for your assistance
Last edited by a moderator: