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)
 

jwallstone

New Member
Reaction score
33
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.
 

Embrace_It

New Member
Reaction score
9
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...
 

Tom Jones

N/A
Reaction score
437
Or something must we wrong with the code wherein you're using your custom function. Could you please post it.
 

SanKakU

Member
Reaction score
21
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?
 

Embrace_It

New Member
Reaction score
9
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 :)
 

jwallstone

New Member
Reaction score
33
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.
 

Embrace_It

New Member
Reaction score
9
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.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top