Question :: Set Player Allowed Heroes

I’m playing around with a 3/2/1 mode and hero reworks. But I’m not seeing a way to add the value of more than 1 hero or category of heroes for the particular line of code “Set Player Allowed Heroes” - So I went to the code page and found the rule information for said action.

Rule Information

SET PLAYER ALLOWED HEROES

Sets the list of heroes available to one or more players. If a player’s current hero becomes unavailable, the player is forced to choose a different hero and respawn at an appropriate spawn location.

Definitions:

  • Player - The player or players whose hero list is being set. Can use most Player based Value Syntax for this value.
  • Hero - The hero or heroes that will be available. If no heroes are provided, the action has no effect. Can use most Hero based Value Syntax for this value including compatible Arrays.

It says we can set up a Value Syntax for an array of heroes in the rule information. How would I set up Such a list? - and how would I then connect the list to the rule “Set Player Allowed Heroes”?

Nevermind ; I found an answer.

For anyone who wants the answer ; it’s as follows

Hero Slot Rule

Ongoing Rule - Each Player
Player on Slot [x]
Actions ::
Reset Player Hero Availability (event player)
Set Global Variable ([a], Empty Array)
Modify Global Variable ([a], append to array, hero (x))
~repeat last rule with as many heroes as you want~
Set Player Hero Availability (global variable (a))

1 Like

I did it but it’s not working.

rule("Rule 1")
{
	event
	{
		Ongoing - Each Player;
		All;
		Slot 0;
	}

	actions
	{
		Reset Player Hero Availability(Event Player);
		Global.A = Empty Array;
		Global.A += Append To Array(All Players(All Teams), Hero(Ana));
		Global.A += Append To Array(All Players(All Teams), Hero(Doomfist));
		Set Player Allowed Heroes(Event Player, Global.A);
	}
}

What did i do wrong?

You cant use the action “add” on arrays, as it only works with numbers/vectors.
Instead, you want to directly use the append to array action (replace the add action with it):

modify global variable(A, append to array, hero(ana))

However, there is an easier way to setup an array since the last patch:

  • create a new “set global variable” action
  • choose the variable (e.g. A)
  • as the value you choose “array”
  • press the “+” button next to it to add new elements to the array
3 Likes

PP198

The above is workshop code for an updated method for hero select (though it’s only roughly translated from an older version, so you may need to play around with it). I basically set up the first three global variables as each role’s hero list - then when the player fills a slot, they get their hero availability reset and are given heroes allowed based on the role variable that slot is assigned.

Essentially, as @Shanalotte stated, you want to create the empty array as its own action within the rule. Then in subsequent actions, append to the array. In the below example - SupportRole is Global Variable A {0}

actions
{
	Global.SupportRole = Empty Array;
	Modify Global Variable(SupportRole, Append To Array, Hero(Ana));
	Modify Global Variable(SupportRole, Append To Array, Hero(Baptiste));
	Modify Global Variable(SupportRole, Append To Array, Hero(Mercy));
	Modify Global Variable(SupportRole, Append To Array, Hero(Moira));
	Modify Global Variable(SupportRole, Append To Array, Hero(Zenyatta));
	Modify Global Variable(SupportRole, Append To Array, Hero(Sombra));
	Modify Global Variable(SupportRole, Append To Array, Hero(Brigitte));
	Modify Global Variable(SupportRole, Append To Array, Hero(Lúcio));
}