HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

More noob JASS help?

08-17-2007, 05:32 AM#1
st33m
Collapse JASS:
function Trig_Ranged_Attack_Filter takes nothing returns boolean
    return IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetFilterUnit())) and GetWidgetLife(GetFilterUnit()) > 0.405
endfunction

function Trig_Ranged_Attack_Condition2 takes nothing returns boolean
    return GetSpellAbilityId() == 'A002'
endfunction

function Trig_Ranged_Attack_Loop takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer i = GetHandleInt(t, "i")
    local unit a = GetHandleUnit(t, "a")
    local unit r = GetHandleUnit(t, "r")
    local boolexpr d = Condition(function Trig_Ranged_Attack_Filter)
    local unit f
    local group g = CreateGroup()
    call GetUnitsInRangeOfLocMatching(100, GetUnitLoc(r), d)
    set g = GetLastCreatedGroup()
        if CountUnitsInGroup(g) >= 1 then
            loop
                set f = FirstOfGroup(g)
                exitwhen f == null
                call UnitDamageTargetBJ(a, f, (100+(I2R(GetHeroStatBJ(bj_HEROSTAT_STR, a, true)))*2.50), ATTACK_TYPE_PIERCE, DAMAGE_TYPE_NORMAL)
                call AddSpecialEffectTargetUnitBJ("head", GetEnumUnit(), "Objects\\Spawnmodels\\Critters\\Albatrosse\\CritterBloodAlbatross.mdl")
                call GroupRemoveUnit(g, f)
            endloop
                set f = null
                set g = null
                set d = null
            else
                call SetUnitPositionLoc(r, PolarProjectionBJ(GetUnitLoc(r), 15.00, GetUnitFacing(r)))
        endif
    call SetHandleInt(t, "i", i+1)
    if i >= 40 then
        call FlushHandleLocals(t)
        call DestroyTimer(t)
        set t = null
    endif
endfunction

function Trig_Ranged_Attack_Actions takes nothing returns nothing
    local timer t
    local location p = PolarProjectionBJ(GetUnitLoc(GetSpellAbilityUnit()), 600.00, GetUnitFacing(GetSpellAbilityUnit()))
    local real i = 1.00
    if GetSpellAbilityId() == 'A002' then
        set t = CreateTimer()
        call CreateNUnitsAtLocFacingLocBJ( 1, 'e000', GetOwningPlayer(GetSpellAbilityUnit()), GetUnitLoc(GetSpellAbilityUnit()), p )
        call SetHandleHandle(t, "r", GetLastCreatedUnit())
        call SetHandleHandle(t, "a", GetSpellAbilityUnit())
        call SetHandleInt(t, "i", R2I(i))
        call TimerStart(t, i, true, function Trig_Ranged_Attack_Loop)
    endif
endfunction


//===========================================================================
function InitTrig_Ranged_Attack takes nothing returns nothing
    set gg_trg_Ranged_Attack = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Ranged_Attack, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( gg_trg_Ranged_Attack, Condition(function Trig_Ranged_Attack_Condition2))
    call TriggerAddAction( gg_trg_Ranged_Attack, function Trig_Ranged_Attack_Actions )
endfunction


Well... there it is. What its supposed to do is when its cast it makes a dummy projectile and shoots it 600 range in from of the caster, and if it comes close to an enemy unit it deals damage to it and then dissapears without going further...

Unfortunately, it makes a dummy and then it doesn't move, and I don't know that if it did move it would do damage.

Also, with my poor coding skills I don't know whats wrong. This is the second or third time I've recoded it from scratch, so I think I keep making the same mistake because they all come out the same with the same problems.
08-17-2007, 09:16 AM#2
cohadar
How about you forget about this trigger and simply modify the model on shockwave spell?
08-17-2007, 09:25 AM#3
Fireeye
I only took a quick look a found several things, like the following ones
Collapse JASS:
function Trig_Ranged_Attack_Filter takes nothing returns boolean
    return IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetFilterUnit())) and GetWidgetLife(GetFilterUnit()) > 0.405
endfunction
due you start this with a timer you don't have any reference to GetTriggerUnit(), which will return null then. (set the boolexpr to null and filter the units within the loop)
also you need to change this part
Collapse JASS:
call AddSpecialEffectTargetUnitBJ("head", GetEnumUnit(), "Objects\\Spawnmodels\\Critters\\Albatrosse\\CritterBloodAlbatross.mdl")
due you loop, you can not use GetEnumUnit(), use f instead.
Then change this part:
Collapse JASS:
else
    call SetUnitPositionLoc(r, PolarProjectionBJ(GetUnitLoc(r), 15.00, GetUnitFacing(r)))
endif
 
to
Collapse JASS:
endif
call SetUnitPositionLoc(r, PolarProjectionBJ(GetUnitLoc(r), 15.00, GetUnitFacing(r)))

and finally add call PauseTimer(t) before you destroy it to prevent bugs.
Also you spell contains several leaks and have some senseless parts.
08-17-2007, 11:57 PM#4
st33m
Okay thanks.
08-19-2007, 01:09 PM#5
Pyrogasm
Carrion swarm with a modified damage cap using a missile with a death animation should do exactly what you want, no triggering involved.
08-29-2007, 01:37 AM#6
st33m
But then I can't also use this to make spells based on the idea... or can I? Is there a way to make that work?


EDIT: Also, sorry I was gone on vacation (last trip of summer T_T) for a week.

Also how do I filter it in a loop >_>

I tried
Collapse JASS:
    call GetUnitsInRangeOfLocMatching(100, GetUnitLoc(r), IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetFilterUnit())) and GetWidgetLife(GetFilterUnit()) > 4.05)

and it says "Cannot convert boolean to boolexpr."

Sorry, I'm, again, really new to this...
08-29-2007, 05:49 AM#7
Pyrogasm
A boolexpr actually uses a function that returns a boolean based on whether or not certain expressions are true. For what you want to do, you'd do this:
Collapse JASS:
function FilterFunction takes nothing returns boolean
    return IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetFilterUnit())) and GetWidgetLife(GetFilterUnit()) > 4.05
endfunction

//In your other function
call GetUnitsInRangeOfLocMatching(100, GetUnitLoc(r), Condition(function FilterFunction))
Some might say that BoolExprs leak, but grim001 has proven that to be false, as a boolexpr always returns the same handle index every time it is used.
08-29-2007, 06:10 AM#8
st33m
Isn't that different than filtering the units in the loop itself though?
08-30-2007, 05:56 AM#9
Pyrogasm
Yes, because the units that don't make the filter return true won't be added to the group. If you wanted to get every unit and then sort through them manually, you'd do this:
Collapse JASS:
function FilterFunc takes nothing returns boolean
    return true //"null" boolexprs leak, apparently
endfunction

//In your script:
set G = GetUnitsInRangeOfLocMatching(100, GetUnitLoc(r), Condition(function FilterFunction))
loop
    set U = FirstOfGroup(G)
    exitwhen U == null

    if (<Your Filter Here>) then
        call DoSomething()
    endif

    call GroupRemoveUnit(G, U)
endloop