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!
Hey yall, got a portal trigger which works but I was hoping to make it a bit better. Currently the trigger will randomly choose one of the variables to spawn a portal. I was hoping to add a check to see if a portal is already there, causing it to try spawning another portal elsewhere. If all 4 portals are already spawned I'd like the trigger to do nothing.
You have a lot of unnecessary actions in your trigger. The only thing that is different in each If/Then/Else is only the region, everything else is the same.
So the first thing to do is to optimize the entire thing by just setting the Point variable in each If/Then/Else and execute all other actions outside those ITE blocks.
Also, this:
Player Group - Pick every player in (All players) and do (Actions)
Loop - Actions
Quest - Create Campaign ...
Unit - Grant shared vision...
Custom script: call RemoveLocation(...
should be like this:
Player Group - Pick every player in (All players) and do (Actions)
Loop - Actions
Quest - Create Campaign ...
Unit - Grant shared vision...
Custom script: call RemoveLocation(...
To further improve this, create a region array variable, on map initialization initialize the array with your regions and in Portals trigger use the random number as the index in array. Something like:
Map Ini
Events
Map Initialization
Conditions
Actions
Set Regions[1] = Portal Left 1 <gen>
Set Regions[2] = Portal Left 2 <gen>
Set Regions[3] = Portal Right 1 <gen>
Set Regions[4] = Portal Right 2 <gen>
// In Portals trigger
Set choice = (Random integer number between 1 and 4)
Set Point = (Center of Regions[choice])
...
I see you also change facing and perhaps even the text message. You can use real array and string array to store angle and text for each choice.
I have recently posted an explanation in another thread about how to pick region randomly without picking same region again. See [Solved] - Random Hero Trigger Leak
The algorithm in the picture describes how to pick a region without picking same region multiple times. It achieves that using:
region array containing all possible regions
integer variable keeping track of number of unpicked regions
region variable which holds the randomly selected region
The algorithm can be described as:
Let variable maxIndex represent the number of unpicked regions. At the start of the game maxIndex will be equal to number of regions in regions array
Let num be random number between 1 and maxIndex
Set region variable reg to region at num position in the regions array (i.e. regions[num])
reg is your randomly picked region
To prevent same region from being picked again, the algorithm takes the following steps:
switch position of region at num position with region at maxIndex position (=last unpicked region) in the regions array.
decrease maxIndex by one, since you have one less region that was not yet picked
As an example, if you had 20 unpicked regions, then maxIndex would be 20. If the random number num was 6, then your randomly picked region would be region[6], which would be for example "Forest Area 1" region.
Now you swap region[6] with whatever is at region[maxIndex] = region[20]. Let's say that is region "Lake Area 3".
Finally, you decrease the maxIndex by one.
So you got from:
JASS:
maxIndex = 20
region[6] = "Forest Area 1"
region[20] = "Lake Area 3"
to
JASS:
maxIndex = 19
region[6] = "Lake Area 3"
region[20] = "Forest Area 1"
Because maxIndex is now 19, then the next time the trigger is executed, it will pick random number between 1 and 19, not 20. Because the random number won't ever be 20, it will never pick "Forest Area 1" again.
On the other hand, if the random number was 6 again, then neither that would be a problem, because previously region[6] was "Forest Area 1", but now region[6] is "Lake Area 3"
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.