• 🏆 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!

Spawn Items/Units randomly from a list of points.

Status
Not open for further replies.
Level 2
Joined
Oct 16, 2004
Messages
16
I'm trying to make an item retrieval quest that spawns the item when the quest is initiated, but I don't want it to have one set spawning point, nor do I want it to spawn anywhere on the entire map. How do I make it so it spawns in a region that is selected randomly from a list of three or four specific regions?

Thanks!
 
Last edited:
Level 14
Joined
Dec 9, 2006
Messages
1,091
I recomend you create an Integer Variable, let say "RandomItem"
Then, when the player starts the quest go.
"Set RandomItem = (Random integer number between 1 and 4)" The last number is how many regions you have.
After that create If/Then/Else Actions that look like:

If (RandomItem Equal to 1) then do (Item - Create QuestItem at (Random point in (Item Spawn Region 1))) else do (Do nothing)

If (RandomItem Equal to 2) then do (Item - Create QuestItem at (Random point in (Item Spawn Region 2))) else do (Do nothing)

If (RandomItem Equal to 3) then do (Item - Create QuestItem at (Random point in (Item Spawn Region 3))) else do (Do nothing)

If (RandomItem Equal to 4) then do (Item - Create QuestItem at (Random point in (Item Spawn Region 4))) else do (Do nothing)


Do that until you have it for all the regions, and you should be good.

~Asomath
 
Level 2
Joined
Oct 16, 2004
Messages
16
It didn't work. Every time I test it the item appears in region 1.

The only variation of the trigger is that instead of creating the item, I move it to the region. And that I set the variable at map initialization, not quest initialization.

Would changing either of those make a difference?

{Moderator (Merge) Edit}
Also, something interesting I just noticed is that the trigger is set to move the item instantly to the center of either region 1,2,3 or 4, but every time, it seems to have a slightly random variation in the region, not in the center.

I checked to see if I somehow crammed all the regions next to eachother, but that's not the case. :\

Do NOT double-post in less than 24 hours in the World Editor Help Zone (48 for all other forums). Use the Edit button at the bottom right of your post.
~Posts Merged
 
Last edited by a moderator:
Level 2
Joined
Oct 16, 2004
Messages
16
  • Events
  • Unit - A unit comes within 200.00 of Colonist (Female) 0086 <gen>
  • Conditions
  • Unit - A unit comes within 200.00 of Colonist (Female) 0086 <gen>
  • Actions
  • Set YtwigInteger = (Random integer number between 1 and 4)
  • Quest - Display to Player Group - Player 1 (Red) the Quest Discovered message: New Optional Quest ...
  • Quest - Create a Optional quest titled Needle in a Haystac... with the description After the death of ..., using icon path ReplaceableTextures\CommandButtons\BTNWand.blp
  • Set NeedleinaHaystackQuest = (Last created quest)
  • Special Effect - Destroy TalktoMeColonist[6]
  • Sound - Play QuestNew <gen>
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • YtwigInteger Equal to 4
    • Then - Actions
      • Item - Move Perfect "Y" Twig 0221 <gen> to (Center of Perfect Y Twig 4 <gen>)
    • Else - Actions
      • Do nothing
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • YtwigInteger Equal to 1
    • Then - Actions
      • Item - Move Perfect "Y" Twig 0221 <gen> to (Center of Perfect Y Twig 1 <gen>)
    • Else - Actions
      • Do nothing
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • YtwigInteger Equal to 2
    • Then - Actions
      • Item - Move Perfect "Y" Twig 0221 <gen> to (Center of Perfect Y Twig 2 <gen>)
    • Else - Actions
      • Do nothing
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • YtwigInteger Equal to 3
    • Then - Actions
      • Item - Move Perfect "Y" Twig 0221 <gen> to (Center of Perfect Y Twig 3 <gen>)
    • Else - Actions
      • Do nothing
  • Trigger - Turn off (This trigger)
I moved it all into the same trigger to make it easier to view.
 
Level 5
Joined
Sep 13, 2008
Messages
165
Another easier way would be to put the regions into a region array at start up

Set RandomSpawnRegion [1] = Spawnplace 1
Set RandomSpawnRegion [2] = Spawnplace 2
Set RandomSpawnRe...

then when it comes to making the item just go,

Spawn Item in RandomSpawnRegion [Random Integer between 1 and however many regions there are]
 
Level 14
Joined
Dec 9, 2006
Messages
1,091
it would be the same length. Instead of setting 1 variable, you would have to set the amount of regions. And instead of makibng a trigger for each region, you only have to randomize it to one. So, it would take the same amount of time.

~Asomath
 
Level 5
Joined
Sep 13, 2008
Messages
165
But if you had to reuse those regions for 50 different items, then all that is needed is just one Event, instead of IF/THEN/ELSE taking up room.

Anyway, BlackstarSirius can choose his preferred way, and he can change the [Unsolved] to [Solved]
 
Level 12
Joined
Mar 16, 2006
Messages
992
it would be the same length. Instead of setting 1 variable, you would have to set the amount of regions. And instead of makibng a trigger for each region, you only have to randomize it to one. So, it would take the same amount of time.

~Asomath

When you set regions to an array, and base the corresponding triggers off that array- the triggers become much easier to manage in the future for any future changes. As well as become much less cluttered.

Why scroll through 100 pages of IF = 1, IF = 2, IF = 3, when you can just use a For loop If check?
 
Status
Not open for further replies.
Top