Added Waypoint zones

Needs further testing
This commit is contained in:
Ciaran Fisher 2016-04-19 21:25:33 +01:00
parent f3f440f0a3
commit 84452da00b
2 changed files with 217 additions and 9 deletions

177
CTLD.lua
View File

@ -13,10 +13,9 @@
Contributors:
- Steggles - https://github.com/Bob7heBuilder
Version: 1.60 - 20/03/2015
- Added ability to disable hover pickup and instead load crates with F10
- Added new function - ctld.removeExtractZone to stop an extract zone after a while
- Added ability to limit the number of AA systems that can be built and active at one time
Version: 1.61 - 19/04/2015
- Added ability to add Waypoint zones
-- Troops dropped in a waypoint zone will automatically head to the center of the zone
]]
@ -124,7 +123,7 @@ ctld.JTAC_location = true -- shows location of target in JTAC message
ctld.JTAC_lock = "all" -- "vehicle" OR "troop" OR "all" forces JTAC to only lock vehicles or troops or all ground units
-- ***************** Pickup and dropoff zones *****************
-- ***************** Pickup, dropoff and waypoint zones *****************
-- Available colors (anything else like "none" disables smoke): "green", "red", "white", "orange", "blue", "none",
@ -185,6 +184,21 @@ ctld.dropOffZones = {
}
--wpZones = { "Zone name", "smoke color", "ACTIVE (yes/no)", "side (0 = Both sides / 1 = Red / 2 = Blue )", }
ctld.wpZones = {
{ "wpzone1", "green","yes", 2 },
{ "wpzone2", "blue","yes", 2 },
{ "wpzone3", "orange","yes", 2 },
{ "wpzone4", "none","yes", 2 },
{ "wpzone5", "none","yes", 1 },
{ "wpzone6", "none","yes", 1 },
{ "wpzone7", "none","yes", 1 },
{ "wpzone8", "none","yes", 1 },
{ "wpzone9", "none","yes", 1 },
{ "wpzone10", "none","no", 1 },
}
-- ******************** Transports names **********************
-- Use any of the predefined names or set your own ones
@ -943,7 +957,6 @@ function ctld.deactivatePickupZone(_zoneName)
end
end
-- Change the remaining groups currently available for pickup at a zone
-- e.g. ctld.changeRemainingGroupsForPickupZone("pickup1", 5) -- adds 5 groups
-- ctld.changeRemainingGroupsForPickupZone("pickup1", -3) -- remove 3 groups
@ -976,6 +989,77 @@ function ctld.changeRemainingGroupsForPickupZone(_zoneName, _amount)
end
-- Activates a Waypoint zone
-- Activates a Waypoint zone when called from a trigger
-- EG: ctld.activateWaypointZone("pickzone3")
-- This means that troops dropped within the radius of the zone will head to the center
-- of the zone instead of searching for troops
function ctld.activateWaypointZone(_zoneName)
local _triggerZone = trigger.misc.getZone(_zoneName) -- trigger to use as reference position
if _triggerZone == nil then
trigger.action.outText("CTLD.lua ERROR: Cant find zone called " .. _zoneName, 10)
return
end
for _, _zoneDetails in pairs(ctld.wpZones) do
if _zoneName == _zoneDetails[1] then
--smoke could get messy if designer keeps calling this on an active zone, check its not active first
if _zoneDetails[3] == 1 then
-- they might have a continuous trigger so i've hidden the warning
--trigger.action.outText("CTLD.lua ERROR: Pickup Zone already active: " .. _zoneName, 10)
return
end
_zoneDetails[3] = 1 --activate zone
if ctld.disableAllSmoke == true then --smoke disabled
return
end
if _zoneDetails[2] >= 0 then
-- Trigger smoke marker
-- This will cause an overlapping smoke marker on next refreshsmoke call
-- but will only happen once
local _pos2 = { x = _triggerZone.point.x, y = _triggerZone.point.z }
local _alt = land.getHeight(_pos2)
local _pos3 = { x = _pos2.x, y = _alt, z = _pos2.y }
trigger.action.smoke(_pos3, _zoneDetails[2])
end
end
end
end
-- Deactivates a Waypoint zone
-- Deactivates a Waypoint zone when called from a trigger
-- EG: ctld.deactivateWaypointZone("wpzone3")
-- This disables wpzone3 so that troops dropped in this zone will search for troops as normal
-- These functions can be called by triggers
function ctld.deactivateWaypointZone(_zoneName)
local _triggerZone = trigger.misc.getZone(_zoneName)
if _triggerZone == nil then
trigger.action.outText("CTLD.lua ERROR: Cant find zone called " .. _zoneName, 10)
return
end
for _, _zoneDetails in pairs(ctld.pickupZones) do
if _zoneName == _zoneDetails[1] then
_zoneDetails[3] = 0 --deactivate zone
end
end
end
-- Continuous Trigger Function
-- Causes an AI unit with the specified name to unload troops / vehicles when
-- an enemy is detected within a specified distance
@ -3786,10 +3870,17 @@ function ctld.spawnDroppedGroup(_point, _details, _spawnBehind, _maxSearch)
_maxSearch = ctld.maximumSearchDistance
end
local _enemyPos = ctld.findNearestEnemy(_details.side, _point, _maxSearch)
local _wpZone = ctld.inWaypointZone(_point,_spawnedGroup:getCoalition())
ctld.orderGroupToMoveToPoint(_spawnedGroup:getUnit(1), _enemyPos)
if _wpZone.inZone then
ctld.orderGroupToMoveToPoint(_spawnedGroup:getUnit(1), _wpZone.point)
env.info("Heading to waypoint - In Zone ".._wpZone.name)
else
local _enemyPos = ctld.findNearestEnemy(_details.side, _point, _maxSearch)
ctld.orderGroupToMoveToPoint(_spawnedGroup:getUnit(1), _enemyPos)
end
return _spawnedGroup
end
@ -4090,6 +4181,29 @@ function ctld.inDropoffZone(_heli)
return false
end
-- are we in a waypoint zone
function ctld.inWaypointZone(_point,_coalition)
for _, _zoneDetails in pairs(ctld.wpZones) do
local _triggerZone = trigger.misc.getZone(_zoneDetails[1])
--right coalition and active?
if _triggerZone ~= nil and (_zoneDetails[4] == _coalition or _zoneDetails[4]== 0) and _zoneDetails[3] == 1 then
--get distance to center
local _dist = ctld.getDistance(_point, _triggerZone.point)
if _dist <= _triggerZone.radius then
return {inZone = true, point = _triggerZone.point, name = _zoneDetails[1]}
end
end
end
return {inZone = false}
end
-- are we near friendly logistics zone
function ctld.inLogisticsZone(_heli)
@ -4155,6 +4269,25 @@ function ctld.refreshSmoke()
end
end
--waypoint zones
for _, _zoneDetails in pairs(ctld.wpZones) do
local _triggerZone = trigger.misc.getZone(_zoneDetails[1])
--only trigger if smoke is on AND zone is active
if _triggerZone ~= nil and _zoneDetails[2] >= 0 and _zoneDetails[3] == 1 then
-- Trigger smoke markers
local _pos2 = { x = _triggerZone.point.x, y = _triggerZone.point.z }
local _alt = land.getHeight(_pos2)
local _pos3 = { x = _pos2.x, y = _alt, z = _pos2.y }
trigger.action.smoke(_pos3, _zoneDetails[2])
end
end
--refresh in 5 minutes
timer.scheduleFunction(ctld.refreshSmoke, nil, timer.getTime() + 300)
end
@ -5527,6 +5660,34 @@ for _, _zone in pairs(ctld.dropOffZones) do
_zone[4] = 1
end
--sort out waypoint zones
for _, _zone in pairs(ctld.wpZones) do
local _zoneColor = _zone[2]
if _zoneColor == "green" then
_zone[2] = trigger.smokeColor.Green
elseif _zoneColor == "red" then
_zone[2] = trigger.smokeColor.Red
elseif _zoneColor == "white" then
_zone[2] = trigger.smokeColor.White
elseif _zoneColor == "orange" then
_zone[2] = trigger.smokeColor.Orange
elseif _zoneColor == "blue" then
_zone[2] = trigger.smokeColor.Blue
else
_zone[2] = -1 -- no smoke colour
end
--mark as active for refresh smoke logic to work
-- change active to 1 / 0
if _zone[3] == "yes" then
_zone[3] = 1
else
_zone[3] = 0
end
end
-- Sort out extractable groups
for _, _groupName in pairs(ctld.extractableGroups) do

View File

@ -61,6 +61,7 @@ The script supports:
* Count Crates in Zone
* Works for both crates added by the Mission Editor and Crates spawned by Transports
* Count soldiers extracted to a zone (the soldiers disappear)
* Waypoint triggers to force dropped groups to head to a location
* Advanced Scripting Callback system
A complete test mission is included.
@ -306,7 +307,7 @@ ctld.spawnGroupAtPoint("blue", {mg=1,at=2,aa=3,inf=4,mortar=5}, {x=1,y=2,z=3}, 2
```
### Activate / Deactivate Pickup Zone
You can activate and deactive a pickup zone as shown below. When a zone is active, troops can be loaded from it as long as there are troops remaining and you are the same side as the pickup zone.
You can activate and deactivate a pickup zone as shown below. When a zone is active, troops can be loaded from it as long as there are troops remaining and you are the same side as the pickup zone.
```lua
ctld.activatePickupZone("pickzone3")
@ -329,12 +330,23 @@ ctld.changeRemainingGroupsForPickupZone("pickup1", -3) -- remove 3 groups for zo
```
### Activate / Deactivate Waypoint Zone
You can activate and deactivate a waypoint zone as shown below. When a waypoint zone is active, and the right coalition of troops is dropped inside, the troops will attempt to head to the center of the zone.
```lua
ctld.activateWaypointZone("wpzone1")
```
or
```lua
ctld.deactivateWaypointZone("wpzone1")
```
### Unload Transport
You can force a unit to unload its units (as long as its on the ground) by calling this function.
```lua
ctld.unloadTransport("helicargo1")
```
###Load Transport
You can force a unit to load its units (as long as its on the ground) by calling this function.
@ -607,6 +619,41 @@ Available colours are:
Smoke can be disabled for all zones regardless of the settings above using the option ```ctld.disableAllSmoke = true``` in the User Configuration part of the script.
### Waypoint Zones Setup
Waypoint zones can be used to make dropped or spawned troops automatically head to the center of a zone. The troops will head to the center of the zone if the coalition matches (or the coalition is set to 0) and if the zone is currently active.
If your Waypoint zone isn't working, make sure the 3rd parameter, the coalition side, is set correctly and the zone is set to active.
```lua
--wpZones = { "Zone name", "smoke color", "ACTIVE (yes/no)", "side (0 = Both sides / 1 = Red / 2 = Blue )", }
ctld.wpZones = {
{ "wpzone1", "green","yes", 2 },
{ "wpzone2", "blue","yes", 2 },
{ "wpzone3", "orange","yes", 2 },
{ "wpzone4", "none","yes", 2 },
{ "wpzone5", "none","yes", 1 },
{ "wpzone6", "none","yes", 1 },
{ "wpzone7", "none","yes", 1 },
{ "wpzone8", "none","yes", 1 },
{ "wpzone9", "none","yes", 1 },
{ "wpzone10", "none","no", 1 },
}
```
Smoke can be enabled or disabled individually for waypoiny zones exactly the same as Pickup and Dropoff zones by editing the second column in the list.
The available colours are:
* ```"green"```
* ```"red"```
* ```"white"```
* ```"orange"```
* ```"blue"```
* ```"none"```
Smoke can be disabled for all zones regardless of the settings above using the option ```ctld.disableAllSmoke = true``` in the User Configuration part of the script.
### Transport Unit Setup
Any unit that you want to be able to transport troops needs to have the **"Pilot Name"** in the ```ctld.transportPilotNames``` list. **Player controlled transport units should be in a group of their own and be the only unit in the group, otherwise other players may have radio commands they shouldn't**. The group name isn't important and can be set to whatever you like. A snippet of the list is shown below.