Run random action. And make it possible to remove one of the options?

X-maul

AKA: Demtrod
Reaction score
201
I want to make a selection system, where I can choose from A, B, C and D. If I choose A, A will be disabled for all players, this is pretty simple as it is right now. But I also want to make it possible to pick a random, so if I pick A and another player selects random, he will get a random from A, B, C and D. But A is no longer an option.

How can I do this?
To clarify even more; a system that takes a random from X amount of options, with the option to remove one of the options from the random group.
 

Siretu

Starcraft 2 Editor Moderator
Reaction score
293
I think it's hard but definitely not impossible to do it in a proper way.

The way I'd do it is probably easier though.

Save the removed options somehow. Maybe a boolean array. So if removedOptions[0] is true, option A is removed. When you random an option, have a while-loop that keeps randoming a new number as long as removedOptions[randNumber] is true.

Basically, make it random a new option until it finds one that isn't removed.

You might need a check to check if they're all removed so you don't get stuck in an infinite loop if it's possible to remove all options.
 

X-maul

AKA: Demtrod
Reaction score
201
Yeah, I thought of keeping randomizing untill I found something which wasnt disabled :) But I just wanted to know if there was a more efficient way to do it :)
But thanks anyway Siretu :)

It's for a hero selection system, so I'll need more hero options than the max amount of players ;)
 

X-maul

AKA: Demtrod
Reaction score
201
I already have it planned out (not done yet though), but please give it a go :)
 

Phubar

Ultra Cool Member
Reaction score
30
Let me understand, you have many heros available (how many?) and only four players that have to choose between them, right?
 

Phubar

Ultra Cool Member
Reaction score
30
I wrote this with openoffice writer, not with the sc2 editor so it's not a real trigger but a list of instructions as near to the editor actions as posible.

I assumed you have 9 heroes in your pool.

You need GLOBAL VARIABLES (with starting values)


MaxRdm=9 (integer)
SelectedType=NoUnitType (unit type)
HeroeType[9]= (array unit type)
HeroP1=NoUnit (unit)
HeroP2=NoUnit (unit)
HeroP3=NoUnit (unit)
HeroP4=NoUnit (unit)

You have to start filling the array with a unit type foe each index.


Code:
TRIGGER "Click button" (one trigger for each player)
 
Event
    Player1 click on a button
 
Action
    case "buttonRaynor"
        Create 1 RaynorType for Player1
        Set HeroP1= last created unit
    case "buttonZeratul"
        Create 1 ZeratulType for Player1
        Set HeroP1= last created unit
    case "buttonKerrighan"
        Create 1 KerrighanType for Player1
        Set HeroP1= last created unit
    ...
    ...
    case "buttonRandom"
        Execute trigger "Random choose" wait the end
        Create 1 SelectedType for Player1
        Set HeroP1= last created unit
        Set SelectedType=NoUnitType


Code:
TRIGGER "Random choose"
 
Event
    none
 
Local variables
    IndexRdm=0 (integer)
    Counter=0 (integer)
 
Actions
    Set IndexRdm= random integer between 1 and MaxRdm
    Set SelectedType= HeroeType[IndexRdm]
    For Counter=  IndexRdm to MaxRdm do
        Set HeroeType[Counter]=HeroeType[counter+1]
    Set MaxRdm=MaxRdm-1


This will work i hope.. cannot check it :(
The only problem is when a player clicks on "random" button before the instance of the previous "random choose" trigger is not finished... you have to add some "conditions" like

Code:
TRIGGER "Click button" (one trigger for each player)
 
Add actions at beginning
 
Set EnableP2=F (boolean)
Set EnableP3=F (boolean)
Set EnableP4=F (boolean)
 
an then this action after case "buttonRandom"
 
wait until EnableP1=T
 
And the actions at the end
 
Set EnableP2=T (boolean)
Set EnableP3=T (boolean)
Set EnableP4=T (boolean)


Of couyrse you need four boolean global variables EnableP, EnableP2, EnableP3, EnableP4.
 

Dave312

Censored for your safe viewing
Reaction score
269
The easy way to do it is to create a local array where the maximum length is the maximum number of options. Then cycle through each option and if the option is available, add it to your local array. Then just get a random index from your local array.
 

Phubar

Ultra Cool Member
Reaction score
30
Dave you are right, my trigger does this by deleting the choosen option and sliding "down" the next ones. Then it "cuts" the array setting the maximum index 1 unit smaller.

The trigger that handles the random choice is the second one, the frist is for the selection of specific hero or random selection.

The third part of code is only an add in order to avoid that the random trigger is executed more than one instance at the time.
 

Phubar

Ultra Cool Member
Reaction score
30
Sorry Dave was totally right!

My trigger works only if all players choose random... if a palyer chooses a specific hero it's hard to delete it's option in the array and modify the array in order to prevent that a random selecion cauld choose the same hero too.
 

X-maul

AKA: Demtrod
Reaction score
201
Yeah, you're most likely right Dave312. But using this method wont make it random? As far as I can see, the method Phubar suggests is flawed; If Player 1 and 2 selects an option, now these are the available options;
Option 1
Option 2
Option 3
Option 4
Option 5
Option 6
Option 7
Option 8
Now player 3 selects random, how will your system check if it's available?

I think I'll use Siretu's suggestion, as I belive it's the easiest way, the most efficient and the most random.

EDIT: I made a custom Action, othervise I would'nt have been able to determine which player the trigger was run for, so I made this;
Code:
Random Hero
    Options: Action
    Return Type: (None)
    Parameters
        Player = 0 <Integer>
    Grammar Text: Create a random Hero for (Player)
    Hint Text: (None)
    Custom Script Code
    Local Variables
        Random = (Random integer between 0 and 12) <Integer>
        ActionDone = False <Boolean>
    Actions
        General - While (Conditions) are true, do (Actions)
            Conditions
                ActionDone == False
            Actions
                General - If (Conditions) then do (Actions) else do (Actions)
                    If
                        Hero Is Available[Random] == True
                    Then
                        Unit - Create 1 HeroTypes[Random] for player Player at (Start location of player Player) facing Energy Fountain Center (No Options)
                        Variable - Set ActionDone = True
                        Variable - Set Hero Is Available[Random] = False
                        General - Skip remaining actions
                    Else
                        Variable - Set Random = (Random integer between 0 and 12)

EDIT 2: The action does not work? How come?
(I'm just running the action 8 times each
EDIT 3: The action works? After I shut down my computer and turned it on again I inserted some debug messages to troubleshoot, and then it worked on the first try.
 

Dave312

Censored for your safe viewing
Reaction score
269
Yeah, you're most likely right Dave312. But using this method wont make it random?

Why wouldn't the value be random? You're just getting a random option from the available options. It would not be biased against any particular option as every option has an equal chance of being selected. This is the method I am using in my map and I haven't had any problems with it.

EDIT 2: The action does not work? How come?
(I'm just running the action 8 times each
It looks like it should work. Did you remember to set the starting values of your Hero Is Available variable to true?
 

X-maul

AKA: Demtrod
Reaction score
201
Why wouldn't the value be random? You're just getting a random option from the available options. It would not be biased against any particular option as every option has an equal chance of being selected. This is the method I am using in my map and I haven't had any problems with it.
I asume I do not fully understand the system you are suggesting then, could you give me a trigger example? (nothing complex, just an example)
It looks like it should work. Did you remember to set the starting values of your Hero Is Available variable to true?
For some reason it does now, I dont know why it didnt before? But now it works. I'm still very eager to see how your method would work?
 

Dave312

Censored for your safe viewing
Reaction score
269
Nope it will not.

Trigger:
  • Random Hero
    • Options: Action
    • Return Type: (None)
    • Parameters
      • Player = 0 &lt;Integer&gt;
    • Grammar Text: Random Hero(Player)
    • Hint Text: (None)
    • Custom Script Code
    • Local Variables
      • AvailableList = 0 &lt;Integer[12]&gt;
      • i = 0 &lt;Integer&gt;
      • Count = 0 &lt;Integer&gt;
    • Actions
      • General - For each integer i from 0 to 12 with increment 1, do (Actions)
        • Actions
          • General - If (Conditions) then do (Actions) else do (Actions)
            • If
              • Hero Is Available<i> == True
            • Then
              • ------- Add Hero to Available List
              • Variable - Set AvailableList[Count] = i
              • Variable - Modify Count: + 1
            • Else
      • ------- Get a random Hero
      • Variable - Set i = (Random integer between 0 and (Count - 1))
      • Variable - Set Hero Is Available[AvailableList<i>] = False
      • Unit - Create 1 HeroTypes[AvailableList<i>] for player Player at (Start location of player Player facing Energy Fountain Center (No Options)</i></i></i>
 

X-maul

AKA: Demtrod
Reaction score
201
Haha, for some reason I coult NOT imagine this in my head before now :rolleyes: thank you Dave312 :) I'll use this instead, as it seems to be easier for the computer to handle, than the continues randomizing.

NOTE: I cant quite see why you have to find a random integer between 0 and (Count - 1)?
(Why the -1?)
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    that sucks i bet they are expensive
  • Varine Varine:
    Not really
  • Varine Varine:
    The entire hot end is like 20 dollars, I just can't get anymore until next week
  • Varine Varine:
    I ordered like five blocks for 15 dollars. They're just little aluminum blocks with holes drilled into them
  • Varine Varine:
    They are pretty much disposable. I have shitty nozzles though, and I don't think these were designed for how hot I've run them
  • Varine Varine:
    I tried to extract it but the thing is pretty stuck. Idk what else I can use this for
  • Varine Varine:
    I'll throw it into my scrap stuff box, I'm sure can be used for something
  • Varine Varine:
    I have spare parts for like, everything BUT that block lol. Oh well, I'll print this shit next week I guess. Hopefully it fits
  • Varine Varine:
    I see that, despite your insistence to the contrary, we are becoming a recipe website
  • Varine Varine:
    Which is unique I guess.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top