Filtering an array of Players by an Array of Locations

What i’m trying to do is either;
(A): Set 1 Player Variable to an Array of all player’s who are near a specific location. And this specific location its self, is with in an array.
OR
(B): Set the players who are near a specific location (this location will be w/in an array) to the player WHO’S array contains “This” locations.

(A) is easy to do IF the array only has 1 entity.
Set Player Var X, Player’s w/in radius, Player Var Y (the location)
or
Set Player Var x, Filtered array, All players, Compare: distance between (Variable Y & Currant Array Element) < Value (5 or whatever)

However, if you have more then 1 element in the array, and the players are closer to any other element that’s NOT Index 0. It doesn’t work correctly.

TLDR:
So im modifying an older rule. The rule worked fine when there was only 1 Sombra / team. But now that im turning off hero limits. And there could be more then 1 Sombra at any given time. I need to filter out all the Other Sombras.

In this rule, when Sombra hacks a Health Pack, this doubles the healing effect OF that Health Pack. And the Sombra that Hacked that HP get’s credit for it (Ult charge and/or whatever else i decide to add)
Well now that there “could be” more then 1 Sombra hacking HPs, how would i go about filtering out All the other Sombra?
Each Sombra that hacks a HP, that Ray Cast Hit Position is stored for 60s (the amount of time hack HPs last for)

So the original rule (the part specific to giving credit to Sombra) went somethin like this:
Rule: Player Received Healing

Conditions:
Event healing was Health Pack
Player Variable (On hero Sombra, team of EventPlayer) HealthPacks != Empty Array
True for Any: Player Variable (on hero Sombra: team of EventPlayer) Variable HealthPacks: Distance between (eventplayer & Current Array Element) < 5

Actions:
Heal Event player; Multiply Event Healing x 2
Set Ult Charge, Player on hero Sombra, team of Event player, Add (Ult charge of Sombra + (Event healing / 10)

It’s a fairly simple Rule. But obviously the “player on Hero” part is a problem. As this doesn’t specify a specif Sombra IF there are more then 1.

I hope this makes sense. Thanks

What you could do is create another array that maps with the hacked health pack, that array contains the sombra who hacked the health pack. Seems like challenging issue, i may have an alternative way of solving it, but i need some thoughts of which attempts might work, and will increase the complexity.

Edit: So the healing event could be look like:

rule("Rule 2")
{
	event
	{
		Ongoing - Global;
	}

	actions
	{
		"Array of health pack positions including big and small sizes, for reference look at https://workshop.codes/wiki/articles/health+packs+locations"
		Global.A = Array();
		"This contains the Sombras who hacked any Health Pack at the specified Positions in Global A"
		Global.B = Array();
	}
}

rule("Rule 1")
{
	event
	{
		Player Received Healing;
		All;
		All;
	}

	conditions
	{
		Event Was Health Pack == True;
		Is True For Any(Global.A, Distance Between(Event Player, Current Array Element) <= 5) == True;
	}

	actions
	{
		"Index of the current Array Value which is closoe to Event player by distance and has gained Health Pack as flagged in condition list."
		Event Player.A = Index Of Array Value(Global.A, First Of(Filtered Array(Global.A, Distance Between(Event Player,
			Current Array Element) <= 5)));
		"Get the corresponding Sombra in Global B who has hacked a Health Pack in Global A, Global A and Global B are mapped/paired."
		Event Player.B = Global.B[Event Player.A];
		Heal(Event Player, Event Player.B, Event Healing * 2);
		Set Ultimate Charge(Event Player.B, Ultimate Charge Percent(Event Player.B) + Event Healing / 10);
		Event Player.A = 0;
		Event Player.B = Null;
	}
}
2 Likes

I’m going to chime in and expect the same base as @ArcanaXXI with the Global Health pack position Array, due to this and me being lazy I couldn’t test the Code though.

variables
{
	global:
		0: HealthPacks
		2: TeamAffiliation

	player:
		0: HackedHPs
		1: HPHackDuration
		2: NextHacked
}

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

	conditions
	{
		Is Firing Secondary(Event Player) == True;
		Is In View Angle(Event Player, First Of(Sorted Array(Filtered Array(Global.HealthPacks,
			Global.TeamAffiliation[Index Of Array Value(Global.HealthPacks, Current Array Element)] != Opposite Team Of(Team Of(
			Event Player))), Distance Between(Event Player, Current Array Element))), 15) == True;
		Is In Line of Sight(Eye Position(Event Player), First Of(Sorted Array(Filtered Array(Global.HealthPacks,
			Global.TeamAffiliation[Index Of Array Value(Global.HealthPacks, Current Array Element)] != Opposite Team Of(Team Of(
			Event Player))), Distance Between(Event Player, Current Array Element))), Enemy Barriers Block LOS) == True;
	}

	actions
	{
		Wait(0.650, Abort When False);
		Event Player.NextHacked = Index Of Array Value(Global.HealthPacks, First Of(Sorted Array(Global.HealthPacks, Distance Between(
			Event Player, Current Array Element))));
		If(Array Contains(Event Player.HackedHPs, Event Player.NextHacked));
			Event Player.NextHacked = Index Of Array Value(Event Player.HackedHPs, Event Player.NextHacked);
			Event Player.HPHackDuration[Event Player.NextHacked] = 60;
		Else;
			Modify Player Variable(Event Player, HPHackDuration, Append To Array, 60);
			Global.TeamAffiliation[Event Player.NextHacked] = Team Of(Event Player);
	}
}

rule("Rule 2")
{
	event
	{
		Ongoing - Each Player;
		All;
		Sombra;
	}

	conditions
	{
		Event Player.HPHackDuration == True;
	}

	actions
	{
		Wait(0.250, Ignore Condition);
		Event Player.HPHackDuration = Mapped Array(Event Player.HPHackDuration, Current Array Element - 0.250);
		If(!First Of(Event Player.HPHackDuration));
			Skip If(Is True For Any(Players On Hero(Hero(Sombra), Team Of(Event Player)), Array Contains(Current Array Element.HackedHPs,
				First Of(Event Player.HackedHPs))), 1);
			Global.TeamAffiliation[First Of(Event Player.HackedHPs)] = All Teams;
			Modify Player Variable(Event Player, HackedHPs, Remove From Array By Index, 0);
			Modify Player Variable(Event Player, HPHackDuration, Remove From Array By Index, 0);
		End;
		Loop If Condition Is True;
	}
}

rule("Rule 3")
{
	event
	{
		Ongoing - Each Player;
		All;
		All;
	}

	conditions
	{
		Hero Of(Event Player) != Hero(Sombra);
		Count Of(Remove From Array(Event Player.HackedHPs, 0)) > Null;
	}

	actions
	{
		Skip If(Is True For Any(Players On Hero(Hero(Sombra), Team Of(Event Player)), Array Contains(Current Array Element.HackedHPs,
			First Of(Event Player.HackedHPs))), 1);
		Global.TeamAffiliation[First Of(Event Player.HackedHPs)] = All Teams;
		Modify Player Variable(Event Player, HackedHPs, Remove From Array By Index, Null);
		Loop If Condition Is True;
	}
}

rule("Rule 4")
{
	event
	{
		Player Left Match;
		All;
		Sombra;
	}

	conditions
	{
		Count Of(Event Player.HackedHPs) != Null;
	}

	actions
	{
		While(Count Of(Event Player.HackedHPs) != Null);
			Skip If(Is True For Any(Players On Hero(Hero(Sombra), Team Of(Event Player)), Array Contains(Current Array Element.HackedHPs,
				First Of(Event Player.HackedHPs))), 1);
			Global.TeamAffiliation[First Of(Event Player.HackedHPs)] = All Teams;
			Modify Player Variable(Event Player, HackedHPs, Remove From Array By Index, Null);
		End;
	}
}

Rule 3 & 4

Are simply there to remove the Hacked health packs once the player switches off Sombra / leaves.
The problem is; once the player leaves, if they were the first to hack any on the Health packs that they hacked, and another Sombra hacked it afterwards the Script will leave that HP hacked, the game will remove the hack of said HP.
I don’t know if the game handles it this way too if the first Player to hack the HP switches Heroes.

Rule 1

Determines if the Player hacked a health pack (also not flawless…) the view Angle might need to get adjusted to the View Angle that’s required to hack a target + to make sure that there’s no enemy in LOS that would get hacked first; both things that I didn’t bother adding.

Rule 2

Tracks the hacked health pack hack duration:
it might eat up to 0.249 seconds of each health pack that’s hacked after the first one.
You can lower the interval to reduce the amount of time that’s being eaten at the cost of server load, whatever you need more, accuracy or server stability.

1 Like

Hey thx for the replies… I’ll give both of them a shot & play around w/ it.