-- Make Sure there is -- 1 A Side called DippyLogic -- 2 4 Reference Points in DippyLogic side called DIPPYSAR1,DIPPYSAR2,DIPPYSAR3,DIPPYSAR4 -- 3 An Event with Trigger and Action for "Unit Destroyed" calling lua script Dippy_EventUnitDestroyed() -- 4 An Event with Trigger and Action for "Unit Enters Area" calling lua script Dippy_EventUnitEntersArea() -- 5 Run This Script "DownedPilot.lua" -- Change the Miles Around the pilot classified as a pickup -- Change the MAximum Minutes to pick up pilot before capture -- Add all the dbid and loadouts for the Search and Rescue Units in the scenario SARAreaMiles=20 --distance around pilot for pickup to be active MaxMinutesToRescue=20 -- checked every 10 minutes F_Air_SAR = {{ 3215, 17256},{ 242, 13623 } }--HC-130J --Add all the possible Search and Rescue Units ----------------------------------------------------------------------------------------------------------------------------------------- DIPPYWreckdbid = 2350 DIPPYRaftdbid=2553 MyTimerdbid=312 --cesna used for 10 minute timer. fuel of 3.3333 is 10 minutes of flight time MyTimerloadout=8399 StartTimeOfMission=nil EndTimeOfMission=nil LastStartTimeofTimer=nil SearchAndRescueActive="No" SearchAndRescueStartTime=0 SARinSea="Unknown" Logic = 'DippyLogic' --Ace L- ThisSide = ScenEdit_PlayerSide() --The Actual Name of the Player Side SARRefPointName="DIPPYSAR" ------------------------------------------------------------------------------------------------------------------------------------------ function Dippy_EventUnitDestroyed() WhichUnit=ScenEdit_UnitX() if (WhichUnit.Type == "Weapon") then --ignore weapon destruction else if(WhichUnit.name=="MyTimer" and WhichUnit.side==Logic ) then IsAirborn=ScenEdit_SetUnit({side=Logic,name="MyTimer",newname="WillBeDeleted"}) -- rename so that MyTimer cant see it - it will be removed at the end of this function call MyTimer() else if (WhichUnit.side == ThisSide ) then if(SearchAndRescueActive == "Yes" ) then ScenEdit_SpecialMessage(ThisSide,"Pilot is down - You dont have enough resources to rescue - We will inform their Family" ) else MissionSearchAndRescue(WhichUnit) end end end end end function Dippy_EventUnitEntersArea() WhichUnit=ScenEdit_UnitX() if (WhichUnit.Type == "Weapon") then --ignore weapon destruction else if (WhichUnit.side == ThisSide ) then -- it will see the wreck and raft in the area if ( SearchAndRescueActive == "Yes" and WhichUnit.type =="Aircraft" ) then -- and IsThisSARUnit(WhichUnit) == "Yes" ) then MissionSearchAndRescuePickup() end end end end ------------------------------------------------------------------------------------------------------------------------------- function StartTimer() --rename the old timer - no longer needed - it will die eventually IsAirborn=ScenEdit_GetUnit({side=Logic,name="MyTimer"}) -- rename so that MyTimer cant see it - it will be removed at the end of this function call if( IsAirborn == nil) then -- unit doesnt exist else IsAirborn=ScenEdit_SetUnit({side=Logic,name="MyTimer",newname="WillBeDeleted"}) -- rename so that MyTimer cant see it - it will be removed at the end of this function call end --setup the new timer LastStartTimeofTimer=ScenEdit_CurrentTime() print("Timer Start " .. LastStartTimeofTimer) ScenEdit_AddUnit({side=Logic,type = "Air",dbid = MyTimerdbid,name="MyTimer",Longitude='48.2602325920361',Latitude='-86.7030485451788',altitude=1000,Loadoutid=MyTimerloadout,heading = 180}) IsAirborn=ScenEdit_GetUnit({side=Logic,name="MyTimer"}) UnitFuel=IsAirborn.fuel for k,v in pairs( UnitFuel ) do UnitFuel[k].current=3.333333 --about 10mins for Cesna (dbid 312) end IsAirborn.fuel=UnitFuel end function MyTimer() TimeNow=ScenEdit_CurrentTime() IsAirborn=ScenEdit_GetUnit({side=Logic,name="MyTimer"}) -- Shouldnt be in timer because timer plane is still flying if( IsAirborn == nil ) then if(SearchAndRescueActive=="Yes" ) then if ( TimeNow > (SearchAndRescueStartTime + (MaxMinutesToRescue*60)) ) then MissionSearchAndRescueFailed() end end StartTimer() end end -------------------------------------------------------------------------------------------------------------------------------- function MissionSearchAndRescue(WhichUnit) if( SearchAndRescueActive == "No" ) then SearchAndRescueStartTime=ScenEdit_CurrentTime() CreatePlaneWreck(ThisSide,WhichUnit,"Active Plane Wreck") TestWater=ScenEdit_GetUnit({side=ThisSide,name="Active Plane Wreck" }) if ( TestWater==nil) then print("wreck is in water - deployed life raft") CreateLifeRaft(ThisSide,Which,"Active Pilot Raft") SARinSea = "Yes" LocationType="in a liferaft at sea" else SARinSea = "No" LocationType="hidden near the wreck on land" end moveReferencePointBox (Logic,SARRefPointName,WhichUnit,SARAreaMiles,SARAreaMiles) ScenEdit_SpecialMessage(ThisSide,"Pilot is down " .. LocationType .. " at Long: " .. WhichUnit.longitude .. " Lat: " .. WhichUnit.Latitude .. " Get them before the OPFOR does" ) SearchAndRescueActive = "Yes" end end function MissionSearchAndRescuePickup() ScenEdit_SpecialMessage(ThisSide,"Pilot is picked Up Safely - Mission is OVER - but get them back to Safety" ) -- delete plane wreck or liferaft if(SARinSea == "No") then ScenEdit_SetUnit( {side=ThisSide,name="Active Plane Wreck",newname="Saved Pilot Wreck"}) else ScenEdit_SetUnit( {side=ThisSide,name="Active Plane Raft",newname="Saved Pilot Raft"}) end SARinSea="Unknown" SearchAndRescueActive="No" end function MissionSearchAndRescueFailed() ScenEdit_SpecialMessage(ThisSide,"Pilot is Captured - Mission is OVER - We will inform their family" ) -- delete plane wreck or liferaft if(SARinSea == "No") then ScenEdit_SetUnit( {side=ThisSide,name="Active Plane Wreck",newname="Captured Pilot Wreck"}) else ScenEdit_SetUnit( {side=ThisSide,name="Active Plane Raft",newname="Captured Pilot Raft"}) end SARinSea="Unknown" SearchAndRescueActive="No" end function IsThisSARUnit(WhichUnit) -- not called until I can look at unit dbid for k,v in pairs( F_Air_SAR ) do if (WhichUnit.type == v[1]) then return "Yes" end end return "No" end -------------------------------------------------------------------------------------------------------------------------------------------------- function CreatePlaneWreck(WhichSide,CentreMarker,WhichName) ScenEdit_AddUnit({type="Land",name= WhichName,side=WhichSide, DBID= DIPPYWreckdbid , Lon=CentreMarker.Longitude+LOmile( 0.0),Lat=CentreMarker.Latitude+LAmile( 0.2)}) end function CreateLifeRaft(WhichSide,CentreMarker,WhichName) ScenEdit_AddUnit({type="Land",name= WhichName,side=WhichSide, DBID= DIPPYRaftdbid, Lon=CentreMarker.Longitude+LOmile( 0.0),Lat=CentreMarker.Latitude+LAmile( 0.2)}) end function LAmile(Latty) Temp= Latty / 2 / 60 return Temp end function LOmile(Longy) Temp= Longy / 2 / 46.09 return Temp end function moveReferencePointBox(WhichSide,ReferenceName,CentrePointUnit,Width,Height) WidthLon=LOmile(Width) HeightLat=LAmile(Height) ScenEdit_SetReferencePoint({side=WhichSide,name=ReferenceName .. "1", Longitude=CentrePointUnit.Longitude-WidthLon,Latitude=CentrePointUnit.Latitude+HeightLat, highlighted=0}) ScenEdit_SetReferencePoint({side=WhichSide,name=ReferenceName .. "2", Longitude=CentrePointUnit.Longitude+WidthLon,Latitude=CentrePointUnit.Latitude+HeightLat, highlighted=0}) ScenEdit_SetReferencePoint({side=WhichSide,name=ReferenceName .. "3", Longitude=CentrePointUnit.Longitude+WidthLon,Latitude=CentrePointUnit.Latitude-HeightLat, highlighted=0}) ScenEdit_SetReferencePoint({side=WhichSide,name=ReferenceName .. "4", Longitude=CentrePointUnit.Longitude-WidthLon,Latitude=CentrePointUnit.Latitude-HeightLat, highlighted=0}) end ---------------------------------------------------------------------------------------------------------------------------------- StartTimer()