• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[General] Max and Min related issue

Status
Not open for further replies.
Level 2
Joined
Dec 19, 2012
Messages
11
Hello fellow Hiveworkshop members! Here is my problem:

Supose I have three units in a Unit Group. Each of them has its own Custom Value and there are some variables that have information of some of these unit's stats according to the unit's custom value.

Example:
Units_HP[1] = 10
Units_HP[2] = 15
Units_HP[3] = 20

And when I need to set the right HP amount on the right unit, I set it using the unit's custom value (i.e If the CV is 1, the HP is 10 and so on...)
Also, there is a variable called "Current HP" that measures how much hitpoints a unit has. It's also related to the unit's custom value and it can range from 0 to the amount determined by Units_HP.

The problem is I don't know much about the math of the World Editor. Of course I know that there are the Max and Min but I don't know how can I make a trigger to pick every unit in a specific unit group and analyse who has the higher value of "Current HP" and also put them in order like

Unit[1] = Unit with higher "Current HP"
Unit[2] = 2nd position unit with the higher "Current HP"
Unit[3] = The remaining

For my example, I would like to make a trigger that picks a unit group with 3 units.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
theres a function to get the unit's max hp... just..

set tempunit = null
pick every unit in (#) and do
if max hp of picked is greater than tempunit
set tempunit = #
endpick
 
Level 2
Joined
Dec 19, 2012
Messages
11
I dont want to use the unit's "HP" and "Mana" that are shown ingame. My units will all have a so much big number of HP that it wouldn't show and I don't want them to engane each other normally (the way warcraft 3 works). I'm doing a Turn Based Battle System's map and I will store everything on variables.

EDIT:
No need to reply, I figured out something and I will post here if it works.
 
Last edited:
Level 17
Joined
Nov 13, 2006
Messages
1,814
Hello fellow Hiveworkshop members! Here is my problem:

Supose I have three units in a Unit Group. Each of them has its own Custom Value and there are some variables that have information of some of these unit's stats according to the unit's custom value.

Example:
Units_HP[1] = 10
Units_HP[2] = 15
Units_HP[3] = 20

And when I need to set the right HP amount on the right unit, I set it using the unit's custom value (i.e If the CV is 1, the HP is 10 and so on...)
Also, there is a variable called "Current HP" that measures how much hitpoints a unit has. It's also related to the unit's custom value and it can range from 0 to the amount determined by Units_HP.

The problem is I don't know much about the math of the World Editor. Of course I know that there are the Max and Min but I don't know how can I make a trigger to pick every unit in a specific unit group and analyse who has the higher value of "Current HP" and also put them in order like

Unit[1] = Unit with higher "Current HP"
Unit[2] = 2nd position unit with the higher "Current HP"
Unit[3] = The remaining

For my example, I would like to make a trigger that picks a unit group with 3 units.

first of all dont use custom value for that, simple just use a indexer (spell section bribe gui damage engine), then set what u want with following methode:

another thing dont exist a single math function what compare with every value so u must do a check with loop
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
I dont want to use the unit's "HP" and "Mana" that are shown ingame. My units will all have a so much big number of HP that it wouldn't show and I don't want them to engane each other normally (the way warcraft 3 works). I'm doing a Turn Based Battle System's map and I will store everything on variables.

EDIT:
No need to reply, I figured out something and I will post here if it works.

thats only on the in-game interface. they dont show because the numbers too large to fit in that box. i modded my wc3 to a slimmer font and I can see numbers up to 999 billion

id also not recommend EVER using values that high because A) theyre hard as hell to balance B) you have little room for late-game content C) users cant see their hp/mp
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
first of all dont use custom value for that, simple just use a indexer (spell section bribe gui damage engine), then set what u want with following methode:

Actually the custom value is quite a good solution. Its faster than a hashtable lookup and easy to use. In fact most indexing systems internally use the custom value. The only limitation is that units only have one custom values, but if its a small map and you are sure you wont need it for other purposes its not a problem.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Actually the custom value is quite a good solution. Its faster than a hashtable lookup and easy to use. In fact most indexing systems internally use the custom value. The only limitation is that units only have one custom values, but if its a small map and you are sure you wont need it for other purposes its not a problem.

its slower than global lookup + it allows for use of indexer
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
its slower than global lookup + it allows for use of indexer

Clearly its slower than a global lookup, but a global lookup doesnt help with indexing units.

Indexing means you search for a Mapping "unit" -> "integer" so you can use the unit as index for arrays. Sure you can loop through a global array, but thats O(n) and muuuuch slower, both Hashtable and CustomValue lookup are O(1) while CustomValue has lower overhead.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
The problem is I don't know much about the math of the World Editor. Of course I know that there are the Max and Min but I don't know how can I make a trigger to pick every unit in a specific unit group and analyse who has the higher value of "Current HP" and also put them in order like
Refer to standard ordering algorthims. This is a common problem in computer science.

I would advise something like bubble sort. AVL trees can be faster but should not be nescescary in such a simple case.
 
Level 2
Joined
Dec 19, 2012
Messages
11
Response to Everone

shadowvzs
first of all dont use custom value for that, simple just use a indexer (spell section bribe gui damage engine), then set what u want with following methode:

another thing dont exist a single math function what compare with every value so u must do a check with loop

I could not find the system you told me about about.

About the math function, I know that. I think I must try comparing each value with the other ones by doing loops.

Arhowk
thats only on the in-game interface. they dont show because the numbers too large to fit in that box. i modded my wc3 to a slimmer font and I can see numbers up to 999 billion

id also not recommend EVER using values that high because A) theyre hard as hell to balance B) you have little room for late-game content C) users cant see their hp/mp

This is what I want. I want the place where the HP and Mana are to be entirely black because the combat between people on my map will not work the way warcraft 3 does. It would use its own formulas and be stored entirely on variables (I.E If a variable that measures how much HP a unit has reaches xero, it dies).

muzzel
Actually the custom value is quite a good solution. Its faster than a hashtable lookup and easy to use. In fact most indexing systems internally use the custom value. The only limitation is that units only have one custom values, but if its a small map and you are sure you wont need it for other purposes its not a problem.

I think the custom value suits my idea very well because I won't need it for any other purposes, as you said :D

Arhowk
its slower than global lookup + it allows for use of indexer

I could not understand very well what you said. The part of a Global Lookup I did and I could be telling that a don't need this on my map.

Dr Super Good
Refer to standard ordering algorthims. This is a common problem in computer science.

I would advise something like bubble sort. AVL trees can be faster but should not be nescescary in such a simple case.

What is a Bubble Sort and what is an AVL tree?

For Everyone:
This kind of System is needed for up of 8 values's comparison.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240

  • SortTest
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Cinematic - Clear the screen of text messages for Player Group - Player 1 (Red)
      • -------- ---------------------------------------- --------
      • -------- Set up array with source values --------
      • -------- ---------------------------------------- --------
      • For each (Integer A) from 1 to 8, do (Actions)
        • Loop - Actions
          • Set IAR[(Integer A)] = (Random integer number between 1 and 10)
      • -------- ---------------------------------------- --------
      • Trigger - Run PrintValues <gen> (ignoring conditions)
      • -------- ---------------------------------------- --------
      • -------- Shuffle values --------
      • -------- ---------------------------------------- --------
      • For each (Integer A) from 1 to 8, do (Actions)
        • Loop - Actions
          • Set ID = ((Integer A) + 8)
          • Set i = (Random integer number between (Integer A) and 8)
          • Set IAR[ID] = IAR[i]
          • Set IAR[i] = IAR[(Integer A)]
      • For each (Integer A) from 1 to 8, do (Actions)
        • Loop - Actions
          • Set IAR[(Integer A)] = IAR[((Integer A) + 8)]
      • -------- ---------------------------------------- --------
      • Trigger - Run PrintValues <gen> (ignoring conditions)
      • -------- ---------------------------------------- --------
      • -------- Sort values --------
      • -------- ---------------------------------------- --------
      • Trigger - Run Sorting <gen> (ignoring conditions)
      • Trigger - Run PrintValues <gen> (ignoring conditions)
  • PrintValues
    • Events
    • Conditions
    • Actions
      • Set s = <Empty String>
      • For each (Integer A) from 1 to 8, do (Actions)
        • Loop - Actions
          • Set s = (s + ((String(IAR[(Integer A)])) + -))
      • Game - Display to Player Group - Player 1 (Red) for 120.00 seconds the text: s
JASS:
function Trig_Sorting_Actions takes nothing returns nothing
    local integer start
    local integer end
    local integer curr
    local integer temp
    
    set start = 1
    set curr = 2
    set end = 8
    loop
        if udg_IAR[start] < udg_IAR[curr] then
            set temp = udg_IAR[start]
            set udg_IAR[start] = udg_IAR[curr]
            set udg_IAR[curr] = temp
        endif
        exitwhen start == end - 1
        if curr == end then
            set curr = start + 2
            set start = start + 1
        else
            set curr = curr + 1
        endif
    endloop
endfunction

//===========================================================================
function InitTrig_Sorting takes nothing returns nothing
    set gg_trg_Sorting = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Sorting, function Trig_Sorting_Actions )
endfunction


When you press ESC, it prints out three lines
Original values
Original values in shuffled order
Top-down sorted values

Here is where you would loop through the unit group and set up the array with units, set UnitArray[integerA] = picked unit.
  • -------- ---------------------------------------- --------
  • -------- Set up array with source values --------
  • -------- ---------------------------------------- --------
  • For each (Integer A) from 1 to 8, do (Actions)
    • Loop - Actions
      • Set IAR[(Integer A)] = (Random integer number between 1 and 10)
The shuffling and printing is just for testing purposes.

Here you would do the same, but with unit array. Temp variable would be unit, not integer
JASS:
if udg_IAR[start] < udg_IAR[curr] then
    set temp = udg_IAR[start]
    set udg_IAR[start] = udg_IAR[curr]
    set udg_IAR[curr] = temp
endif

The condition would be if GetWidgetLife(udg_MyArray[start]) < GetWidgetLife(udg_MyArray[curr]) then

If you want to further improve the code, use another array for the healths, to get rid of repeated GetWidgetLife calls.

A merge sorting algorithm could be a bit better, but with only 8 values, there's no need to go there.
 

Attachments

  • Sorting.w3x
    13.6 KB · Views: 47
Last edited:
Level 2
Joined
Dec 19, 2012
Messages
11
Maker, I really LOVE YOU! You helped me A LOT!!! You had all this work just to help me, I'm so thankfull for your help!
 
Status
Not open for further replies.
Top