• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Picking units in range of angle.

Status
Not open for further replies.
Level 11
Joined
Sep 12, 2008
Messages
657
Hey.. i was trying to check if there is a unit in range X of loc A in angle Y
so i did this:

JASS:
    set AttackingUnitOwner = GetOwningPlayer(attacker)
        call MoveLocation(l, GetUnitX(attacker) + 85 * Cos (GetUnitFacing(attacker) * bj_DEGTORAD), GetUnitY(attacker) + 85 * Cos (GetUnitFacing(attacker) * bj_DEGTORAD))
        call GroupEnumUnitsInRangeOfLoc(Group, l, 45, ber)

it sort of works.. but when the unit face is towards 280 degrees (down),
it kills himself.
btw, ber = Condition(function AttackingBer).

heres the boolexpr:
JASS:
    private function AttackingBer takes nothing returns boolean
    return GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.405 and IsUnitAlly(GetFilterUnit(), AttackingUnitOwner)
    endfunction

thanks in advance.
 
Level 11
Joined
Sep 12, 2008
Messages
657
hmm.. i cant notice much diffrence,
but it seems to not really work..

JASS:
    private function AttackingBer takes nothing returns boolean
    return GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.405 and IsUnitAlly(GetFilterUnit(), GetOwningPlayer(AttackingUnit)) and GetFilterUnit() != AttackingUnit
    endfunction
    
    function AttackTarget takes unit attacker, real damage, boolean IgnoreArmor returns nothing
    local real dmg
    local real armor
    local unit target
    
    local boolexpr ber = Condition(function AttackingBer)
    local group Group = CreateGroup()
    local location l = Location(0, 0)
    set AttackingUnit = attacker
        call SetUnitAnimation(attacker, AttackAnimationOrder)
        call MoveLocation(l, GetUnitX(attacker) + 85 * Cos (GetUnitFacing(attacker)) * bj_DEGTORAD, GetUnitY(attacker) + 85 * Sin (GetUnitFacing(attacker)) * bj_DEGTORAD)
        call GroupEnumUnitsInRangeOfLoc(Group, l, 45, ber)
        
        loop
        set target = FirstOfGroup(Group)
        exitwhen target == null
            set armor = GetUnitArmor(target)
                if IgnoreArmor == true then
                    set armor = GetUnitArmor(target)
                    set dmg = GetReducedDamage(damage, armor)
                else
                    set dmg = GetFullDamage(damage, armor)
                endif
                call UnitDamageTarget(attacker, target, dmg, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
        endloop
    endfunction

any idea? ;/

thanks anyways pharoh =]
 
Level 21
Joined
Mar 19, 2009
Messages
444
I just do not understand what you are trying to do, so my trigger should not do what you want.

But still, there is the way I would build your trigger. (Probably some mistakes, I do not get the editor at the moment)

Basically my trigger pick any units in range of the location wanted (a point depending on a distance and the facing of the attacker)

JASS:
library NoIdeaWhatItIs needs GroupUtils //to get the global group wc3.net for grouputils

    globals
        private constant real AOE = 500. //I guess it's wrong, but set it to your value
        private constant real DISTANCE = 85. //same
        private unit AttackingUnit//for the group  enum
        private real Damage//for the group  enum
        boolean IgnoreArmor//for the group  enum
        string AttackAnimationOrder // just because you use this somewhere, i replaced it there
    endglobals

    private function CheckUnits takes nothing returns boolean//the filter can works as any function; its fastest than your loop
        local unit whichUnit = GetFilterUnit() //since you use GetFilterUnit() a lot, a variable is better
        local real armor = GetUnitArmor(target)
        local real damage = 0.
              //your actions
              //GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.405  is useless, since the latest patchs, IsUnitType works
            if not(IsUnitType(whichUnit,UNIT_TYPE_DEAD)) and IsUnitAlly(AttackingUnit, GetOwningPlayer(whichUnit)) and whichUnit != AttackingUnit then
                if IgnoreArmor == true then
                    set damage = GetReducedDamage(damage, armor)
                else
                    set damage = GetFullDamage(damage, armor)
                endif
                call UnitDamageTarget(AttackingUnit,whichUnit,damage, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
            endif
            set whichUnit = null//do not forget to nullify the variable
            return true //and return to the next unit
    endfunction

    function AttackTarget takes unit attacker, real damage, boolean ignoreArmor returns nothing
        local real x = GetUnitX(attacker) + DISTANCE * Cos (GetUnitFacing(attacker)* bj_DEGTORAD)//your location coordonates
        local real y = GetUnitY(attacker) + DISTANCE * Sin (GetUnitFacing(attacker)* bj_DEGTORAD)//your location coordonates
            call SetUnitAnimation(attacker, AttackAnimationOrder)//blabla
            set AttackingUnit = attacker//for the group  enum
            set Damage = damage//for the group  enum
            set IgnoreArmor = ignoreArmor//for the group  enum
            call GroupEnumUnitsInRange(ENUM_GROUP,x,y,AOE,Filter(function CheckUnits)) //ENUM_GROUP is provided in group utils. No need to store the group like you did, it's an instant action
    endfunction

endlibrary
 
Level 11
Joined
Sep 12, 2008
Messages
657
well.. like custom missle.. just melle o.o
isnt so hard to guess..

JASS:
function AttackTarget takes unit attacker, real damage, boolean IgnoreArmor returns nothing

i cant check replies atm.. ill check them later..

edit: i checked replies..
i took jk2pach reply.. since he did go into so much trouble xD
but for some reason, it wont damage the units.
o.o
 
Last edited:
Status
Not open for further replies.
Top