KnightHawk75
Posts: 1450
Joined: 11/15/2018 Status: offline
|
Think I've posted these before but here they are again: You only need the first one in your trigger, and you can make the func local if it's the only place you'll be using it.
function khRefuelUnit(myunit)
local newfuel = myunit.fuel
for i,v in pairs(newfuel) do
v.current = v.max
myunit.fuel = newfuel
end
newfuel = nil;
end
function khRefuelSide(thesidename,unittype,subtype)
if unittype ==nil then unittype="All" end;
if subtype ==nil then subtype="All" end;
local a = VP_GetSide({Side =thesidename})
for i,v in pairs(a.units) do
local myunit;
myunit = ScenEdit_GetUnit({name=v.name, guid=v.guid})
if myunit ~=nil then
if unittype ~="All" and subtype ~= "All" then
if myunit.type == unittype and myunit.subtype == subtype then
khRefuelUnit(myunit);
end
elseif unittype ~= "All" and subtype =="All" then
if myunit.type == unittype then
khRefuelUnit(myunit);
end
elseif unittype == "All" and subtype ~="All" then
if myunit.subtype == subtype then
khRefuelUnit(myunit);
end
else --either ==All or both ==ALL
if myunit.type ~= "Weapon" then
khRefuelUnit(myunit);
end
end
end
myunit = nil;
end
local a = nil;
end
--usage examples
--single unit refueling, all tanks
khRefuelUnit(ScenEdit_UnitX()) -- used inside a trigger refuel the triggering unit.
khRefuelUnit(ScenEdit_GetUnit({guid="SomeValidUnitGuid"})) -- get unit first, feed unit wrapper to function.
-- Side version: Feed it the name of the side, it will refuel all units of unittype to max capacity.
khRefuelSide('Blue'); -everything.
khRefuelSide('Blue',"Aircraft"); --only aircraft
khRefuelSide('Blue',"Aircraft",3101) --only aircraft with subtype code 3101 (bomber)
khRefuelSide('Blue',"Weapon",2001) --only weapons with subtype guided weapons. (Yes you can refuel missiles if you really want too, handy for debugging purposes)
< Message edited by KnightHawk75 -- 11/2/2021 11:25:28 PM >
|