Conditional Subtype on Unit X

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
BDukes
Posts: 2694
Joined: Wed Dec 27, 2017 12:59 pm

Conditional Subtype on Unit X

Post 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
Don't call it a comeback...
BDukes
Posts: 2694
Joined: Wed Dec 27, 2017 12:59 pm

RE: Conditional Subtype on Unit X

Post by BDukes »

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

Mike
Don't call it a comeback...
BDukes
Posts: 2694
Joined: Wed Dec 27, 2017 12:59 pm

RE: Conditional Subtype on Unit X

Post by BDukes »

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

Think I got most.[:)]

Mike
Don't call it a comeback...
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Conditional Subtype on Unit X

Post 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 
 
BDukes
Posts: 2694
Joined: Wed Dec 27, 2017 12:59 pm

RE: Conditional Subtype on Unit X

Post by BDukes »

Perfect. Thank you!

Mike
Don't call it a comeback...
Post Reply

Return to “Lua Legion”