Need help converting passive spell to self-buff

DubDub

New Member
Reaction score
0
I came across this thread http://www.thehelper.net/forums/showthread.php?t=115492&page=2 with a post including a jass script for a passive spell. The spell basically reduces damage by a percentage if the unit has a passive spell learned.

JASS:
scope ShieldWall initializer Init

globals
    private constant integer Abil_id = '----' // Raw code of the passive ability.
    private constant string Sfx = "Your\\effect\\here." // May want an effect to Play
    private constant string Point = "chest" // Probably the best place for an attachment point.
endglobals

private function Percent takes integer lvl returns real
    return 0.20*lvl    // Percentage of damaged healed. So 100 damage dealt would only be 80/60/40.
endfunction

private function Chance takes integer lvl returns integer
    return 10+(5*lvl) // Percent chance to absorb damage.
endfunction

private function Heal takes nothing returns boolean
    local unit cast = GetTriggerUnit()
    local real dam = GetEventDamage()
    local integer lvl = GetUnitAbilityLevel(cast,Abil_id)
   
    if (dam > 1) then
	if (GetRandomInt(1,100) <= Chance(lvl)) then
            call SetWidgetLife(cast,GetWidgetLife(cast)+(dam*Percent(lvl)))
	    call DestroyEffect(AddSpecialEffectTarget(Sfx,cast,Point))
        endif
    endif
    
    set cast = null
    
    return false
endfunction

private function Actions takes nothing returns nothing
    local unit cast = GetTriggerUnit()
    local trigger trig
    
    if GetUnitAbilityLevel(cast,Abil_id) == 1 then
	set trig = CreateTrigger()
	call TriggerRegisterUnitEvent(trig,cast,EVENT_UNIT_DAMAGED)
	call TriggerAddCondition(trig,Condition(function Heal))
    endif
    
    set cast = null
endfunction

private function Conditions takes nothing returns boolean
    return GetLearnedSkill() == Abil_id and IsUnitIllusion(GetTriggerUnit()) == false
endfunction

private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_HERO_SKILL)
    call TriggerAddCondition(trig,Condition(function Conditions))
    call TriggerAddAction(trig,function Actions)
endfunction

endscope

I've been trying to figure out how to convert this to a self-cast buff with a short duration. After skimming through all the code I understand how it works but I'm not familiar with all the functions in jass, yet. Would anyone be willing to explain how to change this to a self-cast spell?

I've sent a PM to the kenny!, but I was hoping for a quick response so I'm posting my question here. :p
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Well, I haven't looked at the code, but might I suggest just using the Berserk ability with a negative damage-taken-increase value...?

(Simple solutions are good. :D)
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
You need attaching to do it.

JASS:
scope Test //Need init!

///Condition

private struct Data
    trigger trig
    timer t
    unit u
    real percentage
    
    method onDestroy takes nothing returns nothing
        call DisableTrigger(.trig)
        call DestroyTrigger(.trig)
        call ClearTriggerStructA(trig)
        call PauseTimer(d.trig)
    endmethod
endstruct

private function Stop takes nothing returns nothing
    call Data(GetTimerStructA(GetExpiredTimer())).destroy()
endfunction

private function Effects takes nothing returns boolean
    local Data d = GetTriggerStructA(GetTriggeringTrigger())
    local real dam = GetEventDamage()
   
   //~~~blah~~~~
    if GetUnitAbilityLevel(d.u,(buff's id)') > 0 then
        if dam > 1 and (GetRandomInt(1,100) <= d.percentage then
            call SetWidgetLife(d.u,GetWidgetLife(d.u)+(dam*d.percentage))
            call DestroyEffect(AddSpecialEffectTarget(Sfx,d.u,Point))
        endif
    else
        call d.destroy()
    endif
    //~~~~~~~~~
    
    return false
endfunction

private function Act takes nothing returns nothing
    local Data d = Data.create()
    set d.u = GetTriggerUnit()
    set d.trig = CreateTrigger()
    if d.t == null then
        set d.t = CreateTimer()
        call SetTimerStructA(d.t,d)
    endif
    set d.percentage = GetUnitAbilityLevel(d.u,abil_id) * ?//percent
    call SetTriggerStructA(d.trig,d)
    call TriggerRegisterUnitEvent(d.trig,d.u,EVENT_UNIT_DAMAGED)
    call TriggerAddCondition(d.trig,Condition(function Effects))
    call TimerStart(d.t,(duration),false,function Stop)
endfunction

///Init
endscope


It uses ABC. This is free hand. The spell should be something like this.
 

DubDub

New Member
Reaction score
0
Well, I haven't looked at the code, but might I suggest just using the Berserk ability with a negative damage-taken-increase value...?

(Simple solutions are good. :D)

I've tried this out and the hero turned out completely immune to damage instead of having damage reduced by a percentage.

You need attaching to do it.

It uses ABC. This is free hand. The spell should be something like this.

Thanks, kingkingyyk3. Now how do I go about adding this to make a complete script?
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
I've tried this out and the hero turned out completely immune to damage instead of having damage reduced by a percentage.
Hm, you're right. Strange, I thought it worked...maybe I only ever tried to use it for invulnerability...
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
scope DamageBlockSpell initializer Init //Needs ABC
     
    //Change the constant to match your ability in map.
    globals
        private constant integer ABIL_ID = 'A000'
        private constant integer BUFF_ID = 'B000'
        private constant real CHANCE = 10. // lv1 - 10%, lv2 - 20%,...
        private constant real DURATION = 5. //lv1 - 5s, lv2 - 10s,...
        private constant string SFX = "Abilities\\Spells\\Orc\\MirrorImage\\MirrorImageDeathCaster.mdl"
        private constant string POINT = "chest"
    endglobals
    
private struct Data
    trigger trig
    timer t
    unit u
    real percentage
    integer lv
    
    method onDestroy takes nothing returns nothing
        call DisableTrigger(.trig)
        call DestroyTrigger(.trig)
        call ClearTriggerStructA(.trig)
        call PauseTimer(.t)
    endmethod
endstruct

private function Stop takes nothing returns nothing
    call Data(GetTimerStructA(GetExpiredTimer())).destroy()
endfunction

private function Effects takes nothing returns boolean
    local Data d = GetTriggerStructA(GetTriggeringTrigger())
    local real dam = GetEventDamage()
   
   //~~~blah~~~~
    if GetUnitAbilityLevel(d.u,BUFF_ID) > 0 then
        if dam > 1 and GetRandomInt(1,100) <= d.percentage then
            call SetWidgetLife(d.u,GetWidgetLife(d.u)+(dam*d.percentage))
            call DestroyEffect(AddSpecialEffectTarget(SFX,d.u,POINT))
        endif
    else
        call d.destroy()
    endif
    //~~~~~~~~~
    
    return false
endfunction

private function Act takes nothing returns nothing
    local Data d = Data.create()
    set d.u = GetTriggerUnit()
    set d.trig = CreateTrigger()
    if d.t == null then
        set d.t = CreateTimer()
        call SetTimerStructA(d.t,d)
    endif
    set d.lv = GetUnitAbilityLevel(d.u,ABIL_ID)
    set d.percentage = d.lv * CHANCE
    call SetTriggerStructA(d.trig,d)
    call TriggerRegisterUnitEvent(d.trig,d.u,EVENT_UNIT_DAMAGED)
    call TriggerAddCondition(d.trig,Condition(function Effects))
    call TimerStart(d.t,d.lv * DURATION,false,function Stop)
endfunction

private function Cond takes nothing returns boolean
    return GetSpellAbilityId() == ABIL_ID
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t,Condition(function Cond))
    call TriggerAddAction(t,function Act)
endfunction
endscope
 

DubDub

New Member
Reaction score
0
Wow, thanks Kingkingyyk3. It works great!
Except there's one tiny problem. The character is getting healed for a percentage of their total health instead of a percentage based on the damage they take.

Where would I add something like this?
*edit*
I'd like for the ability to have a 100% chance to heal a percentage of the damage taken when the buff is active.

JASS:
private function Percent takes integer lvl returns real
    return 0.20*lvl    // Percentage of damaged healed. So 100 damage dealt would only be 80/60/40.
endfunction


*second edit* Never mind! After some tweaking I got it all figured out! Problem solved. Thanks, again.
 

SanKakU

Member
Reaction score
21
i'm not sure but i was under the impression that there's something wrong with the math in this code...

isn't it saying that percent is a percentage times level and then in your main action you're using that total and then timesing that by the level once again? that may be why you're running into problems...

same question about chance...idk, i find code and algebra to be a tricky combination but it looks like there is a problem in there somewhere to me...
 
General chit-chat
Help Users

      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