Page 1 of 1

Conditional Subtype on Unit X

Posted: Sun Sep 05, 2021 1:52 pm
by BDukes
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?


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

RE: Conditional Subtype on Unit X

Posted: Sun Sep 05, 2021 3:21 pm
by BDukes
Did this a different way! Used subtype in the triggers.

Mike

RE: Conditional Subtype on Unit X

Posted: Sun Sep 05, 2021 4:01 pm
by BDukes
Well almost. Can't see all the subtypes in the edit trigger drop down. Reported[&:]

Think I got most.[:)]

Mike

RE: Conditional Subtype on Unit X

Posted: Sun Sep 05, 2021 5:36 pm
by KnightHawk75
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.

Code: Select all

 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 
 

RE: Conditional Subtype on Unit X

Posted: Sun Sep 05, 2021 7:05 pm
by BDukes
Perfect. Thank you!

Mike