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
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • 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 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