• 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.

[JASS] Is there somethin i should rework?

Status
Not open for further replies.
Level 16
Joined
Feb 22, 2006
Messages
960
So actually i'm learning vJass, this is my first spell i redid in vjass

JASS:
struct lifestruc
    unit caster
    unit target
    real duration
    integer durationtimer
    real interval
    real damage
endstruct

function wait_cond takes nothing returns boolean  
    return (UnitHasBuffBJ(GetSpellTargetUnit(),'B001') == true)
endfunction

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

function execute_lr takes nothing returns nothing
  local timer t = GetExpiredTimer()
  local lifestruc dat
  local real lifecaster
  local real lifetarget
  local real lifedrain
  local real lifeafter
    set lifetarget = GetUnitState(dat.target,UNIT_STATE_LIFE)
    call UnitDamageTarget(dat.caster,dat.target,dat.damage,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
    set lifeafter = GetUnitState(dat.target,UNIT_STATE_LIFE)
    set lifedrain = lifetarget - lifeafter
    set lifecaster = GetUnitState(dat.caster,UNIT_STATE_LIFE)
    call SetUnitState(dat.caster,UNIT_STATE_LIFE,lifecaster+lifedrain)            
    if (dat.durationtimer <= 1) then
        call FlushHandleLocals(t)
        call DestroyTimer(t)
        call lifestruc.destroy(dat)
        set t = null
        return
    endif
    set dat.durationtimer = dat.durationtimer - 1
endfunction

function LR_Actions takes nothing returns nothing
  local lifestruc dat = lifestruc.create()
  local timer t = CreateTimer()
    set dat.caster = GetTriggerUnit()
    set dat.target = GetSpellTargetUnit()
    set dat.duration = 8.00
    set dat.interval = 0.035
    set dat.durationtimer = R2I(dat.duration/dat.interval)
    set dat.damage = ((GetUnitAbilityLevelSwapped('A000', dat.caster)*50)+70)/(dat.durationtimer)          
    loop
        exitwhen (wait_cond())
        call TriggerSleepAction(0.26)
    endloop
    call TimerStart(t,dat.interval,true,function execute_lr)
endfunction

function InitTrig_Life_Rune takes nothing returns nothing
  local trigger lr = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(lr,EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(lr, Condition(function LR_Conditions))
    call TriggerAddAction(lr, function LR_Actions)
  set lr = null
endfunction


Reworked somthing >.<
 
Last edited:
Level 12
Joined
Apr 27, 2008
Messages
1,228
My suggestion:
JASS:
struct lifestruc
    unit caster
    unit target
    integer durationtimer
    real damage

    method onDestroy takes nothing returns nothing
        set this.caster=null
        set this.target=null
    endmethod
endstruct

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

function execute_lr takes nothing returns nothing
  local timer t = GetExpiredTimer()
  local lifestruc dat=GetHandleInt(t,"struct")
  local real lifecaster
  local real lifetarget
  local real lifedrain
  local real lifeafter
    set lifetarget = GetUnitState(dat.target,UNIT_STATE_LIFE)
    call UnitDamageTarget(dat.caster,dat.target,dat.damage,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
    set lifeafter = GetUnitState(dat.target,UNIT_STATE_LIFE)
    set lifedrain = lifetarget - lifeafter
    set lifecaster = GetUnitState(dat.caster,UNIT_STATE_LIFE)
    call SetUnitState(dat.caster,UNIT_STATE_LIFE,lifecaster+lifedrain)
    if (dat.durationtimer <= 1) then
        call FlushHandleLocals(t)
        call DestroyTimer(t)
        call lifestruc.destroy(dat)
    else
        set dat.durationtimer = dat.durationtimer - 1
    endif
    set t = null
endfunction

function LR_Actions takes nothing returns nothing
    local lifestruc dat = lifestruc.create()
    local timer t = CreateTimer()
    set dat.caster = GetTriggerUnit()
    set dat.target = GetSpellTargetUnit()
    set dat.durationtimer = R2I(8.00/0.035)
    set dat.damage = ((GetUnitAbilityLevelSwapped('A000', dat.caster)*50)+70)/(dat.durationtimer)
    call SetHandleInt(t,"struct",dat)
    call TimerStart(t,0.035,true,function execute_lr)
endfunction

function InitTrig_Life_Rune takes nothing returns nothing
  local trigger lr = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(lr,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(lr, Condition(function LR_Conditions))
    call TriggerAddAction(lr, function LR_Actions)
  set lr = null
endfunction
You do not need the interval and duration in the struct - you will not use them in the timer callback function. You need to null the timer in the periodic function. You need to null the units in the struct. Using triggersleepaction is not a very good idea: depending on what your base spell is, you can use another event (unit_spell_effect), but if it does not put the buff instantly(like Frost arrows) than you should add back the TSA part.
 
Last edited:
Status
Not open for further replies.
Top