Too long script

Just a heads up this is a fairly complicated script so i wouldn’t recommend trying to solve this if you are new or unfamiliar to the workshop.

I have made a script that allows Moira to make a wall that works almost exactly like Mei’s wall but with fire, but it can get very laggy and i think it’s because the script is a lot longer than it should be, i have tried to make it shorter in many ways, i even removed the damage of the wall but it’s still laggy if there are several walls at once, i can’t really think of any way to make it shorter. if you have any questions about it or the variables feel free to ask and thanks in advance.
also don’t forget to be moira when testing this.

Code: DWHHG

There's only one important rule so i put it here
rule("Wall")
{
	event
	{
		Ongoing - Each Player;
		All;
		Moira;
	}

	conditions
	{
		Or(Or(Or(Is Button Held(Event Player, Ability 2), False), And(Is Button Held(Event Player, Primary Fire), Player Variable(
			Event Player, W))), And(Is Button Held(Event Player, Secondary Fire), Player Variable(Event Player, W))) == True;
		Is Alive(Event Player) == True;
	}

	actions
	{
		Wait(0.016, Ignore Condition);
		Abort If(And(Compare(Player Variable(Event Player, T), !=, 0), Not(Player Variable(Event Player, F))));
		Skip If(Not(Player Variable(Event Player, F)), 20);
		Skip If(Compare(Team Of(Event Player), ==, Team 1), 5);
		Play Effect(All Players(All Teams), Bad Pickup Effect, Team 2, Value In Array(Player Variable(Event Player, A), 0), 1);
		Play Effect(All Players(All Teams), Bad Pickup Effect, Team 2, Value In Array(Player Variable(Event Player, A), 1), 1);
		Play Effect(All Players(All Teams), Bad Pickup Effect, Team 2, Value In Array(Player Variable(Event Player, A), 2), 1);
		Play Effect(All Players(All Teams), Bad Pickup Effect, Team 2, Value In Array(Player Variable(Event Player, A), 3), 1);
		Play Effect(All Players(All Teams), Bad Pickup Effect, Team 2, Value In Array(Player Variable(Event Player, A), 4), 1);
		Skip If(Compare(Team Of(Event Player), ==, Team 2), 5);
		Play Effect(All Players(All Teams), Bad Pickup Effect, Team 1, Value In Array(Player Variable(Event Player, A), 0), 1);
		Play Effect(All Players(All Teams), Bad Pickup Effect, Team 1, Value In Array(Player Variable(Event Player, A), 1), 1);
		Play Effect(All Players(All Teams), Bad Pickup Effect, Team 1, Value In Array(Player Variable(Event Player, A), 2), 1);
		Play Effect(All Players(All Teams), Bad Pickup Effect, Team 1, Value In Array(Player Variable(Event Player, A), 3), 1);
		Play Effect(All Players(All Teams), Bad Pickup Effect, Team 1, Value In Array(Player Variable(Event Player, A), 4), 1);
		Modify Player Variable(Event Player, G, Add, 1);
		Wait(0.100, Ignore Condition);
		Skip If(Is Button Held(Event Player, Secondary Fire), 1);
		Loop If(Compare(Player Variable(Event Player, G), <, 50));
		Set Player Variable(Event Player, F, False);
		Set Player Variable(Event Player, G, 0);
		Set Player Variable(Event Player, A, Vector(0, 10000, 0));
		Abort;
		Skip If(Or(Not(Is Button Held(Event Player, Ability 2)), Not(Player Variable(Event Player, W))), 34);
		Skip If(Player Variable(Event Player, R), 15);
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 1));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 2));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 3));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 4));
		Create Effect(Event Player, Sphere, Red, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(Event Player),
			Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False), World Vector Of(
			Vector(1.500, 0, 0), Event Player, Rotation)), 1, Position and Radius);
		Set Player Variable At Index(Event Player, B, 1, Last Created Entity);
		Wait(0.016, Ignore Condition);
		Create Effect(Event Player, Sphere, Red, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(Event Player),
			Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False), World Vector Of(
			Vector(3, 0, 0), Event Player, Rotation)), 1, Position and Radius);
		Set Player Variable At Index(Event Player, B, 2, Last Created Entity);
		Wait(0.016, Ignore Condition);
		Create Effect(Event Player, Sphere, Red, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(Event Player),
			Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False), World Vector Of(
			Vector(-1.500, 0, 0), Event Player, Rotation)), 1, Position and Radius);
		Set Player Variable At Index(Event Player, B, 3, Last Created Entity);
		Wait(0.016, Ignore Condition);
		Create Effect(Event Player, Sphere, Red, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(Event Player),
			Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False), World Vector Of(
			Vector(-3.000, 0, 0), Event Player, Rotation)), 1, Position and Radius);
		Set Player Variable At Index(Event Player, B, 4, Last Created Entity);
		Skip If(Not(Player Variable(Event Player, R)), 15);
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 1));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 2));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 3));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 4));
		Create Effect(Event Player, Sphere, Red, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(Event Player),
			Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False), World Vector Of(
			Vector(0, 0, 1.500), Event Player, Rotation)), 1, Position and Radius);
		Set Player Variable At Index(Event Player, B, 1, Last Created Entity);
		Wait(0.016, Ignore Condition);
		Create Effect(Event Player, Sphere, Red, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(Event Player),
			Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False), World Vector Of(
			Vector(0, 0, 3), Event Player, Rotation)), 1, Position and Radius);
		Set Player Variable At Index(Event Player, B, 2, Last Created Entity);
		Wait(0.016, Ignore Condition);
		Create Effect(Event Player, Sphere, Red, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(Event Player),
			Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False), World Vector Of(
			Vector(0, 0, -1.500), Event Player, Rotation)), 1, Position and Radius);
		Set Player Variable At Index(Event Player, B, 3, Last Created Entity);
		Wait(0.016, Ignore Condition);
		Create Effect(Event Player, Sphere, Red, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(Event Player),
			Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False), World Vector Of(
			Vector(0, 0, -3.000), Event Player, Rotation)), 1, Position and Radius);
		Set Player Variable At Index(Event Player, B, 4, Last Created Entity);
		Set Player Variable(Event Player, R, Not(Player Variable(Event Player, R)));
		Abort;
		Skip If(Or(Not(Player Variable(Event Player, W)), Not(Is Button Held(Event Player, Secondary Fire))), 9);
		Allow Button(Event Player, Primary Fire);
		Allow Button(Event Player, Secondary Fire);
		Set Player Variable(Event Player, W, False);
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 0));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 1));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 2));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 3));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 4));
		Abort;
		Skip If(Or(Not(Is Button Held(Event Player, Primary Fire)), Not(Player Variable(Event Player, W))), 24);
		Set Player Variable(Event Player, T, 15);
		Chase Player Variable At Rate(Event Player, T, 0, 1, Destination and Rate);
		Set Player Variable(Event Player, W, False);
		Set Player Variable(Event Player, A, Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(Event Player), Multiply(
			Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False));
		Skip If(Player Variable(Event Player, R), 4);
		Modify Player Variable(Event Player, A, Append To Array, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(
			Event Player), Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False),
			World Vector Of(Vector(0, 0, 1.500), Event Player, Rotation)));
		Modify Player Variable(Event Player, A, Append To Array, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(
			Event Player), Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False),
			World Vector Of(Vector(0, 0, 3), Event Player, Rotation)));
		Modify Player Variable(Event Player, A, Append To Array, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(
			Event Player), Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False),
			World Vector Of(Vector(0, 0, -1.500), Event Player, Rotation)));
		Modify Player Variable(Event Player, A, Append To Array, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(
			Event Player), Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False),
			World Vector Of(Vector(0, 0, -3.000), Event Player, Rotation)));
		Skip If(Not(Player Variable(Event Player, R)), 4);
		Modify Player Variable(Event Player, A, Append To Array, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(
			Event Player), Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False),
			World Vector Of(Vector(1.500, 0, 0), Event Player, Rotation)));
		Modify Player Variable(Event Player, A, Append To Array, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(
			Event Player), Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False),
			World Vector Of(Vector(3, 0, 0), Event Player, Rotation)));
		Modify Player Variable(Event Player, A, Append To Array, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(
			Event Player), Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False),
			World Vector Of(Vector(-1.500, 0, 0), Event Player, Rotation)));
		Modify Player Variable(Event Player, A, Append To Array, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(
			Event Player), Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False),
			World Vector Of(Vector(-3.000, 0, 0), Event Player, Rotation)));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 0));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 1));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 2));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 3));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 4));
		Destroy Effect(Value In Array(Player Variable(Event Player, B), 5));
		Set Player Variable(Event Player, F, True);
		Allow Button(Event Player, Secondary Fire);
		Allow Button(Event Player, Primary Fire);
		Loop;
		Set Player Variable(Event Player, W, True);
		Set Player Variable(Event Player, R, True);
		Create Effect(Event Player, Sphere, Red, Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(Event Player),
			Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False), 1,
			Position and Radius);
		Set Player Variable(Event Player, B, Last Created Entity);
		Wait(0.016, Ignore Condition);
		Create Effect(Event Player, Sphere, Red, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(Event Player),
			Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False), World Vector Of(
			Vector(1.500, 0, 0), Event Player, Rotation)), 1, Position and Radius);
		Modify Player Variable(Event Player, B, Append To Array, Last Created Entity);
		Wait(0.016, Ignore Condition);
		Create Effect(Event Player, Sphere, Red, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(Event Player),
			Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False), World Vector Of(
			Vector(-1.500, 0, 0), Event Player, Rotation)), 1, Position and Radius);
		Modify Player Variable(Event Player, B, Append To Array, Last Created Entity);
		Wait(0.016, Ignore Condition);
		Create Effect(Event Player, Sphere, Red, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(Event Player),
			Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False), World Vector Of(
			Vector(3, 0, 0), Event Player, Rotation)), 1, Position and Radius);
		Modify Player Variable(Event Player, B, Append To Array, Last Created Entity);
		Wait(0.016, Ignore Condition);
		Create Effect(Event Player, Sphere, Red, Add(Ray Cast Hit Position(Eye Position(Event Player), Add(Eye Position(Event Player),
			Multiply(Facing Direction Of(Event Player), 1000)), All Players(All Teams), All Players(All Teams), False), World Vector Of(
			Vector(-3.000, 0, 0), Event Player, Rotation)), 1, Position and Radius);
		Modify Player Variable(Event Player, B, Append To Array, Last Created Entity);
		Disallow Button(Event Player, Primary Fire);
		Disallow Button(Event Player, Secondary Fire);
	}
}

I am not sure if you have tested if removing the cooldown feature improves performance.

Try replacing the chase player variable at rate action with a rule loop that ticks the T down at a slower pace like 0.1 at a time.

I have had that action hog up lots of server performance in my modes.

Especially if the action is ran by multiple players.

Ok first, i REALLY LIKE this idea, looks amazing!


but looking at your code i think you are misunderstanding something. It does not matter if you create multiple functions, the performance of the code (and the code limit) depends on the amount of commands AND SUBCOMMANDS you are using every tick.
The problem with your approach is that he has to iterate over the whole code every tick. This is really inefficient because you are executing quite a lot of SKIP commands (yeah they have a cost too). You could just remove them and replace them by functions.
This way the code will only execute when it is needed AND your code is much more readable...
Take a look at my approach: AWRQR
Only 46 commands (you used 111), runs much smoother because code is only executed when the conditions are true, and the subcommand count is reduced to a minimum because i used quite a few variables.

Here are all the changes i made for functionality
I limited the distance you can spawn the wall to 35 meter
The particles for the mei wall only spawn every 0.5 seconds
The particles are closer together. That is just personal preference
I did not block the input for primary fire while placing the wall.
This will add some nice looking animations for the wall placement and removal!

Here is an explanation for all the variables
E
Array to save the red spheres, so that we can delete them later

L
Position Array for the effects and red spheres, recalculated every tick while placing wall

D
Directional Vector, Controlls rotation of the wall

C
Directional Vector, D in normalized world coordinates


Cheers! And keep it up!

If you would like to have further explanation of the techniques i used just write me.
I used flip flops, direction vectors, function calls using variables and a few other things to optimize the code

First of all i’m glad you liked it, i’ll probably not do anything with it anymore so you can take it if you want.

I have tested it before and using skip ifs is easier for the server to handle than different rule, i think it might be because two reasons:

  • You don’t need to tell the server everytime that it is an ongoing each player rule that is for each team but only for Moira, and also after it calculates all the conditions it goes back and checks if they are all True.

  • If the conditions goes false in the middle of a wait action the server will take notice of this and add another entry (or a lot more than 1 in this case).

  • It doesn’t matter that you do it with functions and the actions don’t do anything it actually just makes it worse because the skip if also doesn’t look at the actions if it skips and both of them still need to be tested the same amount of times which means that it’s worse both because of the first item on the list and because you have a call function command that doesn’t have to be there.

believe me, i would like to do it with more than 1 rule and it used to be 5 rules but it was harder for the server that way, also it’s a very good practice to keep it simple and short anyway. also i checked and if you make my rule the same speed as your wall it will have about the same (about 25 difference) entries. but when i looked at the server load i saw that yours reached higher than mine (about 10-20%), i think it might be the loop for the circles or maybe just the extra rules, so i’m not really sure if it’s actually better for the server or not.

and you did a great job but just a few notes:

  1. it’s really annoying that the circles are delayed and “follow” the reticle and i know i’m nitpicking but i would recommend not having it on a loop anyway because that might cause some problems.

  2. very easy fix, you need to be able to cancel the wall with secondary fire when it’s on.

  3. I have no idea why this happened but one of the spheres didn’t go away after i placed the wall one time (I managed to record it
    h ttps://imgur.com/a/9TGel1U) this happened to me twice on two different matches.

  4. The wall needs to be in the color of the team of the Moira so the players will know which walls belong to which team otherwise there’s no way of knowing if you can walk through a wall or not.

but very good job and Kisses (get it?).