Problem with attaching to Unit and Timer (together)

Faust

You can change this now in User CP.
Reaction score
123
Hey. I'm creating a small, damage over time system for a race in my map.
Using PUI and ABC.
I'm trying to test it with an archer, that has Poison Arrows -like ability (so I can check for buff).
When I damage a unit with an attack, it should create a struct for it, if the struct already exists, modify some of its components (lastAttacker and FlameLevel).

The problem is, it always creates a new struct, so instead of having a value of the struct increase on each attack, it just has multiple struct instances with unchanged variable values.

This is the struct with the methods:
JASS:
scope Burn// initializer I

struct Burn
    //! runtextmacro PUI()
    unit victim
    unit lastAttacker
    timer clock = CreateTimer()
    real FlameLevel = 0
    effect array FlameEffect [2]
    
    method DestroyEffects takes nothing returns nothing
        call DestroyEffect(.FlameEffect[0])
        call DestroyEffect(.FlameEffect[1])
    endmethod
    
    method CalculateEffect takes unit u, real r returns nothing
    local integer i = 0
    call .DestroyEffects()
    if r >= 66 then
     set .FlameEffect[0] = CreateEffectOnUnit("Environment\\LargeBuildingFire\\LargeBuildingFire1.mdl", u, "origin")
     set .FlameEffect[1] = CreateEffectOnUnit("Environment\\LargeBuildingFire\\LargeBuildingFire1.mdl", u, "chest")
    elseif r >= 33 and r < 66 then
     set .FlameEffect[0] = CreateEffectOnUnit("Environment\\LargeBuildingFire\\LargeBuildingFire2.mdl", u, "origin")
     set .FlameEffect[1] = CreateEffectOnUnit("Environment\\LargeBuildingFire\\LargeBuildingFire2.mdl", u, "chest")
    elseif r < 33 then
     set .FlameEffect[0] = CreateEffectOnUnit("Environment\\SmallBuildingFire\\SmallBuildingFire2.mdl", u, "origin")
     set .FlameEffect[1] = CreateEffectOnUnit("Environment\\SmallBuildingFire\\SmallBuildingFire2.mdl", u, "chest")
    endif
    endmethod
    
    method onDestroy takes nothing returns nothing
        call PauseTimer(.clock)
        call ClearTimerStructA(.clock)
        call DestroyTimer(.clock)
        call DestroyEffect(.FlameEffect[0])
        call DestroyEffect(.FlameEffect[1])
    endmethod
    
static method Burning takes nothing returns nothing
    local Burn dat = GetTimerStructA(GetExpiredTimer())
    local real r
    if dat.FlameLevel > 100 then
     set dat.FlameLevel = 100
    endif
    set r = dat.FlameLevel + ((dat.FlameLevel / 2000) * GetUnitState(dat.victim, UNIT_STATE_MAX_LIFE))
    call DisableTrigger(GetTriggeringTrigger())
    call DamageTarget(dat.lastAttacker, dat.victim, r, false, false, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
    call EnableTrigger(GetTriggeringTrigger())
    call BJDebugMsg("Flamelevel: " + R2S(dat.FlameLevel))
    call dat.CalculateEffect(dat.victim, dat.FlameLevel)
    if dat.FlameLevel < 1 or GetWidgetLife(dat.victim) < 1 or dat.victim == null then
      call UnitRemoveAbility(dat.victim, 'A02F')
      call dat.release()
    endif
    if dat.FlameLevel < 33 then
     set dat.FlameLevel = dat.FlameLevel - 5
    endif
endmethod

static method create takes unit Victim, unit LastAttacker returns Burn
    local Burn dat = Burn.allocate()
    set dat.victim = Victim
    set dat.lastAttacker = LastAttacker
    call UnitAddAbility(Victim, 'A02F')
    set Burn[dat.victim] = dat
    call SetTimerStructA(dat.clock, dat)
    call TimerStart(dat.clock, 1, true, function Burn.Burning)
    return dat
endmethod

endstruct
endscope


This is the trigger for using the ability (ignore the item conditions and actions, not relevant):

JASS:
scope FlamingArrows initializer I

private function C1 takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(), 'B00S') > 0
endfunction

private function C2 takes nothing returns boolean
    return GetItemTypeId(GetSoldItem()) == 'I00B'
endfunction

private function A2 takes nothing returns nothing
    set TempItem = GetSoldItem()
    call RemoveItemFromStock(GetSellingUnit(), 'I00B')
    call UnitRemoveItem(GetTriggerUnit(), TempItem)
    call RemoveItem(TempItem)
    call UnitAddAbility(GetSellingUnit(), 'A02E')
endfunction

private function A1 takes nothing returns nothing
    local Burn dat = GetTriggerUnit():Burn
    call UnitRemoveAbility(GetTriggerUnit(), 'B00S')
    if dat == null then
     set dat = Burn.create(GetTriggerUnit(), GetEventDamageSource())
    endif
    set dat.lastAttacker = GetEventDamageSource()
    set dat.FlameLevel = dat.FlameLevel + GetUnitPointValue(dat.lastAttacker)
    call dat.CalculateEffect(dat.victim, dat.FlameLevel)    
endfunction

//===========================================================================
private function I takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitDamaged(t)
    call TriggerAddCondition(t, Condition(function C1))
    call TriggerAddAction(t, function A1)
    set t = CreateTrigger()
    call TriggerRegisterAnyUnitEvent(t,  EVENT_PLAYER_UNIT_SELL_ITEM)
    call TriggerAddCondition(t, Condition(function C2))
    call TriggerAddAction(t, function A2)
endfunction

endscope


So, what should I do?
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
I don't use PUI and neither ABC, so i don't look your code, maybe it's the same for many others.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
That's exactly the same (colon operator), read the jasshelper documentation.
 

cleeezzz

The Undead Ranger.
Reaction score
268
oh and also, if theres no stuct attached the the trig unit, shouldn't dat == 0? not null? but since you said it creates the struct every time, then i dont know
 

Faust

You can change this now in User CP.
Reaction score
123
Hmmm, odd. I always used dat == null, but dat == 0 indeed fixied it o_O Thank you!
 

cleeezzz

The Undead Ranger.
Reaction score
268
O_O *baffled*

thats weird because, it create the struct when dat == null.. when it was really 0

wonder how it passed the condition
 
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