HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

JASS Spell8: Entrapment Ward (need help)

10-16-2006, 02:55 PM#1
Fulla
Entrapment Ward - Creates a ward at target point temporarily. During this period the war will automatically begin 1by1 shackling nearby enemy units locking them down until the ward expires.

Collapse JASS:
                //################################################################\\
                //                                                                \\
                //                     Configuration Section                      \\
                //                                                                \\
                //################################################################\\

constant function EntrapmentWard_AbilId takes nothing returns integer
    return 'A063'
endfunction

constant function EntrapmentWard_Duration takes integer level returns integer
    return (level * 2) + 4
endfunction

constant function EntrapmentWard_SpellRadius takes integer level returns real
    return level * 50. + 400.
endfunction


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


function Trig_EntrapmentWard_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == EntrapmentWard_AbilId()
endfunction

function EntrapmentWard_Group takes nothing returns boolean
    return (GetWidgetLife(GetFilterUnit()) > 0.405) and IsUnitEnemy(GetFilterUnit(), udg_tempplayer) and IsUnitInGroup(GetFilterUnit(), udg_EntrapmentWard_G)
endfunction

function EntrapmentWard_Shackle takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local string s = GetAttachmentTable(t)
    local unit u
    local group g = CreateGroup()
    local unit c = GetTableUnit(s,"Caster")
    local real x = GetTableReal(s,"X")
    local real y = GetTableReal(s,"Y")
    local integer lvl = GetTableInt(s,"Level")
    local integer counter = GetTableInt(s,"Counter")    
    call GroupEnumUnitsInRange(g, x, y, EntrapmentWard_SpellRadius(lvl), Condition(function EntrapmentWard_Group))
    set u = FirstOfGroup(g)
    call GroupAddUnit(udg_EntrapmentWard_G, u)
    call AddLightningEx('LEAS', false, x, y, 0, GetUnitX(u), GetUnitY(u), 0)
    if counter == 0 then
        call PauseTimer(t)
        call DestroyTimer(t)
    endif
 
endfunction

function Trig_EntrapmentWard_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local string s = GetAttachmentTable(t)
    local unit c = GetTriggerUnit()
    local unit d
    local location l = GetSpellTargetLoc()
    local real x = GetLocationX(l)
    local real y = GetLocationY(l)
    local integer lvl = GetUnitAbilityLevel(c, EntrapmentWard_AbilId)
    local integer counter = EntrapmentWard_Duration(level) 
    
    set udg_tempplayer = GetOwningPlayer(c)
    set d = CreateUnit(udg_tempplayer, 'XXXX', x, y, bj_UNIT_FACING)
    
    call SetTableObject(s,"Caster",c)
    call SetTableReal(s,"X",x)
    call SetTableReal(s,"Y",y)
    call SetTableInt(s,"Level",lvl)
    call SetTableInt(s,"Counter",counter)
    call TimerStart(t,0.5,true,function EntrapmentWard_Shackle)
endfunction

//===========================================================================
function InitTrig_EntrapmentWard takes nothing returns nothing
    set gg_trg_EntrapmentWard = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_EntrapmentWard, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_EntrapmentWard, Condition( function Trig_EntrapmentWard_Conditions ) )
    call TriggerAddAction( gg_trg_EntrapmentWard, function Trig_EntrapmentWard_Actions )
endfunction

It keeps coming up, 'Invalid argument type (integer)'

Collapse JASS:
    if counter == 0 then


NOTE:
- still need to destroy lightning at end, havent got to that bit yet
- need to make the group a local, not quite there yet either :D

thx for any help
10-16-2006, 02:58 PM#2
Daelin
I have a better solution. Use the "TriggerRegisterUnitInRange" event. It is far more efficient and does exactly what you want. Everytime an unit comes within the range of the ward (you can add condtions of course) just cast with a dummy unit aerial shackles on it. Or is the unit supposed to be able to attack?

~Daelin
10-16-2006, 02:59 PM#3
Fulla
hmm it shackles a unit every 0.5 seconds for X seconds?
Would thet be compatible?
10-16-2006, 03:17 PM#4
Chuckle_Brother
Collapse JASS:
call AddLightningEx('LEAS', false, x, y, 0, GetUnitX(u), GetUnitY(u), 0)

The error is actually here. 'LEAS' returns an integer, while AddLightningEx takes a string.

Edit: Also failure to set udg_tempplayer before enumerating the group will nab you a null unit(do a check so under normal circumstances it won't do that, if u != null....etc)
10-16-2006, 07:25 PM#5
Daelin
Sorry, didn't notice that part. You didn't sound very obvious and I didn't read super carefully.

Well spotted Chuckle. :D

~Daelin
10-16-2006, 11:53 PM#6
Fulla
It all works now except, the spell doesnt seem to 'stop'
It continually grabs any new units from the spot.

Collapse JASS:
                               
                //################################################################\\
                //                                                                \\
                //                     Configuration Section                      \\
                //                                                                \\
                //################################################################\\


constant function EntrapmentWard_AbilId takes nothing returns integer
    return 'A0DL'
endfunction

constant function EntrapmentWard_Duration takes integer level returns integer
    return (level * 2) + 4
endfunction

constant function EntrapmentWard_SpellRadius takes integer level returns real
    return level * 50. + 400.
endfunction


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


function Trig_EntrapmentWard_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == EntrapmentWard_AbilId()
endfunction

function EntrapmentWard_Group takes nothing returns boolean
    return (GetWidgetLife(GetFilterUnit()) > 0.405) and IsUnitEnemy(GetFilterUnit(), udg_tempplayer) and not IsUnitInGroup(GetFilterUnit(),udg_EntrapmentWard_G)
endfunction

function EntrapmentWard_Shackle takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local string s = GetAttachmentTable(t)
    local boolean b = false
    local group g = CreateGroup()
    local unit d
    local unit e
    local unit c = GetTableUnit(s,"Caster")
    local real x = GetTableReal(s,"X")
    local real y = GetTableReal(s,"Y")
    local integer lvl = GetTableInt(s,"Level")
    local integer counter = GetTableInt(s,"Counter")
    set udg_tempplayer = GetOwningPlayer(c)    
    call GroupEnumUnitsInRange(g, x, y, EntrapmentWard_SpellRadius(lvl), Condition(function EntrapmentWard_Group))
    set e = FirstOfGroup(g)
    call GroupAddUnit(udg_EntrapmentWard_G, e)
    set d = CreateUnit(udg_tempplayer, 'h00L', x, y, bj_UNIT_FACING)
    call UnitAddAbility(d, 'A0DM')
    call IssueTargetOrderBJ(d, "magicleash", e)
    call UnitApplyTimedLifeBJ(EntrapmentWard_Duration(lvl) - (EntrapmentWard_Duration(lvl) - I2R(counter)), 'BTLF', d)
    set counter = counter - 1
    if counter == 0 then
        call PauseTimer(t)
        call DestroyTimer(t)
    endif
 
endfunction

function Trig_EntrapmentWard_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local string s = GetAttachmentTable(t)
    local unit c = GetTriggerUnit()
    local unit d
    local location l = GetSpellTargetLoc()
    local real x = GetLocationX(l)
    local real y = GetLocationY(l)
    local integer lvl = GetUnitAbilityLevel(c, EntrapmentWard_AbilId())
    local integer counter = 6
    
    set udg_tempplayer = GetOwningPlayer(c)
    set d = CreateUnit(udg_tempplayer, 'o00D', x, y, bj_UNIT_FACING)
    call UnitApplyTimedLifeBJ(I2R(EntrapmentWard_Duration(lvl)), 'BTLF', d)
    
    call SetTableObject(s,"Caster",c)
    call SetTableReal(s,"X",x)
    call SetTableReal(s,"Y",y)
    call SetTableInt(s,"Level",lvl)
    call SetTableInt(s,"Counter",counter)
    call TimerStart(t,0.5,true,function EntrapmentWard_Shackle)
    set d = null
endfunction

//===========================================================================
function InitTrig_EntrapmentWard takes nothing returns nothing
    set gg_trg_EntrapmentWard = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_EntrapmentWard, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_EntrapmentWard, Condition( function Trig_EntrapmentWard_Conditions ) )
    call TriggerAddAction( gg_trg_EntrapmentWard, function Trig_EntrapmentWard_Actions )
endfunction
10-17-2006, 01:31 AM#7
Chuckle_Brother
You never set the decremented version of counter back into the cache.

Add a line near the end that reads:
Collapse JASS:
call SetTableInt(s,"Counter",counter)

Do this AFTER you decrease counter by 1.