• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Dummy Adds Buff

Status
Not open for further replies.
Level 6
Joined
Aug 4, 2012
Messages
193
I was trying to make a dummy to add buff to damaged unit, but i failed. Any suggestion?

JASS:
function AntiMagicShell_Conditions takes nothing returns boolean
    return(GetUnitTypeId(udg_GDD_DamagedUnit)=='U001')or(GetUnitTypeId(udg_GDD_DamagedUnit)=='U002')or(GetUnitTypeId(udg_GDD_DamagedUnit)=='U003')
endfunction

function AntiMagicShell_Actions takes nothing returns nothing
    local location udg_GDD_DamagedUnit_Loc=GetUnitLoc(udg_GDD_DamagedUnit)
    local unit AntiMagicShellDummy=CreateUnitAtLoc(Player(10),'h00P',udg_GDD_DamagedUnit_Loc,270.)
    local timer AntiMagicShell_CD=CreateTimer()
    call DisableTrigger(GetTriggeringTrigger())
    call UnitAddAbility(AntiMagicShellDummy,'A000')
    call IssueTargetOrder(AntiMagicShellDummy,"antimagicshell",udg_GDD_DamagedUnit)
    call TimerStart(AntiMagicShell_CD,GetRandomInt(10,20),false,null)
    if TimerGetRemaining(AntiMagicShell_CD)<=0 then
        call EnableTrigger(GetTriggeringTrigger())
    endif
    call RemoveUnit(AntiMagicShellDummy)
    set AntiMagicShellDummy=null
    call DestroyTimer(AntiMagicShell_CD)
    call RemoveLocation(udg_GDD_DamagedUnit_Loc)
endfunction

function InitTrig_AntiMagicShell takes nothing returns nothing
    set gg_trg_AntiMagicShell=CreateTrigger()
    call TriggerRegisterVariableEvent(gg_trg_AntiMagicShell,"udg_GDD_Event",EQUAL,0)
    call TriggerAddCondition(gg_trg_AntiMagicShell,Condition(function AntiMagicShell_Conditions))
    call TriggerAddAction(gg_trg_AntiMagicShell,function AntiMagicShell_Actions)
endfunction
 
Last edited:

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Okay there are quite a few small changes you could make, I can point those out if you want to.

But the main problem is that you do not understand how to use a timer properly.
If you use plain jass, you need a GUI variable for the dummy unit, or if vjass is fine you simply declare a global variable in a global block instead.

Try this (You need a GUI unit variable named "myGuiVariable" to prevent errors):
JASS:
function AntiMagicShell_Conditions takes nothing returns boolean
    return(GetUnitTypeId(udg_GDD_DamagedUnit)=='U001')or(GetUnitTypeId(udg_GDD_DamagedUnit)=='U002')or(GetUnitTypeId(udg_GDD_DamagedUnit)=='U003')
endfunction

function timerIsNowGone takes nothing returns nothing
    call EnableTrigger(gg_trg_AntiMagicShell)
    call RemoveUnit(udg_myGuiVariable)
endfunction

function AntiMagicShell_Actions takes nothing returns nothing
    local location udg_GDD_DamagedUnit_Loc=GetUnitLoc(udg_GDD_DamagedUnit)
    set udg_myGuiVariable =CreateUnitAtLoc(Player(10),'h00P',udg_GDD_DamagedUnit_Loc,270.)
    call DisableTrigger(gg_trg_AntiMagicShell)
    call UnitAddAbility(udg_myGuiVariable,'A000')
    call IssueTargetOrder(udg_myGuiVariable,"antimagicshell",udg_GDD_DamagedUnit)
    call TimerStart(CreateTimer(),GetRandomInt(10,20),false, function timerIsNowGone)
    call RemoveLocation(udg_GDD_DamagedUnit_Loc)
endfunction

function InitTrig_AntiMagicShell takes nothing returns nothing
    set gg_trg_AntiMagicShell=CreateTrigger()
    call TriggerRegisterVariableEvent(gg_trg_AntiMagicShell,"udg_GDD_Event",EQUAL,0)
    call TriggerAddCondition(gg_trg_AntiMagicShell,Condition(function AntiMagicShell_Conditions))
    call TriggerAddAction(gg_trg_AntiMagicShell,function AntiMagicShell_Actions)
endfunction

This example is not MUI, I am too lazy to create that to the honest.
 
Last edited:
Level 6
Joined
Aug 4, 2012
Messages
193
So that's how I use timer? I convert from BJ to native where I see BJ set handlerFunc to null. I shall try it now to see whether it works or not.
 
Level 6
Joined
Aug 4, 2012
Messages
193
Unfortunately, still the same result after I made the changed you mentioned. This is how it looks like now:
JASS:
function AntiMagicShell_Conditions takes nothing returns boolean
    return(GetUnitTypeId(udg_GDD_DamagedUnit)=='U001')or(GetUnitTypeId(udg_GDD_DamagedUnit)=='U002')or(GetUnitTypeId(udg_GDD_DamagedUnit)=='U003')
endfunction

function AMS_CD_End takes nothing returns nothing
    call EnableTrigger(gg_trg_AntiMagicShell)
endfunction

function AntiMagicShell_Actions takes nothing returns nothing
    local location udg_GDD_DamagedUnit_Loc=GetUnitLoc(udg_GDD_DamagedUnit)
    local unit AntiMagicShellDummy=CreateUnitAtLoc(Player(12),'h00P',udg_GDD_DamagedUnit_Loc,270.)
    local timer AntiMagicShell_CD=CreateTimer()
    call DisableTrigger(GetTriggeringTrigger())
    call UnitAddAbility(AntiMagicShellDummy,'A000')
    call IssueTargetOrder(AntiMagicShellDummy,"antimagicshell",udg_GDD_DamagedUnit)
    call TimerStart(AntiMagicShell_CD,GetRandomInt(10,20),false,function AMS_CD_End)
    call RemoveLocation(udg_GDD_DamagedUnit_Loc)
    call RemoveUnit(AntiMagicShellDummy)
    call DestroyTimer(AntiMagicShell_CD)
endfunction

function InitTrig_AntiMagicShell takes nothing returns nothing
    set gg_trg_AntiMagicShell=CreateTrigger()
    call TriggerRegisterVariableEvent(gg_trg_AntiMagicShell,"udg_GDD_Event",EQUAL,0)
    call TriggerAddCondition(gg_trg_AntiMagicShell,Condition(function AntiMagicShell_Conditions))
    call TriggerAddAction(gg_trg_AntiMagicShell,function AntiMagicShell_Actions)
endfunction
 
Status
Not open for further replies.
Top