Jump to content
The simFlight Network Forums
Sign in to follow this  
crwk78

First attempt at LUA function

Recommended Posts

Hi, I'm trying to write a LUA to turn off AI traffic when airborne. So far I have this which doesn't seem to be working.

 

function trafficoff(offset, value)

if value == 0 then
ipc.control(1009)

end

event.offset("0336", "UB",
"trafficoff")

 

Any ideas where the problem is?

 

CK

 

Share this post


Link to post
Share on other sites

I think you want offset 0366, not 0336. Try with
   event.offset(0x0366, "UW", "trafficoff")

John

*update*

You are also missing an end statement for the if: 
 

function trafficoff(offset, value)
    if value == 0 then
        ipc.control(1009)
        ipc.log("AI traffic turned off")
    end
end

 event.offset(0x0366, "UW", "trafficoff")
 

Edited by John Dowson

Share this post


Link to post
Share on other sites

Also i'm not sure that this will do what you want it to do. Control 1009 is the Traffic Density Toggle. Toggling this only works in one session, and if there is no known initial state then this will set/toggle the density to 100%.

You may therefore want to add a 0 parameter or use control 1008 instead.

There is a similar lua example included that may be useful -  this freezes taxi-out AI traffic when you lower gear (or lower flaps) and releases when you land:

-- NOTE: For use with FSUIPC 5 only

-- This small plug in, which should be pre-loaded: for example, by adding
-- [Auto] 
-- 1=Lua AIfreezer
-- to your FSUIPC5.INI file.

-- It freezes taxi-out AI traffic when you lower your gear,
-- and releases them when you touch down.

-- For aircraft with non-retractable gear, it checks the state of
-- the Flaps instead, expecting full flaps for landing. (amend where
-- noted for other flap settings).

function GroundCheck(off, val)
	if ipc.val ~= 0 then
		ipc.control(1149) -- Freeze AI off if user landed
		ipc.log("AI taxiout traffic released")
	end
end

function GearCheck(off, val)
	if val >= 16383 and ipc.readUW(0x0366) == 0 then
		ipc.control(1150) -- Freeze AI on if gear just lowered (whilst in the air)
		ipc.log("AI taxiout traffic frozen")
	end
end

function FlapsCheck(off, val)
	-- See if gear is fixed first:
	if ipc.readUB(0x060C) == 0 then
		if val >= 16383 and ipc.readUW(0x0366) == 0 then
			ipc.control(1150) -- Freeze AI on if now full flaps set when in the air
			ipc.log("AI taxiout traffic frozen")
		end
	end
end

event.offset(0x0366, "UW", "GroundCheck")
event.offset(0x0BE8, "UD", "GearCheck")
event.offset(0x0BDC, "UD", "FlapsCheck")

John

Share this post


Link to post
Share on other sites

Thanks John, very helpful.

Your first suggestion worked. I also hadn't prefixed the filename with 'lua' in the [AUTO] section of fsuipc.ini.

I think it'll work because I always start with traffic on, so it should always go off when I rotate, which is exactly what I need. PSXSeeconTraffic (through it's own settings) will turn its own AI on when I get airborne, so I should get a seamless switch, avoiding the live traffic when on the ground as it's not always very realistic and the default AI in the air for the same reason! 1008 with 0 might be a more robust option though.

I'll look into your post above to see if I can adapt it to what I need. You have given me a good idea to use the gear up event (I'm assuming there is one) rather than the airborne one, as my pitch up attitude will mean I won't see the transition between AI modes.

Many thanks again,

Charlie

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.