• 🏆 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] Chance to spawn in region!

Status
Not open for further replies.
Level 5
Joined
Jul 17, 2010
Messages
140
Heey!
I´m making a trigger that at the start of the game there is a chance to spawn different chest at different regions, but it only spawns 1 of the regions!

This is the trigger for the first spawn, have the same trigger with the other spawn just a different region.


  • Spawn Chest 1
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Spawn 1 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 5) Equal to 1
        • Then - Actions
          • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 1 <gen>) facing ((Center of Chest Spawn 1 <gen>) offset by 256.00 towards 288.90 degrees)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Random integer number between 1 and 5) Equal to 2
            • Then - Actions
              • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 1 <gen>) facing ((Center of Chest Spawn 1 <gen>) offset by 256.00 towards 288.90 degrees)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Random integer number between 1 and 5) Equal to 3
                • Then - Actions
                  • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 1 <gen>) facing ((Center of Chest Spawn 1 <gen>) offset by 256.00 towards 288.90 degrees)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Random integer number between 1 and 5) Equal to 4
                    • Then - Actions
                      • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 1 <gen>) facing ((Center of Chest Spawn 1 <gen>) offset by 256.00 towards 288.90 degrees)
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Random integer number between 1 and 5) Equal to 5
                        • Then - Actions
                          • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 2 <gen>) facing ((Center of Chest Spawn 2 <gen>) offset by 0.00 towards 132.39 degrees)
                        • Else - Actions

Thanks in advance!
 
Last edited:
Level 7
Joined
Mar 10, 2013
Messages
366
Save the random number into a variable and test the variable instead. The way you're using it creates a new random number everytime.
 
Level 5
Joined
Jul 17, 2010
Messages
140
Save the random number into a variable and test the variable instead. The way you're using it creates a new random number everytime.
Save the random number into a variable and test the variable instead. The way you're using it creates a new random number everytime.
'

Like this?

  • Spawn Chest 1
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Random_Number = (Random integer number between 0 and 5)
      • -------- Spawn 1 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Random_Number Equal to 1
        • Then - Actions
          • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 1 <gen>) facing ((Center of Chest Spawn 1 <gen>) offset by 256.00 towards 288.90 degrees)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Random_Number Equal to 2
            • Then - Actions
              • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 1 <gen>) facing ((Center of Chest Spawn 1 <gen>) offset by 256.00 towards 288.90 degrees)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Random_Number Equal to 3
                • Then - Actions
                  • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 1 <gen>) facing ((Center of Chest Spawn 1 <gen>) offset by 256.00 towards 288.90 degrees)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Random_Number Equal to 4
                    • Then - Actions
                      • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 1 <gen>) facing ((Center of Chest Spawn 1 <gen>) offset by 256.00 towards 288.90 degrees)
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Random_Number Equal to 5
                        • Then - Actions
                          • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 2 <gen>) facing ((Center of Chest Spawn 2 <gen>) offset by 0.00 towards 132.39 degrees)
                        • Else - Actions
 
Level 7
Joined
Mar 10, 2013
Messages
366
'

Like this?

  • Spawn Chest 1
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Random_Number = (Random integer number between 0 and 5)
      • -------- Spawn 1 --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Random_Number Equal to 1
        • Then - Actions
          • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 1 <gen>) facing ((Center of Chest Spawn 1 <gen>) offset by 256.00 towards 288.90 degrees)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Random_Number Equal to 2
            • Then - Actions
              • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 1 <gen>) facing ((Center of Chest Spawn 1 <gen>) offset by 256.00 towards 288.90 degrees)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Random_Number Equal to 3
                • Then - Actions
                  • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 1 <gen>) facing ((Center of Chest Spawn 1 <gen>) offset by 256.00 towards 288.90 degrees)
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Random_Number Equal to 4
                    • Then - Actions
                      • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 1 <gen>) facing ((Center of Chest Spawn 1 <gen>) offset by 256.00 towards 288.90 degrees)
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Random_Number Equal to 5
                        • Then - Actions
                          • Unit - Create 1 Chest Glove for Neutral Hostile at (Center of Chest Spawn 2 <gen>) facing ((Center of Chest Spawn 2 <gen>) offset by 0.00 towards 132.39 degrees)
                        • Else - Actions
Yes, but it should be between 1 and 5 (at least if you cant to be sure it will always spawn)
 
Level 8
Joined
Jan 28, 2016
Messages
486
Are you trying to spawn a random item in a random region? If so, you would need to store the item types and regions into arrays at map init. At the moment, you're creating the same type of item in the same region in each If-Then-Else.
 
I saw this problem and I immediately thought, "U want, sum structs?"

Anyway,
It seems that you can just use an array variable, specifically a point array (location in JASS)
Let's call it <some_var>.

We could also have an optional variable for typecasting: (It should be an array variable)
Let's call it <other_var>.

  • Custom Script: local location array udg_<other_var>
  • Set <other_var>[1] = (Center of Chest Spawn 1)
  • Set <other_var>[2] = <other_var>[1]
  • Set <other_var>[3] = <other_var>[2]
  • Set <other_var>[4] = <other_var>[3]
  • Set <some_var>[1] = <other_var>[1] offset by 256.00 towards 288.90 degrees.
  • Set <some_var>[2] = <other_var>[2] offset by 256.00 towards 288.90 degrees.
  • Set <some_var>[3] = <other_var>[3] offset by 256.00 towards 288.90 degrees.
  • Set <some_var>[4] = <other_var>[4] offset by 256.00 towards 288.90 degrees.
  • Set <other_var>[5] = (Center of Chest Spawn 2)
  • Set <some_var>[5] = <other_var> offset by 256.00 towards 288.90 degrees.
  • Set Random_Number = (Random integer number between 1 and 5)
  • Unit - Create 1 Chest Glove for Neutral Hostile at <other_var>[Random_Number] facing <some_var>[Random_Number]
  • For (Integer A) from 1 to 5, do (Actions)
    • Custom Script: call RemoveLocation(udg_<some_var>[1])
    • Set <some_var>[(Integer A)] = no point
  • Custom Script: call RemoveLocation(udg_<other_var>[1])
  • Custom Script: call RemoveLocation(udg_<other_var>[5])
  • For (Integer A) from 1 to 5, do (Actions)
    • Set <other_var>[(Integer A)] = no point
 
Level 5
Joined
Jul 17, 2010
Messages
140
Are you trying to spawn a random item in a random region? If so, you would need to store the item types and regions into arrays at map init. At the moment, you're creating the same type of item in the same region in each If-Then-Else.
I´m trying to spawn a mob.

There will be a % chance if the mob spawn at the region or not, and i need it to do with multiple regions.
 
Level 7
Joined
Mar 10, 2013
Messages
366
What I've suggested didn't worked?

Are you sure it's the 'same random numbers' is unchecked?
 
Level 8
Joined
Jan 28, 2016
Messages
486
You could do something like the trigger I've posted below, every X seconds.

  • Chest
    • Events
    • Conditions
    • Actions
      • -------- --- --------
      • -------- Set up your unit types --------
      • Set ChestType[1] = Peasant 1
      • Set ChestType[2] = Peasant 2
      • Set ChestType[3] = Peasant 3
      • Set ChestType[4] = Peasant 4
      • Set ChestType[5] = Peasant 5
      • -------- --- --------
      • -------- Set up your regions --------
      • Set ChestRegion[1] = Spawn Area 1 <gen>
      • Set ChestRegion[2] = Spawn Area 2 <gen>
      • Set ChestRegion[3] = Spawn Area 3 <gen>
      • Set ChestRegion[4] = Spawn Area 4 <gen>
      • Set ChestRegion[5] = Spawn Area 5 <gen>
      • -------- --- --------
      • -------- Pick 2 independent, random integers --------
      • Set RandomIntegerType = (Random integer number between 1 and 5)
      • Set RandomIntegerRegion = (Random integer number between 1 and 5)
      • -------- --- --------
      • -------- Run a loop to select which region to spawn --------
      • For each (Integer TempLoopRegion) from 1 to 5, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomIntegerRegion Equal to TempLoopRegion
            • Then - Actions
              • -------- --- --------
              • -------- After determining a region, save it to a variable and run another loop to select the unit type --------
              • Set TempRegion = ChestRegion[TempLoopRegion]
              • For each (Integer TempLoopType) from 1 to 5, do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • RandomIntegerType Equal to TempLoopType
                    • Then - Actions
                      • -------- --- --------
                      • -------- After determining a unit type, create it and take care of the location leaks --------
                      • Set TempPoint1 = (Center of TempRegion)
                      • Set TempPoint2 = (TempPoint1 offset by 256.00 towards 288.90 degrees)
                      • Unit - Create 1 ChestType[TempLoopType] for Neutral Hostile at TempPoint1 facing TempPoint2
                      • Custom script: call RemoveLocation( udg_TempPoint1 )
                      • Custom script: call RemoveLocation( udg_TempPoint2 )
                    • Else - Actions
            • Else - Actions
 
Status
Not open for further replies.
Top