luafunctionref
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| luafunctionref [2025/01/08 17:56] – bredroll | luafunctionref [2025/05/05 07:05] (current) – [update] bredroll | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== CC2 Lua Functions | + | ====== CC2 Lua ====== |
| This is a (not exhaustive) reference for functions available to be called in the lua scripts used for screen rendering/ | This is a (not exhaustive) reference for functions available to be called in the lua scripts used for screen rendering/ | ||
| + | |||
| + | CC2 has various lua scripts that directly drive what information you see on screens, in the control seat and ship cameras. They are the way players choose to refit units, set waypoints, see and identify threats. | ||
| + | |||
| + | * screen | ||
| + | * draw the user interface for each bridge station | ||
| + | * hud | ||
| + | * draw the heads-up-display when in direct control of a unit | ||
| + | * library | ||
| + | * shared code usable in screens or hud scripting. | ||
| + | |||
| + | ===== Script Environment ===== | ||
| + | |||
| + | ==== Loading ==== | ||
| + | |||
| + | Each screen on the carrier gets its own Lua interpreter instance. Setting globals at runtime in the script will not have any effect on other screens running the same script. The same is true of the HUD except there is only ever one instance if vehicle_hud.lua running on your PC. | ||
| + | |||
| + | Scripts have the following load order: | ||
| + | |||
| + | * library_enum.lua | ||
| + | * library_util.lua | ||
| + | * library_vehicle.lua | ||
| + | * library_ui.lua | ||
| + | * library_custom_X.lua | ||
| + | * screen/hud | ||
| + | |||
| + | ==== Execution ==== | ||
| + | |||
| + | The whole of each file is evaluated in the same lua interpreter. If you set a global outside of a function in library_enum.lua then you will be able to see the value in library_util.lua and later. | ||
| + | |||
| + | === begin === | ||
| + | |||
| + | Once this is complete, the game will call the '' | ||
| + | |||
| + | === game === | ||
| + | |||
| + | Now that the script is loaded and begin has been called, the input and update functions will be called. These are called once per " | ||
| + | |||
| + | When a player is using the HUD, the update rate of other scripts is reduced to once every 30 ticks (1 time per second), and the input functions are not called. The HUD update function is only called when a player is in the HUD view. | ||
| + | |||
| + | ==== input ==== | ||
| + | |||
| + | During the input cycle, the core game makes calls to the '' | ||
| + | |||
| + | ==== update ==== | ||
| + | |||
| + | Next is the update cycle, most of the heavy lifting goes on in here, these are where you can introspect the current vehicle, carrier details, weapons, map, nearby units, other players, missiles, etc. graphical/ | ||
| + | |||
| + | === Refresh Rate === | ||
| + | |||
| + | I have recently discovered there is another factor that influences how often a script '' | ||
| + | |||
| + | |||
| + | ==== Functions ====== | ||
| ---- | ---- | ||
| Line 7: | Line 60: | ||
| Native/C function | Native/C function | ||
| + | |||
| + | Can be called only during the '' | ||
| + | |||
| + | Returns the name value of the currently executing screen. This is the value set in ''< | ||
| + | |||
| + | < | ||
| + | <screen name=" | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | help_tag=" | ||
| + | </ | ||
| + | |||
| + | If called within a '' | ||
| Usable in: | Usable in: | ||
| - | * screen_inventory.lua | + | * screen_*.lua |
| - | * screen_navigation.lua | + | |
| Example call: | Example call: | ||
| Line 21: | Line 91: | ||
| Native/C function | Native/C function | ||
| + | |||
| + | Can be called only during the '' | ||
| + | |||
| + | Return the index number for a specific UI icon image. | ||
| Usable in: | Usable in: | ||
| Line 89: | Line 163: | ||
| Lua defined function in library_vehicle.lua | Lua defined function in library_vehicle.lua | ||
| + | |||
| + | Called early in '' | ||
| Usable in: | Usable in: | ||
| Line 107: | Line 183: | ||
| Lua defined function in interactions.lua | Lua defined function in interactions.lua | ||
| + | |||
| + | Call to display the on-screen control hints in the bottom left of the screen. | ||
| Usable in: | Usable in: | ||
| Line 1129: | Line 1207: | ||
| Native/C function | Native/C function | ||
| + | |||
| + | Return '' | ||
| Usable in: | Usable in: | ||
| Line 1186: | Line 1266: | ||
| Native/C function | Native/C function | ||
| + | |||
| + | Return the localized string for the given index word/phrase from the '' | ||
| + | < | ||
| + | update_get_loc(e_loc.upp_paste) | ||
| + | </ | ||
| + | Will return " | ||
| Usable in: | Usable in: | ||
| Line 1229: | Line 1315: | ||
| Native/C function | Native/C function | ||
| + | |||
| + | Get the ID of the current player. | ||
| Usable in: | Usable in: | ||
| Line 1242: | Line 1330: | ||
| Native/C function | Native/C function | ||
| + | |||
| + | Get the team ID of the current player. | ||
| Usable in: | Usable in: | ||
| Line 1256: | Line 1346: | ||
| Native/C function | Native/C function | ||
| + | |||
| + | Get the logic tick. This is the game simulation counter starting at zero the moment the map is crated. It increments by one every simulation frame. The game is tuned such that a second of real time covers 30 game ticks. | ||
| + | |||
| + | During the span of an '' | ||
| + | |||
| + | It can be thought of as a primitive low-res clock. | ||
| Usable in: | Usable in: | ||
| Line 1275: | Line 1371: | ||
| Native/C function | Native/C function | ||
| + | |||
| + | Get an object representing a recently destroyed vehicle. Used along with '' | ||
| + | |||
| + | Destroyed vehicles have several methods. | ||
| + | |||
| + | * '' | ||
| + | * get a '' | ||
| + | * '' | ||
| + | * get the team ID of the destroyed vehicle | ||
| + | * '' | ||
| + | * get float in range 0-1 based on the age of destruction, | ||
| Usable in: | Usable in: | ||
| Line 1288: | Line 1395: | ||
| Native/C function | Native/C function | ||
| + | |||
| + | Get the number of destroyed vehicles visible on the game map. | ||
| Usable in: | Usable in: | ||
| Line 1301: | Line 1410: | ||
| Native/C function | Native/C function | ||
| + | |||
| + | Get an object representing a player or AI controlled unit in game, the unit may be docked or active. | ||
| + | |||
| + | The HUD can obtain 3D position (lat-lon-alt) information about a unit where the screen scripts can only obtain 2D (lat-lon). The HUD can also not see unit waypoints where as screens can fully get/set waypoint data. | ||
| + | |||
| + | vehicle objects have many methods, the most commonly used are: | ||
| + | |||
| + | * '' | ||
| + | * locking/ | ||
| + | * '' | ||
| + | * get the vehicle ID number. | ||
| + | * '' | ||
| + | * get the vehicle type (a value in the '' | ||
| + | * '' | ||
| + | * get the vehicle team number | ||
| + | * '' | ||
| + | * get the vehicle team number | ||
| + | * '' | ||
| + | * get the vehicle 2D position as a '' | ||
| + | * '' | ||
| + | * get the vehicle 3D position as a '' | ||
| + | |||
| Usable in: | Usable in: | ||
luafunctionref.1736358990.txt.gz · Last modified: 2025/01/08 17:56 by bredroll
