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 6 : Using the onEnter() event

I read a ton of code examples on CM forum that did not use the onEnter event as it should be used. I mean, when you put a Trigger Zone on the map, you plan to trigger something (an event) when somebody enters the Trigger Zone. But most of the time (maybe 99%) , it's planned to be triggered by a particular unit or group.

So, You should check if the one that entered the trigger Zone (and has triggered the event) is really the one you waited for .
Most of the time, the code I read on CM forums did not check that at all. Then the event could be triggered by anyone (PLA unit or USM unit, or vehicles).

- Say, we put a Trigger Zone on the map called "trigZone1 ".
- Say, we have an echelon called "playerEchelon " (each member is called "player1, player2, playerx...)

The Trigger Zone "trigZone1 " is used to trigger an event when a unit of the "playerEchelon " enters the zone.

Here is how to check if the unit that enters the trigger is part of the "playerEchelon" :

function onEnter_trigZone1(zoneName, unitName)
	if OFP:isInEchelon(unitName, "playerEchelon") then
		-- do what you whant
		OFP:disableEvent("onEnter_trigZone1")
	end
end
 


In the code above, I use the OFP:isInEchelon() function.
If I had not checked that, a PLA unit could have triggered the event and the entire mission may not work as I planned.


Also, do not forget to disable the event if it is not needed once it has been triggered.
In the above case, if i do not disable the event and if the entire playerEchelon enters the trigger zone, the event will be fired each time a unit enters the zone (ie : 4 times).

For example, if you activate an entityset at this time, the entityset may not spawn at all because it has been called several times at once and the game engine become confused.

You can also check if the unit that enters the trigger zone is part of a group :

function onEnter_trigZone1(zoneName, unitName)
	if OFP:isInGroup(unitName, "groupUSM") then
		-- do what you whant
		OFP:disableEvent("onEnter_trigZone1")
	end
end
 


Or you can check if a given unit enters the zone:

function onEnter_trigZone1_player1(zoneName, unitName)
	-- do what you whant
	OFP:disableEvent("onEnter_trigZone1_player1")
end
 


Important :
- Check WHO enters a triggerZone
- Disable an event when it has been fired (if not needed anymore)

 
Back to summary