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.

      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