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

[JASS] Help PLEASE

Status
Not open for further replies.
Level 19
Joined
Aug 24, 2007
Messages
2,888
Jass HELP please

JASS:
function ablecheck1 takes unit attacker2 returns boolean
    if ( not ( IsUnitEnemy(attacker2, GetOwningPlayer(GetEnumUnit())) == true ) ) then
        return false
    endif
    if ( not ( IsUnitAliveBJ(GetEnumUnit()) == true ) ) then
        return false
    endif
    if ( not ( IsUnitType(GetEnumUnit(), UNIT_TYPE_MAGIC_IMMUNE) == false ) ) then
        return false
    endif
    if ( not ( IsUnitType(GetEnumUnit(), UNIT_TYPE_STRUCTURE) == false ) ) then
        return false
    endif
    return true
endfunction

function damagefunc1 takes unit attacker1,real damage1 returns nothing
    if ( ablecheck1(attacker1) ) then
        call UnitDamageTargetBJ( attacker1, GetEnumUnit(), damage1, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
    else
    endif
endfunction

function damagearea takes unit attacker,location point,real area,real damage returns nothing
    call ForGroupBJ( GetUnitsInRectAll(RectFromCenterSizeBJ(point, area, area)), function damagefunc1(attacker,damage) )
endfunction

What should I do for get this working
Putted into map header and I recive error
 
Level 15
Joined
Feb 15, 2006
Messages
851
Level 40
Joined
Dec 14, 2005
Messages
10,532
You can't add parameters to ForGroup's callback.

Anyways, your code could be a lot cleaner;

JASS:
function DamageArea takes unit attacker, location point, real area, real damage returns nothing
    local unit u
    local group g = CreateGroup()
    local player p = GetOwningPlayer(attacker)
    call GroupEnumUnitsInRange(g,GetLocationX(point),GetLocationY(point),area,Filter(null))
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        if IsUnitEnemy(u,p) and GetWidgetLife(u) > 0 and not (IsUnitType(u,UNIT_TYPE_MAGIC_IMMUNE) or IsUnitType(u,UNIT_TYPE_STRUCTURE)) then
            call UnitDamageTarget(attacker,u,damage,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,null)
        endif
        call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    set g = null
    set p = null
endfunction


Double thread merged.
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
so thanks if this works
thanks for trying if doesnt :D
well the thing I posted just GUI converted into custom text
EDIT:
Hmm I learned
I can use if like set
like set u = mother
if u = mother
and very good so we select all units in group then make actions with first unit in group then remove it from group so 2nd unit becomes first unit
Thanks man this is the best tutorial for a Jass learner
Main Lessons: Dont use functions for conditions
And dont forget to remove leaks :D
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
JASS:
function damagearea takes unit attacker, location point, real area, real damage returns nothing
    local group g = CreateGroup()
    local rect r = Rect(GetLocationX(point)-area*0.5,GetLocationY(point)-area*0.5,GetLocationX(point)+area*0.5,GetLocationY(point)+area*0.5)
    local unit u
    call GroupEnumUnitsInRect(g,r,null)
    call RemoveRect(r)
    set r = null
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        call GroupRemoveUnit(g,u)
        if IsUnitEnemy(attacker,GetOwningPlayer(u)) == true and GetUnitState(u,UNIT_STATE_LIFE) > 0 and IsUnitType(u,UNIT_TYPE_MAGIC_IMMUNE) == false and IsUnitType(u,UNIT_TYPE_STRUCTURE) == false then
            call UnitDamageTarget(attacker,u,damage,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
        endif
        set u = null //This might not be needed so feel free to try and remove it but I just like to be sure that an infinate loop does not happen.
    endloop
    call DestroyGroup(g)
    set attacker = null
    set point = null
    set g = null
endfunction

Just use this code and be happy.

And purple, yours leaks and also does not function how he wants it to, he wants it to pick units in a square area and not a circular area or he would not have used rects. You forgot to null "attacker" and "point".
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
JASS:
function DamageArea takes unit attacker, location point, real area, real damage returns nothing
    local unit u
    local group g = CreateGroup()
    local player p = GetOwningPlayer(attacker)
    call GroupEnumUnitsInRange(g,GetLocationX(point),GetLocationY(point),area,Filter(null))
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        if IsUnitEnemy(u,p) and GetWidgetLife(u) > 0 and not (IsUnitType(u,UNIT_TYPE_MAGIC_IMMUNE) or IsUnitType(u,UNIT_TYPE_STRUCTURE)) then
            call UnitDamageTarget(attacker,u,damage,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,null)
        endif
        call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    set attacker = null
    set point = null
    set g = null
    set p = null
endfunction

I do not see why he made a local player still, since he only referenced it once.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Mine doesn't leak, super, you don't need to null parameters.

Also, yeah, I wasn't paying attention really when I made that local player. (Had like 2 mins before class)

JASS:
function DamageArea takes unit attacker, location point, real area, real damage returns nothing
    local unit u
    local group g = CreateGroup()
    call GroupEnumUnitsInRange(g,GetLocationX(point),GetLocationY(point),area,Filter(null))
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        if IsUnitEnemy(u,GetOwningPlayer(attacker)) and GetWidgetLife(u) > 0 and not (IsUnitType(u,UNIT_TYPE_MAGIC_IMMUNE) or IsUnitType(u,UNIT_TYPE_STRUCTURE)) then
            call UnitDamageTarget(attacker,u,damage,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,null)
        endif
        call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    set g = null
endfunction
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Well they don't, (according to a good deal of people) and before people knew how slow locals were they were often used to circumvent things like the timer nulling bug (which I've personally never seen, and Vexorian apparently said he's only seen it a few times) without leaking.

I'll have a shot at testing this tomorrow.
 
Status
Not open for further replies.
Top