Deleted member 247165
D
Deleted member 247165
Would you be able to create a GUI alternate version of this? It would really help me improve the current AI I have. Besides, it's good to learn something new everyday! 
static method registerBehavior takes unit u, Behavior b, boolean isUserBehavior returns nothing
// Adds a custom Behavior to a single unit.
// If isUserBehavior is false, it will fire only for Computer owned units.
// If isUserBehavior is true, it will fire only for Player owned units.
static method registerBehaviorType takes integer uTypeId, Behavior b, boolean isUserBehavior returns nothing
// Adds a custom Behavior to an unit type.
// If isUserBehavior is false, it will fire only for Computer owned units.
// If isUserBehavior is true, it will fire only for Player owned units.
static method removeBehavior takes unit u, Behavior b returns nothing
// Removes a custom Behavior from a single unit.
static method removeBehaviorType takes integer uTypeId, Behavior b returns nothing
// Removes a custom Behavior from an unit type.
method onPeriod takes unit u returns nothing
// Fires on every interval. Use u to access the unit.
method onCast takes unit caster, unit target returns nothing
// Fires when the unit casts an ability. Use caster to access the unit.
method onTargeted takes unit target, unit caster returns nothing
// Fires when the unit is targeted with an ability. Use target to access the unit.
method onAttack takes unit attacker, unit target returns nothing
// Fires when the unit attacks. Use attacker to access the unit.
method onAttacked takes unit target, unit attacker returns nothing
// Fires when the unit is attacked. Use target to access the unit.
method onDamageDealt takes unit source, unit target returns nothing
// Fires when the unit deals damage. Use source to access the unit.
method onDamageTaken takes unit target, unit source returns nothing
// Fires when the unit receives damage. Use target to access the unit.
method onKill takes unit killer, unit victim returns nothing
// Fires when the unit kills another. Use killer to access the unit.
method onAllyCasts takes unit u, unit ally, unit target returns nothing
method onAllyTargeted takes unit u, unit ally, unit caster returns nothing
method onAllyAttacks takes unit u, unit ally, unit target returns nothing
method onAllyAttacked takes unit u, unit ally, unit attacker returns nothing
method onAllyDmgDealt takes unit u, unit ally, unit target returns nothing
method onAllyDmgTaken takes unit u, unit ally, unit source returns nothing
method onAllyKills takes unit u, unit ally, unit victim returns nothing
method onAllyDeath takes unit u, unit ally, unit killer returns nothing
// Events that will fire when a nearby friendly unit performs a certain action.
// These events will only activate if OTHER_UNITS_EVENTS is set to true.
// Use u to access the unit with custom behavior.
// Use ally to access the allied unit that fires the event.
method onEnemyCasts takes unit u, unit enemy, unit target returns nothing
method onEnemyTargeted takes unit u, unit enemy, unit caster returns nothing
method onEnemyAttacks takes unit u, unit enemy, unit target returns nothing
method onEnemyAttacked takes unit u, unit enemy, unit attacker returns nothing
method onEnemyDmgDealt takes unit u, unit enemy, unit target returns nothing
method onEnemyDmgTaken takes unit u, unit enemy, unit source returns nothing
method onEnemyKills takes unit u, unit enemy, unit victim returns nothing
method onEnemyDeath takes unit u, unit enemy, unit killer returns nothing
// Events that will fire when a nearby enemy unit performs a certain action.
// These events will only activate if OTHER_UNITS_EVENTS is set to true.
// Use u to access the unit with custom behavior.
// Use enemy to access the enemy unit that fires the event.
method create takes unit u returns thistype
// Registers the unit so it can use custom orders given by its Behavior.
method checkOrder takes string orderStr returns boolean
// Checks if an orders is already registered.
method checkOrderById takes integer orderId returns boolean
// Checks if an orders is already registered using integers for order id.
method isOrderInCooldown takes string orderStr returns boolean
// Checks if an orders is in cooldown.
method isOrderInCooldownById takes integer orderId returns boolean
// Checks if an orders is in cooldown using integers for order id.
method registerTargetOrder takes string orderStr, widget target, integer priority, real cooldown, integer manaCost returns nothing
method registerPointOrder takes string orderStr, real locX, real locY, integer priority, real cooldown, integer manaCost returns nothing
method registerInstantOrder takes string orderStr, integer priority, real cooldown, integer manaCost returns nothing
// Registers an order using strings.
method registerTargetOrderById takes integer orderId, widget target, integer priority, real cooldown, integer manaCost returns nothing
method registerPointOrderById takes integer orderId, real locX, real locY, integer priority, real cooldown, integer manaCost returns nothing
method registerInstantOrderById takes integer orderId, integer priority, real cooldown, integer manaCost returns nothing
// Registers an order using its order id
1. Used to register behaviors:
-Behavior_Unit (Unit that will be registered for an individual behavior)
-Behavior_UnitType (Used for Unit Type behaviors)
-Behavior_IsPlayerBehavior (If false, it will fire only for Computer owned units. If true, it will fire only for Player owned units)
2. Used to register events for the unit in a behavior:
-Behavior_OnPeriod (Registers a trigger that will fire on every interval. Use "Event_Unit" to access the unit)
-Behavior_OnCast (Registers a trigger that will fire when the unit casts an ability. Use "Event_Caster" to access the unit and "Event_Target" to access the target)
-Behavior_OnTargeted (Registers a trigger that will fire when the unit is targeted with an ability. Use "Event_Target" to access the unit and "Event_Caster" to access the caster)
-Behavior_OnAttack (Registers a trigger that will fire when the unit attacks. Use "Event_Attacker" to access the unit and "Event_Target" to access the target)
-Behavior_OnAttacked (Registers a trigger that will fire when the unit is attacked. Use "Event_Target" to access the unit and "Event_Attacker" to access the attacker)
-Behavior_OnDamageDealt (Registers a trigger that will fire when the unit deals damage. Use "Event_Source" to access the unit and "Event_Target" to access the target)
-Behavior_OnDamageTaken (Registers a trigger that will fire when the unit receives damage. Use "Event_Target" to access the unit and "Event_Source" to access the source of damage)
-Behavior_OnKill (Registers a trigger that will fire when the unit kills another. Use "Event_Killer" to access the unit and "Event_Victim" to access the dying unit)
3. Used to register events of nearby friendly units in a behavior:
-Behavior_OnAllyCasts (Registers a trigger that will fire when a nearby friendly unit casts an ability. Use "Event_Unit" to access the unit with custom behavior, "Event_Ally" to access the ally and "Event_Target" to access the target)
-Behavior_OnAllyTargeted (Registers a trigger that will fire when a nearby friendly unit is targeted with an ability. Use "Event_Unit" to access the unit with custom behavior, "Event_Ally" to access the ally and "Event_Caster" to access the caster)
-Behavior_OnAllyAttacks (Registers a trigger that will fire when a nearby friendly unit attacks. Use "Event_Unit" to access the unit with custom behavior, "Event_Ally" to access the ally and "Event_Target" to access the target)
-Behavior_OnAllyAttacked (Registers a trigger that will fire when a nearby friendly unit is attacked. Use "Event_Unit" to access the unit with custom behavior, "Event_Ally" to access the ally and "Event_Attacker" to access the attacker)
-Behavior_OnAllyDamageDealt (Registers a trigger that will fire when a nearby friendly unit deals damage. Use "Event_Unit" to access the unit with custom behavior, "Event_Ally" to access the ally and "Event_Target" to access the target)
-Behavior_OnAllyDamageTaken (Registers a trigger that will fire when a nearby friendly unit receives damage. Use "Event_Unit" to access the unit with custom behavior, "Event_Ally" to access the ally and "Event_Source" to access the source of damage)
-Behavior_OnAllyKills (Registers a trigger that will fire when a nearby friendly unit kills another. Use "Event_Unit" to access the unit with custom behavior, "Event_Ally" to access the ally and "Event_Victim" to access the dying unit)
-Behavior_OnAllyDeath (Registers a trigger that will fire when a nearby friendly unit is killed. Use "Event_Unit" to access the unit with custom behavior, "Event_Ally" to access the ally and "Event_Killer" to access the killer)
4. Used to register events of nearby enemy units in a behavior:
-Behavior_OnEnemyCasts (Registers a trigger that will fire when a nearby enemy unit casts an ability. Use "Event_Unit" to access the unit with custom behavior, "Event_Enemy" to access the enemy and "Event_Target" to access the target)
-Behavior_OnEnemyTargeted (Registers a trigger that will fire when a nearby enemy unit is targeted with an ability. Use "Event_Unit" to access the unit with custom behavior, "Event_Enemy" to access the enemy and "Event_Caster" to access the caster)
-Behavior_OnEnemyAttacks (Registers a trigger that will fire when a nearby enemy unit attacks. Use "Event_Unit" to access the unit with custom behavior, "Event_Enemy" to access the enemy and "Event_Target" to access the target)
-Behavior_OnEnemyAttacked (Registers a trigger that will fire when a nearby enemy unit is attacked. Use "Event_Unit" to access the unit with custom behavior, "Event_Enemy" to access the enemy and "Event_Attacker" to access the attacker)
-Behavior_OnEnemyDamageDealt (Registers a trigger that will fire when a nearby enemy unit deals damage. Use "Event_Unit" to access the unit with custom behavior, "Event_Enemy" to access the enemy and "Event_Target" to access the target)
-Behavior_OnEnemyDamageTaken (Registers a trigger that will fire when a nearby enemy unit receives damage. Use "Event_Unit" to access the unit with custom behavior, "Event_Enemy" to access the enemy and "Event_Source" to access the source of damage)
-Behavior_OnEnemyKills (Registers a trigger that will fire when a nearby enemy unit kills another. Use "Event_Unit" to access the unit with custom behavior, "Event_Enemy" to access the enemy and "Event_Victim" to access the dying unit)
-Behavior_OnEnemyDeath (Registers a trigger that will fire when a nearby enemy unit is killed. Use "Event_Unit" to access the unit with custom behavior, "Event_Enemy" to access the enemy and "Event_Killer" to access the killer)
5. Used to register custom orders:
-CustomO_Order (The order that will be used)
-CustomO_OrderId (For those abilities which must be cast using their Order Id. In those cases, use this instead of CustomO_Order)
-CustomO_Unit (The unit that will use the order. Check the different events to see which unit you should assign here)
-CustomO_Target (The unit that will be used as target of the order. Check the different events to see which unit you should assign here)
-CustomO_Location (The location to be used as target in Point-based abilities)
-CustomO_Priority (Priority assigned for the custom order. This will define the order in which the abilities will be used)
-CustomO_Cooldown (Cooldown time for the order)
-CustomO_ManaCost (Mana cost for the order)
library Example1 requires AIBehaviorController
// Defining a new Behavior
private struct Knight extends Behavior
// This one will fire when the Knight attacks another unit
method onAttack takes unit attacker, unit target returns nothing
local unit u = attacker
local CustomOrder o = CustomOrder.create(u)
// No target has been defined since the order to be registered will be an Instant Order
// Defining the order, priority, cooldown and mana cost
call o.registerInstantOrder("berserk", 100, 12, 0)
set u = null
endmethod
// Creating the behavior and attaching it to all units of this type
private static method onInit takes nothing returns nothing
local Behavior b = Knight.create()
call Controller.registerBehaviorType('hkni', b, false)
endmethod
endstruct
endlibrary
library Example2 requires AIBehaviorController
// Defining the first Behavior
private struct Sorceress1 extends Behavior
// This one will fire when the Sorceress attacks another unit
method onAttack takes unit attacker, unit target returns nothing
local unit u = attacker
local CustomOrder o = CustomOrder.create(u)
// Registering 2 orders inside the same event.
// In this case, the order that will be used first will be the one with higher priority if not in cooldown
// For the first order, we will use its Id because the order is based on Wand of Illusion
// The unit will cast this ability on itself
call o.registerTargetOrderById(852274, u, 100, 15, 50)
// Registering the second order
call o.registerTargetOrder("shockwave", target, 50, 10, 100)
set u = null
endmethod
// Creating the behavior and attaching it to all units of this type
private static method onInit takes nothing returns nothing
local Behavior b = Sorceress1.create()
call Controller.registerBehaviorType('hsor', b, false)
endmethod
endstruct
// Defining a second Behavior
private struct Sorceress2 extends Behavior
// Using an event fired by a nearby enemy unit. In this case, it will run when an enemy unit uses an ability
method onEnemyCasts takes unit u, unit enemy, unit target returns nothing
local CustomOrder o = CustomOrder.create(u)
// Checking if the enemy unit is a Necromancer
if GetUnitTypeId(enemy) == 'unec' then
call o.registerTargetOrder("frostnova", enemy, 100, 8, 75)
endif
endmethod
// Adding a second event to the Behavior. This one will run when a nearby enemy attacks another unit
method onEnemyAttacks takes unit u, unit enemy, unit attacker returns nothing
local CustomOrder o = CustomOrder.create(u)
// Checking if the enemy unit is a Necromancer
if GetUnitTypeId(enemy) == 'unec' then
call o.registerTargetOrder("frostnova", enemy, 100, 8, 75)
endif
endmethod
// Creating the behavior and attaching it to all units of this type
private static method onInit takes nothing returns nothing
local Behavior b = Sorceress2.create()
call Controller.registerBehaviorType('hsor', b, false)
endmethod
endstruct
endlibrary
library PaladinExample requires AIBehaviorController
// Defining a new Behavior
private struct Paladin extends Behavior
// Using 2 events fired by a nearby friendly unit and another event fired when a Paladin attacks
method onAllyAttacked takes unit u, unit ally, unit attacker returns nothing
local CustomOrder o = CustomOrder.create(u)
// Check if ally is below 50% hit points
if GetUnitStatePercent(ally, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE) <= 50. then
call o.registerTargetOrder("holybolt", ally, 30, 5, 60)
endif
endmethod
method onAllyAttacks takes unit u, unit ally, unit target returns nothing
local CustomOrder o = CustomOrder.create(u)
// If ally does not have the buff, then cast the ability
if not UnitHasBuffBJ(ally, 'Binf') then
call o.registerTargetOrder("innerfire", ally, 20, 3, 35)
endif
endmethod
method onAttack takes unit attacker, unit target returns nothing
local unit u = attacker
local CustomOrder o = CustomOrder.create(u)
// If the Paladin does not have the buff, then cast the ability on himself
if not UnitHasBuffBJ(u, 'Binf') then
call o.registerTargetOrder("innerfire", u, 15, 3, 35)
endif
set u = null
endmethod
// Creating the behavior and attaching it to all units of this type
private static method onInit takes nothing returns nothing
local Behavior b = Paladin.create()
call Controller.registerBehaviorType('Hpal', b, false)
endmethod
endstruct
endlibrary
library PaladinSpc requires AIBehaviorController
// This will be a more complex example. Here I will define 4 custom behaviors for 4 different Paladins
// Each Paladin will only use the Behavior that will be asigned to him
// If combined with the example above, all Paladins will have 2 custom Behaviors (Individual and Unit Type)
// Northwest Paladin
private struct PaladinNW extends Behavior
method onAttack takes unit attacker, unit target returns nothing
local unit u = attacker
local CustomOrder o = CustomOrder.create(u)
call o.registerTargetOrder("acidbomb", target, 25, 12, 75)
set u = null
endmethod
// Creating the behavior and attaching it to an specific Paladin
// Unlike the behaviors assigned to an Unit Type, the behaviors attached to an individual unit
// must be registered after all units have been indexed, so that custom values are available
private static method register takes nothing returns nothing
local Behavior b = PaladinNW.create()
call Controller.registerBehavior(gg_unit_Hpal_0038, b, false)
endmethod
// Once all the units are indexed, the behavior will be registered
private static method onInit takes nothing returns nothing
call OnUnitIndexerInitialized(function thistype.register)
endmethod
endstruct
// Northeast Paladin
private struct PaladinNE extends Behavior
method onAttacked takes unit target, unit attacker returns nothing
local unit u = target
local CustomOrder o = CustomOrder.create(u)
call o.registerInstantOrder("divineshield", 30, 25, 50)
set u = null
endmethod
private static method register takes nothing returns nothing
local Behavior b = PaladinNE.create()
call Controller.registerBehavior(gg_unit_Hpal_0037, b, false)
endmethod
private static method onInit takes nothing returns nothing
call OnUnitIndexerInitialized(function thistype.register)
endmethod
endstruct
// Southwest Paladin
private struct PaladinSW extends Behavior
method onEnemyCasts takes unit u, unit enemy, unit target returns nothing
local CustomOrder o = CustomOrder.create(u)
if GetUnitTypeId(enemy) == 'Udea' then
call o.registerTargetOrder("soulburn", enemy, 20, 12, 85)
endif
endmethod
method onEnemyAttacks takes unit u, unit enemy, unit target returns nothing
local CustomOrder o = CustomOrder.create(u)
if GetUnitTypeId(enemy) == 'Udea' then
call o.registerTargetOrder("soulburn", enemy, 20, 12, 85)
endif
endmethod
private static method register takes nothing returns nothing
local Behavior b = PaladinSW.create()
call Controller.registerBehavior(gg_unit_Hpal_0041, b, false)
endmethod
private static method onInit takes nothing returns nothing
call OnUnitIndexerInitialized(function thistype.register)
endmethod
endstruct
// Southeast Paladin
private struct PaladinSE extends Behavior
method onAllyAttacked takes unit u, unit ally, unit attacker returns nothing
local CustomOrder o = CustomOrder.create(u)
if GetUnitStatePercent(ally, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE) <= 70. then
call o.registerTargetOrder("healingwave", ally, 25, 9, 90)
endif
endmethod
private static method register takes nothing returns nothing
local Behavior b = PaladinSE.create()
call Controller.registerBehavior(gg_unit_Hpal_0046, b, false)
endmethod
private static method onInit takes nothing returns nothing
call OnUnitIndexerInitialized(function thistype.register)
endmethod
endstruct
endlibrary
library DKExample requires AIBehaviorController
// Defining a new Behavior for a Player-owned unit, in this case for our Death Knight
private struct DK extends Behavior
// This event will fire when a nearby enemy attacks
method onEnemyAttacks takes unit u, unit enemy, unit target returns nothing
local CustomOrder o = CustomOrder.create(u)
// If our Death Knight is low on mana, he will automatically use one of the available mana potions
if UnitHasItemOfTypeBJ(u, 'pman') and GetUnitState(u, UNIT_STATE_MANA) <= 80. then
call UnitUseItem(u, GetItemOfTypeFromUnitBJ(u, 'pman'))
endif
// Ordering our Death Knight to automatically use Death Coil against the attacking enemy
call o.registerTargetOrder("deathcoil", enemy, 100, 6, 75)
endmethod
// Creating the behavior and attaching it to all units of this type
private static method onInit takes nothing returns nothing
local Behavior b = DK.create()
call Controller.registerBehaviorType('Udea', b, true) // If true, this Behavior will trigger only for Player units
endmethod
endstruct
endlibrary