CougarFFW04 Posted January 1, 2019 Posted January 1, 2019 (edited) Hi everyone, I would like to know if : - it's possible to find elsewhere the "point of life" associated to any DCS object (for exemple what is life point associated to a TV antenna or whatever) ? - it's possible to change the point of life associated to static object we put somewhere inthe DCS world (for exemple I want that the point of life of a flag I put elsewhere is 5000) ? - or even better, is is possible to add our own object with our associated life point ? Thanks Edited January 1, 2019 by CougarFFW04
Grimes Posted January 2, 2019 Posted January 2, 2019 You can either use the scripting function Unit.getLife0() or read the life table entry from Object.getDesc(). I periodically export the getDesc table for all objects to github, so you can reference the list that way. No, can't modify the life values via scripting. You'd have to find hte DB entry in the install/Scripts/Database folder to change the life values. Yes, setting how much life the object has is part of creating a mod like that. Unsure if it is a required table entry, but I'd guess that most if not all mods that add objects set that value to something. 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
Hardcard Posted January 2, 2019 Posted January 2, 2019 (edited) @Grimes Hi there Grimes! I've been trying to make :getLife0() work with static objects (to help CougarFFW04), but it keeps generating the following scripting error: attempt to call method 'getLife0' (a nil value) However, :getLife() works like a charm. Here's my test script: local StaticSet = SET_STATIC:New() :FilterPrefixes("Static_") -- All relevant statics in ME must use this prefix! :FilterStart() StaticSet:ForEachStatic( function(StaticSet) local StaticDCSObjectCategory = StaticSet:GetCategory() if StaticDCSObjectCategory ~= nil --This is required in order to avoid scripting errors generated by some unsupported static objects in the set (ie. the new Sea Shelf Objects) then local StaticDCSObject = StaticSet:GetDCSObject() local StaticIdentifiableName = StaticSet:GetName() local StaticObjectInitialLife = StaticDCSObject:getLife0() -- Generates the scripting error I mentioned earlier. If I comment this line out, the script works local StaticObjectCurrentLife = StaticDCSObject:getLife() MESSAGE:New(StaticIdentifiableName.." initial life = "..StaticObjectInitialLife,10):ToAll() -- This line needs to be commented out as well for the script to work, obviously MESSAGE:New(StaticIdentifiableName.." current life = "..StaticObjectCurrentLife,10):ToAll() end end ) After struggling with this for hours, I went back to your wiki and noticed something that might explain this behaviour. According to the documentation, :getLife0() isn't available for classes other than Unit (so it can't be used with Static Object or Scenery Object classes). On the other hand, :getLife() seems to be available for Unit, Static Object and Static Scenery classes (that's probably why it works with the statics in my test mission). Can you confirm this? (Or just explain what might be going on) Thanks and happy new year! :thumbup: Edited January 2, 2019 by Hardcard [sIGPIC][/sIGPIC]
Hardcard Posted January 2, 2019 Posted January 2, 2019 (edited) @CougarFFW04 If you're interested, I've modified my test mission from the other thread (yet again) in order to obtain the "life status" of all static objects (except for the two Sea Shelf Objects, which aren't supported). I'm attaching the two modified versions here. The first version will provide the raw numeric life value for each static object when it gets hit (as well as the rest of data you requested in the other thread). NOTE: You'll get spammed with status messages as bombs hit several static objects simultaneously...sorry about that Here's the script it uses: local RedSet = SET_GROUP:New() :FilterPrefixes("Red_") -- All relevant attack groups in ME must use this prefix! :FilterStart() local StaticSet = SET_STATIC:New() :FilterPrefixes("Static_") -- All relevant statics in ME must use this prefix! :FilterStart() RedSet:HandleEvent(EVENTS.Hit) function RedSet:OnEventHit(EventData) local TargetCategory = EventData.TgtObjectCategory Attacker = EventData.IniUnitName if TargetCategory == 3 or TargetCategory == 6 then local TargetName = EventData.TgtUnitName local TargetObjectCurrentLife = EventData.TgtDCSUnit:getLife() local TargetCoalition = EventData.TgtCoalition if TargetCoalition == 1 then MESSAGE:New(TargetName.." (Red coalition) has been hit by "..Attacker.."\nRemaining life --> "..TargetObjectCurrentLife,10):ToAll() elseif TargetCoalition == 2 then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..TargetObjectCurrentLife,10):ToAll() end elseif TargetCategory == 0 then MESSAGE:New("Sea shelf object has been hit by "..Attacker,10):ToAll() end end StaticSet:HandleEvent(EVENTS.Dead) function StaticSet:OnEventDead(EventData) local DeadStatic = EventData.IniUnitName -- This doesn't work for Sea Shelf Objects local DeadStaticCategory = EventData.IniObjectCategory -- 3 = Ground Vehicle/Plane/Helicopter/Structure , 5 = Airport structure, 6 = Cargo, 0 = Sea Shelf Object local DeadStaticCoalition = EventData.IniCoalition -- 1 = Red , 2 = Blue (This doesn't work for Sea Shelf Objects either!) if DeadStaticCategory == 3 or DeadStaticCategory == 6 then if DeadStaticCoalition == 1 then MESSAGE:New(">>> "..DeadStatic.." (Red coalition) has been destroyed by "..Attacker.." <<<",10):ToAll() elseif DeadStaticCoalition == 2 then MESSAGE:New(">>> "..DeadStatic.." (Blue coalition) has been destroyed by "..Attacker.." <<<",10):ToAll() end elseif DeadStaticCategory == 0 then MESSAGE:New(">>> Sea shelf object destroyed by "..Attacker.." <<<",10):ToAll() end end The second version will provide the raw life numerical value for each static object at mission start, then you'll get their individual life values in percentages, as they get hit (as well as the rest of stuff you requested in the other thread). NOTE: You'll get spammed with status messages as bombs hit several static objects simultaneously...sorry about that Here's the ugly script it runs on (I had to do it this way because I couldn't make :getLife0() work with the static objects): local RedSet = SET_GROUP:New() :FilterPrefixes("Red_") -- All relevant attack groups in ME must use this prefix! :FilterStart() local StaticSet = SET_STATIC:New() :FilterPrefixes("Static_") -- All relevant statics in ME must use this prefix! :FilterStart() StaticSet:ForEachStatic( function(StaticSet) local StaticDCSObjectCategory = StaticSet:GetCategory() if StaticDCSObjectCategory == 3 or StaticDCSObjectCategory == 6 then local StaticDCSObject = StaticSet:GetDCSObject() local StaticIdentifiableName = StaticSet:GetName() local StaticObjectCurrentLife = StaticDCSObject:getLife() MESSAGE:New(StaticIdentifiableName.." initial life = "..StaticObjectCurrentLife,10):ToAll() end end ) RedSet:HandleEvent(EVENTS.Hit) function RedSet:OnEventHit(EventData) local TargetCategory = EventData.TgtObjectCategory Attacker = EventData.IniUnitName if TargetCategory == 3 or TargetCategory == 6 then local TargetName = EventData.TgtUnitName local TargetObjectCurrentLife = EventData.TgtDCSUnit:getLife() local TargetCoalition = EventData.TgtCoalition --The following are custom life percentage calculations for (almost) each static object (the only thing that changes is their initial life value) local FlagLife = TargetObjectCurrentLife / 3 * 100 local TwentyLife = TargetObjectCurrentLife / 20 * 100 local TarawaLife = TargetObjectCurrentLife / 7301 * 100 local OilPlatformLife = TargetObjectCurrentLife / 500 * 100 local NormandyLife = TargetObjectCurrentLife / 2701 * 100 local ShelterLife = TargetObjectCurrentLife / 8000 * 100 local ViggenLife = TargetObjectCurrentLife / 18 * 100 local TankYellowLife = TargetObjectCurrentLife / 12 * 100 local M117BombsLife = TargetObjectCurrentLife / 5 * 100 local AirshowCrowdLife = TargetObjectCurrentLife / 10 * 100 local OilTankLife = TargetObjectCurrentLife / 15 * 100 local LocomotiveLife = TargetObjectCurrentLife / 2 * 100 local UH60Life = TargetObjectCurrentLife / 14 * 100 local PaladinLife = TargetObjectCurrentLife / 4 * 100 --The following are custom messages for (almost) each static object. Again, I had to do it like this because I couldn't make :getLife0() work with the statics if TargetName == "Static_RedFlag_Blue" or TargetName == "Static_RedFlag_Red" or TargetName == "Static_WhiteFlag_Blue" or TargetName == "Static_WhiteFlag_Red" then if TargetCoalition == 1 then MESSAGE:New(TargetName.." (Red coalition) has been hit by "..Attacker.."\nRemaining life --> "..FlagLife.."%",10):ToAll() elseif TargetCoalition == 2 then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..FlagLife.."%",10):ToAll() end elseif TargetName == "Static_F117A" or TargetName == "Static_CH47D" then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..TwentyLife.."%",10):ToAll() elseif TargetName == "Static_Tarawa" then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..TarawaLife.."%",10):ToAll() elseif TargetName == "Static_OilPlatform" then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..OilPlatformLife.."%",10):ToAll() elseif TargetName == "Static_Normandy" then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..NormandyLife.."%",10):ToAll() elseif TargetName == "Static_Shelter" then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..ShelterLife.."%",10):ToAll() elseif TargetName == "Static_Viggen" then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..ViggenLife.."%",10):ToAll() elseif TargetName == "Static_TankYellow" then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..TankYellowLife.."%",10):ToAll() elseif TargetName == "Static_M117bombs" then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..M117BombsLife.."%",10):ToAll() elseif TargetName == "Static_Airshow Crowd" then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..AirshowCrowdLife.."%",10):ToAll() elseif TargetName == "Static_Oiltank" then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..OilTankLife.."%",10):ToAll() elseif TargetName == "Static_Locomotive" then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..LocomotiveLife.."%",10):ToAll() elseif TargetName == "Static_UH60A" then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..UH60Life.."%",10):ToAll() elseif TargetName == "Static_Paladin" then MESSAGE:New(TargetName.." (Blue coalition) has been hit by "..Attacker.."\nRemaining life --> "..PaladinLife.."%",10):ToAll() end elseif TargetCategory == 0 then MESSAGE:New("Sea shelf object has been hit by "..Attacker,10):ToAll() end end StaticSet:HandleEvent(EVENTS.Dead) function StaticSet:OnEventDead(EventData) local DeadStatic = EventData.IniUnitName -- This doesn't work for Sea Shelf Objects local DeadStaticCategory = EventData.IniObjectCategory -- 3 = Ground Vehicle/Plane/Helicopter/Structure , 5 = Airport structure, 6 = Cargo, 0 = Sea Shelf Object local DeadStaticCoalition = EventData.IniCoalition -- 1 = Red , 2 = Blue (This doesn't work for Sea Shelf Objects either!) if DeadStaticCategory == 3 or DeadStaticCategory == 6 then if DeadStaticCoalition == 1 then MESSAGE:New(">>> "..DeadStatic.." (Red coalition) has been destroyed by "..Attacker.." <<<",10):ToAll() elseif DeadStaticCoalition == 2 then MESSAGE:New(">>> "..DeadStatic.." (Blue coalition) has been destroyed by "..Attacker.." <<<",10):ToAll() end elseif DeadStaticCategory == 0 then MESSAGE:New(">>> Sea shelf object destroyed by "..Attacker.." <<<",10):ToAll() end end Hope this helps!:thumbup:OnEventDead Static Test life numerical.mizOnEventDead Static Test life percentages.miz Edited January 2, 2019 by Hardcard [sIGPIC][/sIGPIC]
CougarFFW04 Posted January 2, 2019 Author Posted January 2, 2019 Hi Guys, @Grime: Thanks for your prompt reply. I will have a look at the list. @Hardcard: Thanks. Already got things in the other thread but got these ones as well. This helped a lot. This community rocks :smartass::thumbup::pilotfly:
Grimes Posted January 3, 2019 Posted January 3, 2019 getLife0() was added after they changed how getLife() worked. Likely they just forgot to add it to static and scenery objects. Can always fall back on using getDesc().life to get initial life value. The sea shelf objects suffer from the same bug as a FARP where the object fails to return, I should probably update that bug report since its been around for a while. 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
Hardcard Posted January 3, 2019 Posted January 3, 2019 (edited) @Grimes Thanks for the explanation and for the getDesc().life, it'll come in handy! Unfortunately, I've noticed some discrepancies in the returned life values of certain statics. I've attached my test mission, here's the script it runs on (no errors in dcs.log): SCHEDULER:New( nil, function() local StaticSet = SET_STATIC:New() :FilterPrefixes("Static_") -- All relevant statics in ME must use this prefix! :FilterStart() StaticSet:ForEachStatic( function(StaticSet) local StaticDCSObjectCategory = StaticSet:GetCategory() if StaticDCSObjectCategory ~= nil then local StaticDCSObject = StaticSet:GetDCSObject() local StaticIdentifiableName = StaticSet:GetName() local StaticObjectInitialLife = StaticDCSObject:getDesc().life local StaticObjectCurrentLife = StaticDCSObject:getLife() MESSAGE:New(StaticIdentifiableName.." getDesc().life reading = "..StaticObjectInitialLife.."\n"..StaticIdentifiableName.." getLife() reading = "..StaticObjectCurrentLife,10):ToAll() end end ) end, {}, 1, 10 ) Is the description table out of date? It's a real pity, this is really useful stuff :cry:Weird life reading discrepancies.miz Edited January 3, 2019 by Hardcard [sIGPIC][/sIGPIC]
nebsar Posted April 14, 2020 Posted April 14, 2020 I know this is an old thread but would you help me export the life status of objects via export.lua?
Recommended Posts