Simple way to setup highest / lowest values from an array?

So, kind of like a lot of things, I may have realized a possible solution as I came here to type something like a lot of other things I have figured out, but I am dumb and curious if there was a simple way to do this within one action.

Bit of a summary idea of what I am doing and want:
Is there a simple way to grab highest / lowest values from a specified filtered array of all players to a specific player variable? (yeah idk how to word this).

There is a player level variable. Let’s say we have 3 players, level 5, level 40, and level 100. I have a bot I want to spawn, also with a level, but only in a random range of the human player with the lowest level and the player with the highest (multiplied a small amount, like 1.15 x more than the player with the highest level, so the bot can spawn up to level 115 if there is a level 100). I am also using min/max to be able to set minimum and maximum possible values this will output so it doesn’t get too high, that part I already understand.
Is there an easy way to be able to grab these values without having to setup another rule that is creating a separate array in a different variable? Like what can I do so I can just use “current array element” within a filtered array? And keep in mind, I need to only grab this value from human players, so we got to exclude bot players (with either “is dummy bot” or a specified bot variable) from a filtered array.

I have made something that does seem to work the way I want, but as soon as another player joins in, it only cares about the newly joined player’s level, no matter what level they are, or what slot they are in, it ignores the player’s level who was in before they joined.

Here it is, I already know it’s wrong though. I may just be over thinking this.

actions
{
	Event Player.level = Random Integer(Max(Min(First Of(Sorted Array(Filtered Array(All Players(All Teams),
		Current Array Element.bot == False).level * 0.600, Current Array Element.level)), 200), 1), Max(Min(Last Of(Sorted Array(
		Filtered Array(All Players(All Teams), Current Array Element.bot == False).level * 1.150, Current Array Element.level)), 500),
		35));
}

I am pretty sure it’s because of the way I am calling the filtered array within that level variable. It’s not actually an array? I think. It probably just lists one player but it’s also odd it ignores all but one player completely, but I’m not really sure how else I can grab the levels of players in that piece.

Using these min/max’s in the spots they are, to prevent it from going to 0 if there were no players loaded in yet or have a flat range, and to hard limit it so it doesn’t get too high of a level (for my mode).

This also might not be that great for an idea in the first place. It might be better to go for an average level of human players, which will still have this filtered array stuff involved that I want to figure out. If I need to make another global variable for it that’s fine, but I don’t even know a proper way to set that up either atm, but I do have ideas.

THX

I believe the cause of your problem is order of execution, you’re multiplying the player level prior to actually having retrieved the correct players variable from the Array.
Usually when the game doesn’t handle an array it simply takes the first value from the array.
So you’re always multiplying the player level from the first player in the array.

actions
{
	Event Player.level = Random Integer(Max(Min(First Of(Sorted Array(Filtered Array(All Players(All Teams), !Current Array Element.bot),
		Current Array Element.level)).level * 0.600, 1), 200), Max(Min(Last Of(Sorted Array(Filtered Array(All Players(All Teams),
		!Current Array Element.bot), Current Array Element.level)).level * 1.150, 500), 35));
}
1 Like

Alright, thank you for this. Looking at it now, at least that action snippet that I ended up putting in this post, I can def see that it is multiplying it before it even has a chance to sort it. Somehow that flew over my head.

Also had to swap min/max to make more sense for your solution, previous one I put made sense and worked because we were comparing the two numbers in that order correctly so it did what I wanted it to do, but swapping the order of execution around in your solution ended up being wrong for min/max, it was always outputting “200” for the random integer min, because it first compared min between 1 and then the player level, so it just always grabbed the smaller number of 1, then it compared max to 1 and 200, always grabbing the bigger number of 200. Moving some numbers around and swapping min/max fixes it and does what I expect it to do.

But yes, this does work now in the way I would expect it to with 2 players, one small level and a large level, bots output within the full range essentially (which like I said before I might just grab an average but this is great too).

actions
{
	Event Player.level = Random Integer(Min(Max(Last Of(Sorted Array(Filtered Array(All Players(All Teams),
		!Current Array Element.bot), Current Array Element.level)).level * 0.600, 1), 200), Min(Max(First Of(Sorted Array(
		Filtered Array(All Players(All Teams), !Current Array Element.bot), Current Array Element.level)).level * 1.150, 35), 500));
}

Thanks. Also thanks for reminding me I need to use ! (not) instead of just checking for False in things I do just to make it simpler lol.

Quick edit: Also needed to swap first of to last of, and vice versa, which was just an already existing problem I didn’t notice until now, since the way it sorts it is the other way around from what I thought lol (updated the code above).

1 Like