Conditional Subtype on Unit X (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion



Message


BDukes -> Conditional Subtype on Unit X (9/5/2021 4:52:16 PM)

Hi All

I'm rusty. With the code below I'm trying to simulate a 50% chance of a bailout from an aircraft that isn't the subtype 8201 (UAV). Problem is it is not excluding 8201. Code runs fine if I take out the if destroyedUnit.subtype ~= 8201. Feels like I'm missing something stupid. Can somebody take a look?


quote:



local destroyedUnit = ScenEdit_UnitX()
if destroyedUnit.subtype ~= 8201 then
local aircrewsurvival = math.random(1,2)
if aircrewsurvival==1 then
local crew = ScenEdit_AddUnit({
type='Facility',
dbid=2441,
side=destroyedUnit.side,
name=destroyedUnit.name .. " " .. "Aircrew",
latitude=destroyedUnit.latitude,
longitude=destroyedUnit.longitude
})
end
end




BDukes -> RE: Conditional Subtype on Unit X (9/5/2021 6:21:28 PM)

Did this a different way! Used subtype in the triggers.

Mike




BDukes -> RE: Conditional Subtype on Unit X (9/5/2021 7:01:45 PM)

Well almost. Can't see all the subtypes in the edit trigger drop down. Reported[&:]

Think I got most.[:)]

Mike




KnightHawk75 -> RE: Conditional Subtype on Unit X (9/5/2021 8:36:53 PM)

change 8201 to "8201" or change to ~= tostring(8201) if the number is a var, as subtype code is returned as a string somewhat oddly.
local destroyedUnit = ScenEdit_UnitX()
if destroyedUnit.subtype ~= "8201" then
  local aircrewsurvival = math.random(1,2)
  if aircrewsurvival==1 then
    local crew = ScenEdit_AddUnit({
    type='Facility',
    dbid=2441,
    side=destroyedUnit.side,
    name=destroyedUnit.name .. " " .. "Aircrew",
    latitude=destroyedUnit.latitude,
    longitude=destroyedUnit.longitude
    })
  end
end 





BDukes -> RE: Conditional Subtype on Unit X (9/5/2021 10:05:04 PM)

Perfect. Thank you!

Mike




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.0300293