'Damage' (System) Help

WolfieeifloW

WEHZ Helper
Reaction score
372
Hey there.
I've just 'installed' Damage, and am trying to convert all my spells over and I've already ran into problems :)().
I've created a 'DamageText' system to pair up with the Damage system.
It's here:
JASS:
scope DamageText initializer init
    
    private function Conditions takes nothing returns boolean
        local texttag tt
        
        set tt = CreateTextTag()
        call SetTextTagText(tt, I2S(R2I(GetEventDamage())), 8 * 0.023 / 10)
        call SetTextTagPosUnit(tt, GetTriggerUnit(), 0.)
        if (Damage_IsAttack()) then
            call SetTextTagColor(tt, 255, 255, 255, 255)
        elseif (Damage_IsSpell()) then
            call SetTextTagColor(tt, 255, 255, 0, 255)
        endif
        call SetTextTagPermanent(tt, false)
        call SetTextTagLifespan(tt, 2)
        call SetTextTagFadepoint(tt, 1)
        call SetTextTagVelocity(tt, 0, 0.05)
        set tt = null
        return false
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call Damage_RegisterEvent(t)
        call TriggerAddCondition(t, Condition(function Conditions))
        set t = null
    endfunction
        
endscope


Now, I'm trying to convert my Death Coil spell over, so I set the damage in the Object Editor to 0.
I then created this code:
JASS:
scope DeathCoilDK initializer init

    private function Damage takes integer level returns real
        return level * 10.
    endfunction

    private function Conditions takes nothing returns boolean
        call BJDebugMsg("Att: " + GetUnitName(GetAttacker()))
        call BJDebugMsg("EDS: " + GetUnitName(GetEventDamageSource()))
        call BJDebugMsg("Def: " + GetUnitName(GetTriggerUnit()))
        
        if (GetSpellAbilityId() == deathCoilDK) then
            call Damage_Spell(GetEventDamageSource(), GetTriggerUnit(), Damage(GetUnitAbilityLevel(GetEventDamageSource(), deathCoilDK)))
        endif
        return false
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call Damage_RegisterZeroEvent(t)
        call TriggerAddCondition(t, Condition(function Conditions))
        set t = null
    endfunction

endscope

No floating text is created, and the BJ's show this:
Att:
EDS:
Def: TargetUnit
So, I went ahead and set the damage of the Death Coil in the OE to 1, and tried the 'normal' event:
JASS:
scope DeathCoilDK initializer init

    private function Damage takes integer level returns real
        return (level * 10.) - 1
    endfunction

    private function Conditions takes nothing returns boolean
        call BJDebugMsg("Att: " + GetUnitName(GetAttacker()))
        call BJDebugMsg("EDS: " + GetUnitName(GetEventDamageSource()))
        call BJDebugMsg("Def: " + GetUnitName(GetTriggerUnit()))
        
        if (GetSpellAbilityId() == deathCoilDK) then
            call Damage_Spell(GetEventDamageSource(), GetTriggerUnit(), Damage(GetUnitAbilityLevel(GetEventDamageSource(), deathCoilDK)))
        endif
        return false
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call Damage_RegisterEvent(t)
        call TriggerAddCondition(t, Condition(function Conditions))
        set t = null
    endfunction

endscope

Note the change to the Damage function.
It now shows floating text that says '0', but the BJ's display the same thing.

What am I doing wrong?
 

Ayanami

칼리
Reaction score
288
Your code has some problems.

JASS:
scope DeathCoilDK initializer init

    private function Damage takes integer level returns real
        return level * 10.
    endfunction

    private function Conditions takes nothing returns boolean
        call BJDebugMsg("Att: " + GetUnitName(GetAttacker())) // a damage event doesn't have an attacker, only damage source (GetEventDamageSource()) and damaged unit (GetTriggerUnit())
        call BJDebugMsg("EDS: " + GetUnitName(GetEventDamageSource())) // i'm not sure why this isn't showing :/
        call BJDebugMsg("Def: " + GetUnitName(GetTriggerUnit())) // works fine I presume
        
        if (GetSpellAbilityId() == deathCoilDK) then // in a damage event, you can't have GetSpellAbilityId(), as the event doesn't refer to any ability cast, etc
            call Damage_Spell(GetEventDamageSource(), GetTriggerUnit(), Damage(GetUnitAbilityLevel(GetEventDamageSource(), deathCoilDK)))
        endif
        return false
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call Damage_RegisterZeroEvent(t)
        call TriggerAddCondition(t, Condition(function Conditions))
        set t = null
    endfunction

endscope


Instead of detecting for zero damage, why not just deal damage directly from the first place?

JASS:
scope DeathCoil initializer OnInit
    globals
        private constant integer ABILID = 'A000' // raw code of Death Coil
    endglobals

    private function OnCast takes nothing returns boolean
        call Damage_Spell(GetTriggerUnit(), GetSpellTargetUnit(), 100.) // deal the damage

        return false
    endfunction

    private function OnInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call GT_RegisterStartsEffectEvent(t, ABILID)
        call TriggerAddCondition(t, Condition(function OnCast))
        set t = null
    endfunction
endscope


Note that I used GTrigger. I recommend you use it too if you aren't.
 

tooltiperror

Super Moderator
Reaction score
231
GTrigger is a lot of bloat for stuff most people don't need, but I can't complain about that...

Anyways, Glenphir, you should be inlining your GT calls I guess, that's what the kids do these days, since GT_RegisterXEvent returns the trigger passed in.

JASS:
private function onInit takes nothing returns nothing
    call TriggerAddCondition(GT_RegisterStartsEffectEvent(CreateTrigger(), ABILID)), Condition(function OnCast))
endfunction


Also, nowadays it's onEvent, not OnEvent.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Do I need GTrigger?
I have Event (Obviously, a requirement of Damage).
Is there anyway to use what I already have as to avoid another system?
 

tooltiperror

Super Moderator
Reaction score
231
Don't try to avoid adding systems. That is foolish, and leads to making worse code.

GTrigger is really good. Let's say you have 50 spells in your map, as I assume you have something around that.

16 events generated per spell, that's 800 events being created.
With 50 spells, you are running 50 events every time a player casts any spell.

The solution is to use a trigger array, each trigger unique to a Spell ID. Or, to be simpler, use GTrigger. It's a really good system, and saves you a lot of events.
 

Ayanami

칼리
Reaction score
288
GTrigger is a lot of bloat for stuff most people don't need, but I can't complain about that...

Anyways, Glenphir, you should be inlining your GT calls I guess, that's what the kids do these days, since GT_RegisterXEvent returns the trigger passed in.

JASS:
private function onInit takes nothing returns nothing
    call TriggerAddCondition(GT_RegisterStartsEffectEvent(CreateTrigger(), ABILID)), Condition(function OnCast))
endfunction


Also, nowadays it's onEvent, not OnEvent.

I thought camel casing is for methods only? I always thought functions are capital case for the first letter @_@
 

Laiev

Hey Listen!!
Reaction score
188
most of system just don't care about the init function name, they use

function Init takes nothing returns nothing

or

function init takes nothing returns nothing
 

WolfieeifloW

WEHZ Helper
Reaction score
372
It semi-works now.
It deals damage correctly, but the damage text shows a yellow "10", and then a white "0".
How would I fix this? Maybe stop zero damage events from triggering the DamageText?

Here's the Death Coil script:
JASS:
scope DeathCoilDK initializer onInit

    private function Damage takes integer level returns real
        return level * 10.
    endfunction

    private function onCast takes nothing returns boolean
        call Damage_Spell(GetTriggerUnit(), GetSpellTargetUnit(), Damage(GetUnitAbilityLevel(GetTriggerUnit(), deathCoilDK)))
        return false
    endfunction

    private function onInit takes nothing returns nothing
        call TriggerAddCondition(GT_RegisterStartsEffectEvent(CreateTrigger(), deathCoilDK), Condition(function onCast))
    endfunction

endscope

Here's the DamageText script:
JASS:
scope DamageText initializer init
    
    private function Conditions takes nothing returns boolean
        local texttag tt
        
        set tt = CreateTextTag()
        call SetTextTagText(tt, I2S(R2I(GetEventDamage())), 8 * 0.023 / 10)
        call SetTextTagPosUnit(tt, GetTriggerUnit(), 0.)
        if (Damage_IsAttack()) then
            call SetTextTagColor(tt, 255, 255, 255, 255)
        elseif (Damage_IsSpell()) then
            call SetTextTagColor(tt, 255, 255, 0, 255)
        endif
        call SetTextTagPermanent(tt, false)
        call SetTextTagLifespan(tt, 2)
        call SetTextTagFadepoint(tt, 1)
        call SetTextTagVelocity(tt, 0, 0.05)
        set tt = null
        return false
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call Damage_RegisterEvent(t)
        call TriggerAddCondition(t, Condition(function Conditions))
        set t = null
    endfunction
        
endscope
 

Ayanami

칼리
Reaction score
288
This:
JASS:
scope DamageText initializer init
    
    private function Conditions takes nothing returns boolean
        local texttag tt
        
        if GetEventDamage() > 0 then
            set tt = CreateTextTag()
            call SetTextTagText(tt, I2S(R2I(GetEventDamage())), 8 * 0.023 / 10)
            call SetTextTagPosUnit(tt, GetTriggerUnit(), 0.)
            if (Damage_IsAttack()) then
                call SetTextTagColor(tt, 255, 255, 255, 255)
            elseif (Damage_IsSpell()) then
                call SetTextTagColor(tt, 255, 255, 0, 255)
            endif
            call SetTextTagPermanent(tt, false)
            call SetTextTagLifespan(tt, 2)
            call SetTextTagFadepoint(tt, 1)
            call SetTextTagVelocity(tt, 0, 0.05)
        endif

        set tt = null
        return false
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call Damage_RegisterEvent(t)
        call TriggerAddCondition(t, Condition(function Conditions))
        set t = null
    endfunction
        
endscope
 

dudeim

New Member
Reaction score
22
or change the isAttack() to isNormal() (i think that's how it's called) if it still doesn't work, it will register all normal attacks and normal damage dealt using the function provided.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Any optimization I could do to that, besides switching it over to GTrigger?
Nevermind, I don't need to use GTrigger, I think?


/EDIT: It still shows both numbers, even with using IsPhysical() instead of IsAttack().
JASS:
scope DamageText initializer init
    
    private function Conditions takes nothing returns boolean
        local texttag tt
        
        if GetEventDamage() > 0 then
            set tt = CreateTextTag()
            call SetTextTagText(tt, I2S(R2I(GetEventDamage())), 8 * 0.023 / 10)
            call SetTextTagPosUnit(tt, GetTriggerUnit(), 0.)
            if (Damage_IsAttack()) then
            //if (Damage_IsPhysical()) then
                call SetTextTagColor(tt, 255, 255, 255, 255)
            elseif (Damage_IsSpell()) then
                call SetTextTagColor(tt, 255, 255, 0, 255)
            endif
            call SetTextTagPermanent(tt, false)
            call SetTextTagLifespan(tt, 2)
            call SetTextTagFadepoint(tt, 1)
            call SetTextTagVelocity(tt, 0, 0.05)
        endif

        set tt = null
        return false
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call Damage_RegisterEvent(t)
        call TriggerAddCondition(t, Condition(function Conditions))
        set t = null
    endfunction
        
endscope
 

Laiev

Hey Listen!!
Reaction score
188
Damage_RegisterEvent

Don't register 0 damage, this is why we have a Damage_RegisterZeroEvent
 

dudeim

New Member
Reaction score
22
Instead of Death Coil spell use Channel and change it to your needs, channel is the ultimate custom spell as it can change the base order id and lots of other values too, and it doesn't deal damage so I think that might fix all your problems.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
I'm using Damage_RegisterEvent, but it still shows a yellow 10, followed by a white 0 for some reason.
I really don't want to have to change all my spells over to Channel, but I guess it would be better..
 

Ayanami

칼리
Reaction score
288
Actually, it could be that the damage isn't 0, but maybe somewhere in between 0 and 1. Try displaying the real value rather than the I2S value.
 

Laiev

Hey Listen!!
Reaction score
188
I'm using Damage_RegisterEvent, but it still shows a yellow 10, followed by a white 0 for some reason.
I really don't want to have to change all my spells over to Channel, but I guess it would be better..

Whats the base ability of your spell?

Also, make sure that you set the damage in all fields to 0

No other trigger deals damage?
 

WolfieeifloW

WEHZ Helper
Reaction score
372
The base ability is indeed Death Coil.
I didn't plan on using Damage, but I see it would be easier to use later on.

The damage for the level 1 field (What level I'm testing with) is 0.
And I'm quite certain no other trigger would be dealing damage.

And yeah...
The text is 10.000, then 0.500.
I have no idea where the half a damage is coming from though.


/EDIT: Changing the requirement to ">= 1" works though.
JASS:
scope DamageText initializer init
    
    private function Conditions takes nothing returns boolean
        local texttag tt
        
        if GetEventDamage() >= 1 then
            set tt = CreateTextTag()
            call SetTextTagText(tt, I2S(R2I(GetEventDamage())), 8 * 0.023 / 10)
            call SetTextTagPosUnit(tt, GetTriggerUnit(), 0.)
            if (Damage_IsAttack()) then
                call SetTextTagColor(tt, 255, 255, 255, 255)
            elseif (Damage_IsSpell()) then
                call SetTextTagColor(tt, 255, 255, 0, 255)
            endif
            call SetTextTagPermanent(tt, false)
            call SetTextTagLifespan(tt, 2)
            call SetTextTagFadepoint(tt, 1)
            call SetTextTagVelocity(tt, 0, 0.05)
        endif

        set tt = null
        return false
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call Damage_RegisterEvent(t)
        call TriggerAddCondition(t, Condition(function Conditions))
        set t = null
    endfunction
        
endscope

I have one quick question though.
Will showing the floating text to only the localplayer cause desyncs?
I want it so that only the person dealing that damage sees the text, or else your screen would get sort of crowded with everyone's damage.
Just like:
JASS:

Is this even possible with Damage?
Wouldn't it be like, [ljass]GetOwningPlayer(GetEventDamageSource())[/ljass] or something?
 

Ayanami

칼리
Reaction score
288
Do note that using GetLocalPlayer() can cause de-syncs. I heard this happens when you create a handle for the local player. So if you were to create the floating text for GetLocalPlayer(), I believe that would cause a de-sync. Laiev did it in a way that hides the floating text, and not creating it. Thus, it won't cause de-sync. Just saying in case you don't know.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Yeah, I knew it was when handles were created.
I just had trouble finding the texttag thing to see what it extended.
Of course, I found it right after posting :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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 The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/
  • The Helper The Helper:
    I think we need to add something to the bottom of the front page that shows the Headline News forum that has a link to go to the News Forum Index so people can see there is more news. Do you guys see what I am saying, lets say you read all the articles on the front page and you get to the end and it just ends, no kind of link for MOAR!
  • The Helper The Helper:
    Happy Wednesday!
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    Sticking with the desserts for now the latest recipe is Fried Apple Pies - https://www.thehelper.net/threads/recipe-fried-apple-pies.194297/
  • The Helper The Helper:
    Finally finding about some of the bots that are flooding the users online - bytespider apparently is a huge offender here - ignores robots.txt and comes in from a ton of different IPs

      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