//TESH.scrollpos=0
//TESH.alwaysfold=0
Name | Type | is_array | initial_value |
GP_Back | integer | Yes | |
GP_BackToBase | integer | Yes | |
GP_Distance | real | No | |
GP_Engage | boolean | Yes | |
GP_EngageWhileTraveling | boolean | No | |
GP_Fac | real | Yes | |
GP_FacingAngle | real | No | |
GP_GuardingGroup | group | No | |
GP_GuardingUnit | unit | No | |
GP_GuardWhere | location | No | |
GP_Index | integer | No | |
GP_MinimumDelayBackToBase | integer | No | |
GP_MinimumPerimeter | real | No | |
GP_Per | real | Yes | |
GP_Perimeter | real | No | |
GP_TempGroup | group | No | |
GP_U | unit | Yes | |
GP_UI | integer | No | |
GP_X | real | Yes | |
GP_Y | real | Yes | |
UDex | integer | No | |
UDexGen | integer | No | |
UDexNext | integer | Yes | |
UDexPrev | integer | Yes | |
UDexRecycle | integer | No | |
UDexUnits | unit | Yes | |
UDexWasted | integer | No | |
UnitIndexerEnabled | boolean | No | |
UnitIndexEvent | real | No | |
UNRELATED_VARIABLE | location | Yes | |
UNRELATED_VARIABLE_UNIT | unit | No |
//TESH.scrollpos=0
//TESH.alwaysfold=0
[tabs]
[tab=Foreword]
This system allows a unit to guard a certain place or point and attacks any entruders that goes within the guarded perimeter.
[/tab]
[tab=Installation]
- Be sure to check the 'Automatically create unknown variables while pasting trigger data' via File>>>Preferences>>>General tab
- Copy the Unit Indexer to your map (or any Unit Indexer will do)
- Copy the Guard Post folder to your map, be sure to check the ''
[/tab]
[tab=Instructions]
[B]First, set certain variables;[/B]
[COLOR="Orange"]GP_GuardingUnit[/COLOR] = The unit you want to be guarding
[COLOR="Orange"]GP_GuardWhere[/COLOR] = The point where the unit is guarding
[COLOR="orange"]GP_Perimeter[/COLOR] = Guard units will attack any enemy that is in range
[COLOR="orange"]GP_FacingAngle[/COLOR] = This is optional, when unit has no work he will face that angle
[COLOR="orange"]GP_EngageWhileTraveling[/COLOR] = Also optional, default is false, it engages anemy units while going to the place he guards
[B]Then at the last, run the;[/B]
[trigger]Trigger - Run Guard Post Form <gen> (ignoring conditions)[/trigger]
[B]Like this;[/B]
[trigger]
All Units
Events
Time - Elapsed game time is 0.00 seconds
Conditions
Actions
Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
Loop - Actions
-------- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --------
-------- Sets the Guard unit --------
-------- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --------
Set GP_GuardingUnit = (Picked unit)
-------- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --------
-------- Sets the location point of where the unit will guard --------
-------- You do not need to remove the location coz it will be removed from the system automatically --------
-------- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --------
Set GP_GuardWhere = (Position of (Picked unit))
-------- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --------
-------- Sets the range perimeter from the location where the unit is guarding --------
-------- If an enemy unit is in range, he will engage --------
-------- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --------
Set GP_Perimeter = 1000.00
-------- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --------
-------- Facing angle and Engage while traveling are optional --------
-------- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --------
Set GP_FacingAngle = 30.00
Set GP_EngageWhileTraveling = True
-------- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --------
-------- Store the guard unit to the system --------
-------- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --------
Trigger - Run Guard Post Form <gen> (ignoring conditions)
-------- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --------
-------- If you want to remove the unit from the system, just do this --------
-------- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --------
Set GP_GuardingUnit = Mountain King 0010 <gen>
Trigger - Run Guard Post Remove <gen> (ignoring conditions)
[/trigger]
[B][I]For more info, check the [COLOR="Orange"]Demo and Instructions [/COLOR]folder[/I][/B]
[/tab]
[tab=Trigger]
[trigger]
Guard Post Setup
Events
Map initialization
Conditions
Actions
-------- All settings here are default and recommended --------
-------- ======================================= --------
-------- The minimum perimeter of the location where the unit is guarding --------
-------- ======================================= --------
Set GP_MinimumPerimeter = 200.00
-------- ======================================= --------
-------- If the unit doesnt have orders or no more enemies around, it will go back to it's guarding post --------
-------- Calculation is 1x3 since the Movement is every 3 seconds --------
-------- ======================================= --------
Set GP_MinimumDelayBackToBase = 1
[/trigger]
[trigger]
Guard Post Form
Events
Conditions
Actions
-------- ======================================= --------
-------- Take note that if you cause an error message, the location variable will leak --------
-------- ======================================= --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
GP_GuardingUnit Equal to No unit
Then - Actions
Game - Display to (All players) the text: Guard Post Error: C...
Skip remaining actions
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
GP_Perimeter Less than GP_MinimumPerimeter
Then - Actions
Game - Display to (All players) the text: (Guard Post Error: + (Minimum Perimeter should be + (String(GP_MinimumPerimeter))))
Skip remaining actions
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(GP_GuardingUnit is in GP_GuardingGroup) Equal to True
Then - Actions
Game - Display to (All players) the text: (Guard Post Error: + ((Name of GP_GuardingUnit) + is already added as a guard, remove it first))
Skip remaining actions
Else - Actions
AI - Ignore GP_GuardingUnit's guard position
Set GP_UI = (Custom value of GP_GuardingUnit)
Set GP_U[GP_UI] = GP_GuardingUnit
Set GP_Per[GP_UI] = GP_Perimeter
Set GP_Fac[GP_UI] = GP_FacingAngle
Set GP_BackToBase[GP_UI] = GP_MinimumDelayBackToBase
Set GP_Back[GP_UI] = GP_MinimumDelayBackToBase
Set GP_Engage[GP_UI] = GP_EngageWhileTraveling
Set GP_EngageWhileTraveling = False
Unit - Order GP_GuardingUnit to Attack-Move To GP_GuardWhere
Custom script: set udg_GP_X[udg_GP_UI] = GetLocationX(udg_GP_GuardWhere)
Custom script: set udg_GP_Y[udg_GP_UI] = GetLocationY(udg_GP_GuardWhere)
Custom script: call RemoveLocation(udg_GP_GuardWhere)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
GP_Index Equal to 0
Then - Actions
Trigger - Turn on Guard Post Movements <gen>
Else - Actions
Set GP_Index = (GP_Index + 1)
Unit Group - Add GP_U[GP_UI] to GP_GuardingGroup
[/trigger]
[trigger]
Guard Post Movements
Events
Time - Every 3.00 seconds of game time
Conditions
Actions
Unit Group - Pick every unit in GP_GuardingGroup and do (Actions)
Loop - Actions
Custom script: local unit first
Custom script: local real xGuard
Custom script: local real yGuard
Set GP_UI = (Custom value of (Picked unit))
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(GP_U[GP_UI] is alive) Equal to True
Then - Actions
Custom script: set xGuard = GetUnitX(udg_GP_U[udg_GP_UI])
Custom script: set yGuard = GetUnitY(udg_GP_U[udg_GP_UI])
Custom script: set udg_GP_Distance = (udg_GP_X[udg_GP_UI] - xGuard)*(udg_GP_X[udg_GP_UI] - xGuard)+(udg_GP_Y[udg_GP_UI] - yGuard*(udg_GP_Y[udg_GP_UI] - yGuard))
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
GP_Distance Greater than or equal to (GP_Per[GP_UI] x GP_Per[GP_UI])
Then - Actions
-------- ======================================= --------
-------- Engage enemies while going to base if the condition is true --------
-------- Or just moves to the base if away from perimeter --------
-------- ======================================= --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
GP_Engage[GP_UI] Equal to True
Then - Actions
Custom script: call IssuePointOrderById(udg_GP_U[udg_GP_UI], 851983, udg_GP_X[udg_GP_UI], udg_GP_Y[udg_GP_UI])
Else - Actions
Custom script: call IssuePointOrderById(udg_GP_U[udg_GP_UI], 851986, udg_GP_X[udg_GP_UI], udg_GP_Y[udg_GP_UI])
Else - Actions
-------- ======================================= --------
-------- Searches for enemy units within the perimeter --------
-------- ======================================= --------
Custom script: call GroupEnumUnitsInRange(udg_GP_TempGroup, udg_GP_X[udg_GP_UI], udg_GP_Y[udg_GP_UI], udg_GP_Per[udg_GP_UI], null)
Custom script: loop
Custom script: set first = FirstOfGroup(udg_GP_TempGroup)
Custom script: exitwhen first==null
Custom script: if not IsUnitType(first, UNIT_TYPE_DEAD) and IsUnitEnemy(udg_GP_U[udg_GP_UI], GetOwningPlayer(first)) then
Custom script: call IssuePointOrderById(udg_GP_U[udg_GP_UI], 851983, GetUnitX(first), GetUnitY(first))
Custom script: endif
Custom script: call GroupRemoveUnit(udg_GP_TempGroup, first)
Custom script: endloop
-------- ======================================= --------
-------- Setting unit's facing angle if no order is available --------
-------- ======================================= --------
Custom script: if GetUnitCurrentOrder(udg_GP_U[udg_GP_UI])==0 then
Custom script: call SetUnitFacing(udg_GP_U[udg_GP_UI], udg_GP_Fac[udg_GP_UI])
-------- ======================================= --------
-------- Back to base, recycles every XXX seconds if order is 0 --------
-------- ======================================= --------
Set GP_BackToBase[GP_UI] = (GP_BackToBase[GP_UI] - GP_Back[GP_UI])
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
GP_BackToBase[GP_UI] Equal to 0
Then - Actions
Set GP_BackToBase[GP_UI] = GP_Back[GP_UI]
Custom script: call IssuePointOrderById(udg_GP_U[udg_GP_UI], 851983, udg_GP_X[udg_GP_UI], udg_GP_Y[udg_GP_UI])
Else - Actions
Custom script: endif
Else - Actions
Unit Group - Remove GP_U[GP_UI] from GP_GuardingGroup
Set GP_Index = (GP_Index - 1)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
GP_Index Equal to 0
Then - Actions
Trigger - Turn off (This trigger)
Else - Actions
[/trigger]
[trigger]
Guard Post Remove
Events
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(GP_GuardingUnit is in GP_GuardingGroup) Equal to True
Then - Actions
Unit Group - Remove GP_GuardingUnit from GP_GuardingGroup
Set GP_Index = (GP_Index - 1)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
GP_Index Equal to 0
Then - Actions
Game - Display to (All players) the text: adasdadadOFF
Trigger - Turn off Guard Post Movements <gen>
Else - Actions
Else - Actions
Game - Display to (All players) the text: (Guard Post Error: + ((Name of GP_GuardingUnit) + is not recognized to be removed from system.))
[/trigger]
[/tab]
[tab=Credits]
Bribe for his [thread=197329]UnitIndexer[/thread]
[/tab]
[tab=Bugs]
-
[/tab]
[tab=Changelogs]
v 1.3
- All jass codes are converted to GUI
- Simple constant guarding of location is applied
[/tab]
[/tabs]