HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

2 spells need help vjass thingy

09-21-2008, 12:19 PM#1
waaaks
i have 2 spells that have problems
1st spell works fine but sometimes not working correctly
2nd spell i really dont know if i coded it right
both spells uses rising_dusk's damage system and xe0.3

1st spell
Quote:
Cooldown: 15 seconds
Damage Type: Dark
Targets: Organic
Type: Unit Target

Creates a shield with negative energy to the target unit, making it immune to all damage, after the duration has finished while the shield is still active, the shield will be absorbed, dealing damage to the target unit if it is an enemy.
Lasts 5 seconds

Level 1 - 40 shield hit points; 100 damage.
Level 2 - 80 shield hit points; 150 damage.
Level 3 - 120 shield hit points; 200 damage.
Level 4 - 160 shield hit points; 250 damage.
Level 5 - 200 shield hit points; 300 damage.

Collapse JASS:
scope ShieldofDeath initializer init

globals
    private constant integer spell = 'A024'
    private constant integer buffid = 'B00H'
endglobals

private struct data
    unit cast
    unit targ
    integer level
    real life
    real counter
    real dmg
    
    method onDestroy takes nothing returns nothing
        if GetUnitAbilityLevel(this.targ, buffid) > 0 then
            if IsUnitEnemy(this.targ, GetOwningPlayer(this.cast)) then
                call UnitDamageTargetEx(this.cast, this.targ, this.dmg, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_DARK, true)
            endif
        endif
        set this.counter = 0
        call UnitRemoveAbility(this.targ, buffid)
    endmethod
endstruct

private function boom takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local data d = GetTimerStructA(t)
    call ClearTimerStructA(t)
    call DestroyTimer(t)
    call d.destroy()
    set t = null
endfunction
    
private function sodc takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(), buffid) > 0
endfunction

private function soda takes nothing returns nothing
    local trigger trig = GetTriggeringTrigger()
    local data d = GetTriggerStructA(trig)
    local real dmg = GetEventDamage()
    set d.counter = d.counter + dmg
    if d.counter >= d.life then
        set dmg = 0
        set d.counter = 0
        call UnitRemoveAbility(d.targ, buffid)
        call ClearTriggerStructA(trig)
        call DisableTrigger(trig)
        call d.destroy()
        set trig = null
    else
        call SetUnitState(d.targ, UNIT_STATE_LIFE, GetUnitState(d.targ, UNIT_STATE_LIFE) + dmg)
        set dmg = 0
    endif
endfunction

private function check takes nothing returns boolean
    return GetSpellAbilityId() == spell
endfunction

private function start takes nothing returns nothing
    local timer t = CreateTimer()
    local trigger trig = CreateTrigger()
    local data d = data.create()
    set d.cast = GetTriggerUnit()
    set d.targ = GetSpellTargetUnit()
    set d.level = GetUnitAbilityLevel(d.cast, spell)
    set d.life = 40 * d.level
    set d.dmg = 50 + (50 * d.level)
    set d.counter = 0
    call TriggerRegisterUnitEvent(trig, d.targ, EVENT_UNIT_DAMAGED)
    call TriggerAddCondition(trig, Condition(function sodc))
    call TriggerAddAction(trig, function soda)
    call TimerStart(t, 5, false, function boom)
    call SetTimerStructA(t,d)
    call SetTriggerStructA(trig,d)
    set t = null
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 check))
    call TriggerAddAction( t, function start )
endfunction

endscope

Problem: when casted on self i sometimes get a healing effect instead of blocking, when casted on enemy, the targeted unit still takes damage if my hero attacks and only my hero even though the shield is still active

2nd spell
Quote:
Cooldown: 13 seconds
Damage Type: Dark
[b]Targets:[/b Enemy; Organic
Type: Instant

Binds Hypnos and nearby enemy units using Hypnos' telekenetik ability, if a unit goes above 500 range from Hypnos, it gets to sleep for 2 seconds and takes damage. Bind lasts for 5 seconds.

Level 1 - 40 damage.
Level 2 - 80 damage.
Level 3 - 120 damage.
Level 4 - 160 damage.
Level 5 - 200 damage.

Collapse JASS:
scope UnbindingSleep initializer usi // uses PUI and ABCT

globals
    private constant integer spell = 'A02C'
endglobals

private struct data
//! runtextmacro PUI()
    unit cast
    unit u
    integer level
    lightning hey
    timer t
    real x
    real y
endstruct

private function usc takes nothing returns boolean
    return GetSpellAbilityId() == spell
endfunction

private function stop takes nothing returns boolean
    local data d = ABCT_GetData()
    call DestroyLightning(d.hey)
    call d.release()
    return true
endfunction 

private function checkdis takes nothing returns boolean
    local data d = ABCT_GetData()
    local xecast xe = xecast.createA()
    local real x = d.x - GetUnitX(d.u)
    local real y = d.y - GetUnitY(d.u)
    local real dis = SquareRoot(x*x + y*y)
    set xe.abilityid = 'A028'
    set xe.orderstring = "sleep"
    set xe.level = d.level
    set xe.owningplayer = GetOwningPlayer(d.cast)
    if dis > 500 then
        call UnitDamageTargetEx(d.cast, d.u, 40 * d.level, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_DARK, true)
        call xe.castOnTarget(d.u)
        return true
    else
        call MoveLightning(d.hey, true, d.x, d.y, GetUnitX(d.u), GetUnitY(d.u))
        return false
    endif
endfunction

private function usa takes nothing returns nothing
    local timer tim = CreateTimer()
    local unit cast = GetTriggerUnit()
    local group g = CreateGroup()
    local integer l = GetUnitAbilityLevel(cast, spell)
    local data d = data.create()
    call GroupEnumUnitsInRange(g, GetUnitX(cast), GetUnitY(cast), 400, null)
    loop
        set d.u = FirstOfGroup(g)
        exitwhen d.u == null
        if IsUnitEnemy(d.u, GetOwningPlayer(cast)) and not IsUnitType(d.u, UNIT_TYPE_STRUCTURE) and GetWidgetLife(d.u) > 0.405 then
            set d = data[d.u]
            set data[d.u] = d
            call ABCT_Start(function checkdis, d, 0.035)
            set d.cast = cast
            set d.x = GetUnitX(d.cast)
            set d.y = GetUnitY(d.cast)
            set d.hey = AddLightning("SPLK", true, d.x, d.y, GetUnitX(d.u), GetUnitY(d.u))
            set d.level = l
            call SetLightningColor(d.hey, 0, 255, 0, 255)
            call GroupRemoveUnit(g, d.u)
        endif
        call GroupRemoveUnit(g, d.u)
    endloop
    call ABCT_Start(function stop, d, 5)
    call GroupClear(g)
    call DestroyGroup(g)
    set g = null
    set cast = null
endfunction

//===========================================================================
private function usi takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(trig, Condition(function usc))
    call TriggerAddAction( trig, function usa )
endfunction

endscope

Problem: doesnt work ingame


thanks in advance
09-22-2008, 06:38 PM#2
Anitarf
Quote:
both spells uses rising_dusk's damage system and xe0.3
What are you talking about? The first spell uses neither and the second spell only uses xecast.

Quote:
Problem: when casted on self i sometimes get a healing effect instead of blocking, when casted on enemy, the targeted unit still takes damage if my hero attacks and only my hero even though the shield is still active
The first probably happens when you cast the spell on the same unit multiple times since the spell stacks, the second one probably happens when the attacked unit is at full hp since you have a very primitive damage prevention, I'd suggest you use a system like ADamage if you want proper damage prevention.

Quote:
Problem: doesnt work ingame
That's incredibly vague, please give us more information if you want us to help. Put some debug messages into your code to see at what point does it stop working.