Moderator
M
Moderator
11:57, 22nd Nov 2013
Purgeandfire: Approved. still uses bubble sort, but it is functional.
Purgeandfire: Approved. still uses bubble sort, but it is functional.
// High to low sorter Template by deathismyfriend
// Thanks to Maker for showing me how to do these.
// version 1.0.2.5
// FUNCTION LIST
//
//
// THIS IS HOW TO USE EVERY FUNCTION
// Example on how to use.
// Put the units into the unit array. h2LSorterUnitArray[ key]
// Then set the minimum value to the min key value.
// Then set the maximum value to the max key value.
// call the function you want using the custom script.
// Then the values will be sorted from high to low. You can use these values by using the integer stored in the integer array.
// H2LReturnedPlacementH2L[ key]
// the key is the units custom value. The value loaded is an integer value telling the place of the unit.
//
//
//
// HIGH TO LOW SORTER BASED ON HIGHEST CUSTOM VALUE
// This function returns high to low values based on which unit has the highest custom value.
// Custom script: call H2LCustomValueSorter()
//
//
// HIGH TO LOW SORTER BASED ON HIGHEST STATS
// This function returns high to low values based on which unit has the highest stats.
// // Example: Agi + Str + Intel
// Custom script: call H2LStatsSorter( boolean)
// The boolean tells whether or not you want to include bonus stats.
//
//
// HIGH TO LOW SORTER BASED ON HIGHEST AGILITY
// This function returns high to low values based on which unit has the highest Agi.
// Custom script: call H2LAgiSorter( boolean)
// The boolean tells whether or not you want to include bonus stats.
//
//
// HIGH TO LOW SORTER BASED ON HIGHEST INTELIGENCE
// This function returns high to low values based on which unit has the highest Agi.
// Custom script: call H2LIntSorter( boolean)
// The boolean tells whether or not you want to include bonus stats.
//
//
// HIGH TO LOW SORTER BASED ON HIGHEST STRENGTH
// This function returns high to low values based on which unit has the highest Str.
// Custom script: call H2LStrSorter( boolean)
// The boolean tells whether or not you want to include bonus stats.
//
//
// HIGH TO LOW SORTER BASED ON HIGHEST LEVEL
// This function returns high to low values based on which unit has the highest level.
// Custom script: call H2LLevelSorter()
//
//
// HIGH TO LOW SORTER BASED ON HIGHEST REMAINING / MAX HEALTH
// This function returns high to low values based on which unit has the highest remaining / max health.
// Custom script: call H2LHealthSorter( boolean)
// The boolean tells whether or not you want to compare max health or remaining health.
// True means remaining health
//
//
// HIGH TO LOW SORTER BASED ON HIGHEST REMAINING / MAX MANA
// This function returns high to low values based on which unit has the highest remaining / max mana.
// Custom script: call H2LManaSorter( boolean)
// The boolean tells whether or not you want to compare max mana or remaining mana.
// True means remaining mana
//
//
// HIGH TO LOW SORTER BASED ON HIGHEST REMAINING / MAX MANA AND / OR HEALTH
// This function returns high to low values based on which unit has the highest remaining / max mana and / or health.
// Custom script: call H2LHealthManaSorter( boolean, boolean)
// The first boolean tells whether or not you want to compare max health or remaining health.
// True means remaining health.
// The second boolean tells whether or not you want to compare max mana or remaining mana.
// True means remaining mana.
//
//
// HIGH TO LOW SORTER BASED ON INTEGERS MUI
// This function returns high to low values based on which unit has the highest integer.
// By highest integer this is specialized stats like kills / deaths / score / damage done by unit / whatever else you can think of.
// Custom script: call H2LIntegerMUISorter()
// The integer values for kills or whatever you want needs to be stored into the h2LSorterIntegerArray variable.
//
//
// HIGH TO LOW SORTER BASED ON INTEGERS MPI
// This function returns high to low values based on which player has the highest integer.
// This is for displaying which player has the highest.
// By highest integer this is specialized stats like kills / deaths / score / damage done by player / whatever else you can think of.
// Custom script: call H2LIntegerMPISorter()
// The integer values for kills or whatever you want needs to be stored into the h2LSorterIntegerArray variable.
// The integer for players will be taken from the key. This means that you should store the things for player one red into the right keyed variable.
// // Example: h2LSorterIntegerArray[ 1] = score and so on. You can use player number of player also.
// For this make sure the min value is one unless player 1 does not exist in your game.
//
//
// HIGH TO LOW SORTER BASED ON REALS MUI
// This function returns high to low values based on which unit has the highest integer.
// By highest integer this is specialized stats like damage done by unit / damage done to a unit / whatever else you can think of.
// Custom script: call H2LRealMUISorter()
// The integer values for kills or whatever you want needs to be stored into the h2LSorterRealArray variable.
//
//
// HIGH TO LOW SORTER BASED ON REALS MPI
// This function returns high to low values based on which player has the highest integer.
// This is for displaying which player has the highest.
// By highest integer this is specialized stats like damage done by player / damage dont to a player / whatever else you can think of.
// Custom script: call H2LRealMPISorter()
// The integer values for kills or whatever you want needs to be stored into the h2LSorterRealArray variable.
// The integer for players will be taken from the key. This means that you should store the things for player one red into the right keyed variable.
// // Example: h2LSorterRealArray[ 1] = score and so on. You can use player number of player also.
// For this make sure the min value is one unless player 1 does not exist in your game.
//
//
function H2LSortingFunction1 takes nothing returns nothing
//it is easier to read with locals
local integer start = udg_h2LMinValue
local integer curr = start + 1
local integer end = udg_h2LMaxValue
local integer temp
local integer L = start
// This loop sorts those integers in order from highest to lowest.
loop
if udg_h2LGlobalInt1[ start] < udg_h2LGlobalInt1[ curr] then
set temp = udg_h2LGlobalInt1[ start]
set udg_h2LGlobalInt1[ start] = udg_h2LGlobalInt1[ curr]
set udg_h2LGlobalInt1[ 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
// This loop returns the units placement in an array keyed to that units custom value.
loop
exitwhen L > end
set udg_h2LReturnedPlacementH2L[ udg_h2LGlobalInt1[ L]] = L
set L = L + 1
endloop
endfunction
function H2LSortingFunction2 takes nothing returns nothing
//it is easier to read with locals
local integer start = udg_h2LMinValue
local integer curr = start + 1
local integer end = udg_h2LMaxValue
local integer temp1
local integer temp2
local integer L = start
// This loop sorts those integers in order from highest to lowest.
loop
if udg_h2LGlobalInt2[ start] < udg_h2LGlobalInt2[ curr] then
set temp1 = udg_h2LGlobalInt1[ start]
set temp2 = udg_h2LGlobalInt2[ start]
set udg_h2LGlobalInt1[ start] = udg_h2LGlobalInt1[ curr]
set udg_h2LGlobalInt2[ start] = udg_h2LGlobalInt2[ curr]
set udg_h2LGlobalInt1[ curr] = temp1
set udg_h2LGlobalInt2[ curr] = temp2
endif
exitwhen start == end - 1
if curr == end then
set curr = start + 2
set start = start + 1
else
set curr = curr + 1
endif
endloop
// This loop returns the units placement in an array keyed to that units custom value.
loop
exitwhen L > end
set udg_h2LReturnedPlacementH2L[ udg_h2LGlobalInt1[ L]] = L
set L = L + 1
endloop
endfunction
function H2LSortingFunction3 takes nothing returns nothing
//it is easier to read with locals
local integer start = udg_h2LMinValue
local integer curr = start + 1
local integer end = udg_h2LMaxValue
local integer temp1
local real temp2
local integer L = start
// This loop sorts those integers in order from highest to lowest.
loop
if udg_h2LGlobalReal[ start] < udg_h2LGlobalReal[ curr] then
set temp1 = udg_h2LGlobalInt1[ start]
set temp2 = udg_h2LGlobalReal[ start]
set udg_h2LGlobalInt1[ start] = udg_h2LGlobalInt1[ curr]
set udg_h2LGlobalReal[ start] = udg_h2LGlobalReal[ curr]
set udg_h2LGlobalInt1[ curr] = temp1
set udg_h2LGlobalReal[ curr] = temp2
endif
exitwhen start == end - 1
if curr == end then
set curr = start + 2
set start = start + 1
else
set curr = curr + 1
endif
endloop
// This loop returns the units placement in an array keyed to that units custom value.
loop
exitwhen L > end
set udg_h2LReturnedPlacementH2L[ udg_h2LGlobalInt1[ L]] = L
set L = L + 1
endloop
endfunction
function H2LCustomValueSorter takes nothing returns nothing
local integer L = udg_h2LMinValue
// this loop places the units custom values into an array.
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = GetUnitUserData( udg_h2LSorterUnitArray[ L])
set L = L + 1
endloop
call H2LSortingFunction1()
endfunction
function H2LStatsSorter takes boolean bonuses returns nothing
local integer L = udg_h2LMinValue
local unit u // This is here because it is easier to read rather than with the huge unit name
// this loop places the units custom values into an array.
loop
exitwhen L > udg_h2LMaxValue
set u = udg_h2LSorterUnitArray[ L]
set udg_h2LGlobalInt1[ L] = GetUnitUserData( u)
set udg_h2LGlobalInt2[ L] = GetHeroAgi( u,bonuses) + GetHeroInt( u,bonuses) + GetHeroStr( u,bonuses)
set L = L + 1
endloop
call H2LSortingFunction2()
set u = null
endfunction
function H2LAgiSorter takes boolean bonuses returns nothing
local integer L = udg_h2LMinValue
// this loop places the units custom values into an array.
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = GetUnitUserData( udg_h2LSorterUnitArray[ L])
set udg_h2LGlobalInt2[ L] = GetHeroAgi( udg_h2LSorterUnitArray[ L], bonuses)
set L = L + 1
endloop
call H2LSortingFunction2()
endfunction
function H2LIntSorter takes boolean bonuses returns nothing
local integer L = udg_h2LMinValue
// this loop places the units custom values into an array.
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = GetUnitUserData( udg_h2LSorterUnitArray[ L])
set udg_h2LGlobalInt2[ L] = GetHeroInt( udg_h2LSorterUnitArray[ L], bonuses)
set L = L + 1
endloop
call H2LSortingFunction2()
endfunction
function H2LStrSorter takes boolean bonuses returns nothing
local integer L = udg_h2LMinValue
// this loop places the units custom values into an array.
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = GetUnitUserData( udg_h2LSorterUnitArray[ L])
set udg_h2LGlobalInt2[ L] = GetHeroStr( udg_h2LSorterUnitArray[ L], bonuses)
set L = L + 1
endloop
call H2LSortingFunction2()
endfunction
function H2LLevelSorter takes nothing returns nothing
local integer L = udg_h2LMinValue
// this loop places the units custom values into an array.
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = GetUnitUserData( udg_h2LSorterUnitArray[ L])
set udg_h2LGlobalInt2[ L] = GetHeroLevel( udg_h2LSorterUnitArray[ L])
set L = L + 1
endloop
call H2LSortingFunction2()
endfunction
function H2LHealthSorter takes boolean remaining returns nothing
local integer L = udg_h2LMinValue
if remaining then
// this loop places the units custom values into an array using the units remaining health.
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = GetUnitUserData( udg_h2LSorterUnitArray[ L])
set udg_h2LGlobalReal[ L] = GetWidgetLife( udg_h2LSorterUnitArray[ L])
set L = L + 1
endloop
else
// this loop places the units custom values into an array using the units remaining health
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = GetUnitUserData( udg_h2LSorterUnitArray[ L])
set udg_h2LGlobalReal[ L] = GetUnitState( udg_h2LSorterUnitArray[ L], UNIT_STATE_MAX_LIFE)
set L = L + 1
endloop
endif
call H2LSortingFunction3()
endfunction
function H2LManaSorter takes boolean remaining returns nothing
local integer L = udg_h2LMinValue
if remaining then
// this loop places the units custom values into an array using the units remaining health.
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = GetUnitUserData( udg_h2LSorterUnitArray[ L])
set udg_h2LGlobalReal[ L] = GetUnitState( udg_h2LSorterUnitArray[ L], UNIT_STATE_MANA)
set L = L + 1
endloop
else
// this loop places the units custom values into an array using the units remaining health
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = GetUnitUserData( udg_h2LSorterUnitArray[ L])
set udg_h2LGlobalReal[ L] = GetUnitState( udg_h2LSorterUnitArray[ L], UNIT_STATE_MAX_MANA)
set L = L + 1
endloop
endif
call H2LSortingFunction3()
endfunction
function H2LHealthManaSorter takes boolean remHealth, boolean remMana returns nothing
local integer L = udg_h2LMinValue
if remHealth then
// this loop places the units custom values into an array using the units remaining health.
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = GetUnitUserData( udg_h2LSorterUnitArray[ L])
set udg_h2LGlobalReal[ L] = GetWidgetLife( udg_h2LSorterUnitArray[ L])
if remMana then
set udg_h2LGlobalReal[ L] = udg_h2LGlobalReal[ L] + GetUnitState( udg_h2LSorterUnitArray[ L], UNIT_STATE_MANA)
else
set udg_h2LGlobalReal[ L] = udg_h2LGlobalReal[ L] + GetUnitState( udg_h2LSorterUnitArray[ L], UNIT_STATE_MAX_MANA)
endif
set L = L + 1
endloop
else
// this loop places the units custom values into an array using the units remaining health
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = GetUnitUserData( udg_h2LSorterUnitArray[ L])
set udg_h2LGlobalReal[ L] = GetUnitState( udg_h2LSorterUnitArray[ L], UNIT_STATE_MAX_LIFE)
if remMana then
set udg_h2LGlobalReal[ L] = udg_h2LGlobalReal[ L] + GetUnitState( udg_h2LSorterUnitArray[ L], UNIT_STATE_MANA)
else
set udg_h2LGlobalReal[ L] = udg_h2LGlobalReal[ L] + GetUnitState( udg_h2LSorterUnitArray[ L], UNIT_STATE_MAX_MANA)
endif
set L = L + 1
endloop
endif
call H2LSortingFunction3()
endfunction
function H2LIntegerMUISorter takes nothing returns nothing
local integer L = udg_h2LMinValue
// this loop places the integers passed into the stats integer array and the custom value into i.
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = GetUnitUserData( udg_h2LSorterUnitArray[ L])
set udg_h2LGlobalInt2[ L] = udg_h2LSorterIntegerArray[ L]
set L = L + 1
endloop
call H2LSortingFunction2()
endfunction
function H2LIntegerMPISorter takes nothing returns nothing
local integer L = udg_h2LMinValue
// this loop places the integers passed into the stats integer array and the custom value into i.
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = L
set udg_h2LGlobalInt2[ L] = udg_h2LSorterIntegerArray[ L]
set L = L + 1
endloop
call H2LSortingFunction2()
endfunction
function H2LRealMUISorter takes nothing returns nothing
local integer L = udg_h2LMinValue
// this loop places the integers passed into the stats integer array and the custom value into i.
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = GetUnitUserData( udg_h2LSorterUnitArray[ L])
set udg_h2LGlobalReal[ L] = udg_h2LSorterRealArray[ L]
set L = L + 1
endloop
call H2LSortingFunction3()
endfunction
function H2LRealMPISorter takes nothing returns nothing
local integer L = udg_h2LMinValue
// this loop places the integers passed into the stats integer array and the custom value into i.
loop
exitwhen L > udg_h2LMaxValue
set udg_h2LGlobalInt1[ L] = L
set udg_h2LGlobalReal[ L] = udg_h2LSorterRealArray[ L]
set L = L + 1
endloop
call H2LSortingFunction3()
endfunction
function InitTrig_HighToLowSorterCode takes nothing returns nothing
endfunction