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
 
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)
 
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.
 
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?
 
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...
 
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
 
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.
 
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
  • No one is chatting at the moment.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good

      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