scope FriendlyAttackSystem initializer init
private function Conditions takes nothing returns boolean
local unit a = GetAttacker()
local unit u = GetTriggerUnit()
/*
* TriggerPlayer is the owner of the attacked unit.
*/
if IsUnitAlly(a, GetTriggerPlayer()) then
/*
* Is current life > 40%?
*/
if ((GetWidgetLife(u)/GetUnitState(u, UNIT_STATE_MAX_LIFE)) > 0.4) then
/*
* Not much of a difference to "stop".
* - If the previous order was a no target order, it will keep it, for instance "holdposition"
* - easy to detect/filter because a unit can't get this order, except via trigger.
*
* Use whatever you like.
*/
//call IssueImmediateOrder(a, "stop")
call IssueImmediateOrderById(a, 851973)
endif
endif
set a = null
set u = null
return false
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ATTACKED)
call TriggerAddCondition(t, Condition(function Conditions))
//set t = null
endfunction
endscope
- When a unit is attacked.
- If the attacked's owner is the same as the attacker's owner and the health of the attacked is more or equal than 40%
- order stop to the attacker
That should work, but requires JPNG because of scope and the private keyword.
JASS:scope FriendlyAttackSystem initializer init private function Conditions takes nothing returns boolean local unit a = GetAttacker() local unit u = GetTriggerUnit() /* * TriggerPlayer is the owner of the attacked unit. */ if IsUnitAlly(a, GetTriggerPlayer()) then /* * Is current life > 40%? */ if ((GetWidgetLife(u)/GetUnitState(u, UNIT_STATE_MAX_LIFE)) > 0.4) then /* * Not much of a difference to "stop". * - If the previous order was a no target order, it will keep it, for instance "holdposition" * - easy to detect/filter because a unit can't get this order, except via trigger. * * Use whatever you like. */ //call IssueImmediateOrder(a, "stop") call IssueImmediateOrderById(a, 851973) endif endif set a = null set u = null return false endfunction private function init takes nothing returns nothing local trigger t = CreateTrigger() call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ATTACKED) call TriggerAddCondition(t, Condition(function Conditions)) //set t = null endfunction endscope
You should stop wandering and get on your computer!
Use a simple stop command when your hero begins an attack on a disallowed target.
You can use this. It is excacly the same as the vJass code I've posted.
This one is also the same, I guess it looks the most familiar to you.
- Untitled Trigger 001
- Events
- Unit - A unit Is attacked
- Conditions
- Actions
- Custom script: local unit a = GetAttacker()
- Custom script: local unit u = GetTriggerUnit()
- Custom script: if IsUnitAlly(a, GetTriggerPlayer()) then
- Custom script: if ((GetWidgetLife(u)/GetUnitState(u, UNIT_STATE_MAX_LIFE)) > 0.4) then
- Custom script: call IssueImmediateOrderById(a, 851973)
- Custom script: endif
- Custom script: endif
- Custom script: set a = null
- Custom script: set u = null
Note that it is slower in execution then the upper two are.
Because:
1. The way the condition is checked in GUI
2. The way the if then else is checked in GUI
3. The precent life calculation in GUI
4. The unit order in GUI
- Untitled Trigger 001
- Events
- Unit - A unit Is attacked
- Conditions
- ((Attacking unit) belongs to an ally of (Triggering player)) Equal to True
- Actions
- Set Attacker = (Attacking unit)
- Set Attacked = (Triggering unit)
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- (Percentage life of Attacked) Greater than or equal to 40.00
- Then - Actions
- Unit - Order Attacker to Stop
- Else - Actions