HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Quick help on System.

07-21-2007, 11:45 PM#1
Toink
I need some guys to clarify whether my small system works. atm the system only has 1 status ailment, which is bleed.

Collapse JASS:
library StatusAilments initializer InitStatusAilments, requires CasterSystem

    function InitStatusAilments takes nothing returns nothing
    endfunction

    //*********************************************
    //*             B  L  I  N  D                 *
    //*********************************************

    globals
        private unit array Blind
        private integer BlindInt
    endglobals

    struct blind
        unit source
        unit caster
        unit target 
        real dur
    endstruct


    function Blind_Callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local blind dat = blind(GetAttachedInt(t, "dat"))
        if not dat.dur > 0 then
            set dat.dur = dat.dur - 0.10
            call IssueTargetOrder(dat.caster, "curse", dat.target)
        else
            call CleanAttachedVars(t)
            call ReleaseTimer(t)
            call cripple.destroy(dat)
            set BlindInt = BlindInt - 1
        endif
    endfunction

    function ApplyBlind takes unit source, unit target, real dur returns nothing 
    local unit caster
    local timer t
    local cripple dat
        if GetUnitAbilityLevel(target, 'B004') == 0 then
            set t = NewTimer()
            set caster = CreateCaster(GetUnitX(target), GetUnitY(target), 0)
            set dat = cripple.create()
            set dat.source = source
            set dat.target = target
            set dat.dur = dur
            set dat.caster = caster
            set CrippleInt = CrippleInt+1
            call UnitAddAbility(caster, 'A004')
            call AttachInt(t, "dat", dat)
            call TimerStart(t, 0.10, true, function Blind_Callback)
            set Blind[BlindInt] = target
        else
            set s__blind_dur[BlindInt] = s__blind_dur[BlindInt]+dur
        endif
        call RemoveUnit(caster)
        set caster = null
    endfunction
    

    //*********************************************
    //*            C  R  I  P  P  L  E            *
    //*********************************************

    globals
        private unit array Crippler
        private integer CrippleInt
    endglobals

    struct cripple
        unit source
        unit caster
        unit target 
        real dur
    endstruct


    function Cripple_Callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local cripple dat = cripple(GetAttachedInt(t, "dat"))
        if not dat.dur > 0 then
            set dat.dur = dat.dur - 0.10
            call IssueTargetOrder(dat.caster, "cripple", dat.target)
        else
            call CleanAttachedVars(t)
            call ReleaseTimer(t)
            call cripple.destroy(dat)
            set CrippleInt = CrippleInt - 1
        endif
    endfunction

    function ApplyCripple takes unit source, unit target, real dur returns nothing 
    local unit caster
    local timer t
    local cripple dat
        if GetUnitAbilityLevel(target, 'B003') == 0 then
            set t = NewTimer()
            set caster = CreateCaster(GetUnitX(target), GetUnitY(target), 0)
            set dat = cripple.create()
            set dat.source = source
            set dat.target = target
            set dat.dur = dur
            set dat.caster = caster
            set CrippleInt = CrippleInt+1
            call UnitAddAbility(caster, 'A003')
            call AttachInt(t, "dat", dat)
            call TimerStart(t, 0.10, true, function Cripple_Callback)
            set Crippler[CrippleInt] = target
        else
            set s__burn_dur[CrippleInt] = s__bleed_dur[CrippleInt]+dur
        endif
        call RemoveUnit(caster)
        set caster = null
    endfunction

    //*********************************************
    //*               B  U  R  N
    //*********************************************

    globals
        private unit array Crippler
        private integer CrippleInt
    endglobals

    struct burn
        unit target
        unit source
        real dur
    endstruct

    function Burn_Callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local burn dat = burn(GetAttachedInt(t, "dat"))
        if dat.dur > 0 then
            call UnitDamageTarget(dat.source, dat.target, 1.8, false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_FIRE)
            set dat.dur = dat.dur - 0.10
        else
            call RemoveBuff(dat.target, 'B002')
            call CleanAttachedVars(t)
            call ReleaseTimer(t)
            call burn.destroy(dat)
            set BurnInt = BurnInt - 1
        endif
    endfunction

    function ApplyBurn takes unit source, unit target, real dur returns nothing 
    local unit caster
    local timer t
    local burn dat
        if GetUnitAbilityLevel(target, 'B002') == 0 then
            set t = NewTimer()
            set caster = CreateCaster(GetUnitX(target), GetUnitY(target), 0)
            set dat = burn.create()
            set dat.source = source
            set dat.target = target
            set dat.dur = dur
            set BurnInt = BurnInt+1
            call UnitAddAbility(caster, 'A002')
            call IssueTargetOrder(caster, "acidbomb", target) 
            call AttachInt(t, "dat", dat)
            call TimerStart(t, 0.10, true, function Bleed_Callback)
            set Burner[BurnInt] = target
        else
            set s__burn_dur[BurnInt] = s__burn_dur[BurnInt]+dur
        endif
        call RemoveUnit(caster)
        set caster = null
    endfunction

    //*********************************************
    //*              B  L  E  E  D
    //********************************************* 

    globals
        private unit array Bleeder
        private integer BleedInt
    endglobals

    struct bleed
        unit source
        unit target
        real dur
    endstruct

    function Bleed_Callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local bleed dat = bleed(GetAttachedInt(t, "dat"))
        if dat.dur > 0 then
            call UnitDamageTarget(dat.source, dat.target, 1.8, false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL)
            set dat.dur = dat.dur - 0.10
        else
            call RemoveBuff(dat.target, 'B001')
            call CleanAttachedVars(t)
            call ReleaseTimer(t)
            call bleed.destroy(dat)
            set BleedInt = BleedInt-1
        endif
    endfunction

    function ApplyBleed takes unit source, unit target, real dur returns nothing 
    local unit caster
    local timer t
    local bleed dat
        if GetUnitAbilityLevel(target, 'B001') == 0 then
            set t = NewTimer()
            set caster = CreateCaster(GetUnitX(target), GetUnitY(target), 0)
            set dat = bleed.create()
            set dat.source = source
            set dat.target = target
            set dat.dur = dur
            set BleedInt = BleedInt+1
            call UnitAddAbility(caster, 'A001')
            call IssueTargetOrder(caster, "acidbomb", target) 
            call AttachInt(t, "dat", dat)
            call TimerStart(t, 0.10, true, function Bleed_Callback)
            set Bleeder[BleedInt] = target
        else
            set s__bleed_dur[BleedInt] = s__bleed_dur[BleedInt]+dur
        endif
        call RemoveUnit(caster)
        set caster = null
    endfunction


endlibrary

I am not sure about if the line set s__bleed_dur[i] = s_bleed_dur[i]+dur will work. It is like that bec the ailments(buffs caused by the dummy) last 3600 seconds, and I use a timer to remove that after some while. If that target is going to ,let's say bleed, again I just extend the duration of the previous bleed.

Thanks in advance!

EDIT: I found one bug with using UserDatas, fixed already, now I need to know if my new method works. I now use global unit arrays and an integer

EDIT 2: Updated the script, still don't know if it will work.
07-22-2007, 01:16 AM#2
Anitarf
What is "i" in s__bleed_dur[i] = s__bleed_dur[i]+dur, it's not defined anywhere? If I understand what you're trying to do, you can replace that line with set bleed(GetUnitUserData(target)).dur=bleed(GetUnitUserData(target)).dur+dur. Also, it would be safer if, in your condition, you checked if the unit has a bleed struct attached rather than looking for the buff. What you do right now might be safe specificaly in your map if you have absolutely no dispel, but otherwise it's potentialy buggy.

How you're going to make it work for multiple ailments, though, if you already use up the unit user data to hold the bleed struct only. You should instead attach a general struct to the unit that can hold individual ailment structs.
07-22-2007, 01:19 AM#3
Toink
I replaced the user data thingy bec I realized that multiple ailments would be crappily buggy.

Thank goodness you're here, I updated the script. I am still coding the damn thing, I need your help :)

EDIT: Hmm, I would attach structs to units so I can determine if they have ailments.. But I don't know how to approach that.. Maybe like this?

Collapse JASS:

struct ailments
    boolean IsUnitBleeding
    boolean IsUnitBurning
    boolean IsUnitCrippled
endstruct

....

function bleh takes nothing returns nothing
local unit u = GetTriggerUnit()
local ailments dat = ailments(GetUnitUserData())
    if dat.IsUnitBleeding == true then
        ..
    endif
endfunction

Would that be the right way?
07-22-2007, 01:41 AM#4
Anitarf
Naw, you would do it like this:

Collapse JASS:
struct ailments
    burn bu = 0
    bleed bl = 0
    cripple cr = 0
    ...
endstruct

function bleh takes nothing returns nothing
local unit u = GetTriggerUnit()
local ailments dat = ailments(GetUnitUserData())
    if dat.bl != 0 then
        ..
    endif
endfunction
07-22-2007, 01:47 AM#5
Toink
Ah I see, thank you!

But I really have to ask, can you find any more errors in my script? Please bear with me, I'm not that good at vJass scripting. I only know few about structs and manipulating them.

Oh and btw, if for example I crippled You, you are slowed and the cripple lasts 15 seconds. If a trigger removed that cripple buff from you, will you still be slowed?
07-22-2007, 02:01 AM#6
Anitarf
Removing a spell's buff with triggers has the same effect as if you dispel it - the spell effect ends. The slow given by the cripple spell is thus removed when you remove the cripple buff.
07-22-2007, 03:54 AM#7
Toink
Bah, I have rewritten everything. I think it should work..

Collapse JASS:
library StatusAilments initializer InitStatusAilments, requires CasterSystem

    function InitStatusAilments takes nothing returns nothing
    endfunction

    struct ailmentdata
        unit bleedsource
        unit burnsource
        unit blindsource
        unit cripplesource
        unit bleedcaster
        unit burncaster
        unit blindcaster
        unit cripplecaster
        unit bleedtarget
        unit burntarget
        unit blindtarget
        unit crippletarget
        real bleeddur
        real burndur
        real blinddur
        real crippledur
        integer bleed = 0
        integer burn = 0
        integer cripple = 0
        integer blind = 0
    endstruct

    function Buff_Callback takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local ailmentdata dat = ailmentdata(GetAttachedInt(t, "dat"))
        if dat.bleed != 0 then
            if dat.bleeddur > 0 then
                call DamageUnitByOptions(dat.bleedsource, dat.bleedtarget, 1.2, DamageTypes(ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL)+DamageIgnore(UNIT_TYPE_MECHANICAL))
                set dat.bleeddur = dat.bleeddur - 0.10
            else
                call UnitRemoveAbility(dat.bleedtarget, 'B001')
                set dat.bleed = 0
            endif
        endif
        if dat.burn != 0 then
            if dat.bleeddur > 0 then
                call DamageUnitByOptions(dat.burnsource, dat.burntarget, 1.6, DamageTypes(ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL)+DamageIgnore(UNIT_TYPE_MECHANICAL))
                set dat.burndur = dat.burndur - 0.10
            else
                call UnitRemoveAbility(dat.burntarget, 'B002')
                set dat.burn = 0
            endif
        endif
        if dat.cripple != 0 then
            if dat.crippledur > 0 then
                set dat.crippledur = dat.crippledur - 0.10
            else
                call UnitRemoveAbility(dat.crippletarget, 'B003')
                set dat.cripple = 0
            endif
        endif
        if dat.blind != 0 then
            if dat.blinddur > 0 then
                set dat.blinddur = dat.blinddur - 0.10
            else
                call UnitRemoveAbility(dat.target, 'B004')
                set dat.blind = 0
            endif
        endif
        if dat.bleed == 0 and dat.burn == 0 and dat.cripple == 0 and dat.blind == 0 then
            call CleanAttachedVars(t)
            call ReleaseTimer(t)
            call ailmentdata.destroy(dat)
        endif
    endfunction


    function ApplyBuff takes unit source, unit target, integer WhatAilment, real dur returns nothing
    local ailmentdata dat = ailmentdata(GetUnitUserData(target))
    local unit caster
    local timer t
        if dat.bleed == 0 or dat.burn == 0 or dat.cripple == 0 or dat.blind == 0 then
            set t = NewTimer()
            call AttachInt(t, "dat", dat)
            call SetUnitUserData(targ, dat)
            if WhatAilment == 1 then
                if dat.bleed == 0 then
                    call CasterCastAbilityLevel(GetOwningPlayer(source), 'A001', 1, "acidbomb", target, true)
                    set dat.bleedtarget = target
                    set dat.bleedsource = source
                    set dat.bleeddur = dur
                    set dat.bleed = 1
                else
                    set ailmentdata(GetUnitUserData(target)).bleeddur = ailmentdata(GetUnitUserData(target)).bleeddur + dur
                endif
            elseif WhatAilment == 2 then
                if dat.burn == 0 then
                    call CasterCastAbilityLevel(GetOwningPlayer(source), 'A002', 1, "acidbomb", target, true)
                    set dat.burntarget = target
                    set dat.burnsource = source
                    set dat.burndur = dur
                    set dat.burn = 1
                else
                    set ailmentdata(GetUnitUserData(target)).burndur = ailmentdata(GetUnitUserData(target)).burndur + dur
                endif
            elseif WhatAilment == 3 then
                if dat.cripple == 0 then
                    call CasterCastAbilityLevel(GetOwningPlayer(source), 'A003', 1, "cripple", target, true)
                    set dat.crippletarget = target
                    set dat.cripplesource = source
                    set dat.crippledur = dur
                    set dat.cripple = 1
                else
                    set ailmentdata(GetUnitUserData(target)).crippledur = ailmentdata(GetUnitUserData(target)).crippledur + dur
                endif
            elseif WhatAilment == 4 then
                if dat.blind == 0 then
                    call CasterCastAbilityLevel(GetOwningPlayer(source), 'A004', 1, "curse", target, true)
                    set dat.blindtarget = target
                    set dat.blindsource = source
                    set dat.blinddur = dur
                    set dat.blind = 1
                else
                    set ailmentdata(GetUnitUserData(target)).blinddur = ailmentdata(GetUnitUserData(target)).blinddur + dur
                endif
            endif
            call SetUnitUserData(target, dat)
        endif
    endfunction


endlibrary

But I don't know much, so can anyone tell me if this would work? I can't test it now bec I'll be going away for 2-3 hours. In the meanwhile, I hope I can get some feedback and suggestions.