• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] Repeat

Status
Not open for further replies.
Level 17
Joined
Nov 13, 2006
Messages
1,814
Hi all,

I need a trigger which repeats rolling until roll noumber that was not rolled yet. Is there any 'repeat - until' acction?

Repeat
R = Random (1,11);
if THeroes_check[R] == True then create unit (THeroes_check[R]) for player();
until (THeroes_check[R]);

gui or jass? aso u want do a loop?

in gui u can do periodic timer trigger with condition and disable or a timer what u can pause and destory if dont need

in jass u can make timer also, or if u dont want accurated thing then with trigger sleep
(in jass dont need ==true for boolean)
JASS:
local unit u
local player p = Player(u)
local real R = GetRandomReal(1,11)
//where u want create the units?
local real x 
local real y
loop
   //better if set random x/y in region coz dont laggy if u create more unit to same position
   exitwhen THeroes_check[R]
   set u = CreateUnit (p, 'h001', x , y, 0)
     call TriggerSleepAction(1)
set i = i + 1
endloop
set u = null
set p = null
endfunction
 
Last edited:
Level 14
Joined
Apr 20, 2009
Messages
1,543
gui or jass? aso u want do a loop?

in gui u can do periodic timer trigger with condition and disable or a timer what u can pause and destory if dont need

in jass u can make timer also, or if u dont want accurated thing then with trigger sleep
(in jass dont need ==true for boolean)
JASS:
local real R = GetRandomReal(1,11)
loop
   exitwhen THeroes_check[R]
   //do something
     call TriggerSleepAction(1)
set i = i + 1
endloop
endfunction

What is the purpose of this? set i = i + 1
it doesn't do anything, i is not even being used anywhere, nor is it created xD

Also, if THeroes_check[R] != true then this is an infinite loop... Wouldn't that cause a crash?
And I like to add that when using this THeroes_check[R] it ofcourse needs to be created locally, or when using a global variable at least use udg_
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,259
I need a trigger which repeats rolling until roll noumber that was not rolled yet.
The problem is such code is liable to cause a thread crash due to the random nature of rolls. It might get into a state that it never rolls a number not yet rolled if your luck is "bad".

Instead, use exclusions where once a number is rolled you exclude the number from future rolls allowing you to garuente that 1 roll will always give a different number. This sort of system is used for random hero selection. The most common way is to use an array to map a random integer in a range of 0 to X (where X is the number of possible elements minus the number of elements already rolled) to various pieces of data (such as numbers). This works for a reasnoable range and keeps its consistency by replacing the rolled element with the last element.
 
Level 9
Joined
Nov 19, 2011
Messages
516
Idea was good but nothing happend. Look at it and tell me what I've fucked up.
----------------------------------------------------------------------------------------------------------------------------------------------
@Dr Super Good
Function Random(x) is not exacly rolling. It just gives a noumber based on actual byte on CPU memory, so with endless try it will work for sure.
 

Attachments

  • AR.gif
    AR.gif
    132.5 KB · Views: 127
Last edited:
Level 17
Joined
Nov 13, 2006
Messages
1,814
Idea was good but nothing happend. Look at it and tell me what I've fucked up.
------------------------------------------------------------------------------------------

i have no clue since idk nothing about what u made there since it isnt english

create x unit to every user/playing player who allied to somebody and if enemy then create x unit? or x unit to every player od idk
 
Level 9
Joined
Nov 19, 2011
Messages
516
Diffrence is between regions.

That says:
Every 0.5 seconds of gametime (whats is english)
Do
R = Random (1,11)
If THeroes_check[R] = True then
c:=c+1;
If (player[c] is user and ingame) then
If player[c] is ally of player[1] then Create THeroes[R] at center of RedSpawn<gen>
else Create THeroes[R] at center of GreenSpawn<gen> <----There is diffrence
endif;
endif;
endif;
if c=12 then Turn Off (This triggger) endif;

Words that was NOT english:
Czas - (not needed but means "time")
Jednostka - (not needed but means "unit")
Warunek - (not needed but means "if")
Akcja - (not needed but means "Acction")
Wydarzenie - (not needed but means "Event")
Wyzwalacz - (not needed but means "Trigger")

----->You got icons and all IMPORTANT words are english at all.<-----

More or less its not createing unit even if whole table THeroes_check is TRUE.

Oh I forgot. Tak = True
 
Last edited:
Level 17
Joined
Nov 13, 2006
Messages
1,814
Diffrence is between regions.

That says:
Every 0.5 seconds of gametime (whats is english)
Do
R = Random (1,11)
If THeroes_check[R] = True then
c:=c+1;
If (player[c] is user and ingame) then
If player[c] is ally of player[1] then Create THeroes[R] at center of RedSpawn<gen>
else Create THeroes[R] at center of GreenSpawn<gen> <----There is diffrence
endif;
endif;
endif;
if c=12 then Turn Off (This triggger) endif;

Words that was NOT english:
Czas - (not needed but means "time")
Jednostka - (not needed but means "unit")
Warunek - (not needed but means "if")
Akcja - (not needed but means "Acction")
Wydarzenie - (not needed but means "Event")
Wyzwalacz - (not needed but means "Trigger")

----->You got icons and all IMPORTANT words are english at all.<-----

More or less its not createing unit even if whole table THeroes_check is TRUE.

Oh I forgot. Tak = True

THeroes was setted at map init? also where u give value to theroes array?

[u can tell exactly what is ur goal? i understand u want creat to red spot if player R is ally with player else to green but why u need the random for create to every player x hero?]
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
I need to random becouse I want to spawn random heroes, but do not double any of them. I'm giveing values on map init. Each THeroes have diffrent value. THeroes_check have same length as THeroes and deffoult value is True.

random or form every time 1 to every player?
(u can use group count, like count x unit type onwed by x player and if its higher then 0 then run again the trigger else create hero?)
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
1 Random hero for each player. It should work like -ar function for some other maps.

but for this why u need periodic trigger?

u can try this (also map attached)

this do a random unit to player who type "-ar" and remove the previous hero, the new hero cant be same than previous (but can be same than unit what was before previous, so 2 unit ago)

  • Map init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set HeroUnit[0] = Paladin
      • Set HeroUnit[1] = Archmage
      • Set HeroUnit[2] = Mountain King
      • Set HeroUnit[3] = Blood Mage
      • Set HeroUnit[4] = Sylvanas Windrunner
      • Set HeroUnit[5] = Arthas
      • Set HeroUnit[6] = Blademaster
      • Set HeroUnit[7] = Far Seer
      • Set HeroUnit[8] = Tauren Chieftain
      • Set HeroUnit[9] = Shadow Hunter
      • Set HeroUnit[10] = Chen Stormstout
      • Set HeroUnit[11] = Rexxar
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Player((Integer A))) controller) Equal to User
              • ((Player((Integer A))) slot status) Equal to Is playing
            • Then - Actions
              • -------- this add event only to that players who playing --------
              • Trigger - Add to Random hero <gen> the event (Player - (Player((Integer A))) types a chat message containing -ar as An exact match)
            • Else - Actions
JASS:
function Trig_Random_hero_Actions takes nothing returns nothing
local location loc 
local integer p = GetConvertedPlayerId(GetTriggerPlayer())
local integer u1 
local integer u2
local integer r = GetRandomInt(1, 11)

if ( GetUnitTypeId(udg_Hero) != null ) then
   set u1 = GetUnitTypeId(udg_Hero)
   set u2 = udg_HeroUnit[r]
      loop
        exitwhen u1!=u2
             set r = GetRandomInt(1, 11)
             set u2 = udg_HeroUnit[r]
      endloop
      call RemoveUnit(udg_Hero)
endif

if ( IsPlayerAlly(GetTriggerPlayer(), Player(0)) == true ) then
        set loc = GetRandomLocInRect(gg_rct_Red)
else
        set loc = GetRandomLocInRect(gg_rct_Green)
endif

call CreateNUnitsAtLoc( 1, udg_HeroUnit[r], GetTriggerPlayer(), loc, bj_UNIT_FACING )
set udg_Hero = GetLastCreatedUnit()
call RemoveLocation(loc)
set loc = null
endfunction

//===========================================================================
function InitTrig_Random_hero takes nothing returns nothing
    set gg_trg_Random_hero = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Random_hero, function Trig_Random_hero_Actions )
endfunction
 

Attachments

  • create hero.w3x
    17.7 KB · Views: 37
Level 14
Joined
Apr 20, 2009
Messages
1,543
but for this why u need periodic trigger?

u can try this (also map attached)

this do a random unit to player who type "-ar" and remove the previous hero, the new hero cant be same than previous (but can be same than unit what was before previous, so 2 unit ago)

  • Map init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set HeroUnit[0] = Paladin
      • Set HeroUnit[1] = Archmage
      • Set HeroUnit[2] = Mountain King
      • Set HeroUnit[3] = Blood Mage
      • Set HeroUnit[4] = Sylvanas Windrunner
      • Set HeroUnit[5] = Arthas
      • Set HeroUnit[6] = Blademaster
      • Set HeroUnit[7] = Far Seer
      • Set HeroUnit[8] = Tauren Chieftain
      • Set HeroUnit[9] = Shadow Hunter
      • Set HeroUnit[10] = Chen Stormstout
      • Set HeroUnit[11] = Rexxar
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Player((Integer A))) controller) Equal to User
              • ((Player((Integer A))) slot status) Equal to Is playing
            • Then - Actions
              • -------- this add event only to that players who playing --------
              • Trigger - Add to Random hero <gen> the event (Player - (Player((Integer A))) types a chat message containing -ar as An exact match)
            • Else - Actions
JASS:
function Trig_Random_hero_Actions takes nothing returns nothing
local location loc 
local integer p = GetConvertedPlayerId(GetTriggerPlayer())
local integer u1 
local integer u2
local integer r = GetRandomInt(1, 11)

if ( GetUnitTypeId(udg_Hero) != null ) then
   set u1 = GetUnitTypeId(udg_Hero)
   set u2 = udg_HeroUnit[r]
      loop
        exitwhen u1!=u2
             set r = GetRandomInt(1, 11)
             set u2 = udg_HeroUnit[r]
      endloop
      call RemoveUnit(udg_Hero)
endif

if ( IsPlayerAlly(GetTriggerPlayer(), Player(0)) == true ) then
        set loc = GetRandomLocInRect(gg_rct_Red)
else
        set loc = GetRandomLocInRect(gg_rct_Green)
endif

call CreateNUnitsAtLoc( 1, udg_HeroUnit[r], GetTriggerPlayer(), loc, bj_UNIT_FACING )
set udg_Hero = GetLastCreatedUnit()
call RemoveLocation(loc)
set loc = null
endfunction

//===========================================================================
function InitTrig_Random_hero takes nothing returns nothing
    set gg_trg_Random_hero = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Random_hero, function Trig_Random_hero_Actions )
endfunction

a lot of aweful BJ's there mate :(

try this:

JASS:
function Trig_Random_hero_Actions takes nothing returns nothing
local location loc 
local integer p = GetPlayerId(GetTriggerPlayer()) + 1
local integer u1 
local integer u2
local integer r = GetRandomInt(1, 11)

if ( GetUnitTypeId(udg_Hero) != null ) then
   set u1 = GetUnitTypeId(udg_Hero)
   set u2 = udg_HeroUnit[r]
      loop
        exitwhen u1!=u2
             set r = GetRandomInt(1, 11)
             set u2 = udg_HeroUnit[r]
      endloop
      call RemoveUnit(udg_Hero)
endif

if ( IsPlayerAlly(GetTriggerPlayer(), Player(0)) == true ) then
        set loc = Location(GetRandomReal(GetRectMinX(gg_rct_Red), GetRectMaxX(gg_rct_Red)), GetRandomReal(GetRectMinY(gg_rct_Red), GetRectMaxY(gg_rct_Red)))
else
        set loc = Location(GetRandomReal(GetRectMinX(gg_rct_Green), GetRectMaxX(gg_rct_Green)), GetRandomReal(GetRectMinY(gg_rct_Green), GetRectMaxY(gg_rct_Green)))
endif

call CreateNUnitsAtLoc( 1, udg_HeroUnit[r], GetTriggerPlayer(), loc, bj_UNIT_FACING )
set udg_Hero = bj_lastCreatedUnit
call RemoveLocation(loc)
set loc = null
endfunction

4 less function calls already ^.^
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
You said that 3rd hero can be the same as 1st hero. Thats bad. It's not looks nice when you can't double heroes by standard pick, but when ar you can. :/

and what happen if u already used random 11 times? since all hero once was picked :p
have different way just not that easy to make it.

u can do a interget array (but have limit with how much hero will work)
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
There is no repick or 2nd pick. Just one choice from begin til the end.

then what is the problem with that what i posted to u if dont have 2nd pick??? there already cant get 1st choose so its work well then if u dont have 3rd pick

really i got no clue what u want then....

u want make with random every player get different hero type if dont ahve repick?

so player 10 cant get same hero than player 1?

for that u dont need nothing complicated just this

JASS:
function Trig_Random_hero_Conditions takes nothing returns boolean
return udg_Hero[GetPlayerId(GetTriggerPlayer()) + 1] == null
endfunction

function Trig_Random_hero_Actions takes nothing returns nothing
    local boolean b = false
    local location loc
    local integer p = GetPlayerId(GetTriggerPlayer()) + 1
    local integer min = 0
    local integer max = 11
    local integer r = GetRandomInt(min, max)
    local integer f2 = 0
    local integer c
    local integer pos = 1
    local real array x
    local real array y
    set x[1] = GetRandomReal(GetRectMinX(gg_rct_Red), GetRectMaxX(gg_rct_Red))
    set x[2] = GetRandomReal(GetRectMinX(gg_rct_Green), GetRectMaxX(gg_rct_Green))
    set y[1] = GetRandomReal(GetRectMinY(gg_rct_Red), GetRectMaxY(gg_rct_Red))
    set y[2] = GetRandomReal(GetRectMinY(gg_rct_Green), GetRectMaxY(gg_rct_Green))
       
    loop
        exitwhen b
        set r = GetRandomInt(min, max)
        set c = 1
        loop
            exitwhen c > 12
            if udg_HeroUnit[r] == udg_HeroUnit[c] then
                set f2 = 1
            endif
            set c = c + 1
        endloop
        if f2 == 0 then
            set b = true
        endif
    endloop

    if ( IsPlayerAlly(GetTriggerPlayer(), Player(0)) == true ) then
        set pos = 2
    endif

    set udg_Hero = CreateUnit(GetTriggerPlayer(), udg_HeroUnit[r], x[pos], y[pos], 0)

endfunction

//===========================================================================
function InitTrig_Random_hero takes nothing returns nothing
    set gg_trg_Random_hero = CreateTrigger( )
    call TriggerAddCondition( gg_trg_Random_hero, Condition( function Trig_Random_hero_Conditions ) )
    call TriggerAddAction( gg_trg_Random_hero, function Trig_Random_hero_Actions )
endfunction
 
Last edited:
Level 14
Joined
Apr 20, 2009
Messages
1,543
then what is the problem with that what i posted to u if dont have 2nd pick??? there already cant get 1st choose so its work well then if u dont have 3rd pick

really i got no clue what u want then....

u want make with random every player get different hero type if dont ahve repick?

so player 10 cant get same hero than player 1?

for that u dont need nothing complicated just this

JASS:
function Trig_Random_hero_Conditions takes nothing returns boolean
return udg_Hero[GetPlayerId(GetTriggerPlayer()) + 1] == null
endfunction

function Trig_Random_hero_Actions takes nothing returns nothing
    local boolean b = false
    local location loc
    local integer p = GetPlayerId(GetTriggerPlayer()) + 1
    local integer min = 0
    local integer max = 11
    local integer r = GetRandomInt(min, max)
    local integer f2 = 0
    local integer c
    local integer pos = 1
    local real array x
    local real array y
    set x[1] = GetRandomReal(GetRectMinX(gg_rct_Red), GetRectMaxX(gg_rct_Red))
    set x[2] = GetRandomReal(GetRectMinX(gg_rct_Green), GetRectMaxX(gg_rct_Green))
    set y[1] = GetRandomReal(GetRectMinY(gg_rct_Red), GetRectMaxY(gg_rct_Red))
    set y[2] = GetRandomReal(GetRectMinY(gg_rct_Green), GetRectMaxY(gg_rct_Green))
       
    loop
        exitwhen b
        set r = GetRandomInt(min, max)
        set c = 1
        loop
            exitwhen c > 12
            if udg_HeroUnit[r] == udg_HeroUnit[c] then
                set f2 = 1
            endif
            set c = c + 1
        endloop
        if f2 == 0 then
            set b = true
        endif
    endloop

    if ( IsPlayerAlly(GetTriggerPlayer(), Player(0)) == true ) then
        set pos = 2
    endif

    set udg_Hero = CreateUnit(GetTriggerPlayer(), udg_HeroUnit[r], x[pos], y[pos], 0)

endfunction

//===========================================================================
function InitTrig_Random_hero takes nothing returns nothing
    set gg_trg_Random_hero = CreateTrigger( )
    call TriggerAddCondition( gg_trg_Random_hero, Condition( function Trig_Random_hero_Conditions ) )
    call TriggerAddAction( gg_trg_Random_hero, function Trig_Random_hero_Actions )
endfunction

Now that is optimized :thumbs_up:
b.t.w. loc is not being used anymore ^.o
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
error: requested end of line
error: requested end of line
error: wrong type
error: no name
error: no name of variable
...

whats happend?

u check the map.

anyway error is coz u dont made the variables like Hero - unit array variable
and HeroUnit - unit type array

error coz this variable array missing from ur map :)
 

Attachments

  • create hero.w3x
    18.5 KB · Views: 42
Level 17
Joined
Nov 13, 2006
Messages
1,814
set x[1] = GetRandomReal(GetRectMinX(gg_rct_Red), GetRectMaxX(gg_rct_Red))

"expected name"

whats wrong here? (I got both hero and herount vars)

oh that is the region names, Red and Green :p

u can write there any region like this

  • Untitled Trigger 004
    • Events
    • Conditions
    • Actions
      • Unit - Create 1 Footman for Player 1 (Red) at (Random point in Race2 <gen>) facing Default building facing degrees
      • Unit - Create 1 Footman for Player 1 (Red) at (Random point in Race3 <gen>) facing Default building facing degrees
then convert to custom text

JASS:
function Trig_Untitled_Trigger_004_Actions takes nothing returns nothing
    call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), GetRandomLocInRect(gg_rct_Race2), bj_UNIT_FACING )
    call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), GetRandomLocInRect(gg_rct_Race3), bj_UNIT_FACING )
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_004 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_004 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Untitled_Trigger_004, function Trig_Untitled_Trigger_004_Actions )
endfunction

and copy this bolded part because that is ur region and replace with my red and green, if u want i can do for u
GetRandomLocInRect(gg_rct_Race2)
GetRandomLocInRect(gg_rct_Race3)
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
set gg_trg_Random_hero = CreateTrigger( )

same error
What is this?
Should I make var with trigger type? (is there such var?)

u readed what i wrote? before ur post? :p


this that case ur triggername not Random_hero and it is referenced in trigger to that

JASS:
function InitTrig_Random_hero takes nothing returns nothing
    set gg_trg_Random_hero = CreateTrigger( )
    call TriggerAddCondition( gg_trg_Random_hero, Condition( function Trig_Random_hero_Conditions ) )
    call TriggerAddAction( gg_trg_Random_hero, function Trig_Random_hero_Actions )
endfunction

=>


JASS:
function InitTrig_Random_hero takes nothing returns nothing
    set gg_trg_*Your trigger name* = CreateTrigger( )
    call TriggerAddCondition( gg_trg_*Your trigger name*, Condition( function Trig_Random_hero_Conditions ) )
    call TriggerAddAction( gg_trg_*Your trigger name*, function Trig_Random_hero_Actions )
endfunction

JASS:
    set x[1] = GetRandomReal(GetRectMinX(gg_rct_Red), GetRectMaxX(gg_rct_Red))
    set x[2] = GetRandomReal(GetRectMinX(gg_rct_Green), GetRectMaxX(gg_rct_Green))
    set y[1] = GetRandomReal(GetRectMinY(gg_rct_Red), GetRectMaxY(gg_rct_Red))
    set y[2] = GetRandomReal(GetRectMinY(gg_rct_Green), GetRectMaxY(gg_rct_Green))

=>

JASS:
    set x[1] = GetRandomReal(GetRectMinX(gg_rct_*Your region 1 name*), GetRectMaxX(gg_rct_*Your region 1 name*))
    set x[2] = GetRandomReal(GetRectMinX(gg_rct_*Your region 2 name*), GetRectMaxX(gg_rct_*Your region 2 name*))
    set y[1] = GetRandomReal(GetRectMinY(gg_rct_*Your region 1 name*), GetRectMaxY(gg_rct_*Your region 1 name*))
    set y[2] = GetRandomReal(GetRectMinY(gg_rct_*Your region 2 name*), GetRectMaxY(gg_rct_*Your region 2 name*))

example if ur region name is Region1 then instead gg_rct_*Your region 1 name* u write gg_rct_Region1

same with trigger name where is trg

(rct=rect=region/trg=trigger)

u dont have any error if u make like in map what i made for u and attached... in post above, that dont made error :p
 
Level 9
Joined
Nov 19, 2011
Messages
516
function InitTrig_Random_hero takes nothing returns nothing

there still something is missed (name request) coz my trigger mane is alredy "Random hero"

and there:

function InitTrig_Random_hero takes nothing returns nothing
set gg_trg_Random_hero = CreateTrigger( )
call TriggerAddCondition( gg_trg_Random_hero, Condition( function Trig_Random_hero_Conditions ) )
call TriggerAddAction( gg_trg_Random_hero, function Trig_Random_hero_Actions )
endfunction

it says "expected 'endif'" :goblin_wtf:
there is no if... :'(

Now it works well. I wanted to give you rep but it says that I heve not enought... :/
 
Last edited:
Status
Not open for further replies.
Top