Solved [apologizes to Tailord] MODS PLEASE REMOVE THE THREAD

I made an upgrade game, and I want to make it so that you can buy out damage without sitting there and crouching, but, I have a tax on damage that is based on a player’s current damage * 0.01 . I think I need an exponential type thing, but I don’t know how to make that, Can you please help?

[PTR] code: [XZ3C7]

I’m busy for the next few hours so I can’t explain it in detail, but you could use a mathematical formula for compound interest to achieve this

Should only require one action if my thinking is correct

1 Like

Just remove the wait action from your crouch-buy loop.

1 Like

Excuse me, but your post isn’t particularly detailed either. As I understood, you already have an upgrade rule ready, and you are concerned that you have to sit and wait while it upgrades (atleast that’s how most of rpg modes work). So in this case, you can just remove wait action in this loop (and effect actions that are not needed anymore too)

1 Like

Did you try? Your loop is NOT infinite. Either player’s money ends, or he reaches the maximum level.
And you should move some actions that don’t need to be iterated to the end, like applying the level to player’s damage.
Of course, you can try to implement it in a bunch of formulas, but they are probably not gonna be simple, because you also need to check what lvl player is able to reach with his money.

1 Like

rule(“Rule 1”)
{
event
{
Ongoing - Global;
}

actions
{
	Small Message(All Players(All Teams), Custom String("message"));
	Loop;
}

}
Server crashed.

It will always crash without a wait function

1 Like

:man_facepalming: Dude, this is not the loop we are talking about. You can’t even read my message right.
You seem like you just need to learn workshop better. Just play with different options and view others’ codes. See if someone already implemented this.

2 Likes

Yes, it is a loop, if you remove the wait action from a loop (when I’m crouching to buy damage which is a loop) It will crash.

This is the rule you want to remove the wait function from btw:
variables
{
global:
1: DamagePrice

player:
	0: UpgradeShop
	1: IndexSelector
	2: ShopPage
	3: PlayerMoney
	7: PlayerDamage

}

rule(“buy damage”)
{
event
{
Ongoing - Each Player;
All;
All;
}

conditions
{
	Event Player.UpgradeShop == True;
	Event Player.ShopPage == 0;
	Event Player.IndexSelector == 0;
	Is Button Held(Event Player, Button(Interact)) == True;
}

actions
{
	If(Event Player.PlayerMoney >= Global.DamagePrice && Event Player.PlayerDamage < 10000 && Is Button Held(Event Player, Button(
		Crouch)) != True && True);
		Event Player.PlayerMoney = Event Player.PlayerMoney - Global.DamagePrice;
		"tax"
		Event Player.PlayerMoney = Event Player.PlayerMoney - Event Player.PlayerDamage * 0.010;
		Event Player.PlayerDamage = Event Player.PlayerDamage + 5;
		Set Damage Dealt(Event Player, Event Player.PlayerDamage);
		Play Effect(All Players(All Teams), Ring Explosion, Color(Red), Position Of(Event Player), 3.200);
		Small Message(Event Player, Custom String("+ 5 damage\r\n-{0} [price]\r\n-{1} [tax]", Global.DamagePrice,
			Event Player.PlayerDamage * 0.010));
	Else If(Event Player.PlayerMoney >= Global.DamagePrice && Event Player.PlayerDamage < 10000 && Is Button Held(Event Player, Button(
			Crouch)) == True && True);
		Event Player.PlayerMoney = Event Player.PlayerMoney - Global.DamagePrice;
		"tax"
		Event Player.PlayerMoney = Event Player.PlayerMoney - Event Player.PlayerDamage * 0.010;
		Event Player.PlayerDamage = Event Player.PlayerDamage + 5;
		Play Effect(All Players(All Teams), Ring Explosion, Color(Red), Position Of(Event Player), 3.200);
		Wait(0.016, Ignore Condition);
		Set Damage Dealt(Event Player, Event Player.PlayerDamage);
		Loop If Condition Is True;
	Else If(Event Player.PlayerMoney < Global.DamagePrice && True && True && True);
		Small Message(Event Player, Custom String("[{0}] Insufficient money for this action", Icon String(Warning)));
	Else If(Event Player.PlayerDamage >= 10000 && True && True && True);
		Small Message(Event Player, Custom String("[{0}] cannot buy more damage, you have reached the maxumum", Icon String(Warning)));
	End;
}

}

You are missing the part that the loop needs to be INFINITE to crash. If it isn’t too long, it won’t crash. After all, why would developers allow loops without “wait” if they always crashed?
Why do your conditions have useless True checks? Did you create this from scratch?

1 Like

The

were there because I wasn’t sure If I was going to needed them later

You should look at the dan reed post because it legit says that you can make the server crash with only a loop

He never states that not using wait will crash it all the time. Read the definition of infinte loop. Removing Wait action doesn’t always make it infinite. In fact, the loop can still be infinte even if it has a Wait action.

3 Likes

Whatever man, I give up. You are not reading what I’m saying. Just leave it to someone who understands workshop.

1 Like

Working solution using a waitless loop: J61SW

2 Likes

:sweat_smile:

Just to clarify things:
Since there are 60 frames per second happening, each frame has around 0.016 seconds of time reserved. If the computing-time of all the workshop actions that are scheduled within one frame combined extend this time limit, the server might crash.
Since a loop has the potential to create a lot of actions for its relatively small code size, loops wich run without a wait action (they run within one frame) are a typical source of server performance issues.
Though the 0.016 seconds is a time frame that is usually large enough for most looping-operations.
For example, my bot-pathfinding algorithm has a loop wich is quite complex, even with a nested loop inside (don’t mind the O(n²) runtime complexity worst case, please; it should have a runtime complexity of O(x * n) if my mode is used in a practical way :wink:), but it runs smooth without wait actions within 1 frame.
It actually happened to crash the server, when 2 bots looped at the same time, so in the I needed to put a wait action inside of it.

But you see, in general you can try looping without a wait action first and if the loop then happens to crash your mode, you might try to input a wait action.

3 Likes

That’s very interesting!

Have you considered placing a limit on the number of actions per frame within a loop? It will extend computation time, but will also save resources. For example, within a large For loop do a modulo of some desired number of actions per frame, then when mod == 0 execute a wait operation. Should optimize the compute and spread resources over several frames instead of just one! :smiley:

Thanks for the info… but… just why… WHY did you have to necro this thread? :weary:

This is by far my worst thread on the forums.

1 Like

because they obviously wanted you and others to see your trashiest post on the forums, :kissing_heart:

1 Like