HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

unit not inside minimum range?

10-12-2008, 12:52 PM#1
maximilianx
Alright, so basically, I'm brand spankin' new to JASS.
To give you an idea, been self-teaching with tutorials since about.. this time yesterday. :P

Now I'd consider myself damn good with GUI, but I'm tired of the limitations and clicking around and such. It may be a bit soon but i'm trying to construct a spell with JASS right now, and I've encountered a bit of a problem.

My spell (Flood Nova) is an AoE channeling spell that targets a point, while channeling, there will be 6 pulses of water over a 1 second period of time, going outward. Now for each pulse, I want units hit by that water to take damage. And I'll need to set the unit group of all the units effected to units within say, for the first pulse as an example, <=150 and >=0, for the second, maybe <=300 and >=150

this is what i have right now for getting a unit group, and I'd like help knowing what to replace it with, thank you!

Collapse JASS:
call GroupEnumUnitsInRangeOfLoc(targets, target_point, (ring_size+50),null)
ring_size is a variable for the size of the current pulse by the way. (radius)
10-12-2008, 03:16 PM#2
Tide-Arc Ephemera
Not that I can directly answer your question, but when I started learning Jass (still am), I started off with making skeletons of spells in GUI then convert and rewrite the parts of it.

However, you might want to loop through your groups in a fashion of something like...

Collapse JASS:
    loop
         set CurrentUnit == FirstOfGroup(targets)
    exitwhen CurrentUnit == null
         if (Distance)=>0 and (Distance)<=150 and then
         elseif (Distance)>150 and 300<=(Distance) then
         endif
    endloop

Sorry I don't know the name of the distance native, I normally read off the natives, sadly.
10-12-2008, 05:28 PM#3
maximilianx
maybe i should include my entire function, don't see a way to apply your code to my function.

Collapse JASS:
function Trig_Castor_Actions takes nothing returns nothing
  local unit caster = GetSpellAbilityUnit()
  local location target_point = GetSpellTargetLoc()
  local group targets
  local real ring_size = 0.0
    loop
        exitwhen ( GetUnitCurrentOrder(caster) != "channel" )
        set ring_size = (ring_size + 75.0)
        call GroupEnumUnitsInRangeOfLoc(targets, target_point, (ring_size+50),null)//==this is the condition, i want to change this to whatever is necessary to include a minimum range, not just maximum.
            
    endloop  
endfunction
10-12-2008, 05:35 PM#4
DioD
1) Pick some OUTgroup (500 range)

2) Pick some INgroup (100 range)

3) Remove INgroup from OUTgroup (you will get unit from range 100 to 500)
10-12-2008, 05:45 PM#5
Here-b-Trollz
Collapse JASS:
globals
    real tx
    real ty
    real td
globals

function InRange takes nothing returns boolean
    local unit f=GetFilterUnit()
    local real d=(GetUnitX(f)-tx)*(GetUnitX(f)-tx)+(GetUnitY(f)-ty)*(GetUnitY(f)-ty)
    set f=null
    return d>=td*td
endfunction

function Trig_Castor_Actions takes nothing returns nothing
  local unit caster = GetSpellAbilityUnit()
  local location target_point = GetSpellTargetLoc()
  local group targets
  local real ring_size = 0.0
    loop
        exitwhen ( GetUnitCurrentOrder(caster) != "channel" )
        set ring_size = (ring_size + 75.0)
        set tx=GetUnitX(caster)
        set ty=GetUnitY(caster)
        set td=ring_size
        call GroupEnumUnitsInRangeOfLoc(targets, target_point, ring_size+50,Filter(function InRange))//==this is the condition, i want to change this to whatever is necessary to include a minimum range, not just maximum.
            
    endloop  
endfunction
10-12-2008, 06:03 PM#6
maximilianx
EDITED:
okay, I discovered the GroupRemoveGroup native, thank god ha.
now, i need a bit more help:
Collapse JASS:
function Trig_Castor_Actions takes nothing returns nothing
  local unit caster = GetSpellAbilityUnit()
  local location target_point = GetSpellTargetLoc()
  local group OUTgroup
  local group INgroup
  local group targets
  local real damage
  local real ring_size = 0.0
    loop
        exitwhen ( GetUnitCurrentOrder(caster) != "channel" )
        set ring_size = (ring_size + 75.0)
        call GroupEnumUnitsInRangeOfLoc(OUTgroup, target_point, (ring_size+50), null)
        call GroupEnumUnitsInRangeOfLoc(INgroup, target_point, (ring_size-50), null)
        call GroupRemoveGroup(OUTgroup, INgroup)//<--is this the correct order for removing in from out? or do i want INgroup before OUTgroup?
        set targets = OUTgroup
        call ForGroup(targets, call UnitDamageTarget(_,_,damage,_,_,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_NORMAL,null)//really have no idea what to fill in for most of these arguments :/    
    endloop  
endfunction

so i need help with most of the arguments here:
Collapse JASS:
native UnitDamageTarget (unit whichUnit, widget target, real amount, boolean attack, boolean ranged, attacktype attackType, damagetype damageType, weapontype weaponType) returns boolean
10-12-2008, 08:14 PM#7
Anitarf
GroupRemoveGroup is not a native.

Here is a good description of damage and attack types. As for the other parameters of the damage natives, some are self-explanatory while others usualy don't matter.
10-12-2008, 08:44 PM#8
maximilianx
okay so, that didn't help me much.
could anybody explain GroupRemoveGroup a little more clearly?

EDIT here, how about i give you guys my entire code, and tell me aaalll the crap i'm doin wrong?
that'd be very helpful i'm sure.
Collapse JASS:
function Trig_Castor_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A02F'
endfunction

function Pulse_effect takes real radius, location target returns nothing 
  local real angle = 0.0
  local real a = (radius / 15.00)
  local real ang_inc = (360.00 / a)
  local location splash
        loop
            exitwhen angle >= 360.00
            set splash = PolarProjectionBJ(target, radius, angle)
            call DestroyEffect(AddSpecialEffectLoc("Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl", splash))
            set angle = (angle + ang_inc)
        endloop              
endfunction

function TimerDone takes unit caster returns nothing
  local string SpellID = "A02F"
  local unit tempTarget
  local location target_point = GetSpellTargetLoc()
  local group OUTgroup
  local group INgroup
  local group targets
  local real ring_size = 0.0
  local real damage = 0.0
  local integer rings_passed
        set ring_size = (ring_size + 75.0)
        call GroupEnumUnitsInRangeOfLoc(OUTgroup, target_point, (ring_size+50), null)
        call GroupEnumUnitsInRangeOfLoc(INgroup, target_point, (ring_size-50), null)
        call GroupRemoveGroup(OUTgroup, INgroup)
        set targets = OUTgroup
        set damage = (10.00+(15.00*GetUnitAbilityLevel(caster,S2I(SpellID))))
        loop
            exitwhen CountUnitsInGroup(targets) == 0
            set tempTarget = FirstOfGroup(targets)
            call UnitDamageTarget(tempTarget,null,damage,false,false,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_NORMAL,null))//i know somethings wrong here
            call GroupRemoveUnit(targets, tempTarget)
        endloop
        call Pulse_effect(ring_size, target_point)
endfunction

function Trig_Castor_Actions takes nothing returns nothing
    local unit caster = GetSpellAbilityUnit()
    local timer short = CreateTimer()
        loop
        exitwhen ( GetUnitCurrentOrder(caster) != String2OrderIdBJ("channel") )
        call TimerStart(short, 0.2, false, TimerDone(caster))//error on this line "Cannot convert nothing to code" what does that mean?    
    endloop  
endfunction

//===========================================================================
function InitTrig_Castor takes nothing returns nothing
    set gg_trg_Castor = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Castor, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Castor, Condition( function Trig_Castor_Conditions ) )
    call TriggerAddAction( gg_trg_Castor, function Trig_Castor_Actions )
    call Preload("Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl")
endfunction

i know it's gone a lot of leaks, not worried about leaks atm. thanks.
10-12-2008, 10:40 PM#9
Anitarf
You didn't tell us what the problem is, what part of the code isn't working? You can't just throw code at us and expect us to solve all your problems.
10-12-2008, 10:50 PM#10
Here-b-Trollz
Timers to not work that way. You cannot pass arguments through them. This is probably the most common mistake made with them. You need to attach or pass some other way.
10-12-2008, 11:15 PM#11
maximilianx
Quote:
Originally Posted by Anitarf
You didn't tell us what the problem is, what part of the code isn't working? You can't just throw code at us and expect us to solve all your problems.

i did actually put notations in the code stating the problem lines.
and.. okay thanks trolls, ima go read up on some timer tutorials.

EDIT:
so i worked on it a bit more, and i'm still having some trouble. keep in mind people i'm very new to jass and timers. soo having trouble with the timer here.. i did read rising_dusk's timers tutorial, it's not helping me. perhaps i'm retarded.
Collapse JASS:
function Trig_Castor_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A02F'
endfunction

function Pulse_effect takes real radius, location target returns nothing 
  local timer T = GetExpiredTimer()
  
  local real angle = 0.0
  local real a = (radius / 15.00)
  local real ang_inc = (360.00 / a)
  local location splash
        loop
            exitwhen angle >= 360.00
            set splash = PolarProjectionBJ(target, radius, angle)
            call DestroyEffect(AddSpecialEffectLoc("Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl", splash))
            set angle = (angle + ang_inc)
        endloop
  call DestroyTimer(T)
  set T = null              
endfunction

function TimerDone takes unit caster returns nothing
  local string SpellID = "A02F"
  local unit tempTarget
  local location target_point = GetSpellTargetLoc()
  local group OUTgroup
  local group INgroup
  local group targets
  local real ring_size = 0.0
  local real damage = 0.0
  local integer rings_passed
        set ring_size = (ring_size + 75.0)
        call GroupEnumUnitsInRangeOfLoc(OUTgroup, target_point, (ring_size+50), null)
        call GroupEnumUnitsInRangeOfLoc(INgroup, target_point, (ring_size-50), null)
        call GroupRemoveGroup(OUTgroup, INgroup)
        set targets = OUTgroup
        set damage = (10.00+(15.00*GetUnitAbilityLevel(caster,S2I(SpellID))))
        loop
            exitwhen CountUnitsInGroup(targets) == 0
            set tempTarget = FirstOfGroup(targets)
            call UnitDamageTargetBJ(tempTarget,tempTarget,damage,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_NORMAL)
            call GroupRemoveUnit(targets, tempTarget)
        endloop
        call Pulse_effect(ring_size, target_point)
endfunction

function Trig_Castor_Actions takes nothing returns nothing
    local unit caster = GetSpellAbilityUnit()
    local timer short = CreateTimer()
    loop
        exitwhen ( GetUnitCurrentOrder(caster) != String2OrderIdBJ("channel") )
        call TimerStart(short, 0.2, false, TimerDone(caster))//i get the error "Cannot convert nothing to code"    
    endloop
    call PauseTimer(short)
    call DestroyTimer(short)
    set short = null  
endfunction

//===========================================================================
function InitTrig_Castor takes nothing returns nothing
    set gg_trg_Castor = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Castor, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Castor, Condition( function Trig_Castor_Conditions ) )
    call TriggerAddAction( gg_trg_Castor, function Trig_Castor_Actions )
    call Preload("Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl")
endfunction

i'm not sure how to highlight bits of text soo, if you can't find my problem line its about 8 lines up from the //=== line toward the bottom.
10-13-2008, 12:33 PM#12
saw792
Collapse JASS:
local group OUTgroup = CreateGroup()
local group INgroup = CreateGroup()
local group targets = CreateGroup()

GroupEnum... functions merely add the units to the group. If the group doesn't exist, then it won't work.

EDIT: That timer argument is a code argument, in the form:
call TimerStart(short, 0.2, false, function TimerDone)
A code function cannot take arguments itself.
10-13-2008, 01:26 PM#13
Tide-Arc Ephemera
Quote:
Originally Posted by maximilianx
i'm not sure how to highlight bits of text soo, if you can't find my problem line its about 8 lines up from the //=== line toward the bottom.

You use @@ and ## as though they were like brackets. @@ gives you the yellowy highlight, ## gives you the blaring red.

Collapse JASS:
function MyStupid function takes real y returns something_wrong
    call SetUnitY(udg_Blargh, y)
endfunction

10-13-2008, 02:47 PM#14
maximilianx
okay thanks guys :)
yet another question here, in my loop:
Collapse JASS:
loop
        exitwhen ( GetUnitCurrentOrder(caster) != String2OrderIdBJ("channel") )
        call TimerStart(short, 0.2, false, function TimerDone)    
endloop

will this just keep looping instantly over and over?
or will it wait for that timer to end?
10-13-2008, 04:09 PM#15
Anitarf
The timer starts a separate thread. The function will continue with it's execution the moment it starts the timer. Your example would instantly start a couple thousand timers and then hit the oplimit and terminate.