- Joined
- Jan 11, 2009
- Messages
- 3,414
I'm trying to make a system that forbids units to attack enemies that are not standing within 150 degrees infront of it.
For this i am using Vexorians "GetAngleDifference" system:
Combined with this trigger:
I was told by a friend that the "unit is issued an order" event also detects auto-attacks caused by aquisition range.
The problem is, obviously, that it doesn't work. I would be very thankful if someone helped me out on this.
EDIT: +2 rep to whoever solves this for me. :O
For this i am using Vexorians "GetAngleDifference" system:
JASS:
function GetAngleDifference takes unit u1, unit u2 returns real
local location l1 = GetUnitLoc(u1)
local location l2 = GetUnitLoc(u2)
local real a1 = AngleBetweenPoints(l1, l2)
local real a2 = GetUnitFacing(u1)
local real x
call RemoveLocation(l1)
call RemoveLocation(l2)
set l1 = null
set l2 = null
// The Modulo will get the co-terminal angle if the angle is less than -360 or greater than 360.
set a1=ModuloReal(a1,360)
set a2=ModuloReal(a2,360)
// makes sure angle 1 is the smaller angle. If it isn't it switches them.
if a1>a2 then
set x=a1
set a1=a2
set a2=x
endif
// Subtracts 360, to get the first negative co-terminal angle, this is then used in a comparison to check if the angle is greater than 180
set x=a2-360
if a2-a1 > a1-x then
// If it is, use the negative angle instead
set a2=x
endif
// Now, get the difference between the 2 angles.
set x=a1-a2
// If the difference is negative, make it positive and return it. If its positive, return it.
if (x<0) then
return -x
endif
return x
endfunction
Combined with this trigger:
-
Attack Angles
-
Events
-
Unit - A unit Is issued an order targeting an object
-
-
Conditions
-
(Issued order) Equal to (==) (Order(attack))
-
-
Actions
-
Custom script: local Parent P = Parents[GetUnitUserData(GetTriggerUnit())]
-
Custom script: if not(GetAngleDifference(P.controller, GetOrderTargetUnit()) >150.) then
-
Unit - Order (Triggering unit) to Stop
-
Custom script: endif
-
-
I was told by a friend that the "unit is issued an order" event also detects auto-attacks caused by aquisition range.
The problem is, obviously, that it doesn't work. I would be very thankful if someone helped me out on this.
EDIT: +2 rep to whoever solves this for me. :O
Last edited: