External Scripting Quickstart – Arma 2
Lou Montana (talk | contribs) m (Text replacement - "\[\[Category: *Arma 2: *([a-zA-Z0-9 :-]+)\]\]" to "{{GameCategory|arma2|$1}}") |
Lou Montana (talk | contribs) m (Text replacement - "{{arma2}}" to "{{GameCategory|arma2|link= y}}") |
||
(15 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
So you want to dive into the wonderful world of [[Script | {{TOC|side}} | ||
{{Feature|informative|See also [[Introduction to Arma Scripting]].}} | |||
So you want to dive into the wonderful world of [[Script File|external scripting]] for {{GameCategory|arma2|link= y}} or [[Arma 2: Operation Arrowhead]]? | |||
No problem! Simply follow the steps below to create a very simple, and hopefully amusing, external script. | |||
== Quickstart == | == Quickstart == | ||
# Open the [[Arma 2: Mission Editor|mission editor]] and place a player unit. Save the mission. This step will create a new mission folder. | |||
# Shut down {{arma2}}, or use {{Controls|Alt|Tab}} to minimize it while you work on your script. | |||
# Create a text file using Windows Notepad or a similar ''basic'' text editor. | |||
# 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.)<sqf> | |||
sleep 1; | |||
hint "I think"; | |||
sleep 3; | |||
hint "Therefore, I am!"; | |||
sleep 4; | |||
player setDamage 1; | |||
</sqf> | |||
# 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>>Arma 2 Other Profiles>>Your Username>>missions>>MissionName''. | |||
# Rename the text file ''myFirstScript.sqf'' . Be sure that the file extension is changed to .sqf! | |||
# Enter the {{arma2}} mission editor once again, and load the mission you created in Step 1. | |||
# Create a trigger. Under "Activation," select "Radio Alpha." In the "On Act." field, type <sqf>scriptHandle = 0 execVM "myFirstScript.sqf"</sqf>When the trigger is activated, this line of code will tell the game to execute {{hl|myFirstScript.sqf}}. | |||
# Save and preview the mission. | |||
# 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 [[Arma 2: Startup Parameters|startup parameter]], and see if the error report tells you anything. | ||
== Where do I Go from Here? == | == Where do I Go from Here? == | ||
Wherever you want to! Experiment with writing different code in the script file you've created. One variation you can try is creating a unit named ''rene'' and replacing ''player'' with ''rene'' in the script. Now watch what happens! | Wherever you want to! Experiment with writing different code in the script file you've created. One variation you can try is creating a unit named ''rene'' and replacing ''player'' with ''rene'' in the script. Now watch what happens! | ||
Line 50: | Line 35: | ||
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 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. | 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 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. | ||
All of the scripting commands are documented [[:Category:Scripting Commands | All of the scripting commands are documented [[:Category:Arma 2: Scripting Commands| here at the BIKI]] and also at {{Link|http://www.ofpec.com/COMREF/|OFPEC}}. If you have a question, try searching the {{Link|http://forums.bistudio.com/|Official Forums}} and the {{Link|http://www.ofpec.com/forum/|OFPEC forums}}. | ||
Here are some fun commands for beginners: | Here are some fun commands for beginners: | ||
Line 57: | Line 42: | ||
* [[addWeapon]] / [[removeWeapon]] | * [[addWeapon]] / [[removeWeapon]] | ||
* [[addMagazine]] / [[removeMagazine]] | * [[addMagazine]] / [[removeMagazine]] | ||
* [[ | * [[setPosATL]] | ||
* [[ | * [[getPosATL]] | ||
== If Something Goes Wrong == | == If Something Goes Wrong == | ||
If you run into a bug, don't fret! Once again, enable script error reports with the -showScriptErrors [[Arma 2: Startup Parameters|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''. | |||
== See Also == | == See Also == | ||
* [[Scripting]] | |||
* [[Script File]] | |||
* [[Introduction to Arma Scripting]] | |||
* [[Arma 2: Editing]] | |||
* [[SQF Syntax]] | |||
* [[Debugging Techniques]] | |||
* [[ArmA: Mission Editing]] | |||
{{GameCategory|arma2|Tutorials}} | |||
{{GameCategory|arma2| Tutorials}} |
Latest revision as of 13:01, 19 March 2024
So you want to dive into the wonderful world of external scripting for Arma 2 or Arma 2: Operation Arrowhead? No problem! Simply follow the steps below to create a very simple, and hopefully amusing, external script.
Quickstart
- Open the mission editor and place a player unit. Save the mission. This step will create a new mission folder.
- Shut down Arma 2, or use Alt + ↹ Tab to minimize it while you work on your script.
- Create a text file using Windows Notepad or a similar basic text editor.
- 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.)
- 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>>Arma 2 Other Profiles>>Your Username>>missions>>MissionName.
- Rename the text file myFirstScript.sqf . Be sure that the file extension is changed to .sqf!
- Enter the Arma 2 mission editor once again, and load the mission you created in Step 1.
- Create a trigger. Under "Activation," select "Radio Alpha." In the "On Act." field, type When the trigger is activated, this line of code will tell the game to execute myFirstScript.sqf.
- Save and preview the mission.
- 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?
Wherever you want to! Experiment with writing different code in the script file you've created. One variation you can try is creating a unit named rene and replacing player with rene in the 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 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.
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.
Here are some fun commands for beginners:
If Something Goes Wrong
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.