Custom dummy cast function doesnt work

Embrace_It

New Member
Reaction score
9
I have made the following function:

JASS:

function DummyCastTarget takes unit source, unit target, integer abilityID, integer lvl, string order returns nothing
    local unit dummycaster = CreateUnit(GetOwningPlayer(source), DUMMY_CASTER, GetUnitX(source), GetUnitY(source), 0.)

    call UnitAddAbility(dummycaster, abilityID)
    call SetUnitAbilityLevel(dummycaster, abilityID, lvl)
    call IssueTargetOrder(dummycaster, order, target)
    call UnitApplyTimedLife(dummycaster, 'BTLF', LIFE_TIME)
    
    set dummycaster = null
endfunction


I based some abilities on 'Faeriefire' and used this, but it doesnt work...

I have double checked all vars as well...(DUMMY_CASTER/LIFE_TIME are globals)
 
Did you set the mana cost to 0? How long is the dummy alive for? If it's cast animation lasts longer than its life, it might not get to the cast.
 
Mana cost is zero. Dummy lives for 1 second. Casting time is zero.

Casting animation? Does that affect it or did you mean casting time? Also, where is that value found? I dont see it.

EDIT: Just tested with 1.5 and 3 seconds lifetime for the dummy, it does not work

EDIT2: I just tested it by removing 'Locust' and changing the model file from '.mdl' to 'Admiral Proudmoore', and the unit didnt even show up...

EDIT3: Now I tried basing an ability on 'Cripple' does work either. Something must be wrong with DummyCastTarget...
 
Or something must we wrong with the code wherein you're using your custom function. Could you please post it.
 
yeah your custom function is interesting, i've tried to make functions like that and theyall fail. lol. why not just use GetTriggerUnit() and so on instead of source and all that stuff?
 
True. It is not entirely finished yet. I have also double-checked 'Targets Allowed' now:

For DUMMY_CODE_SOURCE: Alive, Allied, Ground
For DUMMY_CODE_TARGET: Enemy, Ground, Neutral

Here is the code (uses TimerUtils (blue)):

JASS:
scope SniffOut initializer Init
private keyword Data

//  -------------
// | START SETUP |
//  -------------
globals
    private constant integer ABILITY_CODE      = 'A004'
    private constant integer DUMMY_CODE_TARGET = 'A003'
    private constant integer DUMMY_CODE_SOURCE = 'A00B'
    private constant integer BUFF_CODE_TARGET  = 'B000'
    private constant integer BUFF_CODE_SOURCE  = 'B003'
    private constant real TICK             = 1.
    private constant real UNIT_SPEED_DELTA = 50.
    private constant real MAX_RANGE        = 1000.
    private constant string ORDER_SOURCE = "cripple"
    private constant string ORDER_TARGET = "faeriefire"
endglobals

private function DurationPerLevel takes integer lvl returns real
    return (lvl - 1) * 2. + 20.
endfunction
//  -----------
// | END SETUP |
//  -----------

private struct Data
    unit source
    unit target
    integer counts

    static method create takes unit source, unit target, real duration returns Data
        local Data d = Data.allocate()
        
        set d.source = source
        set d.target = target
        set d.counts = R2I(duration)
        
        return d
    endmethod
    
    private method onDestroy takes nothing returns nothing
        call CreateFloatingTextTarget(.source, "Sniff Out fades", COMBAT_ABILITY)
        set .source = null
        set .target = null
    endmethod
endstruct

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == ABILITY_CODE
endfunction

private function Update takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local Data d = Data(GetTimerData(t))
    
    //call BJDebugMsg(R2S(RAbsBJ((AngleBetweenPoints(Location(GetUnitX(d.source), GetUnitY(d.source)), Location(GetOrderPointX(), GetOrderPointY()))) - GetUnitFacing(d.source))))
    
    if d.counts > 0 and GetUnitState(d.target, UNIT_STATE_LIFE) > 0.405 and DistanceBetweenUnits(d.source, d.target) <= MAX_RANGE then// and GetUnitAbilityLevel(d.target, BUFF_CODE_TARGET) > 0 then
        if GetUnitCurrentOrder(d.source) == MOVE_ORDER_ID then
            if RAbsBJ((AngleBetweenPoints(Location(GetUnitX(d.source), GetUnitY(d.source)), Location(GetOrderPointX(), GetOrderPointY()))) - GetUnitFacing(d.source)) <= 60. then
                call UnitRemoveAbility(d.source, BUFF_CODE_SOURCE)
                call UnitRemoveAbility(d.target, BUFF_CODE_TARGET)
                call SetUnitMoveSpeed(d.source, GetUnitMoveSpeed(d.source) - UNIT_SPEED_DELTA)
                call d.destroy()
                call ReleaseTimer(t)
            endif
        endif
        set d.counts = d.counts - 1
    else
        call UnitRemoveAbility(d.source, BUFF_CODE_SOURCE)
        call UnitRemoveAbility(d.target, BUFF_CODE_TARGET)
        call SetUnitMoveSpeed(d.source, GetUnitMoveSpeed(d.source) - UNIT_SPEED_DELTA)
        call d.destroy()
        call ReleaseTimer(t)
    endif
    
    set t = null
endfunction

private function AddDebuff takes nothing returns nothing
    local unit source = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local integer alvl = GetUnitAbilityLevel(source, ABILITY_CODE)
    local Data d
    local timer t
    
    call SetUnitMoveSpeed(source, GetUnitMoveSpeed(source) + UNIT_SPEED_DELTA)
    call DummyCastTarget(target, source, DUMMY_CODE_SOURCE, alvl, ORDER_SOURCE)
    call DummyCastTarget(source, target, DUMMY_CODE_TARGET, alvl, ORDER_TARGET)
    set d = Data.create(source, target, DurationPerLevel(alvl))
    set t = NewTimer()
    call SetTimerData(t, integer(d))
    call TimerStart(t, TICK, true, function Update)

    set source = null
    set target = null
    set t = null
endfunction

private function Actions takes nothing returns nothing
    if (GetUnitAbilityLevel(GetSpellTargetUnit(), BUFF_CODE_TARGET) > 0) then
        call CreateFloatingTextTarget(GetSpellTargetUnit(), "Restack!", COMBAT_ABILITY)
    endif
    call AddDebuff()
endfunction

// Main function
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(trig, Condition(function Conditions))
    call TriggerAddAction(trig, function Actions)
    set trig = null
endfunction

endscope


why not just use GetTriggerUnit() and so on instead of source and all that stuff?
Reply With Quote

Since this function is called from a library, GetTriggerUnit() is not defined as far as I know. GetTriggerUnit() is passed as source in the code as you can see. Please correct me, if this isnt true :)
 
In debugging strange problems, I find it very helpful to break down the problem into highly controllable / observable parts. I would modify the function DummyCastTarget temporarily so that the dummy is created and the ability is added. but do not add the expiration timer and do not issue the order. Remove locust, etc, so that the player can see and control it. Put your caster and a target into an isolated area for testing, and observe what happens when the spell is cast. Make sure the dummy is created and has the ability, then select it and order it to cast the ability yourself. Observe what happens, and that may provide a clue as to where this is going wrong.
 
You are absolutely right jwallstone!

I normally do this as well, but should have done so earlier. The function did not even spawn the units. I realized afterwards that the incorrect unit ID for the dummy caster was specified in my library, since I had originally copied it from another map. Very silly mistake indeed :eek:

It works now, lags a little though, but I'll optimize later...

Thanks for your help! +rep
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top