• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Need help

Status
Not open for further replies.
Level 8
Joined
Jul 28, 2008
Messages
211
Haven't been using the editor or WC3 for some time and I decided to come back. I started a project and I'm having troubles with my first spell.

JASS:
scope Spell initializer Init

globals
    timer Timer
endglobals

private struct spell

    unit target
    real life
    integer c
    static spell array arr
    static integer count
    
    static method Heal takes nothing returns nothing
        local spell s
        local integer i = 0
        loop
            exitwhen i > s.count
            set s = s.arr[i]
            
            if GetUnitState(s.target, UNIT_STATE_LIFE) <= 0 then
                call ReviveHero(s.target, GetUnitX(s.target), GetUnitY(s.target), false)
            endif
            call SetWidgetLife(s.target, s.life)
            set s.c = s.c + 1
            if s.c >= 250 then
                call s.destroy()
                set s.count = s.count - 1
                set s.arr[i] = s.arr[s.count]
            endif
            set i = i + 1
        endloop
        if s.count == 0 then
            call PauseTimer(Timer)
        endif
    endmethod
        
    static method Start takes unit u returns nothing
        local spell s = spell.allocate()
        set s.target = u
        set s.life = GetWidgetLife(u)
        if s.count == 0 then
            call TimerStart(Timer, 0.04, true, function spell.Heal)
        endif
        set s.arr[s.count] = s
        set s.count = s.count + 1
    endmethod
endstruct

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

private function Actions takes nothing returns nothing
    call spell.Start(GetSpellTargetUnit())
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 Conditions))
    call TriggerAddAction(t, function Actions)
    
    set Timer = CreateTimer()
endfunction

endscope

The spell should prevent any damage done to the target. It's probably badly coded and stuff but as I said I have been away from the editor for some time.
Can anyone tell what's wrong with it?

Thanks in advance.
 
Level 13
Joined
Mar 16, 2008
Messages
941
Problems:
*This prevents the unit from being healt (heal... in the past? oO) and normal regeneration.
Use a damage detection system and heal for the done damage, use a null timer to heal damage done while having full hp.
*Your "reorder" after a struct destruction prevents one tick:
"i=2, destroy [2], [2]=[last], i=3... old [last] is skipped"
Can't find anymore bugs, just improvenemnts of the code.
 
Level 8
Joined
Jul 28, 2008
Messages
211
Well I know how to make the spell with handle vars but not structs. I'm still new to structs...well not new but I only know how to use them like this.

Or you can just make the target invulnerable.
I could. But if I make it like this, it's easy to make a spell that blocks 50% of the damage or something like that.

heal... in the past? oO
Not sure about that one...

EDIT: Forgot to mention

This prevents the unit from being healt (heal... in the past? oO) and normal regeneration
Actualy it doesn't work at all :grin:
 
Level 8
Joined
Jul 28, 2008
Messages
211
I'm trying to make a spell that blocks a % of the damage done to that unit. It's currently set to 100% but I'll make it lower.

Remaking the spell now. Trying to use the same stuff I used while making it with handle vars.

EDIT: New question : I need to do something like when using handle vars. Store the unit and make a local trigger. Then i add an event to that trigger (that unit takes damage) and add an action (heal that unit for 50% of damage taken) and remove those when a timer expires. Can anyone tell me how to store a unit and do all that?
 
Status
Not open for further replies.
Top