Lyncor's ChainLightning caster problem

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
I'm trying out this awesome looking system, but for some reason it always starts on the caster, and then bounces to nearby enemies, even though the "only hit enemies" boolean is true and the setup should start it on the target of casting unit.

JASS:
scope ChainStun initializer init{
private hashtable ht = InitHashtable()
#define private SPELL_ID = 'A00C'
private int array numberOfBounces[10]
private int array damageDealt[10]
    private bool Cond(){
        return GetSpellAbilityId() == SPELL_ID
    }
    
    private void UnStun(){
        int htKey = GetHandleId(GetExpiredTimer())
        PauseUnit(LoadUnitHandle(ht,htKey,0),false)
        DestroyEffect(LoadEffectHandle(ht,htKey,1))
        Timer.release(GetExpiredTimer())
    }
    
    private void StunUnits(int id, unit target){
        timer t = Timer.get()
        effect e = AddSpecialEffectTarget("Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl",target,"origin")
        SaveUnitHandle(ht,GetHandleId(t),0,target)
        SaveEffectHandle(ht,GetHandleId(t),1,e)
        if GetUnitPointValue(target) == 1 {
            PauseUnit(target,true)
            TimerStart(t,0.75,false,function UnStun) //humans get stunned for way less!
        }
        else {
            PauseUnit(target,true)
            TimerStart(t,2.00,false,function UnStun)
        }
        e = null
        t = null
    }

    
    
    
    private void Act(){
        unit u = GetTriggerUnit()
        unit target = GetSpellAbilityUnit()
        int abilityLevel = GetUnitAbilityLevel(GetTriggerUnit(),SPELL_ID)
        ChainLightning(u,u,target,&quot;CLPB&quot;,damageDealt[abilityLevel-1],numberOfBounces[abilityLevel-1]) // caster/source is the casting unit, target should be who it starts on, yet it starts on caster <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite3" alt=":(" title="Frown    :(" loading="lazy" data-shortname=":(" />
        ChainLightning_ColorLast(1,0,0)
        // Special.
        ChainLightningEx(u,u,&quot;CLPB&quot;,StunUnits,true,numberOfBounces[abilityLevel-1])
        ChainLightning_StartLastEx(target) // should start on the unit I cast the spell on!
        ChainLightning_ColorLast(1,0,0)
    }
    
    private void init(){
        trigger t = CreateTrigger()
        TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        TriggerAddCondition(t,Condition(function Cond))
        TriggerAddAction(t,function Act)
        
        numberOfBounces[0] = 3
        damageDealt[0] = 100
        numberOfBounces[1]= 4
        damageDealt[1]= 100
        numberOfBounces[2]= 5
        damageDealt[2]= 100
        numberOfBounces[3]= 5
        damageDealt[3]= 200
        numberOfBounces[4]= 6
        damageDealt[4]= 200
        numberOfBounces[5]= 7
        damageDealt[5]= 200
        numberOfBounces[6]= 7
        damageDealt[6]= 300
        numberOfBounces[7]= 8
        damageDealt[7]= 300
        numberOfBounces[8]= 9
        damageDealt[8]= 300
        numberOfBounces[9]= 10
        damageDealt[9]= 300
    }
}
 

Jesus4Lyf

Good Idea™
Reaction score
397
Grr. cJass. Harder to help you.

I really like that system. The normal WC3 chain lightning works like this: the first hop starts from the caster. The caster is the source of the damage/effect.

So similarly, if you look in the demo map, the caster "casts" the chain lightning, and is the source of it, but it does not take the effect of it.

Can you clarify exactly what you are trying to achieve? :)
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Basically the same thing as the wc3 chain lightning. I made the source as the caster, and the target as the unit that the caster casts the spell on. For some reason no matter what unit I target, the effect starts on the caster (damage + stun) and then bounces to the nearest unit. Basically, just the classic chain lightning, but it also stuns everything it hits.

I use two different chains, the regular one to do the damage, and the Ex to do the stunning :D. I could make a vjass version.

JASS:
scope ChainStun initializer init{
private hashtable ht = InitHashtable()
private constant integer SPELL_ID = &#039;A00C&#039;
private integer array numberOfBounces[10]
private integer array damageDealt[10]
    private function Cond takes nothing returns boolean
        return GetSpellAbilityId() == SPELL_ID
    endfunction
    
    private function UnStun takes nothing returns nothing
        local int htKey = GetHandleId(GetExpiredTimer())
        PauseUnit(LoadUnitHandle(ht,htKey,0),false)
        DestroyEffect(LoadEffectHandle(ht,htKey,1))
        Timer.release(GetExpiredTimer())
    endfunction
    
    private function StunUnits takes integer id, unit target returns nothing
        local timer t = Timer.get()
        local effect e = AddSpecialEffectTarget(&quot;Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl&quot;,target,&quot;origin&quot;)
        SaveUnitHandle(ht,GetHandleId(t),0,target)
        SaveEffectHandle(ht,GetHandleId(t),1,e)
        if GetUnitPointValue(target) == 1 then
            PauseUnit(target,true)
            TimerStart(t,0.75,false,function UnStun) //humans get stunned for way less!
        else
            PauseUnit(target,true)
            TimerStart(t,2.00,false,function UnStun)
        endif
        e = null
        t = null
    endfunction

    
    
    
    private function Act takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local unit target = GetSpellAbilityUnit()
        local int abilityLevel = GetUnitAbilityLevel(GetTriggerUnit(),SPELL_ID)
        ChainLightning(u,u,target,&quot;CLPB&quot;,damageDealt[abilityLevel-1],numberOfBounces[abilityLevel-1]) // caster/source is the casting unit, target should be who it starts on, yet it starts on caster <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite3" alt=":(" title="Frown    :(" loading="lazy" data-shortname=":(" />
        ChainLightning_ColorLast(1,0,0)
        // Special.
        ChainLightningEx(u,u,&quot;CLPB&quot;,StunUnits,true,numberOfBounces[abilityLevel-1])
        ChainLightning_StartLastEx(target) // should start on the unit I cast the spell on!
        ChainLightning_ColorLast(1,0,0)
    endfunction
    
    private void init(){
        trigger t = CreateTrigger()
        TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        TriggerAddCondition(t,Condition(function Cond))
        TriggerAddAction(t,function Act)
        
        numberOfBounces[0] = 3
        damageDealt[0] = 100
        numberOfBounces[1]= 4
        damageDealt[1]= 100
        numberOfBounces[2]= 5
        damageDealt[2]= 100
        numberOfBounces[3]= 5
        damageDealt[3]= 200
        numberOfBounces[4]= 6
        damageDealt[4]= 200
        numberOfBounces[5]= 7
        damageDealt[5]= 200
        numberOfBounces[6]= 7
        damageDealt[6]= 300
        numberOfBounces[7]= 8
        damageDealt[7]= 300
        numberOfBounces[8]= 9
        damageDealt[8]= 300
        numberOfBounces[9]= 10
        damageDealt[9]= 300
    }
}
 

Jesus4Lyf

Good Idea™
Reaction score
397
Should use Stun instead of Pause/Unpause unit. :)

This is gonna seem strange, but... everything seems perfect to me :confused: (aside from minor optimisations).

I don't see how the system could possibly do that. Are you absolutely sure the caster is being damaged and stunned as well? =/

I might have to test when I get home or something, 'cos that has me puzzled.

By the way, you could do the damage and zap sound in your callback if you care for optimising, but that's up to you. You'd have to attach to the Ex instance though.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
This is gonna seem strange, but... everything seems perfect to me (aside from minor optimisations).

I don't see how the system could possibly do that. Are you absolutely sure the caster is being damaged and stunned as well? =/

Absolutely, the spell doesn't start on the targeted unit, it starts on the caster, and only bounces if the caster is within the bounce distance of an enemy unit.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Oh, did they change that function? Bah, I converted the wrong function.

It works now...
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Having a minor issue. When a unit dies while being chained, the lightning will jump to the middle of the map. This is best noticed on the last unit of the chain or by chaining a unit with no potential jumps.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
I'll have to gather more data on this, in some cases I know the unit is removed, but in some others I don't think it is. How hard/easy would it be to "fix" this? It is not too big of an issue.
 

Bribe

vJass errors are legion
Reaction score
67
"ChainLightningEx" I don't see in your library. Then again, you're using a scope so I don't see what system you're linking to.

My recommendation is you make your own lightning effects, and before you issue each "movelightning" run the native check UnitAlive(target) on it, and obviously, if false, destroy the lightning effect and your problem is gone.
 

Jesus4Lyf

Good Idea™
Reaction score
397
"ChainLightningEx" I don't see in your library.
How can you miss it? He did give the URL in the first post...

My recommendation is you make your own lightning effects
I guess you haven't seen how much the system does for you...

before you issue each "movelightning" run the native check UnitAlive(target) on it, and obviously, if false, destroy the lightning effect and your problem is gone.
That's means the chain lightning can end prematurely, which solves very little... Either the system needs to realise the unit it was on has been removed and use stored x/y versions, or Frozenhelfir needs to not remove the unit ChainLightning is on (seems to make more sense).
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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 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 Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top