So for my custom map, I need buildings to spawn at four locations. I need 1 building to spawn at each location every 180 seconds. Each building spawns in a location that blocks a path.
I have successfully made it so that a building does spawn at one of these four regions. The problem is that the building needs to spawn at a DIFFERENT location each time (when they spawn at the same location they just overlap). I can make a statement that if the chosen region has a building already, don't spawn the building, but I can't figure out how to make the event keep redoing a random selection till it chooses a region without the building.
Help is appreciated, if you want to see my work i'm gonna put it up after i'm done with alpha, so stay tuned in this thread.
the attached file is just the part I can't get to work btw. PM me if you want to see the full map.
Each 180 sec, you make an rand 4. If it's one, it create your building at the first location if the booleen "alreadybuild1" is on false. And you turn your booleen to true. If your booleen is on true, you excecute instantly your trigger. If it's not one, you make a rand 3, if it's one it create your building at the second location. If the booleen "alreadybuild2" is on false. And you turn your booleen on true. If your booleen is on true, you execute your trigger. If it was not 3, you make a random 2...
Etc... If the rand choose a bad location (already build) it will restart until a good one is choosen. And the first action of your trigger must be:
If
Alrdeadybuild1 = true
Alrdeadybuild2 = true
Alrdeadybuild3 = true
Alrdeadybuild4 = true
Then
Turn off this trigger
Stop all instances of this trigger
Else
The rest of your trigger.
This action wil stop the trigger once all your building are done (but only 180 sec after, so you'll have one more iteration of your trigger)
THIS IS NOT THE BEST SOLUTION (by far), if you search you can easily find something more efficient.
I'll try this and let you know how it goes, even if I don't end up doing it this way, it'll help me learn as im kind of new with this stuff but I think I understand how the suggestion would work.
btw I've searched for such a long time and found nothing :(
i more or less did it for you :D ,
Note: i didnt test it so i may have made a mistake somewhere, but other then that it should work
this trigger
Events
Timer - Every 5.0 seconds of Game Time
Local Variables
Random int = 0 <Integer>
Conditions
Actions
Variable - Set Random int = (Random integer between 1 and 4)
General - Switch (Actions) depending on Random int
Cases
General - If (1)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
alreadybuilt1 == false
Then
Unit - Create 1 Supply Depot for player 0 at (Center of Region 005) using default facing (Ignore Placement)
Variable - Set alreadybuilt1 = true
Else
Trigger - Run this trigger (Check Conditions, Don't Wait until it finishes)
General - If (2)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
alreadybuilt2 == false
Then
Unit - Create 1 Supply Depot for player 0 at (Center of Region 006) using default facing (Ignore Placement)
Variable - Set alreadybuilt2 = true
Else
Trigger - Run this trigger (Check Conditions, Don't Wait until it finishes)
General - If (3)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
alreadybuilt3 == false
Then
Variable - Set alreadybuilt3 = true
Unit - Create 1 Supply Depot for player 0 at (Center of Region 007) using default facing (Ignore Placement)
Else
Trigger - Run this trigger (Check Conditions, Don't Wait until it finishes)
General - If (4)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
alreadybuilt4 == false
Then
Unit - Create 1 Supply Depot for player 0 at (Center of Region 008) using default facing (Ignore Placement)
Variable - Set alreadybuilt4 = true
Else
Trigger - Run this trigger (Check Conditions, Don't Wait until it finishes)
Default
General - If (Conditions) then do (Actions) else do (Actions)
If
alreadybuilt1 == true
alreadybuilt2 == true
alreadybuilt3 == true
alreadybuilt4 == true
Then
Trigger - Turn (Current trigger) Off
Else
Oh and just a tip after looking at your attachment, i suggest you use "switch" or "in then else multiple" instead of a ton "if then else" just makes things a beat more neater and easier to look at
@AnyILL
i think the way you said it is more or less the best way to do it, maybe it could've been done through custom actions but that wouldn't have made that big of a difference
that would work except for that you would also need an array for the points, because what that trigger would do is create 4 buildings at random points at a random of 5 from a single points.
so instead of setting a local point variable to a random points around another point or region, he could create a global points array, and then use the variable A to discriminate between them
so the create unit part would look like this
Unit - Create 1 Supply Depot for player 0 at Position of building[A] using default facing (Ignore Placement)
ow wait I read the question wrong sorry. Thought a building needed to spawn at a random location of 4 regions every time the trigger was run your trigger is better.
i more or less did it for you :D ,
Note: i didnt test it so i may have made a mistake somewhere, but other then that it should work
@AnyILL
i think the way you said it is more or less the best way to do it, maybe it could've been done through custom actions but that wouldn't have made that big of a difference
trying this now, seems like not having this part:
General - Switch (Actions) depending on Random int
was the root of my issues, thanks so much, would've never figured this out. This is my first time playing with a map editor or any type of coding really lol can't wait to show the final product
"run this trigger" was the name of that trigger that i made, just put in the name of the trigger into that field and it will run its self (i just realized that you can also set it to a function called "current trigger", sorta how i did for turning off the action xD)
and to create a new case you can press ctrl+r (its the shortcut to create a new action) while having cases selected
dont worry i only started messing around with the editor like a month ago and i had no clue wtf was going on with triggers at first xD
"run this trigger" was the name of that trigger that i made, just put in the name of the trigger into that field and it will run its self
and to create a new case you can press ctrl+r (its the shortcut to create a new action) while having cases selected
dont worry i only started messing around with the editor like a month ago and i had no clue wtf was going on with triggers at first xD
LOL what makes this really funny is that your post tells me this in the first place
"this trigger
Events
Timer - Every 5.0 seconds of Game Time
Local Variables
Random int = 0 <Integer>"
edit: Im so stupid I thought that each action was a separate trigger, rather than the whole thing. Now it logically makes perfect sense to me though >_<
bump, still getting the stack overflow error when I run game after all 4 are filled. It makes no sense because all 4 alreadybuilts are true, so the trigger should turn off....
I prefer the array method. Attached a test map to show you how short the trigger is when you do it that way.
I'm kind of confused...I can tell by what is there you understand what i'm trying to do, but it doesn't actually work that way, it just creates a pylon in every zone at the same time even though you are trying to make it choose 1-4 every x seconds.... >_<
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
So for my custom map, I need buildings to spawn at four locations. I need 1 building to spawn at each location every 180 seconds. Each building spawns in a location that blocks a path.
I have successfully made it so that a building does spawn at one of these four regions. The problem is that the building needs to spawn at a DIFFERENT location each time (when they spawn at the same location they just overlap). I can make a statement that if the chosen region has a building already, don't spawn the building, but I can't figure out how to make the event keep redoing a random selection till it chooses a region without the building.
Help is appreciated, if you want to see my work i'm gonna put it up after i'm done with alpha, so stay tuned in this thread.
the attached file is just the part I can't get to work btw. PM me if you want to see the full map.
Each 180 sec, you make an rand 4. If it's one, it create your building at the first location if the booleen "alreadybuild1" is on false. And you turn your booleen to true. If your booleen is on true, you excecute instantly your trigger. If it's not one, you make a rand 3, if it's one it create your building at the second location. If the booleen "alreadybuild2" is on false. And you turn your booleen on true. If your booleen is on true, you execute your trigger. If it was not 3, you make a random 2...
Etc... If the rand choose a bad location (already build) it will restart until a good one is choosen. And the first action of your trigger must be:
If Alrdeadybuild1 = true Alrdeadybuild2 = true Alrdeadybuild3 = true Alrdeadybuild4 = true Then Turn off this trigger Stop all instances of this trigger Else The rest of your trigger.
This action wil stop the trigger once all your building are done (but only 180 sec after, so you'll have one more iteration of your trigger)
THIS IS NOT THE BEST SOLUTION (by far), if you search you can easily find something more efficient.
@AnyILL: Go
I'll try this and let you know how it goes, even if I don't end up doing it this way, it'll help me learn as im kind of new with this stuff but I think I understand how the suggestion would work.
btw I've searched for such a long time and found nothing :(
@Idralol: Go
Does anyone know another way?
lol I suck I can't get this to work
bumping because I attached my fail attempt
OMG HALPZZZZZZZORRZZZ PLOXZORZ
i more or less did it for you :D ,
Note: i didnt test it so i may have made a mistake somewhere, but other then that it should work
this trigger
Events
Timer - Every 5.0 seconds of Game Time
Local Variables
Random int = 0 <Integer>
Conditions
Actions
Variable - Set Random int = (Random integer between 1 and 4)
General - Switch (Actions) depending on Random int
Cases
General - If (1)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
alreadybuilt1 == false
Then
Unit - Create 1 Supply Depot for player 0 at (Center of Region 005) using default facing (Ignore Placement)
Variable - Set alreadybuilt1 = true
Else
Trigger - Run this trigger (Check Conditions, Don't Wait until it finishes)
General - If (2)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
alreadybuilt2 == false
Then
Unit - Create 1 Supply Depot for player 0 at (Center of Region 006) using default facing (Ignore Placement)
Variable - Set alreadybuilt2 = true
Else
Trigger - Run this trigger (Check Conditions, Don't Wait until it finishes)
General - If (3)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
alreadybuilt3 == false
Then
Variable - Set alreadybuilt3 = true
Unit - Create 1 Supply Depot for player 0 at (Center of Region 007) using default facing (Ignore Placement)
Else
Trigger - Run this trigger (Check Conditions, Don't Wait until it finishes)
General - If (4)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
alreadybuilt4 == false
Then
Unit - Create 1 Supply Depot for player 0 at (Center of Region 008) using default facing (Ignore Placement)
Variable - Set alreadybuilt4 = true
Else
Trigger - Run this trigger (Check Conditions, Don't Wait until it finishes)
Default
General - If (Conditions) then do (Actions) else do (Actions)
If
alreadybuilt1 == true
alreadybuilt2 == true
alreadybuilt3 == true
alreadybuilt4 == true
Then
Trigger - Turn (Current trigger) Off
Else
Oh and just a tip after looking at your attachment, i suggest you use "switch" or "in then else multiple" instead of a ton "if then else" just makes things a beat more neater and easier to look at
@AnyILL
i think the way you said it is more or less the best way to do it, maybe it could've been done through custom actions but that wouldn't have made that big of a difference
shoudn't you use a while loop for that? something like in the attached imige
@allcor:
that would work except for that you would also need an array for the points, because what that trigger would do is create 4 buildings at random points at a random of 5 from a single points.
so instead of setting a local point variable to a random points around another point or region, he could create a global points array, and then use the variable A to discriminate between them
so the create unit part would look like this
Unit - Create 1 Supply Depot for player 0 at Position of building[A] using default facing (Ignore Placement)
@gizmachu: Go
ow wait I read the question wrong sorry. Thought a building needed to spawn at a random location of 4 regions every time the trigger was run your trigger is better.
trying this now, seems like not having this part:
General - Switch (Actions) depending on Random int
was the root of my issues, thanks so much, would've never figured this out. This is my first time playing with a map editor or any type of coding really lol can't wait to show the final product
I'm running into trouble with the if(1), if(2), if(3) business. The first time, I can do:
General - Switch (Actions) depending on Random int Cases General - If (1)
but I can't figure out how to put another case under cases without first going to
General - Switch (Actions) depending on Random int
my other problem is here:
Trigger - Run this trigger (Check Conditions, Don't Wait until it finishes)
I'm not sure what to put for "run this trigger," and I don't understand why I would put that there. Shouldnt I be running NEXT trigger?
I'm trying to figure it out myself but I know it's not going to work because of the case business :(
"run this trigger" was the name of that trigger that i made, just put in the name of the trigger into that field and it will run its self (i just realized that you can also set it to a function called "current trigger", sorta how i did for turning off the action xD)
and to create a new case you can press ctrl+r (its the shortcut to create a new action) while having cases selected
dont worry i only started messing around with the editor like a month ago and i had no clue wtf was going on with triggers at first xD
LOL what makes this really funny is that your post tells me this in the first place
"this trigger Events Timer - Every 5.0 seconds of Game Time Local Variables Random int = 0 <Integer>"
edit: Im so stupid I thought that each action was a separate trigger, rather than the whole thing. Now it logically makes perfect sense to me though >_<
works perfectly, feels so good to solve something even when people practically do it for you lol ;DDD
strange, everything is in red like its broken but it still works
edit: getting stack overflow errors, is it because Else is left blank at the end?
@Idralol: Go
bump, still getting the stack overflow error when I run game after all 4 are filled. It makes no sense because all 4 alreadybuilts are true, so the trigger should turn off....
@Idralol: Go
I prefer the array method. Attached a test map to show you how short the trigger is when you do it that way.
I'm kind of confused...I can tell by what is there you understand what i'm trying to do, but it doesn't actually work that way, it just creates a pylon in every zone at the same time even though you are trying to make it choose 1-4 every x seconds.... >_<