//TESH.scrollpos=0
//TESH.alwaysfold=0
Name | Type | is_array | initial_value |
tempUnitType1 | unitcode | No | |
tempUnitType2 | unitcode | No | |
unitUpgSysAbilityBool | boolean | Yes | |
unitUpgSysHash | hashtable | No | |
unitUpgSysIncludeBonuses | boolean | Yes | |
unitUpgSysInRangeBool | boolean | Yes | |
unitUpgSysItemBool | boolean | Yes | |
unitUpgSysLvlBool | boolean | Yes | |
unitUpgSysMaxIndex | integer | No | |
unitUpgSysMinimumAgi | integer | Yes | |
unitUpgSysMinimumInt | integer | Yes | |
unitUpgSysMinimumStr | integer | Yes | |
unitUpgSysMultiAbilities | integer | Yes | |
unitUpgSysMultiItems | integer | Yes | |
unitUpgSysMultiUnitsBool | boolean | Yes | |
unitUpgSysMultiUnitsCounter | integer | Yes | |
unitUpgSysMultiUnitsRemove | boolean | Yes | |
unitUpgSysMultiUnitsTotal | integer | Yes | |
unitUpgSysRegionBool | boolean | Yes | |
unitUpgSysRegions | integer | Yes | |
unitUpgSysStatBool | boolean | Yes | |
unitUpgSysUnitLvl | integer | Yes | |
unitUpgSysUpgradeUnitType | integer | Yes | |
uniUpgSysAbiTrig | trigger | No |
//TESH.scrollpos=402
//TESH.alwaysfold=0
// Unit Upgrade System by deathismyfriend
// version 1.0.0.0
// PROS
//
// This system is able to upgrade units with a few different options.
// This system can use restrictions from all of these at the same time.
// This can upgrade units by these next several things.
// Based on the lvl of the unit.
// Based on unit enter a region.
// Based on a units stat/stats.
// // Example: Str/Agi/Int
// Based on an ability being used.
// Based on how many units of the base units unit type owned by player.
// Based on up to 6 items that unit has.
// You can use multiple of the same item to require upgrade.
// CONS
//
// Can only make units require multiple units of the same unit type as the base unit.
// Can only make a unit upgrade to one other unit.
// // Example: unit A can upgrade to unit B but it can't upgrade to unit B / C / and D
// FUNCTION LIST
//
//
// REGISTER UNIT MULTI UNITS
// This function allows you to register an amount of the units that player has that will trigger the unit to upgrade.
// Custom script: call UnitUpgSysRegisterMultiUnits( unit-type, integer, boolean)
// The unit type argument should be set in a unit-type variable in the Variable editor then put it in here using that variable.
// The integer variable is the amount of units required for the unit to upgrade.
// The boolean is whether or not i want to remove the units to upgrade the unit.
//
//
// REGISTER UNIT LEVEL
// This function allows you to register a lvl requirement that will trigger the unit to upgrade.
// Custom script: call UnitUpgSysRegisterUnitLvl( unit-type, integer)
// The unit type argument should be set in a unit-type variable in the Variable editor then put it in here using that variable.
// The integer variable is the lvl required for the unit to upgrade.
//
//
// REGISTER UNIT ENTER REGION/S
// This function registers an enter region to a specific unit. This way you can make different units use different regions to upgrade.
// Custom script: call UnitUpgSysRegisterUnitEnterRegion( unit-type, region)
// The unit type argument should be set in a unit-type variable in the Variable editor then put it in here using that variable.
// The region should be a region variable made in the variable editor. Then you can null the variable ( do not remove the region).
// This function allows you to register as many regions that will trigger the unit to upgrade.
//
//
// REGISTER UNIT CASTS ABILITY/IES
// This function registers an ability to a specific unit. This way you can make different units use different abilities to upgrade.
// Max of 50 different abilities allowed for upgrade per base unit type.
// Custom script: call UnitUpgSysRegisterUnitAbility( unit-type, ability, integer)
// The unit type argument should be set in a unit-type variable in the Variable editor then put it in here using that variable.
// The ability can be the ability you want to register to the unit that will allow the unit to upgrade.
// The integer is the minimum allowed lvl of the ability that allows the unit to upgrade.
// This function allows you to register as many abilities that will trigger the unit to upgrade.
//
//
// REGISTER UNIT HAS ITEM/S
// This function registers an item to a specific unit. This way you can make different units use different items to upgrade.
// Max of 50 different items allowed for upgrade per base unit type.
// Custom script: call UnitUpgSysRegisterUnitItem( unit-type, item-type, boolean)
// The unit type argument should be set in a unit-type variable in the Variable editor then put it in here using that variable.
// The item-type should be done the same way as the unit-type is done in the suggestion above.
// Set the boolean to true if you want the item you registered to be removed from the unit when all requirements are met.
// This function allows you to register as many items that will trigger the unit to upgrade.
// Max of 6 items.
//
//
// REGISTER UNIT STATS
// This function is for adding a stat requirement for the unit to upgrade. Example: Agility, Intel, Strength
// These are the minimum requirements for the unit to upgrade.
// Custom script: call UnitUpgSysRegisterUnitStats( unit-type, agi, intel, str, boolean)
// The unit type argument should be set in a unit-type variable in the Variable editor then put it in here using that variable.
// The boolean is wheather or not it includes bonuses. True means it includes bonuses for the stats.
// The agility / intel / strength arguments are integers and can be placed right in the custom script.
// Example: Custom script: call UnitUpgSysRegisterUnitStats( unit-type, 20, 0, 0, false)
//
//
// REGISTER UNIT TYPE
// Custom script: call UnitUpgSysRegisterUnitType( unit-type, unit-type, boolean)
// The unit type argument should be set in a unit-type variable in the Variable editor then put it in here using that variable.
// For the boolean it only needs to know if the base unit is a hero not the upgraded unit.
// If false the unit is not a hero.
// I did it this way so you can have normal units upgrade into heroes after the other requirements are met.
// Example: Custom script: call UnitUpgSysRegisterUnitType( unit-type, unit-type, boolean)
//
//
// REMOVE UNIT TYPE
// This function removes a unit type upgrade. ( this is the base unit not the upgraded unit that it removes)
// Custom script: call UnitUpgSysRemoveUnitType( unit-type)
// The unit type argument should be set in a unit-type variable in the Variable editor then put it in here using that variable.
// Example: Custom script: call UnitUpgSysRemoveUnitType( unit-type)
//
//
function UnitUpgSysRegisterUnitAbility takes integer baseUnit, integer abi, integer lvl returns nothing
local integer i = LoadInteger( udg_unitUpgSysHash, baseUnit, 0)
set udg_unitUpgSysAbilityBool[ i] = true
set udg_unitUpgSysMultiAbilities[ i] = udg_unitUpgSysMultiAbilities[ i] + 1
call SaveInteger( udg_unitUpgSysHash, baseUnit, udg_unitUpgSysMultiAbilities[ i], abi)
call SaveInteger( udg_unitUpgSysHash, baseUnit, udg_unitUpgSysMultiAbilities[ i] + 50, lvl)
endfunction
function UnitUpgSysRegisterUnitItem takes integer baseUnit, integer itm, boolean removeItm returns nothing
local integer i = LoadInteger( udg_unitUpgSysHash, baseUnit, 0)
set udg_unitUpgSysItemBool[ i] = true
set udg_unitUpgSysMultiItems[ i] = udg_unitUpgSysMultiItems[ i] + 1
call SaveInteger( udg_unitUpgSysHash, baseUnit, udg_unitUpgSysMultiItems[ i], itm)
call SaveBoolean( udg_unitUpgSysHash, baseUnit, udg_unitUpgSysMultiItems[ i] + 50, removeItm)
endfunction
function UnitUpgSysRegisterUnitLvl takes integer baseUnit, integer lvl returns nothing
local integer i = LoadInteger( udg_unitUpgSysHash, baseUnit, 0)
set udg_unitUpgSysUnitLvl[ i] = lvl
set udg_unitUpgSysLvlBool[ i] = true
endfunction
function UnitUpgSysRegisterMultiUnits takes integer baseUnit, integer amount, boolean b returns nothing
local integer i = LoadInteger( udg_unitUpgSysHash, baseUnit, 0)
set udg_unitUpgSysMultiUnitsBool[ i] = true
set udg_unitUpgSysMultiUnitsTotal[ i] = amount
set udg_unitUpgSysMultiUnitsCounter[ i] = 0
set udg_unitUpgSysMultiUnitsRemove[ i] = b
endfunction
function UnitUpgSysRegisterUnitEnterRegion takes integer baseUnit, region r returns nothing
local integer i = LoadInteger( udg_unitUpgSysHash, baseUnit, 0)
local integer id = GetHandleId( r)
set udg_unitUpgSysRegions[ i] = udg_unitUpgSysRegions[ i] + 1
call SaveRegionHandle( udg_unitUpgSysHash, baseUnit, udg_unitUpgSysRegions[ i], r)
// This checks if that region handle is already present in the system.
set udg_unitUpgSysRegionBool[ i] = true
if LoadInteger( udg_unitUpgSysHash, id, 0) != id then
call SaveInteger( udg_unitUpgSysHash, id, 0, id)
call TriggerRegisterEnterRegion( udg_uniUpgSysAbiTrig, r, null)
endif
endfunction
function UnitUpgSysRegisterUnitStats takes integer baseUnit, integer agi, integer intel, integer str, boolean b returns nothing
local integer i = LoadInteger( udg_unitUpgSysHash, baseUnit, 0)
set udg_unitUpgSysStatBool[ i] = true
set udg_unitUpgSysMinimumAgi[ i] = agi
set udg_unitUpgSysMinimumStr[ i] = intel
set udg_unitUpgSysMinimumInt[ i] = str
set udg_unitUpgSysIncludeBonuses[ i] = b
endfunction
function UnitUpgSysRegisterUnitType takes integer baseUnit, integer upgradeUnit, boolean isHero returns nothing
if not HaveSavedInteger( udg_unitUpgSysHash, baseUnit, 0) then
set udg_unitUpgSysMaxIndex = udg_unitUpgSysMaxIndex + 1
call SaveInteger( udg_unitUpgSysHash, baseUnit, 0, udg_unitUpgSysMaxIndex)
call SaveInteger( udg_unitUpgSysHash, udg_unitUpgSysMaxIndex, 0, baseUnit)
set udg_unitUpgSysUpgradeUnitType[ udg_unitUpgSysMaxIndex] = upgradeUnit
set udg_unitUpgSysAbilityBool[ udg_unitUpgSysMaxIndex] = false
set udg_unitUpgSysItemBool[ udg_unitUpgSysMaxIndex] = false
set udg_unitUpgSysLvlBool[ udg_unitUpgSysMaxIndex] = false
set udg_unitUpgSysMultiUnitsBool[ udg_unitUpgSysMaxIndex] = false
set udg_unitUpgSysRegionBool[ udg_unitUpgSysMaxIndex] = false
set udg_unitUpgSysStatBool[ udg_unitUpgSysMaxIndex] = false
set udg_unitUpgSysMultiUnitsRemove[ udg_unitUpgSysMaxIndex] = false
set udg_unitUpgSysMultiAbilities[ udg_unitUpgSysMaxIndex] = 0
set udg_unitUpgSysMultiItems[ udg_unitUpgSysMaxIndex] = 100
set udg_unitUpgSysRegions[ udg_unitUpgSysMaxIndex] = 200
endif
endfunction
function UnitUpgSysRemoveUnitType takes integer baseUnit returns nothing
local integer i = LoadInteger( udg_unitUpgSysHash, baseUnit, 0)
local integer i1 = LoadInteger( udg_unitUpgSysHash, udg_unitUpgSysMaxIndex, 0)
// if i is not greater then 0 then this unit upgrade doesn't exist.
if i > 0 then
// I have to de-index everything and then flush the hashtable.
set udg_unitUpgSysUpgradeUnitType[ i] = udg_unitUpgSysUpgradeUnitType[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysAbilityBool[ i] = udg_unitUpgSysAbilityBool[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysAbilityBool[ udg_unitUpgSysMaxIndex] = false
set udg_unitUpgSysItemBool[ i] = udg_unitUpgSysItemBool[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysItemBool[ udg_unitUpgSysMaxIndex] = false
set udg_unitUpgSysLvlBool[ i] = udg_unitUpgSysLvlBool[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysLvlBool[ udg_unitUpgSysMaxIndex] = false
set udg_unitUpgSysMultiUnitsBool[ i] = udg_unitUpgSysMultiUnitsBool[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysMultiUnitsBool[ udg_unitUpgSysMaxIndex] = false
set udg_unitUpgSysRegionBool[ i] = udg_unitUpgSysRegionBool[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysRegionBool[ udg_unitUpgSysMaxIndex] = false
set udg_unitUpgSysStatBool[ i] = udg_unitUpgSysStatBool[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysStatBool[ udg_unitUpgSysMaxIndex] = false
set udg_unitUpgSysMultiUnitsRemove[ i] = udg_unitUpgSysMultiUnitsRemove[ i1]
// This moves the max index to the index being removed.
call SaveInteger( udg_unitUpgSysHash, i, 0, i1)
set udg_unitUpgSysIncludeBonuses[ i] = udg_unitUpgSysIncludeBonuses[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysMinimumAgi[ i] = udg_unitUpgSysMinimumAgi[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysMinimumStr[ i] = udg_unitUpgSysMinimumStr[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysMinimumInt[ i] = udg_unitUpgSysMinimumInt[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysMultiUnitsCounter[ i] = udg_unitUpgSysMultiUnitsCounter[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysMultiUnitsTotal[ i] = udg_unitUpgSysMultiUnitsTotal[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysMultiAbilities[ i] = udg_unitUpgSysMultiAbilities[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysMultiItems[ i] = udg_unitUpgSysMultiItems[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysRegions[ i] = udg_unitUpgSysRegions[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysUnitLvl[ i] = udg_unitUpgSysUnitLvl[ udg_unitUpgSysMaxIndex]
set udg_unitUpgSysMaxIndex = udg_unitUpgSysMaxIndex - 1
call FlushChildHashtable( udg_unitUpgSysHash, baseUnit)
endif
endfunction
function UnitUpgSysUnitInRegion takes unit u, integer id, integer i returns boolean
local integer L2 = 201 // Used for region checking
loop
exitwhen L2 > udg_unitUpgSysRegions[ i]
// If it is equal to one of these it will return true and continue with the upgrade check.
if IsUnitInRegion( LoadRegionHandle( udg_unitUpgSysHash, id, L2), u) then
return true
endif
set L2 = L2 + 1
endloop
return false
endfunction
function UnitUpgSysUnitHasItems takes unit u, integer id, integer i returns boolean
local integer L = 1 // Used for items
local integer L1 = 1 // used for items
local integer array ia
local boolean array b
local integer array itm
local boolean array remove
loop
exitwhen L > udg_unitUpgSysMultiItems[ i]
set b[ L] = false
set ia[ L] = LoadInteger( udg_unitUpgSysHash, id, 100 + L)
set remove[ L] = LoadBoolean( udg_unitUpgSysHash, id, 150 + L)
set itm[ L] = GetItemTypeId( UnitItemInSlot( u, L - 1))
set L = L + 1
endloop
set L = 0
loop
exitwhen L > udg_unitUpgSysMultiItems[ i]
loop
exitwhen L1 > 6
if ia[ L] == itm[ L1] and not b[ L1] then
set b[ L1] = true
set L1 = 6
endif
set L1 = L1 + 1
endloop
set L1 = 1
set L = L + 1
endloop
set L = 1
loop
exitwhen L > udg_unitUpgSysMultiItems[ i]
// If any of these are false then it does not have the required item.
if not b[ L] then
return false
endif
endloop
set L = 1
loop
exitwhen L > udg_unitUpgSysMultiItems[ i]
// If true then it removes the item.
if remove[ L] then
call RemoveItem( UnitItemInSlot( u, L - 1))
endif
set L = L + 1
endloop
return true
endfunction
// This function checks if the unit is able to upgrade by checking all other conditions.
// I put this in a few different condition checks because it is horrible to check everything in one ITE.
function UnitUpgSysUpgradeUnitCheck takes unit u, integer id, integer i returns nothing
local group g
local real x
local real y
local player P
local integer c = 0
call BJDebugMsg( "check 1")
// This checks if certain stats are required for the unit to upgrade.
if udg_unitUpgSysStatBool[ i] then
// If these are greater than the heroes agi / intel / str then it exits the check since the unit is not allowed to upgrade.
if udg_unitUpgSysMinimumAgi[ i] >= GetHeroAgi( u, udg_unitUpgSysIncludeBonuses[ i]) and udg_unitUpgSysMinimumInt[ i] >= GetHeroInt( u, udg_unitUpgSysIncludeBonuses[ i]) and udg_unitUpgSysMinimumStr[ i] >= GetHeroStr( u, udg_unitUpgSysIncludeBonuses[ i]) then
return
endif
endif
// This checks if the unit is the required level to upgrade.
if udg_unitUpgSysLvlBool[ i] then
// if false it exits the rest of the unit upgrade check.
if udg_unitUpgSysUnitLvl[ i] >= GetHeroLevel( u) then
return
endif
endif
// This checks if the unit requires multiple units of the same type to upgrade.
if udg_unitUpgSysMultiUnitsBool[ i] then
// if false it exits the rest of the unit upgrade check.
if udg_unitUpgSysMultiUnitsTotal[ i] > udg_unitUpgSysMultiUnitsCounter[ i] then
return
endif
endif
// This checks if the unit is in the region.
if udg_unitUpgSysRegionBool[ i] then
// if false it exits the rest of the unit upgrade check.
if not UnitUpgSysUnitInRegion( u, id, i) then
return
endif
endif
// This checks if certain items are required for the unit to upgrade.
// This needs to be last so that it will remove the items if all other requirements are met.
if udg_unitUpgSysItemBool[ i] then
// if false it exits the rest of the unit upgrade check.
if not UnitUpgSysUnitHasItems( u, id, i) then
return
endif
endif
set x = GetUnitX( u)
set y = GetUnitY( u)
set P = GetOwningPlayer( u)
// This is where i remove the multiple units to make the upgrade since everything else is true.
if udg_unitUpgSysMultiUnitsRemove[i] then
set g = CreateGroup()
call GroupEnumUnitsInRect( g, bj_mapInitialPlayableArea, null)
set udg_unitUpgSysMultiUnitsCounter[ i] = 0
loop
set u = FirstOfGroup( g)
exitwhen u == null
if id == GetUnitTypeId( u) or c >= udg_unitUpgSysMultiUnitsTotal[ i] then
set c = c + 1
call RemoveUnit( u)
endif
call GroupRemoveUnit( g, u)
endloop
endif
call CreateUnit( P, udg_unitUpgSysUpgradeUnitType[ i], x, y, 0.00)
return
endfunction
function UnitUpgSysRegionCheck takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer id = GetUnitTypeId( u)
local integer i = LoadInteger( udg_unitUpgSysHash, id, 0)
if LoadRegionHandle( udg_unitUpgSysHash, id, udg_unitUpgSysRegions[ i]) == GetTriggeringRegion() then
call UnitUpgSysUpgradeUnitCheck( u, id, i)
endif
set u = null
return false
endfunction
function UnitUpgSysAbiCastCheck takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer id = GetUnitTypeId( u)
local integer i = LoadInteger( udg_unitUpgSysHash, id, 0)
local integer abiId = GetSpellAbilityId()
local integer abiLvl = GetUnitAbilityLevel( u, abiId)
local integer L = 1
loop
exitwhen L > udg_unitUpgSysMultiAbilities[ i]
if LoadInteger( udg_unitUpgSysHash, id, L) == abiId and abiLvl >= LoadInteger( udg_unitUpgSysHash, id, L + 50) then
call UnitUpgSysUpgradeUnitCheck( u, id, i)
endif
set L = L + 1
endloop
set u = null
return false
endfunction
function UnitUpgSysUnitGainsLvl takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer id = GetUnitTypeId( u)
local integer i = LoadInteger( udg_unitUpgSysHash, id, 0)
if udg_unitUpgSysUnitLvl[ i] >= GetHeroLevel( u) then
call UnitUpgSysUpgradeUnitCheck( u, id, i)
endif
return false
endfunction
function UnitUpgSysEnterRegion takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer id = GetUnitTypeId( u)
local integer i = LoadInteger( udg_unitUpgSysHash, id, 0)
if udg_unitUpgSysMultiUnitsBool[ i] then
set udg_unitUpgSysMultiUnitsCounter[ i] = udg_unitUpgSysMultiUnitsCounter[ i] + 1
if udg_unitUpgSysMultiUnitsCounter[ i] >= udg_unitUpgSysMultiUnitsTotal[ i] then
call UnitUpgSysUpgradeUnitCheck( u, id, i)
endif
endif
return false
endfunction
function UnitUpgSysLeaveRegion takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer id = GetUnitTypeId( u)
local integer i = LoadInteger( udg_unitUpgSysHash, id, 0)
if udg_unitUpgSysMultiUnitsBool[ i] then
set udg_unitUpgSysMultiUnitsCounter[ i] = udg_unitUpgSysMultiUnitsCounter[ i] - 1
endif
return false
endfunction
//===========================================================================
function InitTrig_UnitUpgradeSystemCode takes nothing returns nothing
local trigger t = CreateTrigger()
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
local trigger t3 = CreateTrigger()
local region r = CreateRegion()
call RegionAddRect( r, bj_mapInitialPlayableArea)
set udg_uniUpgSysAbiTrig = CreateTrigger()
set udg_unitUpgSysHash = InitHashtable()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerRegisterEnterRegion( t1, r, null)
call TriggerRegisterLeaveRegion( t2, r, null)
call TriggerRegisterAnyUnitEventBJ( t3, EVENT_PLAYER_HERO_LEVEL)
call TriggerAddCondition( t, Condition( function UnitUpgSysAbiCastCheck))
call TriggerAddCondition( t1, Condition( function UnitUpgSysEnterRegion))
call TriggerAddCondition( t2, Condition( function UnitUpgSysLeaveRegion))
call TriggerAddCondition( t3, Condition( function UnitUpgSysUnitGainsLvl))
call TriggerAddCondition( udg_uniUpgSysAbiTrig, Condition( function UnitUpgSysRegionCheck))
set t = null
set t1 = null
set t2 = null
set t3 = null
set r = null
endfunction