ORIGINAL: Parel803
Knighthawk I change the myunit inn line 9 for unit. Is that correct?
Looks like it's working,
thx again, GJ
yeah sorry typo in line 9 "myunit" should read "unit"! I will edit original.
Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command
Post by KnightHawk75 »
ORIGINAL: Parel803
Knighthawk I change the myunit inn line 9 for unit. Is that correct?
Looks like it's working,
thx again, GJ
Post by KnightHawk75 »
Wondering how to make a condition that geves me a reslut to fire the message when boat docked and ready.
Code: Select all
 ---[some global func in this example but doesn't have to be]
 ---function returns true if a passed in unit is not operating, is 'Docked' state and is also fully ready.
 ---@param u unitWrapper: unit wrapper to operate on.
 ---@return boolean
 ---@requires:  CMO build 1147.34+  u.readytime_v returning digit is new.
 function isUnitDockedAndReady(u)
   if ((u ~=nil) and u.isOperating == false) and u.condition_v == 'Docked' and u.readytime_v == 0 then return true; end
   return false;
 endCode: Select all
 ---[in case you need a list of units that qualify and not just a hard-coded one. included here for the hell of it ignore otherwise]
 ---@param hosting CMO__UnitWrapper - the host.
 ---@return table - table of CMO__UnitWrappers one entry for each available docked unit.
 function buildlistOfWrappersDockedAndReadyForHost(h)
   local rettbl = {};
   if ( h ~= nil) and #h.embarkedUnits.Boats > 0 then
     local r,u;
     for i=1,#h.embarkedUnits.Boats do
       r,u = pcall(SE_GetUnit,{guid=h.embarkedUnits.Boats[i]})
       if ((r) and u~=nil) and isUnitDockedAndReady(u) then table.insert(rettbl,u); end
       r,u = nil,nil;
     end
   end
   return rettbl;
 end
 Code: Select all
 ---[condition]
 local r,u = pcall(ScenEdit_GetUnit,{guid='50PVO4-0HMD9K449JTMQ'}); --get unit, suppress errors on fail.
 if ((r) and u~=nil) and isUnitDockedAndReady(u) then --success,not nil, and is docked and ready..
   return true; -- Condition met
 else 
   return false; --was problem getting the unit or it was simply not docked and ready.
 end
 
Post by KnightHawk75 »
Not sure if I understand the list of units correctly?
Code: Select all
 local mob = SE_GetUnit({guid=guidofmob});
 local t = buildlistOfWrappersDockedAndReadyForHost(mob) 
 --t will now contain a table of unit wrappers for all unit that were docked and ready.
 if #t > 0 then -- there are 1 or more that are ready..
   local tmpstring = ''; firstrun=true;
   for entryNumber,unitWrapper in pairs(t) do
      --- do something... maybe make a list of names like here 
      --- or maybe do something to each or for each.. 
     if firstrun == true then tmpstring = unitWrapper.name; firstrun=false;
     else tmpstring = tmpstring .. ' , ' .. unitWrapper.name;    
     end
   end
   ScenEdit_SpecialMessage('playerside','<P> The following boats are now available for launch on unit ' .. mob.name .. ':</P><P>' .. tmpstring .. '</P>');
 end