HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

JASS Spell: Conviction - Having troubles

10-30-2006, 02:33 PM#1
Fulla
Conviction: Every 5 seconds picks a random enemy dead corpse near the hero and converts it into life/mana for friendly units surrounding the corpse.
The health/mana restored is a % of maxhp/mana from the corpse and is shared out equally amongst friendly units.

So here goes, having qutie a few errors :/
Firstly it really doesnt like my first condition

Collapse JASS:

               //################################################################\\
               //                                                                \\
               //                     Configuration Section                      \\
               //                                                                \\
               //################################################################\\


constant function Conviction_AbilId takes nothing returns integer
    return 'A00I'
endfunction

constant function Conviction_UnitId takes nothing returns integer
    return 'Hpal'
endfunction

constant function Conviction_Stats takes integer level returns real
    return (level * 10) + 0.
endfunction

constant function Conviction_Radius takes integer level returns real
    return (level * 0) + 400.
endfunction


               //################################################################\\
               //                                                                \\
               //                        Spell Section                           \\
               //                                                                \\
               //################################################################\\

function Conviction_Conditions_ability takes nothing returns integer
    return (GetUnitAbilityLevel(Conviction_UnitId(), Conviction_AbilId()) > 0)
endfunction

function Conviction_Conditions_corpse takes nothing returns boolean
    return (GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) <= 0.)
endfunction

function Conviction_Conditions_heal takes nothing returns boolean
    return (GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.) and IsUnitAlly(GetFilterUnit(), udg_tempplayer)
endfunction

function Trig_Conviction_Actions takes nothing returns nothing
    local unit caster
    local unit target
    local unit dummy
    local unittype class = Conviction_UnitId()
    local group casters = CreateGroup()
    local group dead = CreateGroup()
    local group targets = CreateGroup()
    local integer level
    local real percent
    local real maxhp
    local real maxma
    local real hpres
    local real mares
    local real temp
    local integer count = 0 
    local boolexpr b = Conviction_Conditions_ability()
    local boolexpr c = Conviction_Conditions_corpse()
    local boolexpr d = Conviction_Conditions_heal()
    call GroupEnumUnitsOfType(casters, class, b)
    loop
        set caster = FirstOfGroup(casters)
        exitwhen caster == null
        set level = GetUnitAbilityLevel(caster, Conviction_AbilId())
        set percent = Conviction_Stats(level) 
        call GroupEnumUnitsInRange(dead, GetUnitX(caster), GetUnitY(caster), 500, c)
        set udg_tempplayer = GetOwningPlayer(caster)
        set target = GroupPickRandomUnit(dead)
        set maxhp = GetUnitState(target, UNIT_STATE_MAX_LIFE)
        set maxma = GetUnitState(target, UNIT_STATE_MAX_MANA)
        call GroupEnumUnitsInRange(targets, GetUnitX(target), GetUnitY(target), 500, d)
        set count = CountUnitsInGroup(targets)
        set hpres = maxhp / percent
        set mares = maxma / percent
        set life = hpres / I2R(hpres)
        set mana = mares / I2R(mares)
            loop
            set dummy = FirstOfGroup(targets)
            exitwhen dummy == null
            call SetUnitLifeBJ(dummy, GetUnitState(dummy, UNIT_STATE_LIFE) + life)
            call SetUnitLifeBJ(dummy, GetUnitState(dummy, UNIT_STATE_MANA) + mana)
            call DestroyEffect(AddSpecialEffectTargetUnitBJ("origin", caster, "Abilities\\Spells\\Human\\Heal\\HealTarget.mdl"))
            endloop
    endloop
    call DestroyBoolExpr(b)
    call DestroyBoolExpr(c)
    call DestroyBoolExpr(d)
    call DestroyGroup(casters)
    call DestroyGroup(dead)
    call DestroyGroup(targets)
    set b = null
    set c = null
    set d = null
    set casters = null
    set dead = null
    set targets = null
    set caster = null
    set target = null
    set dummy = null
endfunction

//===========================================================================
function InitTrig_Conviction takes nothing returns nothing
    set gg_trg_Conviction = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Conviction, 6.00 )
    call TriggerAddAction( gg_trg_Conviction, function Trig_Conviction_Actions )
endfunction

Collapse JASS:
function Conviction_Conditions_ability takes nothing returns integer
    return (GetUnitAbilityLevel(Conviction_UnitId(), Conviction_AbilId()) > 0)
endfunction

How should I code this.

Also note: ill have this deactivated until atleast 1 hero learns that skill.

thx for any help
10-30-2006, 02:42 PM#2
Thunder_Eye
in the first condition (GetUnitAbilityLevel) you are giving it an unittypeid (integer) in the first parameter when it actually should be an unit.
10-30-2006, 04:14 PM#3
Fulla
kk now its acting very dodgy.

Friendly units semm to loose life?? lol

Collapse JASS:

               //################################################################\\
               //                                                                \\
               //                     Configuration Section                      \\
               //                                                                \\
               //################################################################\\


constant function Conviction_AbilId takes nothing returns integer
    return 'A00I'
endfunction

constant function Conviction_UnitId takes nothing returns integer
    return 'Hpal'
endfunction

constant function Conviction_Stats takes integer level returns real
    return (level * 10) + 0.
endfunction

constant function Conviction_Radius takes integer level returns real
    return (level * 0) + 400.
endfunction


               //################################################################\\
               //                                                                \\
               //                        Spell Section                           \\
               //                                                                \\
               //################################################################\\

function Conviction_Conditions_ability takes nothing returns boolean
    return (GetUnitAbilityLevel(GetFilterUnit(), Conviction_AbilId()) > 0)
endfunction

function Conviction_Conditions_corpse takes nothing returns boolean
    return (GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) <= 0.) and IsUnitEnemy(GetFilterUnit(), udg_tempplayer) and (IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false) 
endfunction

function Conviction_Conditions_heal takes nothing returns boolean
    return (GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.) and IsUnitAlly(GetFilterUnit(), udg_tempplayer) and (IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) == false)
endfunction

function Trig_Conviction_Actions takes nothing returns nothing
    local unit caster
    local unit target
    local unit dummy
    local group casters = CreateGroup()
    local group dead = CreateGroup()
    local group targets = CreateGroup()
    local integer level
    local real percent
    local real maxhp
    local real maxma
    local real hpres
    local real mares
    local real temp
    local real life
    local real mana
    local integer count = 0 
    local boolexpr b = Condition(function Conviction_Conditions_ability)
    local boolexpr c = Condition(function Conviction_Conditions_corpse)
    local boolexpr d = Condition(function Conviction_Conditions_heal)
    call GroupEnumUnitsInRect(casters, GetPlayableMapRect(), b)
    loop
        set caster = FirstOfGroup(casters)
        exitwhen caster == null
        set level = GetUnitAbilityLevel(caster, Conviction_AbilId())
        set percent = Conviction_Stats(level) 
        call GroupEnumUnitsInRange(dead, GetUnitX(caster), GetUnitY(caster), 500, c)
        set udg_tempplayer = GetOwningPlayer(caster)
        set target = GroupPickRandomUnit(dead)
        set maxhp = GetUnitState(target, UNIT_STATE_MAX_LIFE)
        set maxma = GetUnitState(target, UNIT_STATE_MAX_MANA)
        call GroupEnumUnitsInRange(targets, GetUnitX(target), GetUnitY(target), 500, d)
        set count = CountUnitsInGroup(targets)
        set hpres = maxhp / percent
        set mares = maxma / percent
        set life = hpres / I2R(count)
        set mana = mares / I2R(count)
        call RemoveUnit(target)
            loop
            set dummy = FirstOfGroup(targets)
            exitwhen dummy == null
            call SetUnitState(dummy, UNIT_STATE_LIFE, (GetUnitState(dummy,UNIT_STATE_LIFE) + life))
            call SetUnitLifeBJ(dummy, GetUnitState(dummy, UNIT_STATE_MANA) + mana)
            call DestroyEffect(AddSpecialEffectTargetUnitBJ("origin", caster, "Abilities\\Spells\\Human\\Heal\\HealTarget.mdl"))
            call GroupRemoveUnit(targets, dummy)
            endloop
       call GroupRemoveUnit(casters, caster)
    endloop
    call DestroyBoolExpr(b)
    call DestroyBoolExpr(c)
    call DestroyBoolExpr(d)
    call DestroyGroup(casters)
    call DestroyGroup(dead)
    call DestroyGroup(targets)
    set b = null
    set c = null
    set d = null
    set casters = null
    set dead = null
    set targets = null
    set caster = null
    set target = null
    set dummy = null
endfunction

//===========================================================================
function InitTrig_Conviction takes nothing returns nothing
    set gg_trg_Conviction = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Conviction, 6.00 )
    call TriggerAddAction( gg_trg_Conviction, function Trig_Conviction_Actions )
endfunction

10-30-2006, 05:26 PM#4
blu_da_noob
Debug message maxhp and make sure it's positive.
10-30-2006, 05:39 PM#5
Captain Griffen
GetWidgetLife/SetWidget life are much better for setting/getting unit's current life (faster, easier to read and easier to type). Also, a unit is dead when it's life is less than 0.405.
11-02-2006, 01:06 PM#6
ArchWorm
Quote:
Also, a unit is dead when it's life is less than 0.405.
It's lame. The fully safe is GetUnitTypeId(u)==0. DioD said about this, Check it here
11-02-2006, 01:24 PM#7
blu_da_noob
Quote:
Originally Posted by ArchWorm
It's lame. The fully safe is GetUnitTypeId(u)==0. DioD said about this, Check it here

GetUnitTypeId will only return 0 if the unit has been removed from the game (ie. the variable points to nothing now).

(The IsUnitType(u,UNIT_TYPE_DEAD) is also wrong, it continued to return false for my perfectly deceased footman)