This system is not fully GUI (I think) because almost half of the code is custom script.
I been searching a system that will make units wandering around with
simple implementation and I can't find any. Most of it is JASS and takes lot of work.
Since I can't find it, I made this system and I made the implementation simple as I could.
I've already post this system to the Hive. I just want share to see how Chaos Realm review this system.
This system will make registered unit move around certain area or everywhere
based on user configuration.
The system will stop forcing unit from wandering when the unit is unit combat
until the unit is out of combat.
For me, this kind of system would be useful for RPG mapping.
Making the forest and village looks lively.
This is just the base of the system.
How to import:
1. Copy all trigger in System and Requirements category. Don't copy the system inside
Requirement if you already have it.
2. Paste the trigger and the custom ability into your map.
3. Check and enable disabled actions in systems trigger.
The triggers:
Wander Initialization
Spoiler
Show
[gui]Wander Initialization
Events
Map initialization
Conditions
Actions
-------- For path checking --------
Set WanderPathRect = (Region(0.00, 0.00, 128.00, 128.00))
Custom script: set udg_WanderPathChecker = CreateItem('wtlg', 0, 0)
Custom script: call SetItemVisible(udg_WanderPathChecker, false)
[/gui]
Events
Map initialization
Conditions
Actions
-------- For path checking --------
Set WanderPathRect = (Region(0.00, 0.00, 128.00, 128.00))
Custom script: set udg_WanderPathChecker = CreateItem('wtlg', 0, 0)
Custom script: call SetItemVisible(udg_WanderPathChecker, false)
[/gui]
Spoiler
Show
[gui]Wander
Events
Conditions
Actions
-------- -------------------------------- --------
-------- Any no unit registeration will be ignored. --------
-------- -------------------------------- --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
And - All (Conditions) are true
Conditions
WanderRegUnit Equal to No unit
WanderRemoveUnit Equal to No unit
Then - Actions
Custom script: call BJDebugMsg("Wander : No unit to be registered or removed.")
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderRegUnit Not equal to No unit
Then - Actions
Custom script: call ExecuteFunc("WanderRegister")
Else - Actions
Custom script: call ExecuteFunc("WanderRemove")
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderCoUnit Not equal to No unit
Then - Actions
Custom script: call ExecuteFunc("WanderCombatDetect")
Else - Actions
Custom script: endfunction
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
Custom script: function WanderCombatDelay takes nothing returns nothing
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(WanderCombatGroup is empty) Equal to True
Then - Actions
Countdown Timer - Pause WanderCoTimer
Set WanderTimerCheck[3] = False
Else - Actions
Unit Group - Pick every unit in WanderCombatGroup and do (Actions)
Loop - Actions
Set WanderUnit = (Picked unit)
Set WanderIndex = (Custom value of WanderUnit)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderDelayCount[WanderIndex] Greater than 0.00
Then - Actions
Set WanderDelayCount[WanderIndex] = (WanderDelayCount[WanderIndex] - 0.50)
Else - Actions
Unit Group - Remove WanderUnit from WanderCombatGroup
Custom script: endfunction
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
Custom script: function WanderCombatDetect takes nothing returns nothing
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderTimerCheck[3] Equal to False
Then - Actions
Custom script: call TimerStart(udg_WanderCoTimer, 0.50, true, function WanderCombatDelay)
Set WanderTimerCheck[3] = True
Else - Actions
Set WanderIndex = (Custom value of WanderCoUnit)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(WanderCoUnit is in WanderCombatGroup) Equal to False
Then - Actions
Unit Group - Add WanderCoUnit to WanderCombatGroup
Else - Actions
Set WanderDelayCount[WanderIndex] = WanderCoDelay[WanderIndex]
Set WanderCoUnit = No unit
Custom script: endfunction
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- This function will remove any registered unit who in combat and add who out of combat. --------
-------- -------------------------------- --------
Custom script: function WanderAddRemove takes nothing returns nothing
-------- If there's no unit in this group, --------
-------- this one will pause the timer. --------
-------- By doing this, this system won't cause lag. --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(WanderRegisteredGroup is empty) Equal to True
Then - Actions
Countdown Timer - Pause WanderARTimer
Set WanderTimerCheck[1] = False
Else - Actions
-------- Check if the registered unit is in combat or not. --------
Unit Group - Pick every unit in WanderRegisteredGroup and do (Actions)
Loop - Actions
Set WanderUnit = (Picked unit)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(WanderUnit is in WanderCombatGroup) Equal to True
Then - Actions
Unit Group - Remove WanderUnit from WanderActiveGroup
Else - Actions
Unit Group - Add WanderUnit to WanderActiveGroup
-------- Resume the timer when there's a unit in group --------
Countdown Timer - Resume WanderWPTimer
Set WanderTimerCheck[2] = True
Custom script: endfunction
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- This is the periodic function. --------
-------- and this function is the one that will make registered unit walk around. --------
-------- -------------------------------- --------
Custom script: function WanderPeriodic takes nothing returns nothing
-------- Checking unit group --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(WanderActiveGroup is empty) Equal to True
Then - Actions
Countdown Timer - Pause WanderWPTimer
Set WanderTimerCheck[2] = False
Else - Actions
-------- Pick all registered unit --------
Unit Group - Pick every unit in WanderActiveGroup and do (Actions)
Loop - Actions
Custom script: local real array x
Custom script: local real array y
Set WanderUnit = (Picked unit)
Set WanderIndex = (Custom value of WanderUnit)
-------- -------------------------------- --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderDelayCount[WanderIndex] Greater than or equal to WanderDelay[WanderIndex]
Then - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderIsAroundLoc[WanderIndex] Equal to True
Then - Actions
Custom script: set udg_WanderPoint[1] = Location(udg_WanderLocX[udg_WanderIndex], udg_WanderLocY[udg_WanderIndex])
Else - Actions
Set WanderPoint[1] = (Position of WanderUnit)
Custom script: loop
Set WanderPoint[2] = (WanderPoint[1] offset by (Random real number between WanderMinDist[WanderIndex] and WanderMaxDist[WanderIndex]) towards (Random angle) degrees)
Custom script: set x[1] = GetLocationX(udg_WanderPoint[2])
Custom script: set y[1] = GetLocationY(udg_WanderPoint[2])
Custom script: call MoveRectTo(udg_WanderPathRect, x[1], y[1])
Custom script: call SetItemPosition(udg_WanderPathChecker, x[1], y[1])
Custom script: set x[2] = GetItemX(udg_WanderPathChecker)
Custom script: set y[2] = GetItemY(udg_WanderPathChecker)
Item - Hide WanderPathChecker
Custom script: set udg_WanderPathCheck = ((x[2]-x[1])*(x[2]-x[1]) + (y[2]-y[1])*(y[2]-y[1]) <= 100) and (not IsTerrainPathable(x[1], y[1], PATHING_TYPE_WALKABILITY))
Custom script: exitwhen udg_WanderPathCheck == true
Custom script: endloop
Custom script: call IssuePointOrderLoc(udg_WanderUnit, udg_WanderOrder[udg_WanderIndex], udg_WanderPoint[2])
Custom script: call RemoveLocation(udg_WanderPoint[1])
Custom script: call RemoveLocation(udg_WanderPoint[2])
Set WanderDelayCount[WanderIndex] = 0.00
Else - Actions
Set WanderDelayCount[WanderIndex] = (WanderDelayCount[WanderIndex] + 0.50)
Custom script: endfunction
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- This function will remove unit from this system. --------
Custom script: function WanderRemove takes nothing returns nothing
-------- Remove unit from system --------
Unit Group - Remove WanderRemoveUnit from WanderActiveGroup
Unit Group - Remove WanderRemoveUnit from WanderRegisteredGroup
-------- nulling variable --------
Set WanderRemoveUnit = No unit
Custom script: endfunction
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- When registering units, all of the information will be --------
-------- send into this function and this function will store them into hashtable. --------
-------- -------------------------------- --------
Custom script: function WanderRegister takes nothing returns nothing
-------- Starting timer for functions. --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderTimerCheck[1] Equal to False
Then - Actions
Custom script: call TimerStart(udg_WanderARTimer, 0.50, true, function WanderAddRemove)
Set WanderTimerCheck[1] = True
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderTimerCheck[2] Equal to False
Then - Actions
Custom script: call TimerStart(udg_WanderWPTimer, 0.50, true, function WanderPeriodic)
Set WanderTimerCheck[2] = True
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderIsAroundLoc[WanderIndex] Equal to True
Then - Actions
Custom script: set udg_WanderLocX[udg_WanderIndex] = GetLocationX(udg_WanderWPoint)
Custom script: set udg_WanderLocY[udg_WanderIndex] = GetLocationY(udg_WanderWPoint)
Else - Actions
-------- Registering unit into the system. --------
Unit Group - Add WanderRegUnit to WanderActiveGroup
Unit Group - Add WanderRegUnit to WanderRegisteredGroup
-------- nulling variable --------
Set WanderRegUnit = No unit
Custom script: call RemoveLocation(udg_WanderWPoint)
[/gui]
Events
Conditions
Actions
-------- -------------------------------- --------
-------- Any no unit registeration will be ignored. --------
-------- -------------------------------- --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
And - All (Conditions) are true
Conditions
WanderRegUnit Equal to No unit
WanderRemoveUnit Equal to No unit
Then - Actions
Custom script: call BJDebugMsg("Wander : No unit to be registered or removed.")
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderRegUnit Not equal to No unit
Then - Actions
Custom script: call ExecuteFunc("WanderRegister")
Else - Actions
Custom script: call ExecuteFunc("WanderRemove")
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderCoUnit Not equal to No unit
Then - Actions
Custom script: call ExecuteFunc("WanderCombatDetect")
Else - Actions
Custom script: endfunction
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
Custom script: function WanderCombatDelay takes nothing returns nothing
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(WanderCombatGroup is empty) Equal to True
Then - Actions
Countdown Timer - Pause WanderCoTimer
Set WanderTimerCheck[3] = False
Else - Actions
Unit Group - Pick every unit in WanderCombatGroup and do (Actions)
Loop - Actions
Set WanderUnit = (Picked unit)
Set WanderIndex = (Custom value of WanderUnit)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderDelayCount[WanderIndex] Greater than 0.00
Then - Actions
Set WanderDelayCount[WanderIndex] = (WanderDelayCount[WanderIndex] - 0.50)
Else - Actions
Unit Group - Remove WanderUnit from WanderCombatGroup
Custom script: endfunction
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
Custom script: function WanderCombatDetect takes nothing returns nothing
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderTimerCheck[3] Equal to False
Then - Actions
Custom script: call TimerStart(udg_WanderCoTimer, 0.50, true, function WanderCombatDelay)
Set WanderTimerCheck[3] = True
Else - Actions
Set WanderIndex = (Custom value of WanderCoUnit)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(WanderCoUnit is in WanderCombatGroup) Equal to False
Then - Actions
Unit Group - Add WanderCoUnit to WanderCombatGroup
Else - Actions
Set WanderDelayCount[WanderIndex] = WanderCoDelay[WanderIndex]
Set WanderCoUnit = No unit
Custom script: endfunction
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- This function will remove any registered unit who in combat and add who out of combat. --------
-------- -------------------------------- --------
Custom script: function WanderAddRemove takes nothing returns nothing
-------- If there's no unit in this group, --------
-------- this one will pause the timer. --------
-------- By doing this, this system won't cause lag. --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(WanderRegisteredGroup is empty) Equal to True
Then - Actions
Countdown Timer - Pause WanderARTimer
Set WanderTimerCheck[1] = False
Else - Actions
-------- Check if the registered unit is in combat or not. --------
Unit Group - Pick every unit in WanderRegisteredGroup and do (Actions)
Loop - Actions
Set WanderUnit = (Picked unit)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(WanderUnit is in WanderCombatGroup) Equal to True
Then - Actions
Unit Group - Remove WanderUnit from WanderActiveGroup
Else - Actions
Unit Group - Add WanderUnit to WanderActiveGroup
-------- Resume the timer when there's a unit in group --------
Countdown Timer - Resume WanderWPTimer
Set WanderTimerCheck[2] = True
Custom script: endfunction
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- This is the periodic function. --------
-------- and this function is the one that will make registered unit walk around. --------
-------- -------------------------------- --------
Custom script: function WanderPeriodic takes nothing returns nothing
-------- Checking unit group --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(WanderActiveGroup is empty) Equal to True
Then - Actions
Countdown Timer - Pause WanderWPTimer
Set WanderTimerCheck[2] = False
Else - Actions
-------- Pick all registered unit --------
Unit Group - Pick every unit in WanderActiveGroup and do (Actions)
Loop - Actions
Custom script: local real array x
Custom script: local real array y
Set WanderUnit = (Picked unit)
Set WanderIndex = (Custom value of WanderUnit)
-------- -------------------------------- --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderDelayCount[WanderIndex] Greater than or equal to WanderDelay[WanderIndex]
Then - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderIsAroundLoc[WanderIndex] Equal to True
Then - Actions
Custom script: set udg_WanderPoint[1] = Location(udg_WanderLocX[udg_WanderIndex], udg_WanderLocY[udg_WanderIndex])
Else - Actions
Set WanderPoint[1] = (Position of WanderUnit)
Custom script: loop
Set WanderPoint[2] = (WanderPoint[1] offset by (Random real number between WanderMinDist[WanderIndex] and WanderMaxDist[WanderIndex]) towards (Random angle) degrees)
Custom script: set x[1] = GetLocationX(udg_WanderPoint[2])
Custom script: set y[1] = GetLocationY(udg_WanderPoint[2])
Custom script: call MoveRectTo(udg_WanderPathRect, x[1], y[1])
Custom script: call SetItemPosition(udg_WanderPathChecker, x[1], y[1])
Custom script: set x[2] = GetItemX(udg_WanderPathChecker)
Custom script: set y[2] = GetItemY(udg_WanderPathChecker)
Item - Hide WanderPathChecker
Custom script: set udg_WanderPathCheck = ((x[2]-x[1])*(x[2]-x[1]) + (y[2]-y[1])*(y[2]-y[1]) <= 100) and (not IsTerrainPathable(x[1], y[1], PATHING_TYPE_WALKABILITY))
Custom script: exitwhen udg_WanderPathCheck == true
Custom script: endloop
Custom script: call IssuePointOrderLoc(udg_WanderUnit, udg_WanderOrder[udg_WanderIndex], udg_WanderPoint[2])
Custom script: call RemoveLocation(udg_WanderPoint[1])
Custom script: call RemoveLocation(udg_WanderPoint[2])
Set WanderDelayCount[WanderIndex] = 0.00
Else - Actions
Set WanderDelayCount[WanderIndex] = (WanderDelayCount[WanderIndex] + 0.50)
Custom script: endfunction
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- This function will remove unit from this system. --------
Custom script: function WanderRemove takes nothing returns nothing
-------- Remove unit from system --------
Unit Group - Remove WanderRemoveUnit from WanderActiveGroup
Unit Group - Remove WanderRemoveUnit from WanderRegisteredGroup
-------- nulling variable --------
Set WanderRemoveUnit = No unit
Custom script: endfunction
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- -------------------------------- --------
-------- When registering units, all of the information will be --------
-------- send into this function and this function will store them into hashtable. --------
-------- -------------------------------- --------
Custom script: function WanderRegister takes nothing returns nothing
-------- Starting timer for functions. --------
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderTimerCheck[1] Equal to False
Then - Actions
Custom script: call TimerStart(udg_WanderARTimer, 0.50, true, function WanderAddRemove)
Set WanderTimerCheck[1] = True
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderTimerCheck[2] Equal to False
Then - Actions
Custom script: call TimerStart(udg_WanderWPTimer, 0.50, true, function WanderPeriodic)
Set WanderTimerCheck[2] = True
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
WanderIsAroundLoc[WanderIndex] Equal to True
Then - Actions
Custom script: set udg_WanderLocX[udg_WanderIndex] = GetLocationX(udg_WanderWPoint)
Custom script: set udg_WanderLocY[udg_WanderIndex] = GetLocationY(udg_WanderWPoint)
Else - Actions
-------- Registering unit into the system. --------
Unit Group - Add WanderRegUnit to WanderActiveGroup
Unit Group - Add WanderRegUnit to WanderRegisteredGroup
-------- nulling variable --------
Set WanderRegUnit = No unit
Custom script: call RemoveLocation(udg_WanderWPoint)
[/gui]
Spoiler
Show
[gui]Wander CoDetect
Events
Unit - A unit Is issued an order targeting an object
Unit - A unit Is attacked
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Attacked unit) is in WanderRegisteredGroup) Equal to True
Then - Actions
Set WanderCoUnit = (Attacked unit)
Trigger - Run Wander <gen> (ignoring conditions)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Attacking unit) is in WanderRegisteredGroup) Equal to True
Then - Actions
Set WanderCoUnit = (Attacking unit)
Trigger - Run Wander <gen> (ignoring conditions)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Ordered unit) is in WanderRegisteredGroup) Equal to True
Then - Actions
Set WanderCoUnit = (Ordered unit)
Trigger - Run Wander <gen> (ignoring conditions)
Else - Actions
[/gui]
Events
Unit - A unit Is issued an order targeting an object
Unit - A unit Is attacked
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Attacked unit) is in WanderRegisteredGroup) Equal to True
Then - Actions
Set WanderCoUnit = (Attacked unit)
Trigger - Run Wander <gen> (ignoring conditions)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Attacking unit) is in WanderRegisteredGroup) Equal to True
Then - Actions
Set WanderCoUnit = (Attacking unit)
Trigger - Run Wander <gen> (ignoring conditions)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Ordered unit) is in WanderRegisteredGroup) Equal to True
Then - Actions
Set WanderCoUnit = (Ordered unit)
Trigger - Run Wander <gen> (ignoring conditions)
Else - Actions
[/gui]
Credit goes to Bribe (Hive) for Unit Indexer