Antares
Spell Reviewer
- Joined
- Dec 13, 2009
- Messages
- 1,106
This is a new system or moved from Code Archive?
TasUnitBonus(unit, key, value) key is one of the supported keys of TasUnitBonus. As said before you can add own custom keys/stats pretty easy, checkout the examples at the bottom.TasUnitBonus(unit, "Primary", 10)--[[
example use of TasUnitBonusItem
setup what each items of RawCode gives while carried by a hero
--]]
do
itemPower = TasUnitBonusItem -- need to write less text
itemPower[FourCC'I000'] = {Armor = 3} -- 3 base armor
itemPower[FourCC'I001'] = {["STR+"] = 3} -- +3 bonus str
itemPower[FourCC'I002'] = {["MOVE+"] = 50}
itemPower[FourCC'I003'] = {Int = 6} -- + 6 base int
itemPower[FourCC'I004'] = {Attack = 9} -- + 9 base dmg
itemPower[FourCC'I005'] = {["INT+"] = 4, ["AGI+"] = 4} -- gives 4 bonus agi and int
itemPower[FourCC'I006'] = {["DMG+"] = 6} -- + 6 bonus dmg
itemPower[FourCC'I007'] = {["PRIMARY+"] = 15}
itemPower[FourCC'I00B'] = {["ATKSP+"] = 0.25}
itemPower[FourCC'I00C'] = {"STR+", 4, "AGI+", 4} -- gives 4 bonus agi and str Format2 key. value, key takes less performance
end
-- MaskOfDeath is an example for item specific TasUnitBonus combined with itemCode bonus.
--+20 ATK|n+5 for each last hit done while holding this item, upto 100 additional ATK.
MaskOfDeathCode = FourCC'I008'
function MaskOfDeath()
TasUnitBonusItem[MaskOfDeathCode] = {["DMG+"] = 20} -- + 20 bonus dmg
local trig = CreateTrigger()
TriggerAddAction(trig, function()
local killer = GetKillingUnit()
if not IsUnitType(killer, UNIT_TYPE_HERO) then return end
for i = 0, bj_MAX_INVENTORY -1 do
local item = UnitItemInSlot(killer, i)
if GetItemTypeId(item) == MaskOfDeathCode then
-- create item speicifc table when not existing yet
if not TasUnitBonusItem[item] then TasUnitBonusItem[item] = {["DMG+"] = 0} end
if TasUnitBonusItem[item]["DMG+"] < 100 then
TasUnitBonusItem[item]["DMG+"] = TasUnitBonusItem[item]["DMG+"] + 5
-- give the bonus now, because TasUnitBonusItem is only given and taken on PIckUP/drop events
TasUnitBonus(killer, "DMG+", 5)
-- update item name & tooltip
TasUnitBonusItemTooltip(item)
BlzSetItemName(item, GetObjectName(MaskOfDeathCode) .. "(+".. TasUnitBonusItem[item]["DMG+"] ..")")
end
end
end
end)
TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_DEATH)
end
--example of 2 custom types backstab and UndeadSlayer
-- backstab gives Bonus ATK when hitting into the back
-- UndeadSlayer gives Bonus ATK when attacking units with the UNDEAD-Class
-- needed for backstab
function AngleW2W(source, target)
return bj_RADTODEG * Atan2(GetWidgetY(target) - GetWidgetY(source), GetWidgetX(target) - GetWidgetX(source))
end
do --
function CustomStats()
udg_BackStab = __jarray(0)
udg_UndeadSlayer = __jarray(0)
TasUnitBonus.AddSimpleType("udg_BackStab")
TasUnitBonus.AddSimpleType("udg_UndeadSlayer")
itemPower[FourCC'I009'] = {udg_UndeadSlayer = 27}
itemPower[FourCC'I00A'] = {udg_BackStab = 35}
-- current Bonus used for reset
local oldBackStab = __jarray(0)
local oldUndeadSlayer = __jarray(0)
local trig = CreateTrigger()
TriggerAddAction(trig, function()
local unit, attacker = GetTriggerUnit(), GetAttacker()
local newValue = udg_BackStab[attacker]
if oldBackStab[attacker] ~= 0 or newValue ~= 0 then
if CosBJ(AngleW2W(attacker, unit) - GetUnitFacing(unit)) < 0 then newValue = 0 end
TasUnitBonus(attacker, "ATK+", newValue - oldBackStab[attacker])
oldBackStab[attacker] = newValue
end
newValue = udg_UndeadSlayer[attacker]
if oldUndeadSlayer[attacker] ~= 0 or newValue ~= 0 then
if not IsUnitType(unit, UNIT_TYPE_UNDEAD) then newValue = 0 end
TasUnitBonus(attacker, "ATK+", newValue - oldUndeadSlayer[attacker])
oldUndeadSlayer[attacker] = newValue
end
end)
TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_ATTACKED)
end
end
TasUnitBonusLearn[FourCC'AHhb'] = { -- HolyLight
["DMG+"] = 3 -- 3 Bonus ATK every time Skilled
,[2] = { Str = 10} -- Skilling level 2 10 base Str
}
-- example for TasUnitBonusBuff
function InitDemoSpellCast()
-- define once what bonus keys buffs give
TasUnitBonusBuff.DefineKeys('Binv', "MOVE+")
TasUnitBonusBuff.DefineKeys('Binf', "STR+")
TasUnitBonusBuff.DefineKeys('Bblo', "Ability")
-- do not run this again
InitDemoSpellCast = nil
end
function DemoSpellCast()
if InitDemoSpellCast then InitDemoSpellCast() end
-- the spellcasts tell TasUnitBonusBuff how much to add for a given buffCode
--Invis buff gives 500 movespeed
if GetSpellAbilityId() == FourCC'Aivs' then TasUnitBonusBuff.add(GetSpellTargetUnit(), 'Binv', 500) end
-- inner fire gives hero str
-- first cast adds 15 recast give 5 more 15 20 25 30
local buffCode = FourCC'Binf'
if GetSpellAbilityId() == FourCC'Ainf' then
local value = TasUnitBonusBuff.Data[buffCode]["STR+"][GetSpellTargetUnit()] or 0
if value < 15 then value = 15 else value = value + 5 end
TasUnitBonusBuff.add(GetSpellTargetUnit(), buffCode, value ) end
-- bloodlust gives an endurance aura
local skill = FourCC'AIae'
if GetSpellAbilityId() == FourCC'ACbb' then TasUnitBonusBuff.add(GetSpellTargetUnit(), 'Bblo', skill) end
end
-- example for TasUnitBonusBuffTable
do
local bonusInvis = {["MOVE+"]=500}
local bonusBlood = {Ability='AIae'}
local frostArmor = {
{}
,{Life = 100}
,{Life = 100, LifeReg = 5}
}
function DemoSpellCast()
local unit = GetSpellTargetUnit()
-- the spellcasts tell TasUnitBonusBuff how much to add for a given buffCode
--Invis buff gives 500 movespeed
if GetSpellAbilityId() == FourCC'Aivs' then TasUnitBonusBuffTable.add(unit, 'Binv', bonusInvis) end
-- inner fire gives hero str
-- first cast adds 15, recast give 5 more; 15 20 25 30
local buffCode = FourCC'Binf'
if GetSpellAbilityId() == FourCC'Ainf' then
local value = 0
local buffData = TasUnitBonusBuffTable.Data[buffCode]
if buffData and buffData[unit] then value = buffData[unit]["STR+"] end
if value < 15 then value = 15 else value = value + 5 end
TasUnitBonusBuffTable(unit, buffCode, {["STR+"]= value})
end
-- bloodlust gives an endurance aura
if GetSpellAbilityId() == FourCC'ACbb' then TasUnitBonusBuffTable.add(unit, 'Bblo', bonusBlood) end
-- Frost armog gives with the first rebuff 100 HP with the second Rebuff also HP/s
local buffCode = FourCC'BUfa'
if GetSpellAbilityId() == FourCC'ACfa' then
local currentBonus = TasUnitBonusBuffTable.get(unit, buffCode)
local newBonus = currentBonus
if not currentBonus then newBonus = frostArmor[1]
elseif currentBonus == frostArmor[1] then newBonus = frostArmor[2]
elseif currentBonus == frostArmor[2] then newBonus = frostArmor[3]
end
TasUnitBonusBuffTable(unit, buffCode, newBonus)
end
end
end
DemoGUISobiMask

Events


Map initialization

Conditions

Actions


Set TasUnitBonus_ItemCode = Sobi-Maske


Set TasUnitBonus_Key = ManaReg


Set TasUnitBonus_Amount = 5.00


Trigger - Run TasUnitBonusGUIAdd <gen> (ignoring conditions)


Set TasUnitBonus_ItemCode = Sobi-Maske


Set TasUnitBonus_Key = INT+


Set TasUnitBonus_Amount = 2.00


Trigger - Run TasUnitBonusGUIAdd <gen> (ignoring conditions)


Set TasUnitBonus_Item = Sobi-Maske 0210 <gen>


Gegenstand - Set Extended Tooltip of TasUnitBonus_Item to ((Extended Item Tooltip of TasUnitBonus_Item) + |n+15 ATK vs Undead)


Gegenstand - Set Name of TasUnitBonus_Item to ((Name of TasUnitBonus_Item) + Paladin)


Set TasUnitBonus_Key = udg_UndeadSlayer


Set TasUnitBonus_Amount = 15.00


Trigger - Run TasUnitBonusGUIAdd <gen> (ignoring conditions)


Set TasUnitBonus_Item = Sobi-Maske 0208 <gen>


Gegenstand - Set Extended Tooltip of TasUnitBonus_Item to ((Extended Item Tooltip of TasUnitBonus_Item) + |n+15 ATK vs Undead)


Gegenstand - Set Name of TasUnitBonus_Item to ((Name of TasUnitBonus_Item) + Paladin)


Set TasUnitBonus_Key = udg_UndeadSlayer


Set TasUnitBonus_Amount = 15.00


Trigger - Run TasUnitBonusGUIAdd <gen> (ignoring conditions)
DemoGUIWindWalk

Events


Unit - A unit Starts the effect of an ability

Conditions


(Ability being cast) Equal to Windlauf

Actions


If (All Conditions are True) then do (Then Actions) else do (Else Actions)



If - Conditions




(Execution count of (This trigger)) Equal to 1



Then - Actions




-------- First use -> create the bonus --------




-------- Unit gains 11 HP/s --------




Set TasUnitBonus_BuffCode = Windlauf




Set TasUnitBonus_Key = LifeReg




Set TasUnitBonus_Amount = 11.00




Trigger - Run TasUnitBonusGUIAdd <gen> (ignoring conditions)




-------- Custom GUI Array is increased under this buff --------




-------- Requires an UnitIndexer --------




Set TasUnitBonus_BuffCode = Windlauf




Set TasUnitBonus_Key = udg_UnitSneaks




Set TasUnitBonus_Amount = 1.00




Trigger - Run TasUnitBonusGUIAdd <gen> (ignoring conditions)



Else - Actions


-------- apply the bonus to the casting unit --------


-------- while it has the buff it benefits from the bonus for this buff --------


Set TasUnitBonus_Unit = (Triggering unit)


Set TasUnitBonus_BuffCode = Windlauf


Trigger - Run TasUnitBonusGUIUse <gen> (ignoring conditions)
DemoGUIInnerFireMana

Events


Unit - A unit Starts the effect of an ability

Conditions


(Ability being cast) Equal to Inneres Fire (Mana)

Actions


-------- Each Cast has unique Data --------


Set TasUnitBonus_BuffCode = Inneres Fire Mana


Trigger - Run TasUnitBonusGUIMakeBuff <gen> (ignoring conditions)


-------- Setup BuffBonus --------


Set TasUnitBonus_BuffCode = Inneres Fire Mana


Set TasUnitBonus_Key = ATK+


Set TasUnitBonus_Amount = ((Mana of (Triggering unit)) x 0.20)


-------- ATK+ needs to be an integer --------


Set TasUnitBonus_Amount = (Real((Integer(TasUnitBonus_Amount))))


Game - Display to (All players) the text: (String(TasUnitBonus_Amount))


Trigger - Run TasUnitBonusGUIAdd <gen> (ignoring conditions)


-------- Apply Buff Bonus --------


Set TasUnitBonus_Unit = (Target unit of ability being cast)


Set TasUnitBonus_BuffCode = Inneres Fire Mana


Trigger - Run TasUnitBonusGUIUse <gen> (ignoring conditions)


-------- Pay Custom cost --------


Unit - Set mana of (Triggering unit) to ((Percentage mana of (Triggering unit)) - 35.00)%
DemoGUIBladeMaster

Events


Map initialization

Conditions

Actions


-------- --- --------


-------- Possible Keys you find at top of TasUnitBonus --------


-------- Also inside TasUnitBonusSkill --------


-------- --- --------


-------- I want to make a special bonus given at level 5 --------


-------- Therefore the blademaster bonusTable needs to be in mapFormat --------


Set TasUnitBonus_Format = True


-------- --- --------


-------- BladeMaster gets +2 Agi on levelUps --------


Set TasUnitBonus_HeroCode = Klingenmeister


Set TasUnitBonus_Key = AGI+


Set TasUnitBonus_Amount = 2.00


Trigger - Run TasUnitBonusGUIAdd <gen> (ignoring conditions)


-------- BladeMaster gets +1 ATK on levelUps --------


Set TasUnitBonus_HeroCode = Klingenmeister


Set TasUnitBonus_Key = ATK+


Set TasUnitBonus_Amount = 1.00


Trigger - Run TasUnitBonusGUIAdd <gen> (ignoring conditions)


-------- BladeMaster At Level 5 get 20 Str+ --------


Set TasUnitBonus_HeroCode = Klingenmeister


Set TasUnitBonus_Key = STR+


Set TasUnitBonus_HeroLevel = 5


Set TasUnitBonus_Amount = 20.00


Trigger - Run TasUnitBonusGUIAdd <gen> (ignoring conditions)


-------- Revert back to arrayFormat, now used by new bonuses --------


Set TasUnitBonus_Format = False


-------- --- --------


-------- Possible Keys you find at top of TasUnitBonus --------


-------- Also inside TasUnitBonusSkill thisData["STR+"] = -> STR+ is the key --------


-------- --- --------


-------- make an GUI array useable in TasUnitBonus --------


-------- in GUI this feature requires an unit indexer that makes Custom Unit Value unique for each unit --------


-------- dont forget the prefix udg_ --------


Set TasUnitBonus_Key = udg_UnitSneaks


Trigger - Run TasUnitBonusGUINewKey <gen> (ignoring conditions)
DemoGUI AddStats

Events


Map initialization

Conditions

Actions


Set TasUnitBonus_Unit = Oger-Magier 0029 <gen>


Set TasUnitBonus_Key = ATK+


Set TasUnitBonus_Amount = 11.00


Trigger - Run TasUnitBonusGUIUse <gen> (ignoring conditions)


Set TasUnitBonus_Unit = Oger-Magier 0137 <gen>


Trigger - Run TasUnitBonusGUIUse <gen> (ignoring conditions)
DemoGUIKrit

Events


Map initialization

Conditions

Actions


-------- Level Specific bonuses require the map format --------


Set TasUnitBonus_Format = True


-------- Learning every Level of Krit give + 12 ATK --------


Set TasUnitBonus_LearnCode = Kritischer Schlag


Set TasUnitBonus_Key = ATK+


Set TasUnitBonus_Amount = 12.00


Trigger - Run TasUnitBonusGUIAdd <gen> (ignoring conditions)


-------- Learning Level 3 gives +5 Int --------


Set TasUnitBonus_LearnCode = Kritischer Schlag


Set TasUnitBonus_Key = INT+


Set TasUnitBonus_Level = 3


Set TasUnitBonus_Amount = 5.00


Trigger - Run TasUnitBonusGUIAdd <gen> (ignoring conditions)


-------- new bonuses will be in array format --------


Set TasUnitBonus_Format = False
TasUnitBonusEquipment.UIAutoEquip = {} -- equip items gained (not tomes) can be set for [0] or [hero] or [player] or [unitTypeId]
this.UIGridMode = false -- (true) requires TasFrameList, (false) -> use this.UIFormation
this.UIGridModeRows = 9 -- should not be changed after InitTasUnitBonusEquipment() run
this.UIGridModeCols = 6
-- 2d offset array each x&y set is one button and how much to move from the previous button, from center to next center
local formationU10 = {-2,0, 0,-1, 0,-1, 0,-1, 1,0, 1,0, 1,0, 0,1, 0,1, 0,1}
local formationTriAngle9 = { 0,0, -1,-1, -1,-1, 1,0, 1,0,1,0,1,0, -1,1, -1,0}
this.UIFormation = formationU10 -- used inside the frame creation when InitTasUnitBonusEquipment() runs
TasUnitBonusEquipment.Inventory[unit] a rule for this unit only
TasUnitBonusEquipment.Inventory[GetUnitTypeId] all paladins use TasUnitBonusEquipment.Inventory.Hpal
TasUnitBonusEquipment.Inventory[Player(0)] units owned by Red Player
TasUnitBonusEquipment.Inventory[0] is the rule used by everyone when the others dont apply for a unit.
prio unit > GetUnitTypeId > player > 0
TasUnitBonusEquipment.Inventory is an array, each entry is one slot for an item.
-1 or ITEM_TYPE_ANY allows any item
-- slot values with special behaviour
this.INV_SLOT_ANY = -1
this.INV_SLOT_BAG = -2 -- inventory slot that can hold anything, but dont give stats
this.INV_SLOT_NONE = -3 -- hidden Slot that cant hold items
supports warcraft 3 itemTypes like ITEM_TYPE_ARTIFACT
or random madeUp numbers, Strings, Lua table
TasUnitBonusEquipment.Inventory[0] = {-1,-1,-1,-1,-1,-1,-1,-1,-1} -- all heroes can equip 9 items of any type
--bloodMage can equip 4 items then has 2 bag Slots
TasUnitBonusEquipment.Inventory[FourCC'Hblm'] = {-1,-1,-1,-1, -2,-2}
equipPower = TasUnitBonusEquipment -- need to write less text
EquipClass_Wand = 3 -- define a new EquipClass
--equipPower.Strings[EquipClass_Wand] = "Wand"
-- i want to write less
InventoryRules = TasUnitBonusEquipment.Inventory
-- bloodMage can equip 10 items and auto equips them
-- 2 ARTIFACT and 7 normal items and 1 Wand
InventoryRules.Hblm = {}
for i= 1, 2 do InventoryRules.Hblm[i] = ITEM_TYPE_ARTIFACT end
for i= 3, 9 do InventoryRules.Hblm[i] = ITEM_TYPE_PERMANENT end
InventoryRules.Hblm[10] = EquipClass_Wand
equipPower.UIAutoEquip[FourCC'Hblm'] = true
local Pos = function(frame) -- where to place this ui
--BlzFrameSetPoint(frame, FRAMEPOINT_TOPRIGHT, BlzGetFrameByName("ResourceBarSupplyText", 0), FRAMEPOINT_TOPRIGHT, 0, 0)
BlzFrameSetAbsPoint(frame, FRAMEPOINT_TOPRIGHT, 0.55, 0.25)
end
this.OpenButton.Pos = function(frame) -- where to place this ui
BlzFrameSetAbsPoint(frame, FRAMEPOINT_TOPRIGHT, 0.79, 0.55)
end
this.DropAllButton.Pos = function(frame) -- where to place this ui
BlzFrameSetAbsPoint(frame, FRAMEPOINT_TOPRIGHT, 0.79, 0.52)
end
local ParentFunc = function() -- who is the parent of this ui
return BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0)
end
TasUnitBonusEquipment[FourCC'I00G'] = {"STR+", 6} -- while equipred I00G gives 6 green STR
TasUnitBonusEquipment.I00I = {"Life", 150, "Spell", (FourCC'AIse')}
TasUnitBonusEquipment[item] = {"Mana", 100, "Life", 50, "Attack", 5}