External Scripting Quickstart – Arma 2

From Bohemia Interactive Community
Revision as of 00:56, 6 February 2011 by RKurtzDmitriyev (talk | contribs) (create page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

So you want to dive into the wonderful world of external scripting for ArmA 2 or ArmA 2: OA? No problem! Simply follow the steps below to create a very simple, and hopefully amusing, external script.


Quickstart

1. Open the mission editor and place a player unit. Save the mission. This step will create a new mission folder.

2. Shut down ArmA2, or use ALT+TAB to minimize it while you work on your script.

3. Create a text file using Windows Notepad or a similar basic text editor.

4. In the text file, type the code below. Don't forget the semicolons! (You may copy-and-paste the code if you wish, but when learning to script, it may be helpful to type the code by hand.)

sleep 1;

hint "I think";

sleep 3;

hint "Therefore, I am!";

sleep 4;

player setDammage 1

5. Save the text file to the mission folder that you created in Step 1. The mission folder should be My Documents>>ArmA2>>Missions>>MissionName, or My Documents>>ArmA2 Other Profiles>>Your Username>>missions>>MissionName.

6. Rename the text file myFirstScript.sqf . Be sure that the file extension is changed to .sqf!

7. Enter the ArmA2 mission editor once again, and load the mission you created in Step 1.

8. Create a trigger, with conditions "Radio Alpha." In the "On Activation" field, type

script = [] execVM "myFirstScript.sqf"

When the trigger is activated, this line of code will tell the game to execute myFirstScript.sqf .

9. Save and preview the mission.

10. Press Radio Alpha (0-0-1). This should activate the external script. Two "hints" should display below your ammo readout. Then, your character will drop dead a few seconds later (from the profundity of his philosophical insight).

If it doesn't work, check to make sure that you typed everything correctly. Enable script error reports with the -showScriptErrors startup parameter, and see if the error report tells you anything.


Where do I Go from Here?

One variation you can try is creating a unit named rene and replacing player with rene in your new external script. Now watch what happens.

But you can do much more with scripting than displaying text and making people die! If you've ever entered little lines of code into the mission editor--in initialization fields or "on activation" trigger fields--then you already know some scripting commands. All of those commands will work in external scripts, too. There are also some commands that work only in external scripts, like sleep, which creates a time delay. Experiment around a bit!

Some fun commands for beginners:

If you run into a bug, don't fret! Once again, enable script error reports with the -showScriptErrors startup parameter, and see if the error report tells you anything. Also, all script errors are recorded in log files called arma2.rpt and arma2OA.rpt found under Documents and Settings >> Username >> Local Settings >> Application Data >> ArmA 2 and >> ArmA 2 OA).

All of the scripting commands are documented here at the BIKI and also at OFPEC. If you have a question, try searching the official forums and the OFPEC forums.


See Also