• 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.

[Trigger] Backstab in GUI

Status
Not open for further replies.
Level 5
Joined
Sep 16, 2008
Messages
47
GUI
  • function Trig_Backstab_Conditions takes nothing returns boolean
    • if ( not ( GetSpellAbilityId() == 'A002' ) ) then
      • return false
    • endif
    • return true
  • endfunction
  • function Trig_Backstab_Func011C takes nothing returns boolean
    • if ( not ( IsUnitType(udg_Backstab_Caster, UNIT_TYPE_MELEE_ATTACKER) == true ) ) then
      • return false
    • endif
    • if ( not ( RAbsBJ(( ModuloReal(AngleBetweenPoints(udg_Backstab_CasterPositon, udg_Backstab_TargetPosition), 360.00) - ModuloReal(GetUnitFacing(udg_Backstab_Target), 360.00) )) < udg_Backstab_MaxA ) ) then
      • return false
    • endif
    • if ( not ( RAbsBJ(( ModuloReal(AngleBetweenPoints(udg_Backstab_CasterPositon, udg_Backstab_TargetPosition), 360.00) - ModuloReal(GetUnitFacing(udg_Backstab_Target), 360.00) )) > udg_Backstab_MinA ) ) then
      • return false
    • endif
    • return true
  • endfunction
  • function Trig_Backstab_Actions takes nothing returns nothing
    • set udg_Backstab_Caster = GetTriggerUnit()
    • set udg_Backstab_Target = GetSpellTargetUnit()
    • set udg_Backstab_MaxA = 240.00
    • set udg_Backstab_MinA = 120.00
    • set udg_Backstab_CasterPositon = GetUnitLoc(udg_Backstab_Caster)
    • set udg_Backstab_TargetPosition = GetUnitLoc(udg_Backstab_Target)
    • set udg_Backstab_Ability = 'A002'
    • set udg_Backstab_AbilityLevel = GetUnitAbilityLevelSwapped(udg_Backstab_Ability, udg_Backstab_Caster)
    • set udg_Backstab_Damage = ( 100 * udg_Backstab_AbilityLevel )
    • set udg_Backstab_Angle = AngleBetweenPoints(udg_Backstab_CasterPositon, udg_Backstab_TargetPosition)
    • if ( Trig_Backstab_Func011C() ) then
      • call DisplayTimedTextToForce( GetPlayersAll(), 0.01, "TRIGSTR_083" )
      • call SetUnitAnimationByIndex (udg_Backstab_Caster, 8)
      • call UnitDamageTargetBJ( udg_Backstab_Caster, udg_Backstab_Target, I2R(udg_Backstab_Damage), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
    • else
    • endif
    • call RemoveLocation (udg_Backstab_CasterPositon)
    • call RemoveLocation (udg_Backstab_TargetPosition)
  • endfunction
  • //===========================================================================
  • function InitTrig_Backstab takes nothing returns nothing
    • set gg_trg_Backstab = CreateTrigger( )
    • call TriggerRegisterAnyUnitEventBJ( gg_trg_Ba
Jass
JASS:
function Trig_Backstab_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A002' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Backstab_Func011C takes nothing returns boolean
    if ( not ( IsUnitType(udg_Backstab_Caster, UNIT_TYPE_MELEE_ATTACKER) == true ) ) then
        return false
    endif
    if ( not ( RAbsBJ(( ModuloReal(AngleBetweenPoints(udg_Backstab_CasterPositon, udg_Backstab_TargetPosition), 360.00) - ModuloReal(GetUnitFacing(udg_Backstab_Target), 360.00) )) < udg_Backstab_MaxA ) ) then
        return false
    endif
    if ( not ( RAbsBJ(( ModuloReal(AngleBetweenPoints(udg_Backstab_CasterPositon, udg_Backstab_TargetPosition), 360.00) - ModuloReal(GetUnitFacing(udg_Backstab_Target), 360.00) )) > udg_Backstab_MinA ) ) then
        return false
    endif
    return true
endfunction

function Trig_Backstab_Actions takes nothing returns nothing
    set udg_Backstab_Caster = GetTriggerUnit()
    set udg_Backstab_Target = GetSpellTargetUnit()
    set udg_Backstab_MaxA = 240.00
    set udg_Backstab_MinA = 120.00
    set udg_Backstab_CasterPositon = GetUnitLoc(udg_Backstab_Caster)
    set udg_Backstab_TargetPosition = GetUnitLoc(udg_Backstab_Target)
    set udg_Backstab_Ability = 'A002'
    set udg_Backstab_AbilityLevel = GetUnitAbilityLevelSwapped(udg_Backstab_Ability, udg_Backstab_Caster)
    set udg_Backstab_Damage = ( 100 * udg_Backstab_AbilityLevel )
    set udg_Backstab_Angle = AngleBetweenPoints(udg_Backstab_CasterPositon, udg_Backstab_TargetPosition)
    if ( Trig_Backstab_Func011C() ) then
        call DisplayTimedTextToForce( GetPlayersAll(), 0.01, "TRIGSTR_083" )
        call SetUnitAnimationByIndex (udg_Backstab_Caster, 8)
        call UnitDamageTargetBJ( udg_Backstab_Caster, udg_Backstab_Target, I2R(udg_Backstab_Damage), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
    else
    endif
    call RemoveLocation (udg_Backstab_CasterPositon)
    call RemoveLocation (udg_Backstab_TargetPosition)
endfunction

//===========================================================================
function InitTrig_Backstab takes nothing returns nothing
    set gg_trg_Backstab = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Ba

I tried to create backstab spell in GUI.
Look at triggers. When i cast this spelll it isn't backstab. It's Frontstab. How to fix it?
 
Last edited:
Level 16
Joined
Jun 24, 2009
Messages
1,409
lol wtf?
this could be better
  • Backstab
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Level of Backstab for (Attacking unit)) Greater than 0
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Attacked unit) belongs to an enemy of (Owner of (Attacking unit))) Equal to True
        • Then - Actions
          • Set Caster[1] = (Attacking unit)
          • Set Target[1] = (Attacked unit)
          • Set Point[1] = (Position of Caster[1])
          • Set Point[2] = (Position of Target[1])
          • Set Real[1] = (Angle from Point[1] to Point[2])
          • Set Real[2] = (Facing of (Attacked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • Real[1] Greater than or equal to (Real[2] - 45.00)
                  • Real[1] Less than or equal to (Real[2] + 45.00)
            • Then - Actions
              • Special Effect - Create a special effect attached to the overhead of Target[1] using Abilities\Spells\Other\Stampede\StampedeMissileDeath.mdl
              • Special Effect - Destroy (Last created special effect)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Caster[1] is an illusion) Equal to True
                • Then - Actions
                  • Unit - Cause Caster[1] to damage Target[1], dealing (0.33 x ((Real((Level of Backstab for Caster[1]))) x (0.50 x (Real((Agility of Caster[1] (Include bonuses))))))) damage of attack type Hero and damage type Normal
                • Else - Actions
                  • Unit - Cause Caster[1] to damage Target[1], dealing ((Real((Level of Backstab for Caster[1]))) x (0.50 x (Real((Agility of Caster[1] (Include bonuses)))))) damage of attack type Hero and damage type Normal
            • Else - Actions
          • Custom script: call RemoveLocation( udg_Point[1] )
          • Custom script: call RemoveLocation( udg_Point[2] )
        • Else - Actions
a simple backstab that deals 0.5x level of backstab for attacker, illusions deal 33% dmg
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
^Does that actually wowrk correctly? Angle from x to y ranges from -180 to 180, facing of unit from 0 to 360.

Here's an alternative that does work:

  • Attack GUI Copy
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • Ability being cast equal to...
    • Actions
      • -------- -------------------------------------------------- --------
      • -------- Set unit variables --------
      • -------- -------------------------------------------------- --------
      • Set u1 = (Triggering unit)
      • Set u2 = (Target unit of ability being cast)
      • -------- -------------------------------------------------- --------
      • -------- 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 caster facing --------
      • -------- -------------------------------------------------- --------
      • Set r2 = (Facing of u2)
      • -------- -------------------------------------------------- --------
      • -------- Get angle difference --------
      • -------- -------------------------------------------------- --------
      • Set r3 = (Acos((Cos((r1 - r2)))))
      • -------- -------------------------------------------------- --------
      • -------- Clear leaks --------
      • -------- -------------------------------------------------- --------
      • Custom script: call RemoveLocation(udg_p1)
      • Custom script: call RemoveLocation(udg_p2)
      • -------- -------------------------------------------------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • r3 Less than 90.00 // adjust this value to alter the "width" of backstab
        • Then - Actions
          • Game - Display to Player Group - Player 1 (Red) the text: Backstab!
        • Else - Actions
 
Level 11
Joined
May 31, 2008
Messages
698
uhh, why would you do Arccos of cos? lol the arccos and cos just cancel each other out...
Just do a1 = facing of caster, a2 = facing of target
if a2 > a1 - 45 and a2 < a1 + 45 then backstab. This would backstab if the target was facing away from the caster within a 45 degree margin.
kinda like this:

\.................../
..\.............../
....\.........../
......\......./
........\.../
......target
......caster

the slashes show the area that the target could be facing for the backstab to work. Although that picture shows about a 20 degree margin on each side
 
Status
Not open for further replies.
Top