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

X-maul

AKA: Demtrod
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
Staff member
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
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 ;)
 

Phubar

Well-Known Member
Let me understand, you have many heros available (how many?) and only four players that have to choose between them, right?
 

Phubar

Well-Known Member
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
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

Well-Known Member
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

Well-Known Member
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
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
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
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
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
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.
  • Ghan Ghan:
    We did!
  • Ghan Ghan:
    The old shoutbox wasn't supported anymore. We updated xenForo, so it had to be replaced.
  • jonas jonas:
    let's see if everyone finds it... the nice thing about the shoutbox was I could check on it even while logged out, but the existence of this one is hidden when you're not logged in
  • Ghan Ghan:
    We can fix that.
  • Ghan Ghan:
    Chat should show on the sidebar when not logged in now.
  • Ghan Ghan:
    (You'll still need to log in to post messages)
  • Ghan Ghan:
    Test!
  • tom_mai78101 tom_mai78101:
    I must be in a test server.
  • tom_mai78101 tom_mai78101:
    Nice, Twitter tweets embedding now works
  • Wizard Wizard:
    Yup.
  • Ghan Ghan:
    Excellent.
  • Ghan Ghan:
    @tom_mai78101 Hello there.
  • Ghan Ghan:
    Tagging works in the chat too.
  • tom_mai78101 tom_mai78101:
    @Ghan Missed it.
  • Wizard Wizard:
    Still fixing things here and there. Added widgets to the portal, will make it match the ones here on the forum index tomorrow.
  • Ghan Ghan:
    The venerable World Editor Tutorials site has been converted to HTTPS at last.
  • jonas jonas:
    cool
  • jonas jonas:
    and I can even edit my messages, nice
  • seph ir oth seph ir oth:
    GENERAL CHIT CHAT, YOU ARE A BOLD ONE
  • Ghan Ghan:
    Hello there
  • The Helper The Helper:
    this new chatbox is great and the forum software update is great too
    +1
  • The Helper The Helper:
    upgrade has fixed forum registration spam problem
  • tom_mai78101 tom_mai78101:
    Something tells me we might be able to customize the chatbox a bit, considering that there's a gap under every message.
  • Wizard Wizard:
    Going to deploy a fix soon, just had to take some time for myself this weekend.

    Members online

    No members online now.

    Affiliates

    Hive Workshop
    Top