Gtam
Lerning how to write and read!! Yeah.
- Reaction score
- 164
GetHeroMainAtt
By Gtam
This snippet will allow people to identify the main attribute of a hero.
Here is 2 snippets. You can choose which one you like.
Firts snippet: Uses ability detection
Second snippet: Uses groups to group heroes.
Hope its helpfull.
The test map has the Human heroes added to each snippet.
By Gtam
This snippet will allow people to identify the main attribute of a hero.
Here is 2 snippets. You can choose which one you like.
Firts snippet: Uses ability detection
JASS:
library HeroMainAttribute1
//==========================================================================================\\
//==========================================================================================\\
//== Hero Main Attribute: Sweet Flavor ==\\
//== HMA ==\\
//== By Gtam ==\\
//== ==\\
//== This is a little handy snippet that will beable to tell you heroes main attributes. ==\\
//== ==\\
//== Well as you probably know by know there is no function to tell you a heroes main ==\\
//== attribute. This is here to fix that. ==\\
//== This flavor uses abilities to tell the main attribute so its your job to make sure ==\\
//== that the correct abilities is added to the correct heroes. ==\\
//== Dont worry its pretty straight forward. ==\\
//== Step 1: Add the Ability "Str Hero" to all your strength heroes. ==\\
//== Step 2: Add the Ability "Agi Hero" to all your Agility heroes. ==\\
//== Step 3: Add the Ability "Int Hero" to all you Intelligence heroes. ==\\
//== Step 4: Configure the global variables to the correct raw codes ==\\
//== Step 5: Use this system to detect hero main atributes ==\\
//== ==\\
//== Functions ==\\
//== ==\\
//== function IsHeroStr takes unit hero returns boolean ==\\
//== returns true if hero strength and false if not ==\\
//== ==\\
//== function IsHeroAgi takes unit hero returns boolean ==\\
//== returns true if hero agility and false if not ==\\
//== ==\\
//== function IsHeroInt takes unit hero returns boolean ==\\
//== returns true if hero intelligence and false if not ==\\
//== ==\\
//== function GetHeroMainAtt takes unit hero, boolean flag returns integer ==\\
//== returns the Hero's main attribute amount ==\\
//== the boolean is if you want bonuses included ==\\
//== ==\\
//==========================================================================================\\
//==========================================================================================\\
globals
private constant integer STR_HERO = 039;A000039; //The "Str Hero" ability raw code
private constant integer AGI_HERO = 039;A001039; //The "Agi Hero" ability raw code
private constant integer INT_HERO = 039;A002039; //The "Int Hero" ability raw code
endglobals
//=========================================================================================\\
// Functions
function IsHeroStr takes unit hero returns boolean
return GetUnitAbilityLevel(hero, STR_HERO) > 0
endfunction
function IsHeroAgi takes unit hero returns boolean
return GetUnitAbilityLevel(hero, AGI_HERO) > 0
endfunction
function IsHeroInt takes unit hero returns boolean
return GetUnitAbilityLevel(hero, INT_HERO) > 0
endfunction
function GetHeroMainAtt takes unit hero, boolean flag returns integer
local integer att
if GetUnitAbilityLevel(hero, STR_HERO) > 0 then
set att = GetHeroStr(hero, flag)
elseif GetUnitAbilityLevel(hero, AGI_HERO) > 0 then
set att = GetHeroAgi(hero, flag)
elseif GetUnitAbilityLevel(hero, INT_HERO) > 0 then
set att = GetHeroInt(hero, flag)
endif
return att
endfunction
endlibrary
Second snippet: Uses groups to group heroes.
JASS:
library HeroMainAtt2 initializer Init
//==========================================================================================\\
//==========================================================================================\\
//== Hero Main Attribute: Sour Flavor ==\\
//== HMA ==\\
//== By Gtam ==\\
//== ==\\
//== This is a little handy snippet that will beable to tell you heroes main attributes. ==\\
//== ==\\
//== Well as you probably know by know there is no function to tell you a heroes main ==\\
//== attribute. This is here to fix that. ==\\
//== This flavor uses groups to tell the main attribute so its your job to make sure ==\\
//== that the correct unit is added to the correct group. ==\\
//== Dont worry its pretty straight forward. ==\\
//== Step 1: Configure all the strenght hero raw codes in the alocated function ==\\
//== Step 2: Configure all the agility hero raw codes in the alocated function ==\\
//== Step 3: Configure all the intelligence hero raw codes in the alocated function ==\\
//== Step 4: Use this system to detect hero main atributes ==\\
//== ==\\
//== Functions ==\\
//== ==\\
//== function IsHeroStr takes unit hero returns boolean ==\\
//== returns true if hero strength and false if not ==\\
//== ==\\
//== function IsHeroAgi takes unit hero returns boolean ==\\
//== returns true if hero agility and false if not ==\\
//== ==\\
//== function IsHeroInt takes unit hero returns boolean ==\\
//== returns true if hero intelligence and false if not ==\\
//== ==\\
//== function GetHeroMainAtt takes unit hero, boolean flag returns integer ==\\
//== returns the Hero's main attribute amount ==\\
//== the boolean is if you want bonuses included ==\\
//== ==\\
//==========================================================================================\\
//==========================================================================================\\
globals
private group STR = CreateGroup()
private group AGI = CreateGroup()
private group INT = CreateGroup()
private group ALL = CreateGroup()
private integer array STRHERO_ID
private integer array AGIHERO_ID
private integer array INTHERO_ID
private integer STRHERO_NUM
private integer AGIHERO_NUM
private integer INTHERO_NUM
endglobals
//=========================================================================================\\
// Configure you strength hero raw codes here
private function STRVars takes nothing returns nothing
set STRHERO_ID[0] = 039;Hpal039;
set STRHERO_ID[1] = 039;Hmkg039;
set STRHERO_NUM = 2
endfunction
//=========================================================================================\\
// Configure you agility hero raw codes here
private function AGIVars takes nothing returns nothing
set AGIHERO_NUM = 0
endfunction
//=========================================================================================\\
// Configure you intelegence hero raw codes here
private function INTVars takes nothing returns nothing
set INTHERO_ID[0] = 039;Hamg039;
set INTHERO_ID[1] = 039;Hblm039;
set INTHERO_NUM = 2
endfunction
//=========================================================================================\\
// Do not touch below this point unless you know what your doing <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" />
private function Filt takes nothing returns boolean
return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == true
endfunction
private function GroopLoop takes nothing returns nothing
local unit u = GetEnumUnit()
local integer str = STRHERO_NUM
local integer agi = AGIHERO_NUM
local integer int = INTHERO_NUM
loop
set str = str - 1
exitwhen str == -1
if GetUnitTypeId(u) == STRHERO_ID[str] then
call GroupAddUnit(STR, u)
endif
endloop
loop
set agi = agi - 1
exitwhen agi == -1
if GetUnitTypeId(u) == AGIHERO_ID[agi] then
call GroupAddUnit(AGI, u)
endif
endloop
loop
set int = int - 1
exitwhen int == -1
if GetUnitTypeId(u) == INTHERO_ID[int] then
call GroupAddUnit(INT, u)
endif
endloop
endfunction
private function Conditions takes nothing returns boolean
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true
endfunction
private function Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer str = STRHERO_NUM
local integer agi = AGIHERO_NUM
local integer int = INTHERO_NUM
loop
set str = str - 1
exitwhen str == -1
if GetUnitTypeId(u) == STRHERO_ID[str] then
call GroupAddUnit(STR, u)
endif
endloop
loop
set agi = agi - 1
exitwhen agi == -1
if GetUnitTypeId(u) == AGIHERO_ID[agi] then
call GroupAddUnit(AGI, u)
endif
endloop
loop
set int = int - 1
exitwhen str == -1
if GetUnitTypeId(u) == INTHERO_ID[int] then
call GroupAddUnit(INT, u)
endif
endloop
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterEnterRectSimple(t, bj_mapInitialPlayableArea)
call TriggerAddCondition(t, Condition(function Conditions))
call TriggerAddAction(t, function Actions)
call STRVars()
call AGIVars()
call INTVars()
call GroupEnumUnitsInRect(ALL, bj_mapInitialPlayableArea, Condition(function Filt))
call ForGroup(ALL, function GroopLoop)
endfunction
//=========================================================================================\\
// Functions
function IsHeroStr takes unit hero returns boolean
return IsUnitInGroup(hero, STR) == true
endfunction
function IsHeroAgi takes unit hero returns boolean
return IsUnitInGroup(hero, AGI) == true
endfunction
function IsHeroInt takes unit hero returns boolean
return IsUnitInGroup(hero, INT) == true
endfunction
function GetHeroMainAtt takes unit hero, boolean flag returns integer
local integer att
if IsUnitInGroup(hero, STR) == true then
set att = GetHeroStr(hero, flag)
elseif IsUnitInGroup(hero, AGI) == true then
set att = GetHeroAgi(hero, flag)
elseif IsUnitInGroup(hero, INT) == true then
set att = GetHeroInt(hero, flag)
endif
return att
endfunction
endlibrary
Hope its helpfull.
The test map has the Human heroes added to each snippet.