Shahdoh Posted February 10, 2015 Share Posted February 10, 2015 I am wanting to display/record different values of an aircraft. 1 of them being the current weight. How would I go about finding where/what this value is in the lua databases? Link to comment Share on other sites More sharing options...
FSFIan Posted February 10, 2015 Share Posted February 10, 2015 Whenever I want to know how to do something in the mission scripting environment using Lua, my first stop is often this page on the hoggit wiki. It has links to the official scripting engine docs and the MiST documentation. After that (or from memory), I know which functions will possibly do what I want. I did not find a function that tells me the current mass of an aircraft, but I know that the results of calling unit:getDesc() will probably have something useful. Now I know where to start, but I still don't know how those results look like. While I could probably infer that after looking hard enough at the "Structures" section of Part 2 of the official docs, a quicker way is trial and error. Once I know where to look, most of the time the next step is to fire up the interactive Lua console of DCS Witchcraft (see link in my sig). So I open my witchcraft-enabled test mission and evaluate the following Lua code in the console ("A10C-1" is the group name of an A-10C I am sitting in): local g = Group.getByName("A10C-1") local u = g:getUnit(1) return u:getDesc() I get the following result: { "Hmax": 10000, "Kab": 0, "Kmax": 0.52999997138977, "NyMax": 5.9000000953674, "NyMin": -2, "RCS": 10, "VyMax": 30, "attributes": { "Air": true, "All": true, "Battle airplanes": true, "Battleplanes": true, "NonAndLightArmoredUnits": true, "NonArmoredUnits": true, "Planes": true, "Refuelable": true }, "box": { "max": { "x": 7.6860585212708, "y": 2.3696703910828, "z": 9.4541301727295 }, "min": { "x": -9.1228017807007, "y": -1.2815840244293, "z": -9.4672021865845 } }, "category": 0, "displayName": "A-10C", "fuelMassMax": 5029, "life": 32, "massEmpty": 11739, "massMax": 21081, "range": 1500, "speedMax": 236, "speedMax0": 236, "speedMax10K": 134, "tankerType": 0, "typeName": "A-10C" } So the first try is this: local u = Group.getByName("A10C-1"):getUnit(1) local KG_TO_LBS = 2.2046226 local mass = u:getDesc().massEmpty mass = mass + u:getFuel()*u:getDesc().fuelMassMax return mass * KG_TO_LBS That gives me 31428 lbs. According to the rearming dialog, my current total mass is 36651. But when I remove all bombs and gun ammo, the rearming dialog shows 31424 lbs -- close enough! So let's try to take the ammunition into account: local g = Group.getByName("A10C-1") local u = g:getUnit(1) return u:getAmmo() result: [ { "count": 1150, "desc": { "box": { "max": { "x": 0.025108814239502, "y": 0.15063416957855, "z": 0.64480221271515 }, "min": { "x": -44.163108825684, "y": -0.16146284341812, "z": -0.64507895708084 } }, "category": 0, "displayName": "30mm AP", "life": 2, "typeName": "weapons.shells.GAU8_30_AP", "warhead": { "caliber": 30, "explosiveMass": 0, "mass": 0.36, "type": 0 } } }, { "count": 6, "desc": { "RCS": 0, "altMax": 12000, "altMin": 100, "box": { "max": { "x": 1.0492290258408, "y": 0.044821295887232, "z": 0.13964723050594 }, "min": { "x": -1.1737260818481, "y": -0.27638137340546, "z": -0.14316475391388 } }, "category": 3, "displayName": "Mk-82", "life": 2, "typeName": "weapons.bombs.Mk_82", "warhead": { "caliber": 279, "explosiveMass": 72, "mass": 72, "type": 1 } } } ] Trying to calculate empty mass + fuel mass + ammo mass: local u = Group.getByName("A10C-1"):getUnit(1) local KG_TO_LBS = 2.2046226 local mass = u:getDesc().massEmpty mass = mass + u:getFuel()*u:getDesc().fuelMassMax if u:getAmmo() then for _, item in pairs(u:getAmmo()) do mass = mass + item.count*item.desc.warhead.mass end end return mass * KG_TO_LBS The result is 33293 lbs, which is still way off from the 36651 lbs it should be. My guess is that item.desc.warhead.mass is, as it says, only the mass of the warhead itself and does not include the rest of the bomb. If you require accurate values, I guess you could build a database of the warhead+rest-of-bomb mass through experimentation. 1 DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua Link to comment Share on other sites More sharing options...
Shahdoh Posted February 10, 2015 Author Share Posted February 10, 2015 Ian, Thank you for the excellent breakdown. That helps immensely. For my purposes, weapon weight is not a concern at the moment so the initial weight plus fuel will work just fine. /Salute Shahdoh Link to comment Share on other sites More sharing options...
NakedSquirrel Posted February 11, 2015 Share Posted February 11, 2015 Thanks for the write up Ian! I've been staring at the wiki and opening up missions not sure where to start with lua, but this is a really good, simple snippet of code, and the description of how it was made/interfaces is very helpful. Modules: A10C, AV8, M2000C, AJS-37, MiG-21, MiG-19, MiG-15, F86F, F5E, F14A/B, F16C, F18C, P51, P47, Spitfire IX, Bf109K, Fw190-D, UH-1, Ka-50, SA342 Gazelle, Mi8, Christian Eagle II, CA, FC3 Link to comment Share on other sites More sharing options...
Shahdoh Posted February 11, 2015 Author Share Posted February 11, 2015 Ok, things started off looking good. In single player tests, the following code worked perfectly. local u = Group.getByName(unit.gname):getUnit(1) -- unit.gname is name of unit entering a trigger zone local KG_TO_LBS = 2.2046226 local mass = u:getDesc().massEmpty mass = mass + u:getFuel()*u:getDesc().fuelMassMax local cmass = mass * KG_TO_LBS env.warning(unit.player..' / '..unit.gname..' - entry weight: '..cmass) The weight is reported correctly at the moment it is called in the script. But things changed with the exact same code in multi-player. In MP, it is reporting the weight of the aircraft when it spawned in, not the weight it actually is at the moment this part of the code ran. (Unlimited fuel is NOT enabled) Any thoughts on why it would be different from SP to MP? Link to comment Share on other sites More sharing options...
xcom Posted February 11, 2015 Share Posted February 11, 2015 Thanks for the write up Ian! I've been staring at the wiki and opening up missions not sure where to start with lua, but this is a really good, simple snippet of code, and the description of how it was made/interfaces is very helpful. Don't do it squirrel! :) [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook Link to comment Share on other sites More sharing options...
FSFIan Posted February 11, 2015 Share Posted February 11, 2015 The weight is reported correctly at the moment it is called in the script. But things changed with the exact same code in multi-player. In MP, it is reporting the weight of the aircraft when it spawned in, not the weight it actually is at the moment this part of the code ran. (Unlimited fuel is NOT enabled) Any thoughts on why it would be different from SP to MP? This may be one of those things that only work in single player or for the host in MP. I played around with getFuel() in a MP mission without problems, but I was the only player/host. If it turns out that getFuel() does not work in MP, I can forget about the mission idea I am working on right now :mad: DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua Link to comment Share on other sites More sharing options...
Vespa Posted February 11, 2015 Share Posted February 11, 2015 Topic really interesting...and Ian always provide great infos Link to comment Share on other sites More sharing options...
FSFIan Posted February 11, 2015 Share Posted February 11, 2015 I reproduced the "not working in MP" behavior. For what it's worth, I have posted it in the bug reports forum. DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua Link to comment Share on other sites More sharing options...
Recommended Posts