This is a code to cast an arrow spell automatically on friendly units.
There are two informations about it, which are important...
The good one: It works.
The bad one: There are two preplaced units, who are able to cast the spell...
It works with the first...
It works with the second...
But it does not work with both at once!
If I activate auto-cast for both units, they never cast at the same time, even if they could
(and when my debug messages say they should)!
I would really like to change that.
Any hints are welcome. ~~
header script:
Trigger "Initialisation":
There are two informations about it, which are important...
The good one: It works.
The bad one: There are two preplaced units, who are able to cast the spell...
It works with the first...
It works with the second...
But it does not work with both at once!
If I activate auto-cast for both units, they never cast at the same time, even if they could
(and when my debug messages say they should)!
I would really like to change that.
Any hints are welcome. ~~
JASS:
globals
integer udg_Cast_RecoverTimer_Order = -1
player array udg_Player
timer array udg_Cast_RecoverTime
trigger udg_CastAutomatical
endglobals
header script:
JASS:
//=================
// Filter - dryads
//=================
function Unitfilter_Dryad takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) == 'edry' and GetUnitUserData(GetFilterUnit()) == 0
endfunction
//===========================
// Filter - keeperOfTheGrove
//===========================
function Unitfilter_KeeperOfTheGrove takes nothing returns boolean
return GetFilterUnit() == gg_unit_Ekee_0040 or GetFilterUnit() == gg_unit_Ekee_0041
endfunction
//==============================
// Trigger - CastAutomatical
//==============================
function Trig_CastAutomatical_Actions takes nothing returns nothing
local filterfunc dryads
local group validTargets
local timer recoverTime
local unit lastTarget = null
local unit triggerUnit
if GetIssuedOrderId() == OrderId("flamingarrows") then
call BJDebugMsg("Automatical cast activated.")
set triggerUnit = GetTriggerUnit()
if triggerUnit == gg_unit_Ekee_0040 then
call BJDebugMsg("Order to keeper one.")
else
call BJDebugMsg("Order to keeper two.")
endif
set dryads = Filter(function Unitfilter_Dryad)
set validTargets = CreateGroup()
if udg_Cast_RecoverTime[0] == null then
call BJDebugMsg("Use of timer one.")
set udg_Cast_RecoverTime[0] = CreateTimer()
set recoverTime = udg_Cast_RecoverTime[0]
if triggerUnit == gg_unit_Ekee_0040 then
set udg_Cast_RecoverTime_Order = 0
else
set udg_Cast_RecoverTime_Order = 1
endif
else
call BJDebugMsg("Use of timer two.")
set udg_Cast_RecoverTime[1] = CreateTimer()
set recoverTime = udg_Cast_RecoverTime[1]
endif
call BJDebugMsg("Aquiring Targets...")
loop
exitwhen recoverTime != udg_Cast_RecoverTime[0] and recoverTime != udg_Cast_RecoverTime[1]
call BJDebugMsg("Target group created.")
call GroupEnumUnitsInRange(validTargets,GetUnitX(triggerUnit),GetUnitY(triggerUnit),1024,dryads)
loop
call ForGroup(validTargets,function GroupPickRandomUnitEnum)
exitwhen lastTarget != bj_groupRandomCurrentPick
endloop
set lastTarget = bj_groupRandomCurrentPick
if lastTarget != null then
call BJDebugMsg("Target aquired.")
call IssueTargetOrder(triggerUnit,"flamingarrowstarg",lastTarget)
call TimerStart(recoverTime,8,false,null)
loop
call TriggerSleepAction(0.01)
exitwhen TimerGetRemaining(recoverTime) <= 0 or (recoverTime != udg_Paarung_Erholung[0] and recoverTime != udg_Paarung_Erholung[1])
endloop
else
call BJDebugMsg("No Target.")
call TriggerSleepAction(0.01)
endif
call BJDebugMsg("Target group reseted.")
call GroupClear(validTargets)
exitwhen recoverTime != udg_Cast_RecoverTime[0] and recoverTime != udg_Cast_RecoverTime[1]
endloop
call DestroyFilter(dryads)
call DestroyGroup(validTargets)
call BJDebugMsg("Deactivation completed.")
set dryads = null
set validTargets = null
set recoverTime = null
set lastTarget = null
set triggerUnit = null
elseif GetIssuedOrderId() == OrderId("unflamingarrows") then
call BJDebugMsg("Automatical cast deactivated.")
if (udg_Cast_RecoverTime[0] != null and udg_Cast_RecoverTime[1] == null) or (udg_Cast_RecoverTime_Order == 0 and GetTriggerUnit() == gg_unit_Ekee_0040) or (udg_Cast_RecoverTime_Order == 1 and GetTriggerUnit() == gg_unit_Ekee_0041) then
call DestroyTimer(udg_Cast_RecoverTime[0])
set udg_Cast_RecoverTime[0] = null
else
call DestroyTimer(udg_Cast_RecoverTime[1])
set udg_Cast_RecoverTime[1] = null
endif
set udg_Cast_RecoverTime_Order = -1
endif
endfunction
Trigger "Initialisation":
JASS:
function Trig_Initialisation_Actions takes nothing returns nothing
//===========
// Variables
//===========
local filterfunc keeperOfTheGrove = Filter(function Unitfilter_KeeperOfTheGrove)
call DestroyTimer(udg_Cast_RecoverTime[0])
call DestroyTimer(udg_Cast_RecoverTime[1])
set udg_Cast_RecoverTime[0] = null
set udg_Cast_RecoverTime[1] = null
set udg_Player[0] = Player(0)
set udg_Player[1] = Player(1)
set udg_Player[2] = Player(10)
set udg_Player[3] = Player(12)
set udg_Player[4] = Player(15)
//==========
// Auslöser
//==========
set udg_CastAutomatical = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(udg_CastAutomatical,udg_Player[2],EVENT_PLAYER_UNIT_ISSUED_ORDER,keeperOfTheGrove)
call TriggerAddAction(udg_CastAutomatical,function Trig_CastAutomatical_Actions)
set keeperOfTheGrove = null
call DestroyTrigger(gg_trg_Initialisation)
endfunction
function InitTrig_Initialisation takes nothing returns nothing
set gg_trg_Initialisation = CreateTrigger()
call TriggerAddAction(gg_trg_Initialisation,function Trig_Initialisation_Actions)
endfunction