Zayets Posted September 3, 2018 Posted September 3, 2018 Anyone have an idea how to use (just an example here but I have the same result with all these functions) DCS.getUnitProperty (https://wiki.hoggitworld.com/view/DCS_func_getUnitProperty) ? When I try to use one of them, for example : local name = DCS.getUnitProperty(Unit.getID(flight[i]),'DCS.UNIT_PLAYER_NAME') I invariably get the dreaded message : attempt to index global 'DCS' (a nil value) [sIGPIC]OK[/sIGPIC]
Grimes Posted September 4, 2018 Posted September 4, 2018 Its part of the server API. It can be run by anything called by the scripts in your saved games/Scripts/Hooks folder. It is an entirely separate lua environment from the mission scripting environment that something like Unit.getID() is in. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Zayets Posted September 4, 2018 Author Posted September 4, 2018 So basically only a script saved in the Hooks folder can call these functions. Say I have the snippet above in a script file saved in Hooks. When is this one executed, or more precisely are the scripts in Hooks folder automatically included in the mission or they have to be added just like any other script? The later would be good as when you package a mission the scripts should be there with the mission but not sure about the first option though. [sIGPIC]OK[/sIGPIC]
Grimes Posted September 4, 2018 Posted September 4, 2018 It loads when the game loads. For instance I have an file in there for slmod that basically just points to another folder to load all of the slmod stuff. You can use "callbacks" that are available to it to run extra code to check the state of the sim to make sure it is in a mission so it can run relevant code for when a mission is running and stops when the mission is not. I really need to go back and finish that documentation on the wiki. You can check your DCSinstall/API folder for DCS_controlAPI.html or something like that for the full documentation. This lua environment really is mostly for running a server and having custom code on it to do stuff like server admin functionality, stats, etc. Anything in there has to be installed by the user. SRS, tacview, etc also are installed there, but they are there mostly for using the export lua environment. If you want to do mission scripting stuff you gotta use the mission lua environment with stuff like Unit.getPlayerName(). The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Zayets Posted September 4, 2018 Author Posted September 4, 2018 Roger that. I will use then getPlayerName to check if the unit is controlled by a player (hope it works with multiple clients, like returning the name of the player controlling a particular unit). [sIGPIC]OK[/sIGPIC]
Grimes Posted September 4, 2018 Posted September 4, 2018 getPlayerName only has issues with combined arms units and multicrew aircraft. Specifically it just doesn't work for ground units and for multicrew aircraft it only returns the pilots name. There is a bug report/feature request for access to additional players in the same aircraft. You can get that information in the server environment by getting the slots players are in. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Zayets Posted September 4, 2018 Author Posted September 4, 2018 That's OK Grimes, as I assume the co-pilot is in the same group as the pilot. Sending a text message to the same group should include the co-pilot as well. [sIGPIC]OK[/sIGPIC]
Recommended Posts