Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
0 Active | 72 Guests
Online:

LATEST FORUM THREADS

»
CoD: Battle Royale
CoD+UO Map + Mod Releases
Damaged .pk3's
CoD Mapping
heli to attack ai
CoD4 SP Mapping

Tutorials

»
OFP2
ratings:
Awful Rating
Poor Rating
Average Rating
Good Rating
Excellent Rating
Lua scripting advanced
Versions: You must be logged in to view history.

Advanced Lua scripting.

Lua Arguments

Each Lua command requires a set of inputs and conditions, these inputs vary from command to command. Many of the commands can be found in the Appendix, with details of how to get them to work.

Here is a common line of Lua script requiring multiple arguments:



When you are referencing an entity in Lua, you have to use the correct Name that they have been given (either by the Mission Editor or by you in the Modify tab when the entity is selected) in order to issue commands to them correctly. These names have to be written with the same lowercase lettering and be flanked by speech marks (“”) when referenced in Lua.

Some functions and scripts require the use of Arguments (or conditions); to be referenced by the script so functions can work. Arguments also have to be referenced in the same way as Names, unless they are a variable or number.
 

 


Lua Colour Coding

The script editor tab/page appears once you have placed a Level Script entity on the map. Like many of today's popular programming languages, the text that you type in to the script page can appear in varying colours. The colour of the text will depend on the script type, for example keywords, comments and variables. The scripting colourisation of the text can help you indentify particular formatting errors and typing mistakes such as missing quote marks.

You can see the different colour coding used in the Lua Editor in the following table.

Colour

Script Type

Example(s)

Green

Commented code

-- Mission Created 22-0609

Blue

Keywords

function, end, if, else if, and, or, then

Teal

OFP Script Command

onCreate(), OFP:damageVehicle();

Black

Variable

patrolcamp = 0

Brown

Entity or Argument name

“destlav00”

Brown

Number

patrolcamp = 0

You can see an example of this colour coding in the following Figure:

 

 


Lua Menu

You can access some of the Lua editor features by right mouse clicking on the Lua editor screen. On right clicking you will see a pop-up menu appear as shown in the Figure below.

Cut: Remove any select text and place its contents in the clipboard.
Copy: Make a copy of any selected text in the editor and place its contents in the clipboard.
Paste: Paste any text that is currently stored in the clipboard.
Undo: Undo any changes made.
Redo: Redo any changes made.
Find: Find a particular string. This is very useful for finding particular functions.
Replace: This will allow you to find a particular text item and replace it with another.
Go To Line: Each line in the Lua editor is numbered, this option allows you to jump to a particular line. This is very useful in very long script pages.
Outlining: Toggle Outlining Expansion: This option is selected by default. All functions will contain a line encompassing all of code within it, allowing the user to collapse or expand any functions.
Outlining: Stop Outlining: The code can no longer be collapsed.
Outlining: Collapse To Definition: Collapses all related code, and will display the definition type, for example function.

 


Creating Comments

Adding comments to your code is very important to ensure readability and clarity, especially if you haven’t looked at the code for some time .If you intend to make missions with a group of people then commenting the code is particularly useful as this will allow them to understand what a piece of code is trying to do rather than having to read the code line by line.

To create a comment you have to access the Lua script file level.lua and place a -- in front of any text. You can see an example of comments in use in the Figure below.

You can also block out whole sections of code using --[[ at the beginning and ]] at the end of any section of code that you want to comment out.

Some things that you can use comments for in your mission:

  • The mission name
  • Date it was created
  • The author(s) of the mission
  • Current version number of the file
  • Any specific mission details, how the mission works
  • Creating a section header for particular code
  • Explaining difficult code in more detail

 



OFP Prefix

You need to put "OFP:" prefix before every OFP specific script command – e.g.: OFP: guard("alpha", "entrance", "CAddToFront").

The entity and group names cannot contain "_"




Variables

You can use variables to store numeric, text or bool values . Variables are useful for storing, retrieving and comparing values at any time in your game. For example you could create a variable that stores the number of AI enemy soldiers that have been killed, and then create a function that runs when this value hits a certain target. The function could be to play a sound, display a message or send more enemy troops to attack the player.

To create a variable you need to specify the variables name and its value:





Using Secondary Level Scripts

It is not mandatory to put all the script codes to one file. You can add secondaryScript entities to your mission, and there you can specify your additional script-file by the scriptName parameter.

You have to specify a category which will be identifier of your secondary script – when you want to use its functions from another scripts you have to use this ID as a prefix (e.g. enemy.startAttack("")).

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»