Name | Type | is_array | initial_value |
GDD__Integers | integer | Yes | |
GDD__LeftMapGroup | group | No | |
GDD__TriggerArray | trigger | Yes | |
GDD__UnitArray | unit | Yes | |
GDD_Damage | real | No | |
GDD_DamagedUnit | unit | No | |
GDD_DamageSource | unit | No | |
GDD_Event | real | No | |
groupStoneDropOff | group | Yes | |
groupStoneResource | group | No | |
groupStoneWorker | group | No | |
InitialAmount | integer | No | |
J_EatTreeAbility | abilcode | No | |
J_HarvestReturnAbility | abilcode | No | |
J_LumberHarvestAbility | abilcode | No | |
J_Stone | unitcode | No | |
J_StoneMill | unitcode | Yes | |
MultiplierPerUpgrade | integer | No | |
OCG_Ability_Close | abilcode | No | |
OCG_Ability_Open | abilcode | No | |
OCG_Blocker_Column_Horizontal | destructablecode | No | |
OCG_Blocker_Column_Vertical | destructablecode | No | |
OCG_Blocker_Path | destructablecode | No | |
OCG_Gate_AnimTag | string | No | |
OCG_Path_Area | real | No | |
OCG_Structure_Horizontal | abilcode | No | |
OCG_Structure_Vertical | abilcode | No | |
playerStoneGather | integer | Yes | |
playerStoneHaul | integer | Yes | |
point | location | No | |
RangeCheck | integer | No | |
RangeCheck2 | real | No | |
StoneHash | hashtable | No | |
stopGroup | group | No | |
stopTimer | timer | No | |
tempGroup | group | No | |
tempGroup2 | group | No | |
tempInt | integer | No | |
tempPoint | location | No | |
tempPoint2 | location | No | |
tempPoint3 | location | No | |
unit | unit | No | |
UpUnit | unit | No | UnitNull |
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GroupTownHallIni_PlayerForce takes nothing returns nothing
set udg_playerStoneHaul[1+GetPlayerId(GetEnumPlayer())] = 10
set udg_playerStoneGather[1+GetPlayerId(GetEnumPlayer())] = 1
endfunction
function Trig_GroupTownHallIni_Actions takes nothing returns nothing
local group g
local unit u
local integer i
call ForForce( bj_FORCE_ALL_PLAYERS, function Trig_GroupTownHallIni_PlayerForce )
set udg_StoneHash = InitHashtable()
set g = CreateGroup()
call GroupEnumUnitsInRect(g,bj_mapInitialPlayableArea, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
set i = GetUnitTypeId(u)
call GroupRemoveUnit(g,u)
if( GetUnitTypeId(u) == udg_J_Stone) then
call GroupAddUnit( udg_groupStoneResource,u )
elseif ( GetUnitAbilityLevel( u, udg_J_HarvestReturnAbility) != 0 ) then
call GroupAddUnit( udg_groupStoneWorker, u )
elseif ( i == udg_J_StoneMill[1] or i == udg_J_StoneMill[2] or i == udg_J_StoneMill[3] or i == udg_J_StoneMill[4]) then
call GroupAddUnit(udg_groupStoneDropOff[1+GetPlayerId(GetOwningPlayer(u))], u )
endif
endloop
call DestroyGroup(g)
set g = null
endfunction
//===========================================================================
function InitTrig_StoneGroupsInit takes nothing returns nothing
set gg_trg_StoneGroupsInit = CreateTrigger( )
call TriggerAddAction( gg_trg_StoneGroupsInit, function Trig_GroupTownHallIni_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GroupAddStoneAndWorker_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
if ( GetUnitTypeId(u) == udg_J_Stone ) then
call GroupAddUnit( udg_groupStoneResource, u )
endif
if ( GetUnitAbilityLevel(u,udg_J_HarvestReturnAbility) > 0 ) then
call GroupAddUnit( udg_groupStoneWorker, u )
endif
set u = null
endfunction
//===========================================================================
function InitTrig_GroupAddStoneAndWorker takes nothing returns nothing
set gg_trg_GroupAddStoneAndWorker = CreateTrigger( )
call TriggerRegisterEnterRectSimple( gg_trg_GroupAddStoneAndWorker, bj_mapInitialPlayableArea )
call TriggerAddAction( gg_trg_GroupAddStoneAndWorker, function Trig_GroupAddStoneAndWorker_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GroupTownHallAdd_Conditions takes nothing returns boolean
local integer i = GetUnitTypeId(GetTriggerUnit())
return ( i == udg_J_StoneMill[1] or i == udg_J_StoneMill[2] or i == udg_J_StoneMill[3] or i == udg_J_StoneMill[4])
endfunction
function Trig_GroupTownHallAdd_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
call GroupAddUnit( udg_groupStoneDropOff[1+GetPlayerId(GetOwningPlayer(u))], u )
set u = null
endfunction
//===========================================================================
function InitTrig_GroupAddTownhall takes nothing returns nothing
set gg_trg_GroupAddTownhall = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GroupAddTownhall, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH )
call TriggerAddCondition( gg_trg_GroupAddTownhall, Condition( function Trig_GroupTownHallAdd_Conditions ) )
call TriggerAddAction( gg_trg_GroupAddTownhall, function Trig_GroupTownHallAdd_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GroupTownHallRemove_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer i = 1+GetPlayerId(GetOwningPlayer(u))
call GroupRemoveUnit(udg_groupStoneResource, u)
call GroupRemoveUnit(udg_groupStoneWorker, u)
call GroupRemoveUnit(udg_groupStoneDropOff[i], u)
call FlushChildHashtable( udg_StoneHash, GetHandleId(u) )
set u = null
endfunction
//===========================================================================
function InitTrig_GroupRemove takes nothing returns nothing
set gg_trg_GroupRemove = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GroupRemove, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddAction( gg_trg_GroupRemove, function Trig_GroupTownHallRemove_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GetPeasantOrder_Actions takes nothing returns nothing
local unit t = GetOrderTargetUnit()
local unit u = GetTriggerUnit()
if ( GetUnitTypeId(t) == udg_J_Stone ) then
if ( GetUnitAbilityLevel( u, udg_J_HarvestReturnAbility ) > 0 ) then
call SaveUnitHandle( udg_StoneHash, GetHandleId(u), 0, t )
if ( GetIssuedOrderId() != OrderId("attack") ) then
call IssueTargetOrder( u, "attack", t )
endif
else
call IssuePointOrder( u, "move", GetUnitX(t), GetUnitY(t) )
endif
endif
set t = null
set u = null
endfunction
//===========================================================================
function InitTrig_GetPeasantOrder takes nothing returns nothing
set gg_trg_GetPeasantOrder = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GetPeasantOrder, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
call TriggerAddAction( gg_trg_GetPeasantOrder, function Trig_GetPeasantOrder_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_GetPeasantReturn_Conditions takes nothing returns boolean
return GetUnitAbilityLevel( GetTriggerUnit(), udg_J_HarvestReturnAbility) != 0
endfunction
function Trig_GetPeasantReturn_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit t = GetOrderTargetUnit()
local integer h = GetHandleId(u)
if ( IsUnitInGroup(t, udg_groupStoneDropOff[1+GetPlayerId(GetOwningPlayer(u))]) == true and GetIssuedOrderId() == OrderId("smart") ) then
call SaveUnitHandle( udg_StoneHash, h, 2, t)
else
call SaveUnitHandle( udg_StoneHash, h, 2, u)
endif
set u = null
set t = null
endfunction
//===========================================================================
function InitTrig_GetPeasantReturn takes nothing returns nothing
set gg_trg_GetPeasantReturn = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GetPeasantReturn, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GetPeasantReturn, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
call TriggerRegisterAnyUnitEventBJ( gg_trg_GetPeasantReturn, EVENT_PLAYER_UNIT_ISSUED_ORDER )
call TriggerAddCondition( gg_trg_GetPeasantReturn, Condition( function Trig_GetPeasantReturn_Conditions ) )
call TriggerAddAction( gg_trg_GetPeasantReturn, function Trig_GetPeasantReturn_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_StoneDeath_StoneGroup takes nothing returns nothing
local unit u = GetEnumUnit()
local real distance
set udg_tempPoint2 = GetUnitLoc(u)
set distance = DistanceBetweenPoints(udg_tempPoint, udg_tempPoint2)
if ( udg_RangeCheck2 >= distance and udg_unit != u ) then
set udg_RangeCheck2 = distance
call IssueTargetOrder( udg_UpUnit, "smart", u )
else
endif
call RemoveLocation(udg_tempPoint2)
set u = null
endfunction
function Trig_StoneDeath_WorkerGroup takes nothing returns nothing
local unit u = GetEnumUnit()
if ( udg_unit == LoadUnitHandle(udg_StoneHash, GetHandleId(u), 0 ) ) then
set udg_tempPoint = GetUnitLoc(u)
set udg_UpUnit = u
set udg_RangeCheck2 = 999999.00
call ForGroup( udg_groupStoneResource, function Trig_StoneDeath_StoneGroup )
call RemoveLocation(udg_tempPoint)
endif
set u = null
endfunction
function Trig_StoneDeath_Actions takes nothing returns nothing
set udg_unit = GetTriggerUnit()
if ( GetUnitTypeId(udg_unit) == udg_J_Stone ) then
call ForGroup( udg_groupStoneWorker, function Trig_StoneDeath_WorkerGroup )
endif
endfunction
//===========================================================================
function InitTrig_StoneDeath takes nothing returns nothing
set gg_trg_StoneDeath = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_StoneDeath, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddAction( gg_trg_StoneDeath, function Trig_StoneDeath_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_TakeDamageStone_Conditions takes nothing returns boolean
return GetUnitAbilityLevel(udg_GDD_DamageSource,udg_J_HarvestReturnAbility) > 0 and GetUnitTypeId(udg_GDD_DamagedUnit) == udg_J_Stone
endfunction
function Trig_TakeDamageStone_Actions takes nothing returns nothing
local unit s = udg_GDD_DamageSource
local integer h = GetHandleId(s)
call UnitRemoveAbility(s,udg_J_LumberHarvestAbility)
call UnitAddAbility(s,udg_J_EatTreeAbility)
call AddUnitAnimationProperties( s, "lumber", FALSE )
if ( GetUnitAbilityLevel( s, udg_J_HarvestReturnAbility ) > 0 ) then
call AddUnitAnimationProperties( s, "gold", TRUE )
call SaveInteger(udg_StoneHash, h, 1, ( LoadInteger(udg_StoneHash, h, 1) + udg_playerStoneGather[1+GetPlayerId(GetOwningPlayer(s))] ))
if ( LoadInteger(udg_StoneHash, h, 1 ) >= udg_playerStoneHaul[1+GetPlayerId(GetOwningPlayer(s))] ) then
call IssueImmediateOrder( s, "berserk" )
else
call IssueTargetOrder( GetEventDamageSource(), "attack", udg_GDD_DamagedUnit )
endif
endif
set s = null
endfunction
//===========================================================================
function InitTrig_TakeDamageStone takes nothing returns nothing
set gg_trg_TakeDamageStone = CreateTrigger( )
call TriggerRegisterVariableEvent( gg_trg_TakeDamageStone, "udg_GDD_Event", EQUAL, 0 )
call TriggerAddAction( gg_trg_TakeDamageStone, function Trig_TakeDamageStone_Actions )
call TriggerAddCondition( gg_trg_TakeDamageStone, Condition(function Trig_TakeDamageStone_Conditions ))
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_ForceReturn_Conditions takes nothing returns boolean
return GetSpellAbilityId() == udg_J_HarvestReturnAbility
endfunction
function Trig_ForceReturn_DropOffGroup takes nothing returns nothing
local unit u = GetEnumUnit()
local real distance
set udg_tempPoint2 = GetUnitLoc(u)
set distance = DistanceBetweenPoints(udg_tempPoint, udg_tempPoint2)
if ( udg_RangeCheck2 >= distance ) then
set udg_RangeCheck2 = distance
call IssueTargetOrder( udg_unit, "smart", u )
endif
call RemoveLocation(udg_tempPoint2)
set u = null
endfunction
function Trig_ForceReturn_Actions takes nothing returns nothing
set udg_unit = GetTriggerUnit()
if(LoadInteger(udg_StoneHash, GetHandleId(udg_unit), 1) > 0) then
call IssueImmediateOrder( udg_unit, "stop" )
set udg_tempPoint = GetUnitLoc(udg_unit)
set udg_RangeCheck2 = 999999.00
call ForGroup( udg_groupStoneDropOff[1+GetPlayerId(GetOwningPlayer(udg_unit))], function Trig_ForceReturn_DropOffGroup )
call RemoveLocation(udg_tempPoint)
else
call IssueImmediateOrder( udg_unit, "resumeharvesting" )
endif
endfunction
//===========================================================================
function InitTrig_ForceReturn takes nothing returns nothing
set gg_trg_ForceReturn = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_ForceReturn, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_ForceReturn, Condition( function Trig_ForceReturn_Conditions ) )
call TriggerAddAction( gg_trg_ForceReturn, function Trig_ForceReturn_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_CheckRockDropoff_DropOff takes nothing returns nothing
local group g
local unit u
local integer h
set udg_unit = GetEnumUnit()
set g = CreateGroup()
call GroupEnumUnitsInRange(g,GetUnitX(udg_unit),GetUnitY(udg_unit ),300,null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g,u)
set h = GetHandleId(u)
if(GetOwningPlayer(u) == GetOwningPlayer(udg_unit) and LoadInteger(udg_StoneHash, h, 1) > 0 and LoadUnitHandle(udg_StoneHash, h, 2) == udg_unit ) then
call CreateTextTagUnitBJ( ( "+" + I2S(LoadInteger(udg_StoneHash, h, 1 )) ), u, 0, 9.00, 60.00, 60.00, 60.00, 0 )
call SetTextTagVelocityBJ( bj_lastCreatedTextTag, 64.00, 90 )
call SetTextTagFadepoint( bj_lastCreatedTextTag, 0.75 )
call SetTextTagLifespan( bj_lastCreatedTextTag, 1.50 )
call SetTextTagPermanent( bj_lastCreatedTextTag, false )
call AdjustPlayerStateBJ( LoadInteger(udg_StoneHash, h, 1), GetOwningPlayer(u), PLAYER_STATE_RESOURCE_GOLD )
call SaveInteger( udg_StoneHash, h, 1, 0 )
call AddUnitAnimationProperties( u, "gold", FALSE )
call IssueTargetOrder( u, "attack", LoadUnitHandle(udg_StoneHash, h, 0) )
endif
endloop
call DestroyGroup(g)
set g = null
set u = null
endfunction
function Trig_CheckRockDropoff_AllPlayers takes nothing returns nothing
call ForGroup( udg_groupStoneDropOff[1+GetPlayerId(GetEnumPlayer())], function Trig_CheckRockDropoff_DropOff )
endfunction
function Trig_CheckRockDropoff_Actions takes nothing returns nothing
call ForForce( bj_FORCE_ALL_PLAYERS, function Trig_CheckRockDropoff_AllPlayers )
endfunction
//===========================================================================
function InitTrig_CheckRockDropoff takes nothing returns nothing
set gg_trg_CheckRockDropoff = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_CheckRockDropoff, 0.33 )
call TriggerAddAction( gg_trg_CheckRockDropoff, function Trig_CheckRockDropoff_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_StopAttacking_Conditions takes nothing returns boolean
return IsUnitInGroup(GetTriggerUnit(), udg_groupStoneResource)
endfunction
function Trig_StopAttacking_Actions takes nothing returns nothing
local unit u = GetAttacker()
local integer h = GetHandleId(u)
if ( LoadInteger(udg_StoneHash, h,1 ) >= udg_playerStoneHaul[1+GetPlayerId(GetOwningPlayer(u))] ) then
call GroupAddUnit( udg_stopGroup, u )
call TimerStart( udg_stopTimer, 0.00, false, null )
endif
set u = null
endfunction
//===========================================================================
function InitTrig_StopAttacking takes nothing returns nothing
set gg_trg_StopAttacking = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_StopAttacking, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition( gg_trg_StopAttacking, Condition( function Trig_StopAttacking_Conditions ) )
call TriggerAddAction( gg_trg_StopAttacking, function Trig_StopAttacking_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_StartHarvestLumber_Conditions takes nothing returns boolean
return GetSpellAbilityId() == udg_J_EatTreeAbility
endfunction
function Trig_StartHarvestLumber_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local destructable d = GetSpellTargetDestructable()
call IssueImmediateOrder( u, "stop" )
call SetUnitAnimation( u, "attack" )
call AddUnitAnimationProperties( u, "gold", FALSE )
call SaveInteger(udg_StoneHash, GetHandleId(u), 1, 0)
call UnitRemoveAbility(u,udg_J_EatTreeAbility)
call UnitAddAbility(u,udg_J_LumberHarvestAbility)
call IssueTargetOrder( u, "harvest", d )
set u = null
endfunction
//===========================================================================
function InitTrig_StartHarvestLumber takes nothing returns nothing
set gg_trg_StartHarvestLumber = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_StartHarvestLumber, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_StartHarvestLumber, Condition( function Trig_StartHarvestLumber_Conditions ) )
call TriggerAddAction( gg_trg_StartHarvestLumber, function Trig_StartHarvestLumber_Actions )
endfunction
//TESH.scrollpos=39
//TESH.alwaysfold=0
// GUI-Friendly Damage Detection -- v1.2.1 -- by Weep
// http:// www.thehelper.net/forums/showthread.php?t=137957
//
// Requires: only this trigger and its variables.
//
// -- What? --
// This snippet provides a leak-free, GUI-friendly implementation of an "any unit takes
// damage" event. It requires no JASS knowledge to use.
//
// It uses the Game - Value Of Real Variable event as its method of activating other
// triggers, and passes the event responses through a few globals.
//
// -- Why? --
// The traditional GUI method of setting up a trigger than runs when any unit is damaged
// leaks trigger events. This snippet is easy to implement and removes the need to do
// you own GUI damage detection setup.
//
// -- How To Implement --
// 0. Before you copy triggers that use GDD into a new map, you need to copy over GDD
// with its GDD Variable Creator trigger, or there will be a problem: the variables
// won't be automatically created correctly.
//
// 1. Be sure "Automatically create unknown variables while pasting trigger data" is
// enabled in the World Editor general preferences.
// 2. Copy this trigger category ("GDD") and paste it into your map.
// (Alternately: create the variables listed in the globals block below, create a
// trigger named "GUI Friendly Damage Detection", and paste in this entire text.)
// 3. Create your damage triggers using Game - Value Of Real Variable as the event,
// select GDD_Event as the variable, and leave the rest of the settings to the default
// "becomes Equal to 0.00".
// The event responses are the following variables:
// GDD_Damage is the amount of damage, replacing Event Response - Damage Taken.
// GDD_DamagedUnit is the damaged unit, replacing Event Response - Triggering Unit.
// Triggering Unit can still be used, if you need to use waits.
// Read the -- Notes -- section below for more info.
// GDD_DamageSource is the damaging unit, replacing Event Response - Damage Source.
//
// -- Notes --
// GDD's event response variables are not wait-safe; you can't use them after a wait in
// a trigger. If you need to use waits, Triggering Unit (a.k.a. GetTriggerUnit()) can
// be used in place of GDD_DamageSource. There is no usable wait-safe equivalent to
// Event Damage or Damage Source; you'll need to save the values yourself.
//
// Don't write any values to the variables used as the event responses, or it will mess
// up any other triggers using this snippet for their triggering. Only use their values.
//
// This uses arrays, so can detect damage for a maximum of 8190 units at a time, and
// cleans up data at a rate of 33.33 per second, by default. This should be enough for
// most maps, but if you want to change the rate, change the value returned in the
// GDD_RecycleRate function at the top of the code, below.
//
// By default, GDD will not register units that have Locust at the moment of their
// entering the game, and will not recognize when they take damage (which can only
// happen if the Locust ability is later removed from the unit.) To allow a unit to have
// Locust yet still cause GDD damage events if Locust is removed, you can either design
// the unit to not have Locust by default and add it via triggers after creation, or
// edit the GDD_Filter function at the top of the code, below.
//
// -- Credits --
// Captain Griffin on wc3c.net for the research and concept of GroupRefresh.
//
// Credit in your map not needed, but please include this README.
//
// -- Version History --
// 1.2.1: Minor code cleaning. Added configuration functions. Updated documentation.
// 1.2.0: Made this snippet work properly with recursive damage.
// 1.1.1: Added a check in order to not index units with the Locust ability (dummy units).
// If you wish to check for damage taken by a unit that is unselectable, do not
// give the unit-type Locust in the object editor; instead, add the Locust ability
// 'Aloc' via a trigger after its creation, then remove it.
// 1.1.0: Added a check in case a unit gets moved out of the map and back.
// 1.0.0: First release.
//===================================================================
// Configurables.
function GDD_RecycleRate takes nothing returns real //The rate at which the system checks units to see if they've been removed from the game
return 0.03
endfunction
function GDD_Filter takes unit u returns boolean //The condition a unit has to pass to have it registered for damage detection
return GetUnitAbilityLevel(u, 'Aloc') == 0 //By default, the system ignores Locust units, because they normally can't take damage anyway
endfunction
//===================================================================
// This is just for reference.
// If you use JassHelper, you could uncomment this section instead of creating the variables in the trigger editor.
// globals
// real udg_GDD_Event = 0.
// real udg_GDD_Damage = 0.
// unit udg_GDD_DamagedUnit
// unit udg_GDD_DamageSource
// trigger array udg_GDD__TriggerArray
// integer array udg_GDD__Integers
// unit array udg_GDD__UnitArray
// group udg_GDD__LeftMapGroup = CreateGroup()
// endglobals
//===================================================================
// System code follows. Don't touch!
function GDD_Event takes nothing returns boolean
local unit damagedcache = udg_GDD_DamagedUnit
local unit damagingcache = udg_GDD_DamageSource
local real damagecache = udg_GDD_Damage
set udg_GDD_DamagedUnit = GetTriggerUnit()
set udg_GDD_DamageSource = GetEventDamageSource()
set udg_GDD_Damage = GetEventDamage()
set udg_GDD_Event = 1.
set udg_GDD_Event = 0.
set udg_GDD_DamagedUnit = damagedcache
set udg_GDD_DamageSource = damagingcache
set udg_GDD_Damage = damagecache
set damagedcache = null
set damagingcache = null
return false
endfunction
function GDD_AddDetection takes nothing returns boolean
// if(udg_GDD__Integers[0] > 8190) then
// call BJDebugMsg("GDD: Too many damage events! Decrease number of units present in the map or increase recycle rate.")
// ***Recycle rate is specified in the GDD_RecycleRate function at the top of the code. Smaller is faster.***
// return
// endif
if(IsUnitInGroup(GetFilterUnit(), udg_GDD__LeftMapGroup)) then
call GroupRemoveUnit(udg_GDD__LeftMapGroup, GetFilterUnit())
elseif(GDD_Filter(GetFilterUnit())) then
set udg_GDD__Integers[0] = udg_GDD__Integers[0]+1
set udg_GDD__UnitArray[udg_GDD__Integers[0]] = GetFilterUnit()
set udg_GDD__TriggerArray[udg_GDD__Integers[0]] = CreateTrigger()
call TriggerRegisterUnitEvent(udg_GDD__TriggerArray[udg_GDD__Integers[0]], udg_GDD__UnitArray[udg_GDD__Integers[0]], EVENT_UNIT_DAMAGED)
call TriggerAddCondition(udg_GDD__TriggerArray[udg_GDD__Integers[0]], Condition(function GDD_Event))
endif
return false
endfunction
function GDD_PreplacedDetection takes nothing returns nothing
local group g = CreateGroup()
local integer i = 0
loop
call GroupEnumUnitsOfPlayer(g, Player(i), Condition(function GDD_AddDetection))
set i = i+1
exitwhen i == bj_MAX_PLAYER_SLOTS
endloop
call DestroyGroup(g)
set g = null
endfunction
function GDD_GroupRefresh takes nothing returns nothing
// Based on GroupRefresh by Captain Griffen on wc3c.net
if (bj_slotControlUsed[5063] == true) then
call GroupClear(udg_GDD__LeftMapGroup)
set bj_slotControlUsed[5063] = false
endif
call GroupAddUnit(udg_GDD__LeftMapGroup, GetEnumUnit())
endfunction
function GDD_Recycle takes nothing returns nothing
if(udg_GDD__Integers[0] <= 0) then
return
elseif(udg_GDD__Integers[1] <= 0) then
set udg_GDD__Integers[1] = udg_GDD__Integers[0]
endif
if(GetUnitTypeId(udg_GDD__UnitArray[udg_GDD__Integers[1]]) == 0) then
call DestroyTrigger(udg_GDD__TriggerArray[udg_GDD__Integers[1]])
set udg_GDD__TriggerArray[udg_GDD__Integers[1]] = null
set udg_GDD__TriggerArray[udg_GDD__Integers[1]] = udg_GDD__TriggerArray[udg_GDD__Integers[0]]
set udg_GDD__UnitArray[udg_GDD__Integers[1]] = udg_GDD__UnitArray[udg_GDD__Integers[0]]
set udg_GDD__UnitArray[udg_GDD__Integers[0]] = null
set udg_GDD__Integers[0] = udg_GDD__Integers[0]-1
endif
set udg_GDD__Integers[1] = udg_GDD__Integers[1]-1
endfunction
function GDD_LeaveMap takes nothing returns boolean
local boolean cached = bj_slotControlUsed[5063]
if(udg_GDD__Integers[2] < 64) then
set udg_GDD__Integers[2] = udg_GDD__Integers[2]+1
else
set bj_slotControlUsed[5063] = true
call ForGroup(udg_GDD__LeftMapGroup, function GDD_GroupRefresh)
set udg_GDD__Integers[2] = 0
endif
call GroupAddUnit(udg_GDD__LeftMapGroup, GetFilterUnit())
set bj_slotControlUsed[5063] = cached
return false
endfunction
// ===========================================================================
function InitTrig_GUI_Friendly_Damage_Detection takes nothing returns nothing
local region r = CreateRegion()
call RegionAddRect(r, GetWorldBounds())
call TriggerRegisterEnterRegion(CreateTrigger(), r, Condition(function GDD_AddDetection))
call TriggerRegisterLeaveRegion(CreateTrigger(), r, Condition(function GDD_LeaveMap))
call GDD_PreplacedDetection()
call TimerStart(CreateTimer(), GDD_RecycleRate(), true, function GDD_Recycle)
set r = null
endfunction