Need help with skip if; compare

Hello,
can someone tell me what’s wrong with this code? Everything looks fine to me and yet, when someone is killed for the first time everything works just fine. The problem occurs when the victim is ressurected, when I kill him twice he shows at the victims list for the second time.

variables
{
	player:
		4: Victims
}

rule("Victims")
{
	event
	{
		Player Dealt Final Blow;
		All;
		All;
	}

	conditions
	{
		Attacker == Event Player;
		Is Alive(Victim) == False;
	}

	actions
	{
		Skip If(Event Player.Victims != 0, 1);
		Event Player.Victims = Victim;
		Skip If(Victim == Event Player.Victims, 1);
		Modify Player Variable(Event Player, Victims, Append To Array, Victim);
	}
}

I want to do that this way: (second skip if, first skip if works perfectly fine) Skip If Victim’s name is already on the list of the killer’s victims but it doesn’t work with my code. Can someone help?

You can remove these conditions, as the event type assures that the attacker is the event player and that the victim died (cause thats what final blow means).

This wont work if “Victims” is an array, so use the action “array contains” instead.

Additional tips are that you can remove the first skip action if you use “empty array” as initialisation of “victims” and the “array contains” action. You could also use the “if” action instead of the “skip if”, since it makes your code easier to read.

Here is the fixed code:

variables
{
	player:
		4: Victims
}

rule("Initialize Player")
{
	event
	{
		Ongoing Each Player;
		All;
		All;
	}

	conditions
	{
		Has Spawned(Event Player) == True;
	}

	actions
	{
		Event Player.Victims = Empty Array;
	}
}

rule("Victims")
{
	event
	{
		Player Dealt Final Blow;
		All;
		All;
	}

	actions
	{
		If(Not(Array Contains(Event Player.Victims, Victim)));
			Modify Player Variable(Event Player, Victims, Append To Array, Victim);
		End;
	}
}

Of course, these are just my recommendations. You can fix the code aswell by simply replacing

With:
Skip If(Array Contains(Event Player.Victims, Victim), 1);

1 Like

Hey,

Thank you very much! Works like a charm!
Is there any chance to remove/subtract array by value from multiple global variables? It’s hard to explain, but I mean, let’s say - at the start of the match role picker picks a random role for all players, then deletes their names from all players variable. He gets a role blah blah blah and after being converted to another role, I want him to switch his role and delete from the previous one. I’ve done something like this: when Plague doctor uses his ability, he marks a random hero from his “Punched” variable, after 30 seconds (if the target is dead) the target resurrects as a Plague Minion. In this moment the problem occurs, how to “find” his variable (previous role) and delete it/remove it and replace it with a new? I’ve done it to remove value from the array from all roles separately but when there were no player assigned to this role it shows [0] to this variable value and it’s a really problem when there are a lot of roles.
I just want to make sure that everything works fine, sorry for the length of this post.

Code to test it: 5K5R9

I checked your code. Seems fine to me. Afaik if you try to remove a value from an array that does not exist in the array, nothing happens.

If you want to make sure that the array you try to remove from contains the player, you can use “if” and “array contains” before doing so.

The only thing that is wrong in your code is the “has spawned” condition in your “role distribution” rule. If you give “has spawned()” an array as input, the action will only check the first element of the array. So I recommend you to use Is True For All(All Players(All Teams), Has Spawned(Current Array Element)) == True as condition instead.