gyrovague Posted August 23, 2016 Share Posted August 23, 2016 I'm hoping somebody here can point me in the right direction. I want to be able to detect damage to various parts of an SFM/SSM aircraft in Lua. The main aircraft definition file has entries such as: --damage , index meaning see in Scripts\Aircrafts\_Common\Damage.lua Damage = { [0] = {critical_damage = 5, args = {82}}, -- 0 - nose center [3] = {critical_damage = 10, args = {65}}, -- 3 - cockpit and DamageParts = { [1] = "plane_damage_wing_R", -- Right Wing [2] = "plane_damage_wing_L", -- Left Wing and Failures = { { id = 'autopilot', label = _('AUTOPILOT'), enable = false, hh = 0, mm = 0, mmint = 1, prob = 100 }, { id = 'engine', label = _('ENGINE'), enable = false, hh = 0, mm = 0, mmint = 1, prob = 100 }, Damage and DamageParts seem to define the anim args and 3D models that are activated on various system damage (I've also trawled the Scripts\Aircrafts\_Common\Damage.lua file for further clues with no success). Failures seems to show up in mission editor and flight logs in game (though I don't know how to make those failures associated with any code either). All the aircraft systems are implemented as simple avLuaDevice entries, e.g. creators = {} creators[devices.AVIONICS] = {"avLuaDevice", LockOn_Options.script_path.."Systems/avionics.lua"} creators[devices.RADARWARN] = {"avLuaDevice", LockOn_Options.script_path.."Systems/radarwarn.lua"} creators[devices.ENGINE] = {"avLuaDevice", LockOn_Options.script_path.."Systems/engine.lua"} creators[devices.GUNSIGHT] = {"avLuaDevice", LockOn_Options.script_path.."Systems/gunsight.lua"} My question is: how can I detect/query damage (or failures) to parts of the aircraft from within those avLuaDevice systems Lua code? I've noticed (from checking key/value pairs of the avLuaDevice object, and looking at DCS dll files) that there is a function named SetDamage, but I'm unsure whether it is a callback (like SetCommand and update) or whether an API meant to be called by our code. I've tried just implementing a SetDamage function with a print_message_to_user, but it never gets triggered (even when the aircraft is just a flying ball of fire after being shot to bits), so it doesn't seem to be a callback (unless something more needs to be done to register the system somehow). If I can detect or query damage to specific parts of the plane somehow, I can start to emulate damage to the various systems in the code, e.g. have some electrical or hydraulics failures, radar altimeter failures, etc. etc. Any pointers in the right direction would be greatly appreciated! ____________ Heatblur Simulations [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
BR55Sevas Posted August 23, 2016 Share Posted August 23, 2016 Try to use "get_aircraft_draw_argument" or something like that. Look for in dcs mod structure thread exact function name. I suppose it will work, but only when plane part completly gone from model. Medium values of damage probably impossible get without sdk... МиГ-29 Fly by wire СДУ Su-27SM second display panel https://www.youtube.com/embed/videoseries?list=PL_2GGwNpWNp_fKXfRtDhIk8s5Jf4a9XHS http://berkuts.ru Пилотажный сервер с роботом | Aerobatic server with PhantomControl Link to comment Share on other sites More sharing options...
gyrovague Posted November 3, 2016 Author Share Posted November 3, 2016 Some parts of wHumanCustomPhysicsAPI.h maybe give some tiny clues/insight: // damages and failures // void ed_fm_on_planned_failure(const char * ) callback when preplaneed failure triggered from mission typedef void (*PFN_ON_PLANNED_FAILURE) (const char *); If we can get the corresponding Lua callback, then we could get the mission editor failures too. Basically just a callback with a string value (from the Failures entry in the aircraft definition) which the code must interpret as it wants to. // void ed_fm_on_damage(int Element, double element_integrity_factor) callback when damage occurs for airframe element typedef void (*PFN_ON_DAMAGE) (int Element, double element_integrity_factor); I initially thought (see my first post above) that SetDamage in the Lua is maybe a callback similar to SetCommand.. it may well still be (like ed_fm_on_damage callback), but perhaps needs to be registered somehow (similar to how one needs to do listen_command prior to getting SetCommand callbacks). //inform DCS about internal simulation event, like structure damage , failure , or effect struct ed_fm_simulation_event { unsigned event_type; char event_message[512]; // optional float event_params [16]; // type specific data , like coordinates , scales etc }; // bool ed_fm_pop_simulation_event(ed_fm_simulation_event & out) called on each sim step /* ed_fm_simulation_event event; while (ed_fm_pop_simulation_event(event)) { do some with event data; } */ typedef bool (*PFN_FM_POP_SIMULATION_EVENT) (ed_fm_simulation_event & out); // event type declaration enum ed_fm_simulation_event_type { ED_FM_EVENT_INVALID = 0, ED_FM_EVENT_FAILURE, ED_FM_EVENT_STRUCTURE_DAMAGE, ED_FM_EVENT_FIRE, }; /* ED_FM_EVENT_FAILURE event_message - failure id , like "autopilot" or "r-engine" event_params - not used for failure ED_FM_EVENT_STRUCTURE_DAMAGE event_message - not used event_params[0] damage element number like in ed_fm_on_damage event_params[1] integrity factor like in ed_fm_on_damage ED_FM_EVENT_FIRE event_message - not used , but you can send something like "engine fire" or "left wing tank fire" event_params[0] fire control handle, index used to control change of effect in time event_params[1] event_params[2] event_params[3] x , y ,z coordinates of fire origin in aircraft body space event_params[4] event_params[5] event_params[6] x , y ,z components of orientation of emitter direction event_params[7] emitted particles speed event_params[8] scale of fire , if scale will less or equal to zero , fire with this index will be stopped */ There seems to be a listen_event Lua function, which maybe works similar to the listen_command function used for getting all clickable cockpit commands... Perhaps one can then somehow receive events similar to the C API above. ____________ Heatblur Simulations [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Recommended Posts