• 🏆 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] Trying to use structs+timers daily

Status
Not open for further replies.
Level 3
Joined
Apr 8, 2009
Messages
34
JASS:
scope mark
globals
        private constant integer ABIL_ID  = 'A001'  
        private constant integer BUFF_ID  = 'A003'  
        private constant string  EFFECT   = "Abilities\\Spells\\Human\\MagicSentry\\MagicSentryCaster.mdl" 
endglobals
struct Target
    unit targ
    real level
    
    static method create takes unit targ, real level returns Target
        local Target t = Target.allocate()
        
        set t.targ = target
        set t.level= level
        return t                                                              
    endmethod
    
    method onDestroy takes nothing returns nothing
        call Target.destroy(targ)
        call Target.destroy(level)
    endmethod
endstruct

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


function remove takes nothing returns nothing
    local real getlev = GetUnitAbilityLevel(trig,ABIL_ID)
    local unit sptarg = GetSpellTargetUnit()
local Target t = Target.create(sptarg,getlev)
set t = GetExpiredTimer()
    call UnitRemoveAbility(t.targ,BUFF_ID)
 call Target.destroy()
 call DestroyTimer(t)
  set sptarg = null
endfunction

function Trig_Mark_Actions takes nothing returns nothing
    local unit sptarg = GetSpellTargetUnit()
    local unit trig = GetTriggerUnit()
    local real getlev = GetUnitAbilityLevel(trig,ABIL_ID)
    local timer time = CreateTimer()
    local Target t = Target.create(sptarg,getlev)
    if GetUnitAbilityLevel(t.targ, BUFF_ID) < 1 then
       call UnitAddAbility(t.targ,BUFF_ID) 
       call TimerStart(t, t.level*10,false,function remove)
     endif
 set sptarg = null
 call Target.destroy()
 set trig = null

endfunction

//===========================================================================
function InitTrig_Mark takes nothing returns nothing
    set gg_trg_Mark = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Mark, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Mark, Condition( function Trig_Mark_Conditions ) )
    call TriggerAddAction( gg_trg_Mark, function Trig_Mark_Actions )
endfunction
endscope


The spell is supposed to first check if the unit has a certain buff, if not, then apply one.

Anyway I'm trying to learn structs and timers but obviously I still have a lot to learn because this got a lot of errors.
 
Level 10
Joined
Mar 31, 2009
Messages
732
Not sure how overriding the create method works.

JASS:
set t.targ = target
Change to:
JASS:
set t.targ = targ

JASS:
    method onDestroy takes nothing returns nothing
        call Target.destroy(targ)
        call Target.destroy(level)
    endmethod
Change to:
JASS:
    method onDestroy takes nothing returns nothing
        set this.targ = null
        // dont need to destroy a real
    endmethod

JASS:
       call TimerStart(t, t.level*10,false,function remove)
Change to:
JASS:
       call TimerStart(time, t.level*10,false,function remove)
 
Status
Not open for further replies.
Top