• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Special Indexing

Level 3
Joined
Feb 28, 2025
Messages
11
Hey there,

I'm currently working on my Assistance System for a Moba-Typed Map. The Assistance systems out there doesn't fit my needs so i began to code one myself.
I managed to fulfill all my needs and coded it bugless. The only thing I'm questioning is about my Indexing.
For you to understand I'll explain how my System works:

First of all there are only 10 playing Players. 5 playing Players for each Force (Force 1, Force 2).
Player 1 (Bot), Player 2, Player 3, Player 4, Player 5, Player 6 belongs to Force 1
and the rest to Force 2.

Now my indexing looks like this:
If Player 1 attacks Player 8 => Index = 18
If Player 1 attacks Player 9 => Index = 19
If Player 1 attacks Player 10 => Index = 110
If Player 1 attacks Player 11 => Index = 111
If Player 1 attacks Player 12 => Index = 112

If Player 2 attacks Player 8 => Index = 28
...

Now for this indexing method a problem appears:
If Player 11 attacks Player 2 => Index = 112

Its the same Index as for Player 1 attacks Player 12. So they share the same Timer.
I managed to fix it, through giving Player 11 a Custom Player Number 14. But this solution isn't quite beautiful.


So back to topic: this means every Player can have 5 maximum Timer.

Why I indexed it like this?
Because I need a unique Number depending to the DamageSource and the DamageTarget.
So after a hero or unit damages an enemy hero, which was damaged before from the same player the specific Timer just refreshes.

An simply Indexing wouldn't work for my special usecase. When I always count Index +1, I would have to many Timers but the Timers should be limited to 5 for each Player.

So my question is: Do you know a better Indexing for this Usecase?
 
Level 3
Joined
Feb 28, 2025
Messages
11
Could you add a zero for numbers below 10?

P1 vs P12 -> 0112
P11 vs P2 -> 1102

Edit: although I guess it doesn't work with integers, I assume the game turns 01 to 1

Unfortunately it wouldn't work since I'm referring to Player Numbers.
And also the term "0112" is a string type which i can't use for Indexing.
If I convert it into an Int it gets "112" again.

Tho it would be a much more beautiful solution as mine if it would be possible. :grin:
 
We can treat it as a grid of size 12 by 12 where the first index corresponds to the source player while the second index corresponds to the target player. Since v/JASS wc3 only accepts 1-D arrays, this can be implemented as follows:

targetIndex = 12*(sourcePlayerId) + (targetPlayerId) + indexOffset

Given that the maximum array size of an array variable is 32,768 (8,192 for versions below 1.29), the index scheme above should well be within the array size limit.

=======================

Alternatively, considering that we have 2 forces, we can go for a 2 by 6 by 6 grid, giving us 72 indices to work with, instead of 144.

Code:
targetIndex = 36*(teamIndex) + 6*(sourcePlayerId) + (targetPlayerId) + indexOffset

While a bit more complex than the first, this uses up fewer indices (though this should be negligible). You'll have to alter both sourcePlayerId and targetPlayerId slightly, but it shouldn't be too complex.

You'll have to implement the pseudocode below before getting the target index.
Code:
teamIndex = sourcePlayerId / 6
sourcePlayerId = sourcePlayerId % 6
targetPlayerId = targetPlayerId % 6
 
Top