1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Lead your forces to battle in the 15th Techtree Contest. The call is yours, commander!
    Dismiss Notice
  4. The reforging of the races is complete. Come see the 14th Techtree Contest Results.
    Dismiss Notice
  5. It's time to choose your horse in the race - the 32nd Modeling Contest Poll is up!
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Need help inverting Backstab Trigger

Discussion in 'Triggers & Scripts' started by bruunk, May 24, 2020.

  1. bruunk

    bruunk

    Joined:
    Mar 17, 2016
    Messages:
    69
    Resources:
    0
    Resources:
    0
    Hi, I want to make a skill like Rikis Backstab from dota 2, but instead of the back it would do the effect if the attacking unit is striking from the front.

    What I know so far is to have a damage detection trigger, condition "if unit has buff", then I have this

    • Then - Actions
      • Set VariableSet Backstab_Point[3] = (Position of UnitPlayerCaster[14])
      • Set VariableSet Backstab_Point[4] = (Position of AbilTargetUnit[3])
      • Set VariableSet Backstab_Angle = (Angle from Backstab_Point[3] to Backstab_Point[4])
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • And - All (Conditions) are true
                • Conditions
                  • (Facing of UnitPlayerCaster[14]) Greater than or equal to ((Facing of AbilTargetUnit[3]) - 120.00)
                  • (Facing of UnitPlayerCaster[14]) Less than or equal to ((Facing of AbilTargetUnit[3]) + 120.00)
              • And - All (Conditions) are true
                • Conditions
                  • Backstab_Angle Greater than or equal to ((Facing of AbilTargetUnit[3]) - 120.00)
                  • Backstab_Angle Less than or equal to ((Facing of AbilTargetUnit[3]) + 120.00)
        • Then - Actions
          • Game - Display to (All players) the text: step 3 - damage
          • Unit - Cause UnitPlayerCaster[14] to damage AbilTargetUnit[3], dealing 5 damage of attack type Hero and damage type Normal
        • Else - Actions


    I've tried rotating and shifting the numbers that calculate the locations but I can't seem to make it work from the front, only varying degrees from the back and that's not what this hero will be about. I know that I must be missing something and I'm hoping someone can identify the issue, because I've ran out of ideas.

    Thanks!
     
  2. BloodSoul

    BloodSoul

    Joined:
    May 10, 2009
    Messages:
    781
    Resources:
    2
    Spells:
    2
    Resources:
    2
    Here's a function that I have stored on my PC -- I'm not sure who made it anymore, sorry (Maker or Killcide, maybe?). Anyway... declare the following function in your map header and use it like this:
    Code (vJASS):

    function IsUnitBehindTarget takes unit u, unit t, real tolerance returns boolean
        // Acos( Cos( (angle from U to T) - T facing angle )) <= Tolerance
        return (Acos(Cos(Atan2(GetUnitY(t) - GetUnitY(u), GetUnitX(t) - GetUnitX(u)) - GetUnitFacing(t) * bj_DEGTORAD)) <= tolerance * bj_DEGTORAD)
    endfunction
     


    Example:
    • Initialization
      • Events
        • Map initialization
      • Conditions
      • Actions
        • Set source = Footman 0001 <gen>
        • Set target = Peasant 0000 <gen>

    • Events
      • Time - Every 0.15 seconds of game time
    • Conditions
    • Actions
      • Cinematic - Clear the screen of text messages for (All players)
      • Custom script: if not IsUnitBehindTarget(udg_source, udg_target, 115) then
      • Game - Display to (All players) the text: Source is in front of target
      • Custom script: endif


    Do note that "Tolerance" (the third function parameter) ranges from 0 to 180 degrees.
     

    Attached Files: