Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

refuel an air aircraft that enters an area

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> refuel an air aircraft that enters an area Page: [1]
Login
Message << Older Topic   Newer Topic >>
refuel an air aircraft that enters an area - 10/25/2021 4:37:43 PM   
orca

 

Posts: 501
Joined: 11/6/2013
Status: offline
I would like to create an event that refuels any aircraft that enters an area for a particular side.

I would assume I'd use a trigger for unit enters area that would run a script. But how can I know which unit enters the area so that I can refuel that particular aircraft?

I could use a variation of this refuel scrip but don't know how to make it work to get the appropriate unit.

u = ScenEdit_GetUnit({UNIT THAT ENTERS AREA OR SOMETHING LIKE THIS...})
if u ~= nil then
local newfuel = u.fuel
newfuel[2001].current = newfuel[2001].max
u.fuel = newfuel
end

Does anyone have suggestions? Thanks.
Post #: 1
RE: refuel an air aircraft that enters an area - 10/25/2021 5:50:07 PM   
KLAB


Posts: 355
Joined: 2/27/2007
Status: offline
Apologies If i was near a Pcomputer id find the script i used but off the cuff and copied from https://commandlua.github.io/#ScenEdit_UnitX


ScenEdit_UnitX () -- this grabs the unit that triggered the event such as entering the area and from there it's just a matter of adapting your existing script I suspect?

Activating Unit ..that triggered the current Event.Otherwise,a nilis returned.

Note that UnitX()can also be used as a shortcut for ScenEdit_UnitX()

Returns

UnitThe triggering unit

Example

ScenEdit_SetUnitDamage({side=UnitX().side, unitname=UnitX().name, fires=1, components={ {'rudder','Medium'}, {'type',type='sensor',1} } })

local unit = ScenEdit_UnitX()

Etc


(in reply to orca)
Post #: 2
RE: refuel an air aircraft that enters an area - 11/2/2021 11:23:35 PM   
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 >

(in reply to KLAB)
Post #: 3
RE: refuel an air aircraft that enters an area - 11/5/2021 3:31:24 PM   
orca

 

Posts: 501
Joined: 11/6/2013
Status: offline
Thanks for the replies. I'm sorry I'm very bad at LUA and despite a lot of effort usually resort to copying and modifying others scripts and then trial and error to trouble shoot! Despite this I can't get it to work.

I have an event composed of a trigger of a unit aircraft entering the area and the action is this script. The trigger works but when the script runs the unit does not refuel. Can you see what I'm doing wrong?

Thanks

this is the LUA script in the action:

local myunit = ScenEdit_UnitX()

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


(in reply to KnightHawk75)
Post #: 4
RE: refuel an air aircraft that enters an area - 11/5/2021 6:49:30 PM   
KnightHawk75

 

Posts: 1450
Joined: 11/15/2018
Status: offline
Need to actually call the function after defining it, as show in example usage.

See attached functional sample scene.

att: ShowAutomaticRefueling.zip


Attachment (2)

(in reply to orca)
Post #: 5
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> refuel an air aircraft that enters an area Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

2.000