Add functions in server GUI

Add AI enum table
Add some missing functions
This commit is contained in:
omltcat 2024-05-20 15:25:25 -04:00
parent fb09e97c37
commit d8022bc029
9 changed files with 373 additions and 10 deletions

View File

@ -1,6 +1,6 @@
# DCS World Lua Definitions
This is a [definition addon](https://luals.github.io/wiki/definition-files/) for [VS Code Lua extension](https://marketplace.visualstudio.com/items?itemName=sumneko.lua). It provides types, classes, functions and enumerators from DCS World Scripting Engine, to help with code completion and prevent errors.
This is a [definition addon](https://luals.github.io/wiki/definition-files/) for [VS Code Lua extension](https://marketplace.visualstudio.com/items?itemName=sumneko.lua). It provides types, classes, functions and enumerators from DCS World Scripting Engine, to help with code completion and prevent errors.
```lua
-- For example
@ -13,9 +13,11 @@ tomcat:getSize()
```
## Credits
These definitions are pulled from Hoggit Wiki [Simulator Scripting Engine Documentation](https://wiki.hoggitworld.com/view/Simulator_Scripting_Engine_Documentation) and permission was granted by Grimes before sharing or this repo. I take no credit for the content. I simply converted it to a format for Lua extension and did some structuring and cleaning.
These definitions are pulled from Hoggit Wiki [Simulator Scripting Engine Documentation](https://wiki.hoggitworld.com/view/Simulator_Scripting_Engine_Documentation) and permission was granted by Grimes before sharing or this repo. I take no credit for the content. I simply converted it to a format for Lua extension and did some structuring and cleaning.
## Current State
At this point, *most* of the mission scripting environment definitions are in place. As I started with the most commonly used ones, some may still be missing. If you find any missing or incorrect definitions, you are welcome to open an issue or a pull request.
Other environments, like hooks and export are mostly uncharted territory. I will be working on when mission is complete. Naturally, I would appreciate any help at the mean time as I am not very familiar with them.
@ -23,9 +25,11 @@ Other environments, like hooks and export are mostly uncharted territory. I will
When this project is more complete, I will PR it to [LLS-Addons](https://github.com/LuaLS/LLS-Addons) so that it can be installed directly from the Lua extension's Addon Manager.
## Installation (for now)
Install the [Lua extension](https://marketplace.visualstudio.com/items?itemName=sumneko.lua) for VS Code.
Create a folder somewhere to store all the Lua addons and clone this repo.
```sh
mkdir lua-addons
cd lua-addons
@ -33,6 +37,7 @@ git clone https://github.com/omltcat/dcs-lua-definitions.git
```
Then add it to VS Code settings:
```json
"Lua.workspace.userThirdParty": [
"/path/to/lua-addons"
@ -40,5 +45,6 @@ Then add it to VS Code settings:
```
## Recommended Extensions
- [DCS Lua Runner](https://marketplace.visualstudio.com/items?itemName=omltcat.dcs-lua-runner)
- Made by me. Execute Lua code in running DCS missions straight from VS Code.
- Made by me. Execute Lua code in running DCS missions straight from VS Code.

View File

@ -15,7 +15,8 @@
"lfs",
"io",
"os",
"mist"
"mist",
"log"
]
}
}

165
library/mission/AI.lua Normal file
View File

@ -0,0 +1,165 @@
---@meta
---@class AI
AI = {
Skill = {
PLAYER = "Player",
CLIENT = "Client",
AVERAGE = "Average",
GOOD = "Good",
HIGH = "High",
EXCELLENT = "Excellent"
},
Task = {
OrbitPattern = {
RACE_TRACK = "Race-Track",
CIRCLE = "Circle"
},
Designation = {
NO = "No",
WP = "WP",
IR_POINTER = "IR-Pointer",
LASER = "Laser",
AUTO = "Auto"
},
TurnMethod = {
FLY_OVER_POINT = "Fly Over Point",
FIN_POINT = "Fin Point"
},
VehicleFormation = {
VEE = "Vee",
ECHELON_RIGHT = "EchelonR",
OFF_ROAD = "Off Road",
RANK = "Rank",
ECHELON_LEFT = "EchelonL",
ON_ROAD = "On Road",
CONE = "Cone",
DIAMOND = "Diamond"
},
AltitudeType = {
RADIO = "RADIO",
BARO = "BARO"
},
WaypointType = {
TAKEOFF = "TakeOff",
TAKEOFF_PARKING = "TakeOffParking",
TURNING_POINT = "Turning Point",
TAKEOFF_PARKING_HOT = "TakeOffParkingHot",
LAND = "Land"
},
WeaponExpend = {
QUARTER = "Quarter",
TWO = "Two",
ONE = "One",
FOUR = "Four",
HALF = "Half",
ALL = "All"
}
},
Option = {
Air = {
id = {
ROE = 0,
REACTION_ON_THREAT = 1,
RADAR_USING = 3,
FLARE_USING = 4,
Formation = 5,
RTB_ON_BINGO = 6,
SILENCE = 7,
RTB_ON_OUT_OF_AMMO = 10,
ECM_USING = 13,
PROHIBIT_AA = 14,
PROHIBIT_JETT = 15,
PROHIBIT_AB = 16,
PROHIBIT_AG = 17,
MISSILE_ATTACK = 18,
PROHIBIT_WP_PASS_REPORT = 19,
OPTION_RADIO_USAGE_CONTACT = 21,
OPTION_RADIO_USAGE_ENGAGE = 22,
OPTION_RADIO_USAGE_KILL = 23,
JETT_TANKS_IF_EMPTY = 25,
FORCED_ATTACK = 26,
PREFER_VERTICAL = 32
},
val = {
ROE = {
WEAPON_FREE = 0,
OPEN_FIRE_WEAPON_FREE = 1,
OPEN_FIRE = 2,
RETURN_FIRE = 3,
WEAPON_HOLD = 4
},
REACTION_ON_THREAT = {
NO_REACTION = 0,
PASSIVE_DEFENCE = 1,
EVADE_FIRE = 2,
BYPASS_AND_ESCAPE = 3,
ALLOW_ABORT_MISSION = 4,
AAA_EVADE_FIRE = 5
},
RADAR_USING = {
NEVER = 0,
FOR_ATTACK_ONLY = 1,
FOR_SEARCH_IF_REQUIRED = 2,
FOR_CONTINUOUS_SEARCH = 3
},
FLARE_USING = {
NEVER = 0,
AGAINST_FIRED_MISSILE = 1,
WHEN_FLYING_IN_SAM_WEZ = 2,
WHEN_FLYING_NEAR_ENEMIES = 3
},
ECM_USING = {
NEVER_USE = 0,
USE_IF_ONLY_LOCK_BY_RADAR = 1,
USE_IF_DETECTED_LOCK_BY_RADAR = 2,
ALWAYS_USE = 3
},
MISSILE_ATTACK = {
MAX_RANGE = 0,
NEZ_RANGE = 1,
HALF_WAY_RMAX_NEZ = 2,
TARGET_THREAT_EST = 3,
RANDOM_RANGE = 4
}
}
},
Ground = {
id = {
ROE = 0,
FORMATION = 5,
DISPERSE_ON_ATTACK = 8,
ALARM_STATE = 9,
ENGAGE_AIR_WEAPONS = 20,
AC_ENGAGEMENT_RANGE_RESTRICTION = 24,
Restrict_AAA_min = 27,
Restrict_Targets = 28,
Restrict_AAA_max = 29
},
val = {
ALARM_STATE = {
AUTO = 0,
GREEN = 1,
RED = 2
},
ROE = {
OPEN_FIRE = 2,
RETURN_FIRE = 3,
WEAPON_HOLD = 4
}
}
},
Naval = {
id = {
ROE = 0
},
val = {
ROE = {
OPEN_FIRE = 2,
RETURN_FIRE = 3,
WEAPON_HOLD = 4
}
}
}
}
}

View File

@ -0,0 +1,16 @@
---@meta
---@class Airbase: CoalitionObject
---@field id_ integer
Airbase = {}
---@enum Airbase.Category
Airbase.Category = {
AIRDROME = 0,
HELIPAD = 1,
SHIP = 2,
}
---Returns a localized string of the airbases's callsign.<br>
---In the case of airbases, the callsign of world airbases is defined by the game. Callsigns for units, farps, or ships can be specified by the user with the mission editor or scripting engine.
---@return string
function Airbase:getCallsign() end

View File

@ -139,9 +139,9 @@ function missionCommands.removeItemForCoalition(coalition, path) end
---@param name string -- The name of the command.
---@param path table | nil -- Optional. Defines whether the command will be in a named submenu.
---@param functionToRun function -- The function to be run when the command is selected.
---@param anyArguement any -- Optional. Any argument to be passed to the function.
---@param ... any -- Optional. Any argument to be passed to the function.
---@return table -- A table indicating where in the F10 menu the command resides.
function missionCommands.addCommandForGroup(groupId, name, path, functionToRun, anyArguement) end
function missionCommands.addCommandForGroup(groupId, name, path, functionToRun, ...) end
---Creates a submenu of a specified name for the specified group. Can be used to create nested submenus. If the path is not specified, submenu is added to the root menu.<br>
---This function returns a table indicating where in the F10 menu the submenu resides.<br>

View File

@ -3,6 +3,16 @@
---@class net
net = {}
---Executes a lua string in a given lua environment in the game.
---@param state 'mission'|'gui'|'server'|'export'|'config' -- The lua environment in the game.<br>
--- `'mission'`: holds current mission <br>
--- `'server'`: GUI (hooks) environment <br>
--- `'export'`: runs $WRITE_DIR/Scripts/Export.lua and the relevant export API <br>
--- `'config'`: the state in which $INSTALL_DIR/Config/main.cfg is executed, as well as $WRITE_DIR/Config/autoexec.cfg. Used for configuration settings <br>
---@param dostring string -- The lua string to be executed.
---@return string -- The result of the lua string execution.
function net.dostring_in(state, dostring) end
---Forces the player to occupy the set slot.<br>
---SlotId matches unit Ids of client aircraft. The exception being Combined Arms slots and multicrew slots. The latter of which have "_X" appended to denote the seat.
---SideID:
@ -55,4 +65,10 @@ function net.lua2json(lua) end
---Converts a JSON string to a lua table.
---@param json string
---@return table
function net.json2lua(json) end
function net.json2lua(json) end
---Kicks a player from the server. Can display a message to the user.
---@param playerId integer -- The id of the player to be kicked.
---@param message string? -- The message to player received after kicked.
---@return boolean
function net.kick(playerId, message) end

View File

@ -66,6 +66,14 @@ function Object:getTypeName() end
---@return vec3
function Object:getVelocity() end
---Returns a boolean value if the object in question has the passed attribute.<br>
---See [Article list of Attributes](https://wiki.hoggitworld.com/view/DCS_enum_attributes) for more details.<br>
---Additionally, attributes for each object are defined within their DB lua file. DB files provided on [github](https://github.com/mrSkortch/DCS-miscScripts/tree/master/ObjectDB) for reference.<br>
---Function also works with Unit, Weapon, Static Object, Scenery Object, Airbase.
---@param attribute string -- The attribute to check for.
---@return boolean -- True if the object has the attribute, false otherwise.
function Object:hasAttribute(attribute) end
---Returns a boolean value if the object in question is in the air.
---@return boolean
function Object:inAir() end

View File

@ -10,20 +10,23 @@
---@field weapon_name string?
---@field target Unit?
---@field comment string?
---@field subPlace number?
---@field place Airbase?
---@field subPlace integer?
---`vec2.x = vec3.x = north`<br>`vec2.y = vec3.z = east`
---@class vec2
---@field x number positive x is north
---@field y number positive y is east
---`vec3.x = north`<br>`vec3.y = up`<br>`vec3.z = east`![](https://www.digitalcombatsimulator.com/upload/medialibrary/c96/Pos3_illustration2.jpg)
---`vec3.x = north`<br>`vec3.y = up`<br>`vec3.z = east`<br>
---![](https://www.digitalcombatsimulator.com/upload/medialibrary/c96/Pos3_illustration2.jpg)
---@class vec3
---@field x number positive x is north
---@field y number positive y is up
---@field z number positive z is east
---A table describing how a unit's local nose, up, right axes translate to world axes using three unit vectors. Also contains its location.<br>`pos.x = vec3` unit vector of nose direction<br>`pos.y = vec3` unit vector of up direction<br>`pos.z = vec3` unit vector of right direction<br>`pos.p = vec3` location of the object![](https://www.digitalcombatsimulator.com/upload/medialibrary/c96/Pos3_illustration2.jpg)
---A table describing how a unit's local nose, up, right axes translate to world axes using three unit vectors. Also contains its location.<br>`pos.x = vec3` unit vector of nose direction<br>`pos.y = vec3` unit vector of up direction<br>`pos.z = vec3` unit vector of right direction<br>`pos.p = vec3` location of the object<br>
---![](https://www.digitalcombatsimulator.com/upload/medialibrary/c96/Pos3_illustration2.jpg)
---@class pos3
---@field x vec3 nose unit vector
---@field y vec3 up unit vector

View File

@ -1,3 +1,151 @@
---@meta
---@class DCS
DCS = {
UNIT_RUNTIME_ID = 1,
UNIT_MISSION_ID = 2,
UNIT_NAME = 3,
UNIT_TYPE = 4,
UNIT_CATEGORY = 5,
UNIT_GROUP_MISSION_ID = 6,
UNIT_GROUPNAME = 7,
UNIT_GROUPCATEGORY = 8,
UNIT_CALLSIGN = 9,
UNIT_HIDDEN = 10,
UNIT_COALITION = 11,
UNIT_COUNTRY_ID = 12,
UNIT_TASK = 13,
UNIT_PLAYER_NAME = 14,
UNIT_ROLE = 15,
UNIT_INVISIBLE_MAP_ICON = 16
}
---Pauses/resumes the simulation. Server-side only.
---@param action boolean -- If true, pauses the server. If false, resumes the server.
---@return nil
---Example: This example pauses the server
---```
---DCS.setPause(true)
---```
---This would resume the server
---```
---DCS.setPause(false)
---```
function DCS.setPause(action) end
---Returns the pause state of a server. True for server is paused, false if server is not paused.
---@return boolean -- True if the server is paused, false otherwise.
function DCS.getPause() end
---Command to stop the mission.
function DCS.stopMission() end
---Command to close the DCS application.
function DCS.exitProcess() end
---Returns whether or not the game is in the multiplayer mode.
---@return boolean -- True if the game is in multiplayer, false in single player.
function DCS.isMultiplayer() end
---Returns whether or not the game is running as a server or is in the single player mode.
---@return boolean
function DCS.isServer() end
---Returns the DCS simulation time in seconds. Dependent on how long the mission has been running.
---@return number
function DCS.getModelTime() end
---Returns the current time in a mission relative to the DCS process start time.
---@return number
function DCS.getRealTime() end
---Returns the table of the options for a given mission as stored in the options.lua file embedded in a miz.
---@return table
function DCS.getMissionOptions() end
---Returns a list of coalitions which have client slots available.
---@return table
function DCS.getAvailableCoalitions() end
---Returns a table of slots available to a given coalition.
---@param coalition 'red' | 'blue'
---@return table
function DCS.getAvailableSlots(coalition) end
---Returns the table of the mission as stored in the mission file embedded in a miz.
---@return table
function DCS.getCurrentMission() end
---Returns the name of the mission.
---@return string
function DCS.getMissionName() end
---Returns the file name of the current mission file.
---@return string
function DCS.getMissionFilename() end
---Returns the current result for a given coalition as defined by the mission goals in the mission.
---@param coalition 'red' | 'blue'
---@return number
function DCS.getMissionResult(coalition) end
---Returns the given property for the passed unit. <br>
---List of properties:
---```
--- DCS.UNIT_RUNTIME_ID -- unique within runtime mission. int
--- DCS.UNIT_MISSION_ID -- unique within mission file. int>0
--- DCS.UNIT_NAME -- unit name, as assigned by mission designer.
--- DCS.UNIT_TYPE -- unit type (Ural, ZU-23, etc)
--- DCS.UNIT_CATEGORY,
--- DCS.UNIT_GROUP_MISSION_ID -- group ID, unique within mission file. int>0
--- DCS.UNIT_GROUPNAME -- group name, as assigned by mission designer.
--- DCS.UNIT_GROUPCATEGORY,
--- DCS.UNIT_CALLSIGN,
--- DCS.UNIT_HIDDEN -- ME hiding
--- DCS.UNIT_COALITION -- "blue", "red" or "unknown"
--- DCS.UNIT_COUNTRY_ID,
--- DCS.UNIT_TASK --"unit.group.task"
--- DCS.UNIT_PLAYER_NAME -- valid for network "humanable" units
--- DCS.UNIT_ROLE --"artillery_commander", "instructor", etc
--- DCS.UNIT_INVISIBLE_MAP_ICON --ME invisible map icon
---```
---@param unitId integer
---@param property enum
---@return string
function DCS.getUnitProperty(unitId, property) end
---Shortcut of `DCS.getUnitProperty(missionId, DCS.UNIT_TYPE)`
---@param unitId integer
function DCS.getUnitType(unitId) end
---Returns the attribute of the specified type for the specified unit type.<br>
---Example:
---```
---DCS.getUnitTypeAttribute("Ural", "DisplayName")
---```
---@param typeName string -- The type of the unit.
---@param attribute string -- The attribute to get.
---@return string, number, table
function DCS.getUnitTypeAttribute(typeName, attribute) end
---Adds the functions defined in the table to be run when the given event is called from the GameGUI environment.<br>
---For each grouping of callbacks you create it needs to be added to a file placed in your saved games folder.<br>
---This file is automatically loaded when the game starts. File is placed in Users\%YOURWINDOWSUSERNAME%\Saved Games\DCS\Scripts\Hooks folder. If this folder does not exist create it.<br>
---Some callbacks can have a return value. If returned in your code then that value will take precedence over any other callback that might be checking the same thing.<br>
---It is best to return nothing unless you want to force a given action to occur.<br>
---@param functions table -- A table of functions to be run when the corresponding event is called.
---Example: The following saves and modifies global values for the current mission name and a list of connected clients.
---```lua
---local myCall = {}
---clients = {}
---function myCall.onMissionLoadBegin()
--- current_mission = DCS.getMissionName()
---end
---function myCall.onPlayerConnect(id)
--- clients[id] = {id = id, addr = net.get_player_info(id, 'ipaddr'), name = net.get_player_info(id, 'name'), ucid = net.get_player_info(id, 'ucid'), ip = net.get_player_info(id, 'ipaddr')}
---end
---function myCall.onPlayerDisconnect(id)
--- clients[id] = nil
---end
---DCS.setUserCallbacks(myCall)
---```
function DCS.setUserCallbacks(functions) end