Get SaintAxe&Ror SpeechMaker Now
And build your conversations easily !
 
Using OFDR Mission Editor - How-To
 

This is a page that displays some short How-To to help using OFDR Mission Editor for basic mission editing.
These How-To are not the "best way" or are not endorsed by CodeMasters in any way. They are just the result of the long time I spent coding a lot of Single Player / Coop missions with simple and complex scripting (+ 115) .

Link : Official LUA Documentation

 
 
Back to summary
 

HOWTO 1 : Working with helo

This is a very simple mission that shows you how to work with a helicopter.

The scenario is :
The player echelon (echSAR) moves forward, following the yellow flags, then triggers the helo. The helicopter + the crew are spawned, the helo flies away and land at a given location marked with green smoke. Then the echelon mount the helo. When all the team is mounted, the helo takes-off and fly away to the sea. End of the story.

Here is the complete level.lua :

-- -------------------------------------------------------- --
--    __       _       _     _              __              --
--   / _\ __ _(_)_ __ | |_  /_\ __  _____  /__\ ___  _ __   --
--   \ \ / _` | | '_ \| __|//_\\\ \/ / _ \/ \/// _ \| '__|  --
--   _\ \ (_| | | | | | |_/  _  \>  <  __/ _  \ (_) | |     --
--   \__/\__,_|_|_| |_|\__\_/ \_/_/\_\___\/ \_/\___/|_|     --
--                                                          --
-- -------------------------------------------------------- --


-- OFP Dragon Rising
-- HOWTO 1 : Working with helo
-- Author : Thierry Godin (SaintAxe&Ror)
-- Web : http://sar.n1bus.eu
-- Date de creation : 01/01/2012

function onCreate()
	-- Speech
	conversations = scripts.library.convLib.convLib:new()
	speech()
end

function onMissionStart()
	
	OFP:displaySystemMessage("HOWTO 1 : Working with helo - 1.0.0")
	OFP:displaySystemMessage("Thanks for playing SaintAxe&Ror mission")
	OFP:displaySystemMessage("Other stuff here = http://sar.n1bus.eu")
	OFP:displaySystemMessage("Have fun !")  
	
	OFP:setObjectiveState("objHelo", "IN_PROGRESS")
	OFP:setObjectiveVisibility("objHelo", true)
	
	OFP:setInvulnerable("echSAR", true)	
	OFP:activateRVChain("RVPoint")
end

-- ---------------------------------------------------------------
-- COMMON
-- ---------------------------------------------------------------
function isAllInSameVehic(echelonName, vehicleName)
     local size = OFP:getEchelonSize(echelonName)
     local fullSize = OFP:getEchelonFullSize(echelonName)
     local inSameVehic = 0

     for i = 0, fullSize -1 , 1 do
         local mate = OFP:getEchelonMember(echelonName, i)
         if OFP:isAlive(mate) then
	         if OFP:getMountedVehicle(mate) == string.lower(vehicleName) then
	             inSameVehic = inSameVehic + 1
	         end
	     end
     end

     if inSameVehic == size then
          return true
     else
          return false
     end
end
-- -------------------------------

-- ---------------------------------------------------------------
-- SPAWN
-- ---------------------------------------------------------------
function onSpawnedReady( setName, setID, tableOfEntities, errorCode )
        if setID == setHeloID then
		OFP:setMood("eSarHelo", "EMoodCautious", "ADDTOEND")
		OFP:addTimer("TimerHelo", 7000)
	end
end
-- -------------------------------

-- ---------------------------------------------------------------
-- LZ
-- ---------------------------------------------------------------
function onEnter_trigLz(zoneName, unitName)
	if OFP:isInEchelon(unitName, "echSAR")then
		setHeloID = OFP:activateEntitySet("setHelo")
		conversations:start(spArriveAtLz)
		OFP:disableEvent("onEnter_trigLz")
	end
end

function onTimer_TimerHelo()
	OFP:removeTimer("TimerHelo")
	OFP:setVehicleMountableStatus("sarHelo", 1)
	OFP:startParticleSystem("psSmoke", 0)
	OFP:move("eSarHelo", "wpHeloInp", "ADDTOEND")
end

function onArriveAtWaypoint_sarHelo_xpHeloIn(entityName, waypointName)
	OFP:stopParticleSystem("psSmoke")
	conversations:start(spMountHelo)
	OFP:disableEvent("onArriveAtWaypoint_sarHelo_xpHeloIn")
end

function onMount_sarHelo(vehicleName, unitName, echelonName)
	if OFP:isInEchelon(unitName, "echSAR")then
		if isAllInSameVehic("echSAR", "sarHelo") then
			conversations:start(spAllInHelo)
			OFP:takeoff("eSarHelo", "ADDTOFRONT")
			OFP:move("eSarHelo", "wpHeloOutp", "ADDTOEND")	 
			OFP:setObjectiveState("objHelo", "COMPLETED")
			OFP:disableEvent("onMount_sarHelo")
		end
	end
end
-- -------------------------------

-- ---------------------------------------------------------------
-- SPEECHS 
-- ---------------------------------------------------------------
function speech()   
    spAllInHelo = conversations:add({
    {actor = "player", say = "spc3_x12_hid_04"},       -- All in - get us out of here!
    }, true);  

    spArriveAtLz = conversations:add({
    {actor = "player", say = "dem1_10_m06_01"},        -- We are at the LZ, where are you?
    {actor = "radio", say = "dem1_15_del_01"},         -- We have to land… right now… pop smoke and stand by for evac.
    {actor = "player", say = "inf1_15_hun_01"},        -- Roger that.
    {actor = "player", say = "sf_smoke_away"},         -- Smoke away!
    }, true);   

    spMountHelo = conversations:add({
    {actor = "player", say = "inf3_12_hun_01"},        -- Ok, let's do this. Mount up.
    }, true); 
end

function onSpeechEnd(entity, speech, id)
	finished = conversations:onEnd(id);
end
-- -------------------------------

function onEnter_trigEnd(zoneName, unitName)
	if OFP:isInEchelon(unitName, "echSAR") then
		if OFP:getObjectiveState("objHelo") == "COMPLETED"	then
			OFP:missionCompleted()
		else
			OFP:missionFailed()
		end
	end
end

function onAllPlayersDead()
	OFP:missionFailedKIA();
end
 



1. The echelon moves forward and follows the flags : nothing to add. Simple.

2. The echelon enters the triggerzone called "trigLz" : We activate the entityset that contains the helicopter + the crew.

function onEnter_trigLz(zoneName, unitName)
	if OFP:isInEchelon(unitName, "echSAR")then
		setHeloID = OFP:activateEntitySet("setHelo")
		conversations:start(spArriveAtLz)
		OFP:disableEvent("onEnter_trigLz")
	end
end
 


First, we check that one unit of the echelon player (echSAR) enters the triggerzone. We do not want that the event to be triggered by another unit (PLA ?) . In the same time, we let's talk the voice (sentence) to make the story more "alive". Once triggered, we de-acivate the event. Not de-activating the event will causes the event being fired several times (and the sentence too). Game would probably do nothing, sometimes crash or freeze ...

3. Activating the Helo Set : Before the Helo starts flying, we verify that all are rendered properly

function onSpawnedReady( setName, setID, tableOfEntities, errorCode )
        if setID == setHeloID then
		OFP:setMood("eSarHelo", "EMoodCautious", "ADDTOEND")
		OFP:addTimer("TimerHelo", 7000)
	end
end
 


We use the onSpawnedReady function to be sure that all the units and vehicles are really in-game (rendered). Then we can set the units/vehicles because they exist now. I always use a timer for cosmetics : I mean, sometimes, the engine says "Hey buddy, it's okay, the helo and the units are here . They are well rendered !" but in fact, there is some decay and they are really visible a few seconds later. So, I activate them in a hidden location , or far . Then After a few seconds (Timer) I can use them.

4. Now Helo can Fly :

function onTimer_TimerHelo()
	OFP:removeTimer("TimerHelo")
	OFP:setVehicleMountableStatus("sarHelo", 1)
	OFP:startParticleSystem("psSmoke", 0)
	OFP:move("eSarHelo", "wpHeloInp", "ADDTOEND")
end
 


When the Timer is Fired, We start the green smoke, set the helo mountable in passenger seats only, finally the helo can move along the path.

5. Helo lands :
We set the last waypoint height to 0 (ground) . That way, without any else command or order, the helo will land at the waypoint (because it's on the ground)

function onArriveAtWaypoint_sarHelo_xpHeloIn(entityName, waypointName)
	OFP:stopParticleSystem("psSmoke")
	conversations:start(spMountHelo)
	OFP:disableEvent("onArriveAtWaypoint_sarHelo_xpHeloIn")
end
 


In the same time, we stop the green smoke (because in-game we see nothing !) and the voice says "We can mount the helo".

6. The echelon mount the helicopter :

function onMount_sarHelo(vehicleName, unitName, echelonName)
	if OFP:isInEchelon(unitName, "echSAR")then
		if isAllInSameVehic("echSAR", "sarHelo") then
			conversations:start(spAllInHelo)
			OFP:takeoff("eSarHelo", "ADDTOFRONT")
			OFP:move("eSarHelo", "wpHeloOutp", "ADDTOEND")	 
			OFP:setObjectiveState("objHelo", "COMPLETED")
			OFP:disableEvent("onMount_sarHelo")
		end
	end
end
 


We want the entire team is mounted BEFORE the helo takes-off. We use a special function : isAllInSameVehic to be sure that all the units of the team are in the same helicopter. Then the helo can take-off and fly to the end. In the same time we make the objective COMPLETED.

Download

Download MSSN file : SAR_HT1_Helo.zip

 
Back to summary