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

How to detect backstab?

Status
Not open for further replies.
  • Backstab
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Set Point = (Position of (Attacking unit))
      • Set angle[1] = (Facing of (Attacked unit))
      • Set Point2 = (Position of (Attacked unit))
      • Set angle[2] = (Angle from Point to Point2)
      • Set angle[2] = ((angle[2] - angle[1]) + 180.00)
      • If (angle[2] Greater than or equal to 360.00) then do (Set angle[2] = (angle[2] - 360.00)) else do (Do nothing)
      • If (angle[2] Less than 0.00) then do (Set angle[2] = (angle[2] + 360.00)) else do (Do nothing)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • angle[2] Greater than or equal to 90.00
          • angle[2] Less than or equal to 270.00
        • Then - Actions
          • -------- Target is facing away from attacker --------
          • Unit - Cause (Attacking unit) to damage (Attacked unit), dealing (Damage taken) damage of attack type Normal and damage type Normal
          • Special Effect - Create a special effect attached to the chest of (Attacked unit) using Objects\Spawnmodels\Human\HumanLargeDeathExplode\HumanLargeDeathExplode.mdl
          • Special Effect - Destroy (Last created special effect)
        • Else - Actions
          • -------- Target is not facing away from attacker --------
      • Custom script: call RemoveLocation(udg_Point)
      • Custom script: call RemoveLocation(udg_Point2)
 
Last edited:
That's a hard one..
hmmmm....

I tried making something like that to detect if 2 units are facing each other, but to no avail.. i failed...

I'll try again :D

--------
EDIT:
Credits to Maker for the concept:
I think this should work.
If not, the problem is with the values in the comparison

JASS:
function CheckIfFacing takes unit u,unit u2 returns boolean
    local unit u = u
    local unit u2 = u2
    local real uX = GetUnitX(u)
    local real uY = GetUnitY(u)
    local real u2X = GetUnitX(u2)
    local real u2Y = GetUnitY(u2)
    local real r = Atan2(u2Y - uY, u2X - uX)
    local real r2 = GetUnitFacing(u) * bj_DEGTORAD
    local real r3
    
    set r3 = Acos(Cos(r) * Cos(r2) + Sin(r) * Sin(r2)) * bj_RADTODEG
    
    if r3 <= 185 and r3 >= 175 then
        return true
    endif
    return false
endfunction
 
Last edited:
Level 37
Joined
Aug 14, 2006
Messages
7,601
Well it's actually a channeling spell. Of course I'll add some extra twists to it, but I want the basic idea. When player 1 units look at the boss they take damage per second.

You don't need to create other things, I'll of course do that myself. Just the idea, just the idea. Thanks for your effort.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
@Mathgeridon
set r3 = Acos(Cos(r) * Cos(r2) + Sin(r) * Sin(r2)) * bj_RADTODEG
->
set r3 = Cos(r-r2)
and remove *bj_DEGTORAD from the facing.

If r3 > 0 then
backstab!
endif

Aero, you can change the event to periodic and use this:

  • Attack GUI Copy
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
    • Actions
      • -------- -------------------------------------------------- --------
      • -------- Set unit variables --------
      • -------- -------------------------------------------------- --------
      • Set u1 = (Triggering unit)
      • Set u2 = (Target unit of issued order)
      • -------- -------------------------------------------------- --------
      • -------- Set location variables --------
      • -------- -------------------------------------------------- --------
      • Set p1 = (Position of u1)
      • Set p2 = (Position of u2)
      • -------- -------------------------------------------------- --------
      • -------- Get angle from "caster" to target --------
      • -------- -------------------------------------------------- --------
      • Set r1 = (Angle from p1 to p2)
      • -------- -------------------------------------------------- --------
      • -------- Get target facing --------
      • -------- -------------------------------------------------- --------
      • Set r2 = (Facing of u2)
      • -------- -------------------------------------------------- --------
      • -------- Get angle difference --------
      • -------- -------------------------------------------------- --------
      • Set r3 = (Cos((r1 - r2)))
      • -------- -------------------------------------------------- --------
      • -------- Clear leaks --------
      • -------- -------------------------------------------------- --------
      • Custom script: call RemoveLocation(udg_p1)
      • Custom script: call RemoveLocation(udg_p2)
      • -------- -------------------------------------------------- --------
      • Game - Display to Player Group - Player 1 (Red) the text: (String(r3))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • r3 Greater than 0.00
        • Then - Actions
          • Game - Display to Player Group - Player 1 (Red) the text: Backstab!
        • Else - Actions
You don't have to set r1,r2,r3, just use Cos((angle from p1 to p2) - facing of u2)) as the condition.
  • Attack GUI Copy Copy
    • Events
      • Time - Every 0.25 seconds of game time
    • Conditions
    • Actions
      • Set p1 = (Position of u1)
      • Set p2 = (Position of u2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Cos(((Angle from p1 to p2) - (Facing of u2)))) Greater than 0.00
        • Then - Actions
          • Game - Display to Player Group - Player 1 (Red) the text: Paladin is backstab...
        • Else - Actions
          • Game - Display to Player Group - Player 1 (Red) the text: Paladin is NOT back...
      • Custom script: call RemoveLocation(udg_p1)
      • Custom script: call RemoveLocation(udg_p2)
 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,240
Press ESC to make the Blood Mage channel.

  • Start channel
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set u1 = Blood Mage 0000 <gen>
      • Custom script: call IssueImmediateOrder(udg_u1 , "channel")
      • Trigger - Turn on Channel <gen>
  • Channel
    • Events
      • Time - Every 0.25 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (String((Current order of u1))) Equal to channel
        • Then - Actions
          • Set p1 = (Position of u1)
          • Set r1 = (Facing of u1)
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units owned by Player 1 (Red)) and do (Actions)
            • Loop - Actions
              • Set u2 = (Picked unit)
              • Set p2 = (Position of u2)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Cos(((Angle from p1 to p2) - r1))) Greater than 0.00
                • Then - Actions
                  • Floating Text - Create floating text that reads I'm, hurting! above u2 with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
                • Else - Actions
                  • Floating Text - Create floating text that reads Jolly gosh, I'm fin... above u2 with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
              • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
              • Floating Text - Change (Last created floating text): Disable permanence
              • Floating Text - Change the lifespan of (Last created floating text) to 1.00 seconds
              • Floating Text - Change the fading age of (Last created floating text) to 0.75 seconds
              • Custom script: call RemoveLocation(udg_p2)
          • Custom script: call RemoveLocation(udg_p1)
        • Else - Actions
          • Trigger - Turn off (This trigger)
 

Attachments

  • Angle_Difference.w3x
    19.1 KB · Views: 72
Level 37
Joined
Mar 6, 2006
Messages
9,240
  • (Cos(((Angle from p2 to p1) - (Facing of u2)))) Greater than 0.00
  • ((Cos((Angle from p2 to p1))) - (Facing of u2)) Greater than 0.00
The brackets. First one is correct, second one is not. First calculate angle from p2 to p1, then reduce facing of u2 from that. Then take cos of the whole thing.

In the editor:
New action -> set variable
Select cos function.
Select arithmetic inside the cos.
For the first part, select angle between points.
For the second part choose facing of unit.
 
Status
Not open for further replies.
Top