• 🏆 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!

[vJASS] Learning group.

Status
Not open for further replies.
Level 10
Joined
May 28, 2011
Messages
455
i want to make a spell which damage enemy units within radius of 150 in the line from caster point to target point instantly.
how to implement this
1st - make group
2nd - add all unit in line into the group
3rd - filter them
4th - loop through unit and damage 1 by 1 + remove them
need pros teach me proper way :) actually i will try n error n refer to example. however, assistance from pros will hasten my learning process right?
 
Last edited:
Level 9
Joined
Jul 4, 2007
Messages
130
I think that's it, there are still many leaks here but they are easy to fix and would just deface the basic code.
JASS:
function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A006' // Well it is your ability raw ID here (you can find it with Ctrl+D in the object editor)
endfunction

function FilterFunc takes nothing returns boolean
local unit filter = GetFilterUnit()
return (GetUnitTypeId(filter) != 'e000' ) and (GetUnitState(filter, UNIT_STATE_LIFE) > 0)
endfunction

function Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local unit tempu
local group tempg = CreateGroup()
local group g = CreateGroup()
local real LINE_ACCURACY = 20 //kinda a constant to improve readability
local integer imax = DistanceBetweenPoints(GetUnitLoc(caster),GetSpellTargetPoint())/LINE_ACCURACY
local integer i = 0
local filterfunc MyFilter = Filter(function FilterFunc)

loop
set i = i + 1
exitwhen i > imax
call GroupEnumUnitsInRangeOfLoc(tempg,PolarProjectionBJ(GetUnitLoc(caster),i*20+150,GetUnitFacing(caster))
,150,MyFilter)
call GroupAddGroup(tempg,g)
endloop

loop
set tempu = FirstOfGroup(g)
exitwhen tempu == null
call UnitDamageTargetBJ(caster,tempu,999, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL) // huge damage bro
call GroupRemoveUnit(g,tempu)
set tempu = null
endloop

call DestroyGroup(tempg)
call DestroyGroup(g)
call DestroyFilter(MyFilter)
set caster = null
endfunction

private function InitTrig_MYTRIGGER takes nothing returns nothing
    set gg_trg_MYTRIGGER = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_MYTRIGGER, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_MYTRIGGER, Condition( function Conditions) )
    call TriggerAddAction( gg_trg_MYTRIGGER, function Actions )
endfunction
 
Level 9
Joined
Jul 4, 2007
Messages
130
to get a distance between 2 points you usually use:

JASS:
function DistanceBetweenPoints(LocA,LocB) // which returns a real, the distance between these 2 locations

but as you can see if you dont do it properly (as I did ^^) it will leak 2 locations everytime it is called, so you should clean the locations leak.
 
Level 10
Joined
May 28, 2011
Messages
455
ops. im sory. i didnt state what i need clearly. i have 4 points extract from 2 locations
JASS:
local unit caster = GetTriggerUnit()
local location spellLoc = GetSpellTargetLoc()
local real spellX = GetLocationX(spellLoc)
local real spellY = GetLocationY(spellLoc)
local location casterLoc = GetUnitLoc(caster)
local real casterX = GetLocationX(casterLoc)
local real casterY = GetLocationY(casterLoc)
i prefer use the real variables. can help me? :)
 
Level 4
Joined
Mar 27, 2008
Messages
112
He would still leak 2 locations as they are still on a local var, also instead of GetSpellTargetLoc() you can also directly use GetSpellTargetX/Y() and instead of GetUnitLoc(unit) you can use GetUnitX/Y() in that case you wouldn't even use locations so no location leaks there;)
 
Status
Not open for further replies.
Top