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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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