How can I make condition: Check if Player Changed Role

I want the condition to check if player switched ROLE of the hero.

ex) Reaper to Winston

How can I put this as a condition?

1 Like

I haven’t tested it yet but isn’t there a way to detect the role?

I don’t think you can. You’ll probably need some variables to check switching role.

So how could that be done? I’m no good with these things…

Here is one way how it could be done, using only one player variable which I named previous_hero in this example (the Small Message action is the one that is run when a player changed role; you could add more actions by increasing the number of actions that are skipped in the preceding Skip If action):

rule("Player Hero Changed")

{

event
{
	Ongoing - Each Player;
	All;
	All;
}

conditions
{
	Has Spawned(Event Player) == True;
	Hero Of(Event Player) != Player Variable(Event Player, previous_hero);
}

actions
{
	Skip If(And(Compare(Player Variable(Event Player, previous_hero), !=, 0), Compare(Add(Array Contains(All Tank Heroes, Hero Of(Event Player)), Multiply(Array Contains(All Support Heroes, Hero Of(Event Player)), 2)), ==, Add(Array Contains(All Tank Heroes, Player Variable(Event Player, previous_hero)), Multiply(Array Contains(All Support Heroes, Player Variable(Event Player, previous_hero)), 2)))), 1);
	Small Message(Event Player, Custom String("Role changed", Null, Null, Null));
	Set Player Variable(Event Player, previous_hero, Hero Of(Event Player));
}

}

How to implement this rule in an existing script:

  1. Name an unused player variable in your script previous_hero.
  2. Copy the rule from this thread and paste it into your script (unfortunately, this only works on PC, for consoles you’d have to recreate it manually).
  3. Rename the player variable previous_hero to whatever you want it to be called (optional).
  4. Replace the Small Message action with the action you want to happen when a player switched role. If you want to add more than one action, set the number at the end of the preceding Skip If action to the number of actions you need to run and add the actions (but make sure that the action Set Player Variable(Event Player, previous_hero, Hero Of(Event Player)) stays at the end of the list and is not skipped by the Skip If action).
3 Likes

Sigh, biased.

Maybe dont cut off the “unfortunately” in the quote XD

Thanks!! it worked!!

1 Like

I meant the people who didn’t allow it.