• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

melee ignore ranged attacks

Status
Not open for further replies.
Level 22
Joined
Jan 10, 2005
Messages
3,426
i have a map in my campaign where a castle will be attacked, but i want te melee attackers to run further if they r attacked by archers that stand on cliffs or some unreachable place, or else all attackers will try to move to the archer and it will get stuck when there r to many. is there a way to solve this?
thnx
 
Level 11
Joined
Feb 22, 2006
Messages
752
Events

Unit - A unit is attacked

Conditions

((Attacking unit) is A ranged attacker) Equal to True
((Triggering unit) is A melee attacker) Equal to True
((*whatever area includes your wall*) contains (Attacking unit)) Equal to True

Actions

Unit - Order (Triggering unit) to Move To ((Position of (Attacking unit)) offset by *how far you want the units to run* towards (Facing of (Attacking unit))

Basically, when a melee unit is attacked by a ranged unit that is located on your wall, this trigger orders the melee unit to run in the opposite direction of the ranged attacker for a specified distance. Now, if you want your melee units to run to a certain point on your map, you can change the Trigger Action so that it reads:

Unit - Order (Triggering unit) to Move To (Point(*X coordinate of point*, *Y coordinate of point*))
 
Level 22
Joined
Jan 10, 2005
Messages
3,426
no its harder then this, cuz i want them only to ignore the ranged attackers and not the nearby melee enemies. now it ignores every unit when its attacked by a ranged attacker. i thought maybe there was some thing u could uncheck in object editor or anything. i alrdy looked at gameplay constants but nothing helpful there
 
Level 5
Joined
Feb 16, 2006
Messages
151
Hmm, k, then try this:(sry, I don't know how to do it in GUI >>)
JASS:
...
local group g = CreateGroup()
local unit u = GetAttackedUnit()
local integer target_index = 0
local unit first
local unit array target
call GroupEnumUnitsInRange(g,500.00,GetUnitX(u),GetUnitY(u), null)     // to be tweaked, 500 is a proper range because you won't be that close to the archers
// Credits to PurplePoot for this cheat-function btw!! >_<
loop
    set first = FirstOfGroup(g)
    exitwhen (first == null)
    if (IsUnitEnemy(first)) and (not GetUnitName(first)=="Archer") and (not GetUnitName(first)=="Sniper") then  
    // Change the String "Archer" if they are called differently, and put more "ands" if you have more than only Archers and Snipers
        set target[target_index] = first
        set target_index = target_index + 1
    endif
    call GroupRemoveUnit(g,first)
endloop
if (target[0]==null) then
    call IssuePointOrder(u,"move",ATTACK_POINT)//attack_point is the attack point...it's a Location btw
else
    call IssueTargetOrder(u,"attack",target[GetRandomInt(0,target_index)])
endif
 
Level 4
Joined
Feb 1, 2006
Messages
107
Wards...

I do not if it's possible but try and make the archers classified as wards and see if you can diasble the ability to attack wards by melee attackers, alternatively you could make them invulnerable and let any units you need be able to attack invulnerable units.
 
Level 5
Joined
Feb 16, 2006
Messages
151
@PurplePoot! If you are reading this,
JASS:
call GroupEnumUnitsInRange
kinda does not work here, but GroupEnumUnitsInRangeOfLoc does...
I don't know what I did wrong there...
@Ramza, create a Trigger called
"Ignore Rangers",
and make it into custom text.
Then, delete everyting there and just paste the following:
(Don't forget to change the X / Y coordinates!)
JASS:
function Trig_Ignore_Rangers_Conditions takes nothing returns boolean
    return (IsUnitType(GetTriggerUnit(), UNIT_TYPE_MELEE_ATTACKER)) and (IsUnitType(GetAttacker(), UNIT_TYPE_RANGED_ATTACKER))
endfunction

function Trig_Ignore_Rangers_Actions takes nothing returns nothing
    local group g = CreateGroup()
    local unit u = GetTriggerUnit()
    local location target_loc = GetUnitLoc(u)
    local integer target_index = 0
    local unit first
    local unit array target
    call GroupEnumUnitsInRangeOfLoc(g,target_loc,500.00,null)
    loop
        set first = FirstOfGroup(g)
        exitwhen (first == null)
        if (IsUnitEnemy(first,GetTriggerPlayer())) and (not IsUnitType(first,UNIT_TYPE_RANGED_ATTACKER)) then
            set target[target_index] = first
            set target_index = target_index + 1
        endif
        call GroupRemoveUnit(g,first)
    endloop
    if (target[0]==null) then
        call IssuePointOrder(u,"move",1,2)
//those are X/Y coordinates, you have to change them to those you are using 
    else
        call IssueTargetOrder(u,"attack",target[GetRandomInt(0,target_index)])
    endif
endfunction

//===========================================================================
function InitTrig_Ignore_Rangers takes nothing returns nothing
    set gg_trg_Ignore_Rangers = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Ignore_Rangers, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Ignore_Rangers, Condition( function Trig_Ignore_Rangers_Conditions ) )
    call TriggerAddAction( gg_trg_Ignore_Rangers, function Trig_Ignore_Rangers_Actions )
endfunction
 
Level 24
Joined
Jun 26, 2006
Messages
3,406
Re: Wards...

gerbal_warfare said:
I do not if it's possible but try and make the archers classified as wards and see if you can diasble the ability to attack wards by melee attackers,

actually you can do that. make the archers targeted as wards. the field is Combat - Targeted as. it's the last field under Combat, right before the Editor fields.
you can change that and change the allowed targets for melee around and get it to work. maybe target them as ancients and for melee attackers have non-ancients under the targets allowed.
 
Status
Not open for further replies.
Top