User Tools

Site Tools


arma2:scripting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
arma2:scripting [2010-07-13 13:13]
snakeman added general editing stuff.
arma2:scripting [2015-06-08 02:24] (current)
Line 1: Line 1:
-====== Scripting ======+====== ​ArmA 2 Scripting ======
  
 ArmA 2 will be largely compatible with Armed Assault. To make porting of content from ArmA as simple as possible, there are few important things: ArmA 2 will be largely compatible with Armed Assault. To make porting of content from ArmA as simple as possible, there are few important things:
Line 9: Line 9:
   * in order to maintain smooth frame rate in real-time content, time limit for all scripts in each frame is enforced by the engine in ArmA 2. Generally speaking, in case of more demanding scripts, be prepared that their result may come way later and also there probably can suffer from significant latency. It is under evaluation if and how possibly allow user scripts to change how much time they may take from the CPU in every frame.   * in order to maintain smooth frame rate in real-time content, time limit for all scripts in each frame is enforced by the engine in ArmA 2. Generally speaking, in case of more demanding scripts, be prepared that their result may come way later and also there probably can suffer from significant latency. It is under evaluation if and how possibly allow user scripts to change how much time they may take from the CPU in every frame.
  
-  * SQS script format will be fully supported in ArmA 2.+  * SQS script format will be fully supported in ArmA 2 (but they should never be used).
  
-**initJIPcompatible.sqf** is automatically started at unknown timebest guess would be when JIP player joins?+**initJIPcompatible.sqf** ​initJIPcompatible.sqf gets called from the MP mission framework (scripts in modules MP directory). A script waits until the player object ​is initialized and execs initJIPcompatible.sqf on clients (all clientseven those that were allready there at mission start as it is basically the same). Has nothing todo with init.sqf.
  
 +[[arma2:​scripting:​basics_of_sqf|Basics of SQF]]
  
-====== Scripting Commands ======+Multiplayer [[arma2:​scripting:​dedicated_server_broadcasting|Dedicated server broadcasting]] to all clients.
  
-There'​s a lot of cool scripts (functions) available in Modules.pbo - especially under "​Functions"​ and even an multiplayer Framework in "​MP"​.+Some [[arma2:​scripting:​code_optimization|Code optimization]] tips.
  
-Since ArmA 2 you must first initialize a variable before you reference it in your scripts. In ArmA, it was not a problem, at least for conditions. +[[arma2:​scripting:​zone_markers|Zone Markers]] creating script ​for warning zones.
-<code cpp> +
-// this will error if myBoolean was not previously defined. +
-if (myBoolean) then { hint "​test"​ }; +
-</​code>​ +
-Usage of isNil is still valid.+
  
 +[[arma2:​scripting:​ied_usage|IED usage]] improvised explosive device usage through script.
  
-===== BIS fnc locations =====+Few more [[arma2:​scripting:​comref|Scripting command reference]] items.
  
-BIS fnc locations+[[arma2:​scripting:​common_scripting_errors|Common scripting errors]] help you to debug your code.
  
-Description:​ Creates or registers location logics (used in various modules, like [[arma2:editor_modules:alice|Ambient Civilians]],​ [[arma2:​editor_modules:​silvie|Ambient Civilian Vehicles]] or Warfare 2).+[[arma2:scripting:group_in_vehicle|Group in Vehicle]] check.
  
-Upon registering,​ function will set following variables into location logic'​s variable space:+[[arma2:scripting:​bis_fnc_spawngroup|BIS_fnc_spawnGroup]] how to create whole groups from CfgGroups class.
  
-  * "​class"​ - unique class of location (either BIS_loc_<​configname>​ or BIS_loc_custom_<​ID>​) +[[arma2:​scripting:​bis_fnc_findsafepos|BIS_fnc_findSafePos]] how to find safe position with open ground etc.
-  * "​name"​ - name of location from config or setName commandIf none is defined, class is used +
-  * "​type"​ - config type +
-  * "​neighbors"​ - config defined neighbor locations ​+
  
-If you're registering currently existing object and some of variables above is already stored in itit won't be replaced.+Global scripts dir or common scripts dir is very useful. This feature has been known since OFPcheck out the details from [[arma:​scripting#​global_scripts_dir|ArmA:​ Scripting - Global scripts dir]], as same feature works in ArmA 2.
  
-Syntax+Howto create and use [[arma2:​scripting:​object-compositions|Object Compositions]] in missions.
  
-Syntax: ​[type(s),​area,​debugcall BIS_fnc_locations+[[arma2:​scripting:​addpublicvariableeventhandler|addPublicVariableEventhandler]examples.
  
-Parameterstype(s)String or Array of strings\\ +[[arma2:scripting:benchmark-cutscene|Benchmark Cutscene]]
-area: Array in format [center,​distance]\\ +
-debug: (Optional): Boolean+
  
-Return Value: Array - List of registered locations +[[arma2:scripting:enablesaving|enableSaving]] and why its useful ​to disable.
- +
-Alternative Syntax +
- +
-Syntax: ​[objects] call BIS_fnc_locations +
- +
-Parameters: objects: Array of Objects or Locations - list of specific locations to be registered +
- +
-Return Value: Array - List of registered locations +
- +
-Examples +
- +
-Example 1: +
-<code cpp> +
-["​CityCenter",​[position player,​1000]] call bis_fnc_locations;​ +
-</​code>​ +
- +
-Example 2: +
-<code cpp> +
-[["​acityc_dolina"​]] call bis_fnc_locations;​ +
-</​code>​ +
- +
-Example 3: +
-<code cpp> +
-[[myLocation1,​myLocation2],​[],​true] call bis_fnc_locations;​ +
-</​code>​ +
- +
-See also: +
- +
-Functions Library (above hehe) +
- +
- +
-===== allowDamage ===== +
- +
-Description:​ Allow an object to be damaged (or injured, or killed). +
- +
-Syntax: object allowDamage allow +
- +
-Parameters: object: Object - allow: Boolean - +
- +
-Example 1: +
-<code cpp> +
-player allowDamage false +
-</​code>​ +
- +
- +
-===== setVariable ===== +
- +
-setVariable now has a 3rd parameter: Global. +
- +
-If you set the 3rd parameter to true, the variable will broadcast its value to every machine. +
-<code cpp> +
-_myObject setVariable ["​myVariable",​ 1, true]; +
-</​code>​ +
- +
-setVariable is now usable on any object, like groups for instance. This was not the case in ArmA. +
- +
- +
-===== uiNameSpace ===== +
- +
-Working with UI related ​scripting ​commands, is not accepted in global or private variable space, and needs to be done inside uiNameSpace by using setVariable. +
- +
-example: +
-<code cpp> +
-// set it +
-uiNameSpace setVariable ["​myVariable",​ ctrl...]+
-// use it +
-ctrl.... (uiNameSpace getVariable "​myVariable"​);​ +
-</​code>​ +
- +
- +
-===== createDiaryRecord ===== +
- +
-createDiaryRecord +
- +
-<code cpp> +
-_diary = player createDiaryRecord ["​Diary",​ ["​Technische Details",​ "​Keine"​]]; +
-</​code>​ +
- +
- +
-===== createSimpleTask ===== +
- +
-createSimpleTask +
- +
-<code cpp> +
-task1 = player createSimpleTask ["​obj1"​];​ +
-</​code>​ +
- +
- +
-===== setSimpleTaskDescription ===== +
- +
-setSimpleTaskDescription +
- +
-<code cpp> +
-task1 setSimpleTaskDescription ["​Description <marker name=""​Start"">​Start</​marker>​ posit.","​more text","​more text"​];​ +
-</​code>​ +
- +
- +
-===== setSimpleTaskDestination ===== +
- +
-setSimpleTaskDestination +
- +
-<code cpp> +
-task1 setSimpleTaskDestination markerPos "​Start";​ +
-</​code>​ +
- +
- +
-===== setTaskState ===== +
- +
-setTaskState +
- +
-<code cpp> +
-task1 setTaskState "​Created";​ +
-</​code>​ +
- +
- +
-===== setCurrentTask ===== +
- +
-setCurrentTask +
- +
-<code cpp> +
-player setCurrentTask task1; +
-</​code>​ +
- +
- +
-===== attachTo ===== +
- +
-attachTo, see also detach. +
- +
-<code cpp> +
-// Make player float exactly 2m above center of car, automatically changing vectordir + relative position as car moves. +
-player attachTo [car, [0,0,2]]; +
-detach player; +
-</​code>​ +
- +
- +
-===== diag_log ===== +
- +
-diag_log writes any variable ([_fish, _frog] or "​Hello,​ I'm starting to initialize myself"​) directly to the log, without needing to pass it via format/​str ​and without any extra text. +
- +
- +
-===== Changing nameSpace ===== +
- +
-You can change namespace inside another namespace. Note that 1 misionNamespace refers ​to the normal global scope and 1 uiNamespace is the one where you are forced to store any control/​display handles: +
-<code cpp> +
-fish = "​Frog!";​ +
- +
-with uiNamespace do +
-+
- // Do some stuff with dialogs here. +
- +
- with missionNamespace do +
-+
- hint fish; // This sees the "​regular"​ mission namespace. +
- }; +
- // Do some more stuff with dialogs here. +
-}; +
-</​code>​ +
- +
-I have no idea what the purpose of 1 parsingNamespace is. +
- +
- +
-===== Access nameSpace ===== +
- +
-The command 1 with gives you a much nicer way to access namespaces and is especially cleaner when making multiple accesses: +
-<code cpp> +
-with uiNameSpace do +
-+
- // Any globals in this block are taken from uiNameSpace. +
- // Any locals are normal locals from current scope. +
- (fishDisplay displayCtrl 102) ctrlSetText _frog; +
- piesControl ctrlSetText _pies; +
- cheeseControl ctrlSetText _cheese; +
-}; +
-</​code>​ +
- +
-Rather than: +
-<code cpp> +
-((uiNameSpace getVariable "​fishDisplay"​) displayCtrl 102) ctrlSetText _frog; +
-(uiNameSpace getVariable "​piesControl"​) ctrlSetText _pies; +
-(uiNameSpace getVariable "​cheeseControl"​) ctrlSetText _cheese; +
-</​code>​ +
- +
- +
-===== fromEditor ===== +
- +
-Return if given team was inserted directly from mission editor.  +
- +
-Syntax: +
- +
-fromEditor teamMember  +
- +
-Parameters:​ +
- +
-teamMember: Team Member +
- +
-Return Value: +
- +
-Boolean  +
- +
-Example: +
-<code cpp> +
-_fromEditor = fromEditor _member; +
-</​code>​ +
- +
- +
-===== addTeamMember ===== +
- +
-Add given member to given team.  +
- +
-Syntax: +
- +
-team addTeamMember member  +
- +
-Parameters:​ +
- +
-team: Team_Member\\ +
-member: Team_Member +
- +
-Return Value: +
- +
-Nothing  +
- +
-Example 1: +
-<code cpp> +
-_team addTeamMember _teamMember;​ +
-</​code>​ +
- +
- +
-===== copyWaypoints ===== +
- +
-Copy the chain of waypoints from source to target group. The target group will start to process waypoints from the first one.  +
- +
-Syntax: +
- +
-groupTo copyWaypoints groupFrom  +
- +
-Parameters:​ +
- +
-groupTo: Group\\ +
-groupFrom: Group +
- +
-Return Value: +
- +
-Nothing +
- +
- +
-===== execFSM ===== +
- +
-Execute the scripted FSM. The FSM file is first searched in the mission folder, then in the campaign scripts folder and finally in the global scripts folder. Returns the FSM handler or 0 when failed.  +
- +
-Syntax: +
- +
-execFSM filename  +
- +
-Parameters:​ +
- +
-filename: - +
- +
-Return Value: +
- +
-Number  +
- +
-Example 1: +
-<code cpp> +
-execFSM "​test.fsm";​ +
-</​code>​ +
- +
-Example 2:\\ +
-execFSM: +
-<code cpp> +
-hndl = [player] execFSM "​group_follow.fsm";​ +
-</​code?​ +
- +
-execVM: +
-<code cpp> +
-hndl = player execVM "​group_follow.sqf";​ +
-</​code>​ +
- +
- +
-====== taskHint.sqf ====== +
- +
-How to make task hints +
- +
-taskHint is relatively useless itself (because it requires too much effort), but there is a script that makes it easier to use. So instead of executing a hint, do this: +
-<code cpp> +
-[objNull, objNull, tskExample1,​ "​SUCCEEDED"​] execVM "​CA\Modules\MP\data\scriptCommands\taskHint.sqf";​ +
-</​code>​ +
- +
-The first 2 arguments are useless so i just send objNull, the 3rd is the task that you've created, and the 4th is the status. +
- +
-Supported task states: "​CREATED",​ "​CURRENT",​ "​CANCELED",​ "​SUCCEEDED"​ and "​FAILED"​. +
- +
-  * This command does not set the state of the task, so you still need to do this command, and the setTaskState command in your trigger. +
-  * It creates the hint in the middle of the screen, not at the right side (this means that taskHint and hint can be used at the same time).+
arma2/scripting.1279026790.txt.gz · Last modified: 2010-07-13 13:13 by snakeman