• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Cannot set local location

Status
Not open for further replies.
Level 7
Joined
Feb 26, 2005
Messages
210
So I am working on a spell that kills player units in an area. The spell isn't setting a local location to where I want it to be thus causing it not to work properly. Here's the code:

JASS:
function Trig_MDR_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A007' ) ) then
        return false
    endif
    return true
endfunction

function Group_Actions takes nothing returns nothing
    call KillUnit(GetEnumUnit())
endfunction

function LivingPlayerOwnedNonHeroGround takes nothing returns boolean
    return GetOwningPlayer(GetFilterUnit()) == GetOwningPlayer(GetSpellAbilityUnit()) and GetWidgetLife(GetFilterUnit()) > .405 and IsUnitType(GetFilterUnit(), UNIT_TYPE_GROUND) == true and IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == false
endfunction

function Trig_MDR_Actions takes nothing returns nothing
    local location l
    local group g
    local integer x
    set l = GetSpellTargetLoc()
    set g = GetUnitsInRangeOfLocMatching(200.00, l, Condition(function LivingPlayerOwnedNonHeroGround))
    set x = CountUnitsInGroup(g)
    call DisplayTextToForce( GetPlayersAll(), I2S(x) )
    call ForGroup(g,function Group_Actions)
    call DestroyGroup(g)
endfunction

//===========================================================================
function InitTrig_MDR takes nothing returns nothing
    set gg_trg_MDR = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_MDR, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_MDR, Condition( function Trig_MDR_Conditions ) )
    call TriggerAddAction( gg_trg_MDR, function Trig_MDR_Actions )
endfunction

I imagine there is a simple solution to this. Please help.
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
Script can be improved a lot:

GetSpellAbilityUnit(), even changed to GetTriggerUnit() should be replaced with global parameter since it's another function call.
Let's say it's 'Caster' -> created via GUI variable editor.
It's safer to replace 'GetWidgetLife(GetFilterUnit()) > .405' with 'not IsUnitType(u, UNIT_TYPE_DEAD)'.
While using comparison and checking if it's actually 'true' you don't need to add '== true'.
Actiona and conditions should be merged. Additionaly you can make use of filter function while enumerating untis to apply actions immidiately.
Coordinates in form of reals prove to be faster than locations. As last advice: use natives to improve the speed of script.
JASS:
function LivingPlayerOwnedNonHeroGround takes nothing returns boolean
    local unit u = GetFilterUnit()
    if GetOwningPlayer(u) == GetOwningPlayer(udg_Caster) and not IsUnitType(u, UNIT_TYPE_DEAD) and IsUnitType(u, UNIT_TYPE_GROUND) and not IsUnitType(u, UNIT_TYPE_HERO) then
        call KillUnit(u)
    endif
    set u = null
    return false
endfunction

function Trig_MDR_Conditions takes nothing returns boolean
    local real x
    local real y
    if GetSpellAbilityId() == 'A007' then
        set x = GetSpellTargetX()
        set y = GetSpellTargetY()
        set udg_Caster = GetTriggerUnit()
        call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, 200., Filter(function LivingPlayerOwnedNonHeroGround)) 
    endif
    return false
endfunction

//===========================================================================
function InitTrig_MDR takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t, Condition(function Trig_MDR_Conditions))
    set t = null
endfunction
 
Status
Not open for further replies.
Top