• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Shield System

Status
Not open for further replies.
Level 7
Joined
Nov 19, 2007
Messages
253
I was making new hero in my map and i wanted to create shield spell for him about after 3 hours of hard work i done something that WORKS.. but not rly.. at first cast everythings fine shield absorbs damage how it should but after it ends or is destroyed after recast absorption gets messed up and for every recast shield absorbs less and less damage (eg. at level 4 shield absorbs 400 damage, at 1st cast it absorbs 400 damage, at 2nd cast it absorbs about 200 damage... and so on)
Heres the code(its not perfect because im new on vJass and because I haven't finished it yet(still need to make MUI)):
JASS:
scope darkShield initializer start

    globals
        private timer time=CreateTimer()
        private unit target
        private real shieldMax
        private real shieldLeft
        private trigger trig2=CreateTrigger()
        private integer count=0
    endglobals
    
    private function b takes nothing returns nothing
        set count=count+1
        if count>=500 then
            set target=null
            set shieldLeft=0
            call DisplayTextToPlayer(GetLocalPlayer(),0,0,"Shield timedout") //Debug Message
            call PauseTimer(time)
        endif
    endfunction
    
    private function a takes nothing returns nothing
        local real damage=GetEventDamage()
        if GetUnitAbilityLevel(target,'B035') > 0 then //Checks if target has buff
            if shieldLeft>=damage then
                set shieldLeft=shieldLeft-damage
                call SetUnitState(target,UNIT_STATE_LIFE,GetUnitState(target,UNIT_STATE_LIFE)+damage)
                call DisplayTextToPlayer(GetLocalPlayer(),0,0,"Shield left "+R2S(shieldLeft))//Debug Message
                call DisplayTextToPlayer(GetLocalPlayer(),0,0,GetUnitName(target))//Debug Message
            elseif shieldLeft<damage then
                set shieldLeft=0
                call SetUnitState(target,UNIT_STATE_LIFE,GetUnitState(target,UNIT_STATE_LIFE)+(damage-shieldLeft))
                call UnitRemoveAbility(target, 'B035')
                call DisplayTextToPlayer(GetLocalPlayer(),0,0,"Shield gone")//Debug Message
                set target=null
                call PauseTimer(time)
            endif
        endif
    endfunction
    
    private function s takes nothing returns boolean
        local unit dummy
        if GetSpellAbilityId()=='A09L' then
            set target=GetSpellTargetUnit()
            set shieldMax=I2R(GetUnitAbilityLevel(GetTriggerUnit(),'A09L'))*100
            set shieldLeft=shieldMax
            set dummy=CreateUnit(GetOwningPlayer(target),'h004',GetUnitX(target),GetUnitY(target),0)
            call UnitApplyTimedLife(dummy,'BTLF',3)
            call UnitAddAbility(dummy,'A09M')
            call SetUnitAbilityLevel(dummy,'A09M',GetUnitAbilityLevel(GetTriggerUnit(),'A09L'))
            call IssueTargetOrder(dummy,"innerfire",target)
            call TriggerRegisterUnitEvent( trig2, target, EVENT_UNIT_DAMAGED )
            call TriggerAddAction(trig2, function a)
            call TimerStart(time,0.03,true,function b)
            set count=0
        endif
        return false
    endfunction
 
    private function start takes nothing returns nothing
        local trigger trig=CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(trig,Condition(function s))
        set trig=null
    endfunction
    
endscope
 
Shieldleft is not multiple-instanciable. I don't know why it's just a global.

Since you're using vJass, I advise using structs to create each instance. http://warcraft.ingame.de/forum/showthread.php?t=189977

Then use Timer32 for the periodic stuff. http://www.thehelper.net/forums/showthread.php/132538-Timer32

SetUnitState(unit, UNIT_STATE_LIFE, value)

->

SetWidgetLife(unit, value)

Same goes for GetWidgetLife.


You also create a damage event for the unit, which will cause leaks per cast because you use it with trigger actions instead of conditions. You would be better using a Damage Detection Engine for that.
 
Level 7
Joined
Nov 19, 2007
Messages
253
I wasnt even trying to make this spell MUI I just want it to work and understand how it should work then i would try to make it MUI and use those structs and other stuff.. and please read what i wrote before posting problem is not thats its not MUI or thats everything in globals problem is that it doesnt absorb damage how it should after first cast
 
every recast shield absorbs less and less damage

I believe it's mor and more damage...

you're registering trigger2 again and again which is bad...if you cast the spell, it will take normal damage, when you cast again it will take
double, then trpple, etc...

I've created something like this before, check it out...
 

Attachments

  • Damage Shield - vJASS.w3x
    72.3 KB · Views: 74
Level 7
Joined
Nov 19, 2007
Messages
253
No shield breaks faster and faster every time i recast it you can copy that code and test for your self and about your damage shield system i dont like hastables so im not going to use that

About that damage event library somehow it doesnt work when i save map jasshelper gives me this error:
Line 13661: Unable to find textmacro: "optional"
and it highlights
globals
private constant integer MAX_WASTED = 15
endglobals <<< this line
have i done something wrong or it doesnt work or smt ??
I created new trigger named it DamageEvent converted it to custom text and pasted all code from that post.
 
Level 7
Joined
Nov 19, 2007
Messages
253
Ye i got that allready. My jasshelper version is 0.9.I.2 (thats what it says in JassHelper>about JassHelper...) and somehow this guide doesnt works for me i get error at step 2
if you can help me somehow write pm instead of spaming this thread
 
Level 7
Joined
Nov 19, 2007
Messages
253
i dont rly trust GUI anymore.. but ill give it a try because i dont have any other choise now
thx for help

EDIT: i finished it and its working fine now still need to make it MUI thx alot
 
Last edited:
Status
Not open for further replies.
Top