OFP:DR LUA Tutorial 1

October 24th, 2009 | Tags: , , , , , , ,

:edit – 12 Nov 09: I’ve rewritten the lua scripts for this mission and will now share it with you. I will assume you know how to create a simple mission and set up the entities in the map panel. If not, please refer to one of the many tutorials on the OFP:DR mission editor forums.

First thing’s first, you need to create your playing field and set up your entities. You will need the following:

- 3 vehicles (destructible ones)
- 1 level script
- 1 mission objective
- 1 fireteam

You will need to set up your Mission Objective marker and set the objective text and everything like that, then you want to select the Fireteam’s echelon and Jump to a character within the fireteam. Set control mode to “player” and leave the rest as AI or multiplayer. Whichever you wish. Rename the trucks to truck1, truck2, and truck3 (this is just for ease of naming, you can do whatever names you want). Once everything is set up you want to enter the following code to the level.lua panel:

-- onMissionStart().. place everything you want to initialise at the BEGINNING of the mission here..
-- such as setting up primary start objectives like "rendezvous with such and such"
function onMissionStart()
	OFP:setObjectiveState("trucks", "IN_PROGRESS") -- sets objective "trucks" to in prog. makes sense..
	OFP:setObjectiveMarkerVisibility("trucks", true) -- trucks objective marker set to visible
	tP = 0; -- sets variable tP to 0 - more on this soon
end
 
-- custom method, not built into OFP:DR API
-- what it does...
-- when progressCheck() is run
-- if value of tP is 3 then set objective "trucks" to complete
function progressCheck()
	if tP == 3 then
		OFP:setObjectiveState("trucks", "COMPLETED");
	end
end
 
-- the onDeath method can be used in two ways
-- either onDeath_truck1() etc etc and create new blocks for each entity on the kill list.. OR!
-- create an array/table of victims and place everything into a single block statement
function onDeath(victim, killer)
	victim = {truck1, truck2, truck3} -- sets array with all three kill targets' entity names
	tP = tP + 1; -- each time a victim in the above list is killed tP is incremented
	OFP:displaySystemMessage(tP.."/3 trucks destroyed"); -- display console message "value of tP" out of 3 destroyed...
	progressCheck() -- run the block we created above, so when tP increments to a value of 3 (when all are dead) the mission completes.
end
-- easy stuff, eh!?

My map screen looks like this, and my code is as above….

Popularity: 31% [?]

No comments yet.