• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Determining Highest Value

Status
Not open for further replies.
Level 16
Joined
Mar 27, 2011
Messages
1,349
Use a high to low sorter.

I'm not sure what a sorter is. I know under "Math" there is a min and max value, but I'm not entirely sure how they work or how to sort a group of numbers.

Also, if anybody could tell me how to sort them, that would be great. That is, do I sort the highest custom value as 1 in an variable array? Or is there some other way? Not sure how to go about it.
 
Level 5
Joined
Nov 30, 2012
Messages
200
This is an incredibly crude way to do it:

  • Sort
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Random 1 units from (Units in (Playable map area))) and do (Actions)
        • Loop - Actions
          • Set FirstUnit = (Picked unit)
          • Set FirstUnitCustomValue = (Custom value of FirstUnit)
      • Unit Group - Pick every unit in (Random 1 units from (Units in (Playable map area))) and do (Actions)
        • Loop - Actions
          • Set SecondUnit = (Picked unit)
          • Set SecondUnitCustomValue = (Custom value of SecondUnit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • SecondUnit Equal to FirstUnit
        • Then - Actions
          • Trigger - Run (This trigger) (ignoring conditions)
          • Skip remaining actions
        • Else - Actions
      • Set CurrentHighestCustomValue = (Max(FirstUnitCustomValue, SecondUnitCustomValue))
      • Set LowestCustomValue = (Min(FirstUnitCustomValue, SecondUnitCustomValue))
      • Set X = (100.00 x (Real(CurrentHighestCustomValue)))
      • Unit - Move (Random unit from (Units in (Playable map area) matching ((Custom value of (Matching unit)) Equal to CurrentHighestCustomValue))) instantly to (Point(X, 0.00))
      • Unit - Move (Random unit from (Units in (Playable map area) matching ((Custom value of (Matching unit)) Equal to LowestCustomValue))) instantly to (Point((100.00 x (Real(LowestCustomValue))), 0.00))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Execution count of (This trigger)) Less than or equal to 100
        • Then - Actions
          • Trigger - Run (This trigger) (ignoring conditions)
        • Else - Actions
Maybe someone can improve this? I only wrote it because I thought it could be done in GUI, which apparently it can, just not to any degree near perfect or even good. Obviously, it wouldn't work if you had a lot of units as the amount of trials required might make the game lag. It has the small chance of error, too, I guess.
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
What exactly do you want to do? Pick a unit with the highest custom value? (Sorry I can't understand GUI very well)
 
Level 5
Joined
Nov 30, 2012
Messages
200
I made my thing so that it orders the units with the highest custom value and physically puts them in order.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
That is not very good to use.

@TO
how many unit are you trying to sort ?

Edit: I will try to make a template to be posted on hive that you can use. Give me about an hr or so.

Edit 2: It will be in jass but it is GUI friendly meaning that how you use it is easy in GUI and how to install it to your map is easy.

Edit3: Will take longer than expected i just got back on pc.

Edit4: Here is the link to the template. There is examples on how to use. And an explanation on how to use.
http://www.hiveworkshop.com/forums/spells-569/high-low-sorter-v-1-0-0-0-a-240626/
 
Last edited:
Level 12
Joined
Nov 20, 2007
Messages
660
You take the first value and set it as the Highest then you take the next value. If the value is higher then your Highest value you set Highest to the higher value.
Example:
You have the next numbers : 1 3 2 and the variable var_highest.
In the first step you set var_highest to 1.
Step 2, you compare var_highest to the next value (3).
3 is higher then var_highest (1) and you set var_highest to 3.
Next step you take number 2.
Compare to var_highest (3) and it's lower then it so it results that 3 is the highest value.
If you don't understand feel free to replay me.
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Sorry I haven't replied. Believe it or not, I've actually been scratching my head trying to implement your system. I know your system works because it ordered my units correctly in the "Demo Code".

Here is a modified Demo Code in which I set the units up.

  • DemoCode
    • Events
    • Conditions
    • Actions
      • Set F = 1
      • Unit - Set the custom value of Ryu 0000 <gen> to 5
      • Unit - Set the custom value of Rand 0008 <gen> to 4
      • Unit - Set the custom value of Bow 0005 <gen> to 3
      • Unit - Set the custom value of Nina 0007 <gen> to 6
      • Unit Group - Pick every unit in Figh_All_Units_Group and do (Actions)
        • Loop - Actions
          • Set h2LSorterUnitArray[F] = (Picked unit)
          • Set F = (F + 1)
      • Set F = 1
      • -------- The minimum value is the lowest key value that you use in the array. Example: I used tempInt from 1 to 10. The minimum value is 1. --------
      • Set h2LMinValue = 1
      • -------- The maximum value is the highest key value that you use in the array. Example: I used tempInt from 1 to 10. The maximum value is 1. --------
      • Set h2LMaxValue = h2LMaxValue
      • -------- Then you call the sorter function --------
      • Custom script: call H2LCustomValueSorter()
      • -------- After that is called you can use the data. The array for high to low is sorted in here. --------
      • -------- It is keyed to the units custom value and it stores the placement number in the integer array. Example: If h2LReturnedPlacementH2L[ 5] == 1 then it is in first. If h2LReturnedPlacementH2L[ 200] is 1 it is in first. --------
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • -------- You can display which unit is in first second and so on using this. --------
          • Game - Display to (All players) for 30.00 seconds the text: (Name of h2LSorterUnitArray[(Integer A)])
          • Game - Display to (All players) for 30.00 seconds the text: (String(h2LReturnedPlacementH2L[(Custom value of h2LSorterUnitArray[(Integer A)])]))
Here's my second trigger which isn't working. It doesn't seem to be referencing the units at all.

  • Commence Fight 2
    • Events
    • Conditions
    • Actions
      • Game - Display to (All players) for 5.00 seconds the text: (Fighting Unit: + (Name of h2LSorterUnitArray[h2LReturnedPlacementH2L[(Custom value of h2LSorterUnitArray[F])]]))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Fight_Enemy_Group) Greater than or equal to 1
          • (Number of units in Party_Group) Greater than or equal to 1
          • (Fight_Source_Unit[F] is alive) Equal to True
          • (Fight_Targeted_Enemy[F] is alive) Equal to True
        • Then - Actions
          • Game - Display to (All players) for 5.00 seconds the text: Conditions Passed.....
          • Animation - Play h2LSorterUnitArray[h2LReturnedPlacementH2L[(Custom value of h2LSorterUnitArray[F])]]'s attack animation
          • Animation - Queue h2LSorterUnitArray[h2LReturnedPlacementH2L[(Custom value of h2LSorterUnitArray[F])]]'s stand animation
          • Unit - Cause h2LSorterUnitArray[h2LReturnedPlacementH2L[(Custom value of h2LSorterUnitArray[F])]] to damage Fight_Targeted_Enemy[F], dealing 100.00 damage of attack type Normal and damage type Normal
          • Special Effect - Create a special effect attached to the origin of Fight_Targeted_Enemy[F] using Abilities\Spells\Undead\AnimateDead\AnimateDeadTarget.mdl
          • Special Effect - Destroy (Last created special effect)
          • Set F = (F + 1)
          • Wait 3.00 seconds
          • Trigger - Run Commence Fight 2 <gen> (checking conditions)
        • Else - Actions
The message says "Fighting Unit: "

It returns a blank space. What am I Doing wrong?
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Lol oops. But still not working. I don't know if you can be bothered, but I'm going to post my whole system and see if anybody is interested in helping. Its simply not working for me :(

I am creating a turn based fighting system. I'm basically replicating a game called "Breath of Fire", I doubt anyone has played it though.

The problem is, the unit's don't take their turns in the correct order. One unit doesn't even display a name on message? Maybe this turn based system is not possible. Maybe I should give up :(

  • Count Distance
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Set WalkPoint1 = WalkPoint2
      • Set WalkPoint2 = (Position of Party_Order[1])
      • Set WalkAmount = (WalkAmount + (Distance between WalkPoint1 and WalkPoint2))
      • Custom script: call RemoveLocation (udg_WalkPoint1)
      • Custom script: set udg_WalkPoint1=null
  • Encounter
    • Events
      • Game - WalkAmount becomes Greater than or equal to 900.00
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • WalkAmount Greater than or equal to WalkAmountRandomReal
        • Then - Actions
          • Game - Display to (All players) for 5.00 seconds the text: (String(WalkAmount))
          • Set WalkAmount = 0.00
          • Set WalkAmountRandomReal = (Random real number between 900.00 and 1900.00)
          • Sound - Play Enemy_Encountered <gen>
          • Cinematic - Fade out and back in over 2.10 seconds using texture Black Mask and color (0.00%, 0.00%, 0.00%) with 0.00% transparency
          • Trigger - Run Fight Setup <gen> (checking conditions)
          • Trigger - Turn off Count Distance <gen>
        • Else - Actions
  • Fight Setup
    • Events
    • Conditions
    • Actions
      • Set Fight_Unit_Pending = Party_Order[1]
      • Set F = 1
      • Selection - Select Fight_Unit_Pending for Player 1 (Red)
      • Unit Group - Pick every unit in Party_Group and do (Actions)
        • Loop - Actions
          • Unit - Move (Picked unit) instantly to (Center of Battle 1 Alliance <gen>), facing (Center of Battle 1 Enemies <gen>)
          • Unit - Set (Picked unit) movement speed to 0.00
      • Camera - Apply BattleScene1 <gen> for Player 1 (Red) over 0.00 seconds
      • Camera - Lock camera target for Player 1 (Red) to Fight_Camera_Unit[1], offset by (0.00, 0.00) using Default rotation
      • Unit - Create 1 Furbolg Ursa Warrior for Player 12 (Brown) at (Center of Battle 1 Enemies <gen>) facing (Center X of Battle 1 Alliance <gen>) degrees
      • Unit Group - Add (Last created unit) to Fight_Enemy_Group
      • Unit Group - Add all units of Fight_Enemy_Group to Figh_All_Units_Group
      • Unit Group - Add all units of Party_Group to Figh_All_Units_Group
      • Unit Group - Add (Last created unit) to Fight_Enemy_Group
      • Unit - Set the custom value of (Last created unit) to 2
      • Unit - Set (Last created unit) movement speed to 0.00
      • -------- -------------- --------
      • -------- Start Sort Code --------
      • -------- -------------- --------
      • Trigger - Run DemoCode <gen> (checking conditions)
      • -------- -------------- --------
      • -------- End Sort Code --------
      • -------- -------------- --------
      • Wait 1.00 seconds
      • Sound - Play Breath_of_Fire_II_SNES_OST_Cross_Counter <gen>
  • DemoCode
    • Events
    • Conditions
    • Actions
      • Set F = 1
      • Unit - Set the custom value of Ryu 0000 <gen> to 5
      • Unit - Set the custom value of Rand 0008 <gen> to 4
      • Unit - Set the custom value of Bow 0005 <gen> to 3
      • Unit - Set the custom value of Nina 0007 <gen> to 6
      • Unit Group - Pick every unit in Figh_All_Units_Group and do (Actions)
        • Loop - Actions
          • Set h2LSorterUnitArray[F] = (Picked unit)
          • Set F = (F + 1)
      • Set F = 1
      • -------- The minimum value is the lowest key value that you use in the array. Example: I used tempInt from 1 to 10. The minimum value is 1. --------
      • Set h2LMinValue = 1
      • -------- The maximum value is the highest key value that you use in the array. Example: I used tempInt from 1 to 10. The maximum value is 1. --------
      • Set h2LMaxValue = (Number of units in Figh_All_Units_Group)
      • -------- Then you call the sorter function --------
      • Custom script: call H2LCustomValueSorter()
      • -------- After that is called you can use the data. The array for high to low is sorted in here. --------
      • -------- It is keyed to the units custom value and it stores the placement number in the integer array. Example: If h2LReturnedPlacementH2L[ 5] == 1 then it is in first. If h2LReturnedPlacementH2L[ 200] is 1 it is in first. --------
      • For each (Integer A) from 1 to h2LMaxValue, do (Actions)
        • Loop - Actions
          • -------- You can display which unit is in first second and so on using this. --------
          • Game - Display to (All players) for 30.00 seconds the text: (Name of h2LSorterUnitArray[(Integer A)])
          • Game - Display to (All players) for 30.00 seconds the text: (String(h2LReturnedPlacementH2L[(Custom value of h2LSorterUnitArray[(Integer A)])]))
  • Que Orders
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • (Triggering unit) Equal to Fight_Unit_Pending
    • Actions
      • Game - Display to (All players) for 5.00 seconds the text: (((Name of Fight_Unit_Pending) + (Ordered Unit): ) + (String(F)))
      • Unit - Order (Triggering unit) to Stop
      • Set Fight_Targeted_Enemy[F] = (Target unit of issued order)
      • Set Fight_Source_Unit[F] = (Triggering unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Issued order) Equal to (Order(attack))
        • Then - Actions
          • Set Fight_Basic_Attack[F] = True
        • Else - Actions
      • Unit - Change ownership of Fight_Unit_Pending to Player 9 (Gray) and Change color
      • Set F = (F + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • F Less than or equal to 4
        • Then - Actions
          • Set Fight_Unit_Pending = Party_Order[F]
          • Unit - Change ownership of Fight_Unit_Pending to Player 1 (Red) and Change color
          • Selection - Select Fight_Unit_Pending for Player 1 (Red)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • F Equal to 5
        • Then - Actions
          • Set F = 1
          • Game - Display to (All players) for 5.00 seconds the text: (Fighting Unit: + (Name of h2LSorterUnitArray[h2LReturnedPlacementH2L[1]]))
          • Wait 2.00 seconds
          • Trigger - Run Commence Fight 2 <gen> (checking conditions)
          • Trigger - Turn off (This trigger)
        • Else - Actions
  • Commence Fight 2
    • Events
    • Conditions
    • Actions
      • Game - Display to (All players) for 30.00 seconds the text: (Fighting Unit: + (Name of h2LSorterUnitArray[h2LReturnedPlacementH2L[(Custom value of h2LSorterUnitArray[F])]]))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Fight_Enemy_Group) Greater than or equal to 1
          • (Number of units in Party_Group) Greater than or equal to 1
          • (Fight_Source_Unit[F] is alive) Equal to True
          • (Fight_Targeted_Enemy[F] is alive) Equal to True
        • Then - Actions
          • Game - Display to (All players) for 30.00 seconds the text: Conditions Passed.....
          • Animation - Play h2LSorterUnitArray[h2LReturnedPlacementH2L[(Custom value of h2LSorterUnitArray[F])]]'s attack animation
          • Animation - Queue h2LSorterUnitArray[h2LReturnedPlacementH2L[(Custom value of h2LSorterUnitArray[F])]]'s stand animation
          • Unit - Cause h2LSorterUnitArray[h2LReturnedPlacementH2L[(Custom value of h2LSorterUnitArray[F])]] to damage Fight_Targeted_Enemy[F], dealing 100.00 damage of attack type Normal and damage type Normal
          • Special Effect - Create a special effect attached to the origin of Fight_Targeted_Enemy[F] using Abilities\Spells\Undead\AnimateDead\AnimateDeadTarget.mdl
          • Special Effect - Destroy (Last created special effect)
          • Set F = (F + 1)
          • Wait 3.00 seconds
          • Trigger - Run Commence Fight 2 <gen> (checking conditions)
        • Else - Actions
Note: The system hasn't been coded past Commence Fight 2.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
  • DemoCode
    • Events
    • Conditions
    • Actions
      • Set F = 1
      • Unit - Set the custom value of Ryu 0000 <gen> to 5
      • Unit - Set the custom value of Rand 0008 <gen> to 4
      • Unit - Set the custom value of Bow 0005 <gen> to 3
      • Unit - Set the custom value of Nina 0007 <gen> to 6
      • Unit Group - Pick every unit in Figh_All_Units_Group and do (Actions)
        • Loop - Actions
          • Set h2LSorterUnitArray[F] = (Picked unit)
          • Set F = (F + 1)
      • Set F = 1
      • -------- The minimum value is the lowest key value that you use in the array. Example: I used tempInt from 1 to 10. The minimum value is 1. --------
      • Set h2LMinValue = 1
      • -------- The maximum value is the highest key value that you use in the array. Example: I used tempInt from 1 to 10. The maximum value is 1. --------
      • Set h2LMaxValue = (Number of units in Figh_All_Units_Group)
      • -------- Then you call the sorter function --------
      • Custom script: call H2LCustomValueSorter()
      • -------- After that is called you can use the data. The array for high to low is sorted in here. --------
      • -------- It is keyed to the units custom value and it stores the placement number in the integer array. Example: If h2LReturnedPlacementH2L[ 5] == 1 then it is in first. If h2LReturnedPlacementH2L[ 200] is 1 it is in first. --------
      • For each (Integer A) from 1 to h2LMaxValue, do (Actions)
        • Loop - Actions
          • -------- You can display which unit is in first second and so on using this. --------
          • Game - Display to (All players) for 30.00 seconds the text: (Name of h2LSorterUnitArray[(Integer A)])
          • Game - Display to (All players) for 30.00 seconds the text: (String(h2LReturnedPlacementH2L[(Custom value of h2LSorterUnitArray[(Integer A)])]))
  • DemoCode
    • Events
    • Conditions
    • Actions
      • Set F = 1
      • Unit - Set the custom value of Ryu 0000 <gen> to 5
      • Unit - Set the custom value of Rand 0008 <gen> to 4
      • Unit - Set the custom value of Bow 0005 <gen> to 3
      • Unit - Set the custom value of Nina 0007 <gen> to 6
      • -------- Are these units above added to the group ??????? --------
      • Unit Group - Pick every unit in Figh_All_Units_Group and do (Actions)
        • Loop - Actions
          • Set h2LSorterUnitArray[F] = (Picked unit)
          • Set F = (F + 1)
      • -------- The minimum value is the lowest key value that you use in the array. Example: I used tempInt from 1 to 10. The minimum value is 1. --------
      • Set h2LMinValue = 1
      • -------- The maximum value is the highest key value that you use in the array. Example: I used tempInt from 1 to 10. The maximum value is 1. --------
      • Set h2LMaxValue = F
      • -------- Set f to one again. --------
      • Set F = 1
      • -------- Then you call the sorter function --------
      • Custom script: call H2LCustomValueSorter()
      • -------- After that is called you can use the data. The array for high to low is sorted in here. --------
      • -------- It is keyed to the units custom value and it stores the placement number in the integer array. Example: If h2LReturnedPlacementH2L[ 5] == 1 then it is in first. If h2LReturnedPlacementH2L[ 200] is 1 it is in first. --------
      • Unit Group - Pick every unit in Figh_All_Units_Group and do (Actions)
        • Loop - Actions
          • Set F = custom value of picked unit
          • -------- You can display which unit is in first second and so on using this. --------
          • Game - Display to (All players) for 30.00 seconds the text: (Name of h2LSorterUnitArray[F])
          • Game - Display to (All players) for 30.00 seconds the text: (String(h2LReturnedPlacementH2L[F]))
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
According to this image, the order of which the units should move appears to be reversed. However, if this is true, why is the Furbolg last? It has the lowest custom value. If it were reversed, he should be first.

attachment.php


Custom Values:

Nina: 6
Ryu: 5
Rand: 4
Bow: 3
Furbolg Warrior: 2
 

Attachments

  • Order Executed.jpg
    Order Executed.jpg
    149 KB · Views: 139
Status
Not open for further replies.
Top