Tom_Kazansky
--- wraith it ! ---
- Reaction score
- 157
I don't know how should I name this snippet, so if anyone can rename it, please tell me.
----
ok, now, about my snippet.
There is two units, unit U and unit S, this snippet allows you to check if U is in front of S or U is behind S or U is at left side of S or U is at right side of S.
Here is my code:
Implement
- For GUI users:
+ Copy and Paste these functions to the map header. (In the Trigger Editor (F4), left click on your map's name)
+ Create a boolean variable, ex: TempCheck, and use custom script actions:
and then check the udg_TempCheck variable
- For Jass users:
+ Copy and Paste these functions to the map header, or to your library (if you use NewGen)
+ You can directly call function UnitPosChecker (it returns integer) or you can call function IsUnitInfront, IsUnitBehind, IsUnitAtLeftSide, IsUnitAtRightSide.
Demo
I have made a spell called Kris Slice:
I have attached the demo map below.
-----
Please comment :thup:
----
ok, now, about my snippet.
There is two units, unit U and unit S, this snippet allows you to check if U is in front of S or U is behind S or U is at left side of S or U is at right side of S.
Here is my code:
JASS:
function UnitPosChecker takes unit check, unit source returns integer
local real face = GetUnitFacing(source)
local real angle = bj_RADTODEG * Atan2(GetUnitY(check) - GetUnitY(source), GetUnitX(check) - GetUnitX(source))
//I think it is easier if we check when source face 0 degree,
// so the angle between source and check should be decreased by facing angle of source
if angle < 0 then //only check with positive angle
set angle = angle + 360. - face
else
set angle = angle - face
endif
if angle < 0 then //only check with positive angle
set angle = angle + 360.
endif
if ( angle <= 30. and angle >= 0. ) or ( angle <= 360. and angle >= 330. ) then
return 1 //check is in front of source
endif
if angle > 30. and angle < 135. then
return 2 //check is at left side of source
endif
if angle > 225. and angle < 330. then
return 3 //check is at right side of source
endif
//angle >= 135 and angle <= 225
return 4 //check is behind source
endfunction
function IsUnitInfront takes unit check, unit source returns boolean
return (UnitPosChecker( check , source ) == 1)
endfunction
function IsUnitAtLeftSide takes unit check, unit source returns boolean
return (UnitPosChecker( check , source ) == 2)
endfunction
function IsUnitAtRightSide takes unit check, unit source returns boolean
return (UnitPosChecker( check , source ) == 3)
endfunction
function IsUnitBehind takes unit check, unit source returns boolean
return (UnitPosChecker( check , source ) == 4)
endfunction
Implement
- For GUI users:
+ Copy and Paste these functions to the map header. (In the Trigger Editor (F4), left click on your map's name)
+ Create a boolean variable, ex: TempCheck, and use custom script actions:
Code:
Custom Script: set udg_TempCheck = IsUnitInfront( udg_<unit U variable name>, udg_<unit S variable name> )
//or
Custom Script: set udg_TempCheck = IsUnitBehind( udg_<unit U variable name>, udg_<unit S variable name> )
//or
Custom Script: set udg_TempCheck = IsUnitAtLeftSide( udg_<unit U variable name>, udg_<unit S variable name> )
//or
Custom Script: set udg_TempCheck = IsUnitAtRightSide( udg_<unit U variable name>, udg_<unit S variable name> )
and then check the udg_TempCheck variable
- For Jass users:
+ Copy and Paste these functions to the map header, or to your library (if you use NewGen)
+ You can directly call function UnitPosChecker (it returns integer) or you can call function IsUnitInfront, IsUnitBehind, IsUnitAtLeftSide, IsUnitAtRightSide.
Demo
I have made a spell called Kris Slice:
JASS:
A strike that deals 100 + 1.5 times Agility of the Hero to a single target.
If this unit is struck from sides, it will suffer more damage.
If this unit is struck from behide, it will suffer more damage and be knocked back.
[Level 1] Extra damage: 100
[Level 2] Extra damage: 125
[Level 3] Extra damage: 150
[Level 4] Extra damage: 175
Code:
Kris Slice
Events
Unit - A unit Starts the effect of an ability
Conditions
(Ability being cast) Equal to Kris Slice
Actions
Set TempUnit = (Triggering unit)
Set TempInt = (Level of Kris Slice for TempUnit)
Set TempUnit2 = (Target unit of ability being cast)
Set TempReal = (100.00 + (1.50 x (Real((Agility of TempUnit (Include bonuses))))))
[B]Custom script: set udg_TempCheck = IsUnitBehind( udg_TempUnit , udg_TempUnit2 )[/B]
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
TempCheck Equal to True
Then - Actions
-------- plus the damage --------
Set TempReal = (TempReal + (75.00 + (25.00 x (Real(TempInt)))))
-------- slide (knockback) --------
Set TempLoc = (Position of TempUnit)
Set TempLoc2 = (Position of TempUnit2)
Set SlideIndex = (SlideIndex + 1)
Set SlideUnit[SlideIndex] = TempUnit2
Set SlideAngle[SlideIndex] = (Angle from TempLoc to TempLoc2)
Set SlideTick[SlideIndex] = 20
Set SlideDistance[SlideIndex] = 10.00
Custom script: call RemoveLocation( udg_TempLoc )
Custom script: call RemoveLocation( udg_TempLoc2 )
Else - Actions
[B]Custom script: set udg_TempCheck = ( IsUnitAtLeftSide( udg_TempUnit , udg_TempUnit2 ) or IsUnitAtRightSide( udg_TempUnit , udg_TempUnit2 ) )[/B]
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
TempCheck Equal to True
Then - Actions
-------- plus the damage --------
Set TempReal = (TempReal + (75.00 + (75.00 x (Real(TempInt)))))
Else - Actions
-------- Visual and Deals damage --------
Floating Text - Create floating text that reads ((String((Integer(TempReal)))) + !) above TempUnit with Z offset 0.00, using font size 10.00, color (100.00%, 0.00%, 0.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 3.00 seconds
Floating Text - Change the fading age of (Last created floating text) to 1.00 seconds
Unit - Cause TempUnit to damage TempUnit2, dealing TempReal damage of attack type Chaos and damage type Normal
I have attached the demo map below.
-----
Please comment :thup: