Added Player lives and other Modes

Added New Readme
This commit is contained in:
Ciaran Fisher 2016-04-22 18:58:35 +01:00
parent 1310cf02a6
commit d7f29a74e7
3 changed files with 147 additions and 35 deletions

View File

@ -6,7 +6,7 @@
-- 0 - No Limit - NO Aircraft disabling or pilot lives -- 0 - No Limit - NO Aircraft disabling or pilot lives
-- 1 - Disable Aircraft when its down - Timeout to reenable aircraft -- 1 - Disable Aircraft when its down - Timeout to reenable aircraft
-- 2 - Disable Aircraft for Pilot when he's shot down -- timeout to reenable pilot for aircraft -- 2 - Disable Aircraft for Pilot when he's shot down -- timeout to reenable pilot for aircraft
-- 3 - Pilot Life Limit - No Aircraft Disabling -- timeout to reset lives? -- 3 - Pilot Life Limit - No Aircraft Disabling
csar = {} csar = {}
@ -215,6 +215,33 @@ csar.pilotDisabled = {} -- tracks what aircraft a pilot is disabled for
csar.pilotLives = {} -- tracks how many lives a pilot has csar.pilotLives = {} -- tracks how many lives a pilot has
-- ***************************************************************
-- **************** Mission Editor Functions *********************
-- ***************************************************************
-----------------------------------------------------------------
-- Resets all life limits so everyone can spawn again. Usage:
-- csar.resetAllPilotLives()
--
function csar.resetAllPilotLives()
csar.pilotLives = {}
env.info("Pilot Lives Reset!")
end
-----------------------------------------------------------------
-- Resets all life limits so everyone can spawn again. Usage:
-- csar.resetAllPilotLives()
--
function csar.resetPilotLife(_playerName)
csar.pilotLives[_playerName] = nil
env.info("Pilot life Reset!")
end
-- ***************************************************************
-- **************** BE CAREFUL BELOW HERE ************************
-- ***************************************************************
function csar.tableLength(T) function csar.tableLength(T)
if T == nil then if T == nil then
@ -265,10 +292,10 @@ function csar.eventHandler:onEvent(_event)
end end
end end
if _event.initiator:getName() then if _event.initiator:getName() and _event.initiator:getPlayerName() then
env.info("Checking Unit - ".._event.initiator:getName()) env.info("Checking Unit - ".._event.initiator:getName())
csar.checkDisabledAircraftStatus( _event.initiator:getName()) csar.checkDisabledAircraftStatus({_event.initiator:getName(), _event.initiator:getPlayerName() })
end end
return true return true
@ -430,30 +457,30 @@ function csar.handleEjectOrCrash(_unit,_crashed)
elseif csar.csarMode == 2 then -- disable aircraft for pilot elseif csar.csarMode == 2 then -- disable aircraft for pilot
--csar.pilotDisabled --csar.pilotDisabled
if _unit:getPlayerName() ~= nil and csar.pilotDisabled[_unit:getPlayerName().."_".._unit:getName()] == nil then if _unit:getPlayerName() ~= nil and csar.pilotDisabled[_unit:getPlayerName().."_".._unit:getName()] == nil then
if csar.countCSARCrash == false then if csar.countCSARCrash == false then
for _, _heliName in pairs(csar.csarUnits) do for _, _heliName in pairs(csar.csarUnits) do
if _unit:getName() == _heliName then if _unit:getName() == _heliName then
-- IGNORE Crashed CSAR -- IGNORE Crashed CSAR
return return
end
end end
end end
csar.pilotDisabled[_unit:getPlayerName().."_".._unit:getName()] = {timeout = (csar.disableTimeoutTime*60) + timer.getTime(),desc="",noPilot = true,unitId=_unit:getID(), player=_unit:getPlayerName(), name=_unit:getName() }
-- disable aircraft
-- strip special characters from name gsub('%W','')
trigger.action.setUserFlag("CSAR_AIRCRAFT".._unit:getPlayerName():gsub('%W','').."_".._unit:getID(),100)
env.info("Unit Disabled for player : ".._unit:getName())
end end
csar.pilotDisabled[_unit:getPlayerName().."_".._unit:getName()] = {timeout = (csar.disableTimeoutTime*60) + timer.getTime(),desc="",noPilot = true,unitId=_unit:getID(), player=_unit:getPlayerName(), name=_unit:getName() }
-- disable aircraft
-- strip special characters from name gsub('%W','')
trigger.action.setUserFlag("CSAR_AIRCRAFT".._unit:getPlayerName():gsub('%W','').."_".._unit:getID(),100)
env.info("Unit Disabled for player : ".._unit:getName())
end
elseif csar.csarMode == 3 then -- No Disable - Just reduce player lives elseif csar.csarMode == 3 then -- No Disable - Just reduce player lives
--csar.pilotDisabled --csar.pilotDisabled
@ -477,11 +504,8 @@ function csar.handleEjectOrCrash(_unit,_crashed)
csar.pilotLives[_unit:getPlayerName()] = _lives - 1 csar.pilotLives[_unit:getPlayerName()] = _lives - 1
trigger.action.setUserFlag("CSAR_PILOT".._unit:getPlayerName():gsub('%W',''),_lives-1) trigger.action.setUserFlag("CSAR_PILOT".._unit:getPlayerName():gsub('%W',''),_lives-1)
end end
end end
@ -523,6 +547,12 @@ function csar.enableAircraft(_name,_playerName)
_lives = csar.maxLives + 1 --plus 1 because we'll use flag set to 1 to indicate NO MORE LIVES _lives = csar.maxLives + 1 --plus 1 because we'll use flag set to 1 to indicate NO MORE LIVES
else else
_lives = _lives + 1 -- give back live! _lives = _lives + 1 -- give back live!
if csar.maxLives + 1 <= _lives then
_lives = csar.maxLives + 1 --plus 1 because we'll use flag set to 1 to indicate NO MORE LIVES
end
end end
csar.pilotLives[_playerName] = _lives csar.pilotLives[_playerName] = _lives
@ -567,11 +597,15 @@ function csar.reactivateAircraft()
end end
function csar.checkDisabledAircraftStatus(_name) function csar.checkDisabledAircraftStatus(_args)
local _name = _args[1]
local _playerName = _args[2]
local _unit = Unit.getByName(_name) local _unit = Unit.getByName(_name)
if _unit ~= nil and _unit:getPlayerName() ~= nil then --if its not the same user anymore, stop checking
if _unit ~= nil and _unit:getPlayerName() ~= nil and _playerName == _unit:getPlayerName() then
-- disable aircraft for ALL pilots -- disable aircraft for ALL pilots
if csar.csarMode == 1 then if csar.csarMode == 1 then
@ -607,7 +641,7 @@ function csar.checkDisabledAircraftStatus(_name)
return --plane destroyed return --plane destroyed
else else
--check again in 10 seconds --check again in 10 seconds
timer.scheduleFunction(csar.checkDisabledAircraftStatus, _name, timer.getTime() + 10) timer.scheduleFunction(csar.checkDisabledAircraftStatus,_args, timer.getTime() + 10)
end end
end end
@ -647,7 +681,7 @@ function csar.checkDisabledAircraftStatus(_name)
return --plane destroyed return --plane destroyed
else else
--check again in 10 seconds --check again in 10 seconds
timer.scheduleFunction(csar.checkDisabledAircraftStatus, _name, timer.getTime() + 10) timer.scheduleFunction(csar.checkDisabledAircraftStatus, _args, timer.getTime() + 10)
end end
end end
@ -667,6 +701,7 @@ function csar.checkDisabledAircraftStatus(_name)
csar.displayMessageToSAR(_unit,_text, 20,true) csar.displayMessageToSAR(_unit,_text, 20,true)
return
else else
@ -679,12 +714,10 @@ function csar.checkDisabledAircraftStatus(_name)
return --plane destroyed return --plane destroyed
else else
--check again in 10 seconds --check again in 10 seconds
timer.scheduleFunction(csar.checkDisabledAircraftStatus, _name, timer.getTime() + 10) timer.scheduleFunction(csar.checkDisabledAircraftStatus, _args, timer.getTime() + 10)
end end
end end
end end
end end

View File

@ -1,5 +1,86 @@
# DCS-CSAR # DCS-CSAR
Simplified Medevac script specifically for pilot rescue. Simplified MEDEVAC script specifically for pilot rescue simulating Combat Search and Rescue (CSAR)
By default, any crashed plane with an ejected pilot will be disabled until the pilot is rescued and dropped back safely to a friendly MASH By default, any crashed plane with an ejected pilot will be disabled until the pilot is rescued and dropped back safely to a friendly MASH, Airfield or FARP
## Setup in Mission Editor
### Script Setup
**This script requires MIST version 4.0.57 or above: https://github.com/mrSkortch/MissionScriptingTools**
First make sure MIST is loaded, either as an Initialization Script for the mission or the first DO SCRIPT with a "TIME MORE" of 1. "TIME MORE" means run the actions after X seconds into the mission.
Load the CSAR script a few seconds after MIST using a second trigger with a "TIME MORE" and a DO SCRIPT of CSAR.lua.
You will also need to load in the **beacon.ogg** sound file for Radio beacon homing. This can be done by adding a Sound To Country action. Pick an unused country, like Australia, so no one actually hears the audio when joining at the start of the mission. If you don't add the Audio file, radio beacons will not work and you will be unable to use ADF to find a downed pilot. Make sure not to rename the file as well.
### Script Configuration
The script has lots of configuration options that can be used to further customise the behaviour. Make sure after making any changes to save your file and re-add to the mission.
````lua
csar.csarMode = 0
-- 0 - No Limit - NO Aircraft disabling
-- 1 - Disable Aircraft when its down - Timeout to reenable aircraft
-- 2 - Disable Aircraft for Pilot when he's shot down -- timeout to reenable pilot for aircraft
-- 3 - Pilot Life Limit - No Aircraft Disabling -- timeout to reset lives?
csar.maxLives = 8 -- Maximum pilot lives
csar.countCSARCrash = false -- If you set to true, pilot lives count for CSAR and CSAR aircraft will count.
csar.reenableIfCSARCrashes = true -- If a CSAR heli crashes, the pilots are counted as rescued anyway. Set to false to Stop this
-- - I recommend you leave the option on below IF USING MODE 1 otherwise the
-- aircraft will be disabled for the duration of the mission
csar.disableAircraftTimeout = true -- Allow aircraft to be used after 20 minutes if the pilot isnt rescued
csar.disableTimeoutTime = 10 -- Time in minutes for TIMEOUT
csar.destructionHeight = 150 -- height in meters an aircraft will be destroyed at if the aircraft is disabled
csar.enableForAI = false -- set to false to disable AI units from being rescued.
csar.enableForRED = true -- enable for red side
csar.enableForBLUE = true -- enable for blue side
csar.enableSlotBlocking = true -- if set to true, you need to put the csarSlotBlockGameGUI.lua
-- in C:/Users/<YOUR USERNAME>/DCS/Scripts for 1.5 or C:/Users/<YOUR USERNAME>/DCS.openalpha/Scripts for 2.0
-- For missions using FLAGS and this script, the CSAR flags will NOT interfere with your mission :)
csar.bluesmokecolor = 4 -- Color of smokemarker for blue side, 0 is green, 1 is red, 2 is white, 3 is orange and 4 is blue
csar.redsmokecolor = 1 -- Color of smokemarker for red side, 0 is green, 1 is red, 2 is white, 3 is orange and 4 is blue
csar.requestdelay = 2 -- Time in seconds before the survivors will request Medevac
csar.coordtype = 3 -- Use Lat/Long DDM (0), Lat/Long DMS (1), MGRS (2), Bullseye imperial (3) or Bullseye metric (4) for coordinates.
csar.coordaccuracy = 1 -- Precision of the reported coordinates, see MIST-docs at http://wiki.hoggit.us/view/GetMGRSString
-- only applies to _non_ bullseye coords
csar.immortalcrew = true -- Set to true to make wounded crew immortal
csar.invisiblecrew = true -- Set to true to make wounded crew insvisible
csar.messageTime = 30 -- Time to show the intial wounded message for in seconds
csar.loadDistance = 60 -- configure distance for pilot to get in helicopter in meters.
csar.radioSound = "beacon.ogg" -- the name of the sound file to use for the Pilot radio beacons. If this isnt added to the mission BEACONS WONT WORK!
csar.allowFARPRescue = true --allows pilot to be rescued by landing at a FARP or Airbase
````
#### Slot Blocking
If you want to enable slot blocking, you'll need to use one of the 3 modes by changing ```csar.csarMode``` in the configuration options, set ```csar.enableSlotBlocking = true``` and copy **csarSlotBlockGameGUI.lua** to C:/Users/<YOUR USERNAME>/DCS/Scripts for 1.5 or C:/Users/<YOUR USERNAME>/DCS.openalpha/Scripts for 2.0.
The 3 modes are:
* Mode 1 - Disable the specific aircraft when it crashes or is destroyed for **All** players - Re-enabled when the pilot is rescued or after a set time
* Mode 2 - Disable the specific aircraft when it crashes or is destroyed for **The pilot that crashed / ejected** - Re-enabled when the pilot is rescued or after a set time
* Mode 3 - No specific aircraft disabling. Each pilot has a number of lives and can no longer fly when their lives are used up
Its recommended that you leave the ```csar.disableAircraftTimeout = true``` if you use Mode 1 as otherwise its possible that all aircraft in a mission could be disabled!
You can configure how long an aircraft is disabled in Mode 1 or Mode 2 by changing ```csar.disableTimeoutTime``` which will control how long until an aircraft will be disabled for in minutes.

View File

@ -9,8 +9,6 @@ local csarSlotBlock = {} -- DONT REMOVE!!!
The flags will NOT interfere with mission flags The flags will NOT interfere with mission flags
]] ]]
csarSlotBlock.showEnabledMessage = true -- if set to true, the player will be told that the slot is enabled when switching to it csarSlotBlock.showEnabledMessage = true -- if set to true, the player will be told that the slot is enabled when switching to it