Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: diamondgeezer on March 06, 2007, 06:45:11 pm

Title: AI, repeat events and creating a toggle effect
Post by: diamondgeezer on March 06, 2007, 06:45:11 pm
'Lo again peeps. So I'm having all kinds of fun with the new stuff in FREDO, but something is still beating my brain.

I'm trying to use the player_use_ai function to bodge an automatic landing for Alpha 1. Now, a simple press-a-key-and-you-land kind of scenario seems to work just fine. But I'm trying to build in an option for the player to disengage the AI and retake control... just in case he/she feels they want to fly around a bit longer admiring their handiwork, or whatever.

My initial attempt was to have one SEXP adding the use-ai command when a key was pressed, with a repeat count of 999, and another with the not-use-ai version, again repeating... in tests, this simply makes my fighter do cartwheels when I use the disengage bit.

I think repeats are not my friend here. I've just discovered the new bits like every-time and such, but not convinced they're right for me. What I really want is a toggle-type feature, where you can flip a switch on and off. Is there any way to call up the last key pressed? Or any hackey simulation of that?

Strangely, despite the huge demand for this kind of auto-landing back in the day, there doesn't seem to be a thread on this subject...

DG
Title: Re: AI, repeat events and creating a toggle effect
Post by: Axem on March 06, 2007, 07:32:36 pm
After a few minutes of tinkering, I've made a test mission that does what you describe. I use variables and every-times to check what the player's ship should be doing when he presses the auto landing key (in my mission I used ALT-J).

everytime autoLand is 0 and the player presses ALT-J, autoLand gets set to 1.
everytime autoLand is 1, the ship goes to AI control and gets an order to fly the waypoint into the hangar. autoLand also gets set 2 right after so this won't trigger every frame.
everytime autoLand is 2 and the player presses ALT-J, the ship goes back to player control and autoLand resets to 0 so the cycle can begin anew.

Here's a link to my mission if you want to take a look.
http://www.axemspace.com/files/misc/_autolanding.fs2
Title: Re: AI, repeat events and creating a toggle effect
Post by: karajorma on March 07, 2007, 02:21:27 am
I'm still not entirely sure the 1 key works properly with repearing events. If you have problems try switching to something like G and see if that solves it.
Title: Re: AI, repeat events and creating a toggle effect
Post by: CP5670 on March 07, 2007, 03:02:18 am
If you're referring to the multiplayer messaging key, it works fine. I've used it that way in a couple of missions, with a pair of every-time events.
Title: Re: AI, repeat events and creating a toggle effect
Post by: diamondgeezer on March 07, 2007, 12:08:25 pm
Thanks Axem, I'll take that apart and have a look.

Had to check your profile to make sure you weren't Tiara there ;)
Title: Re: AI, repeat events and creating a toggle effect
Post by: Turey on March 08, 2007, 02:12:25 am
Had to check your profile to make sure you weren't Tiara there ;)

 :wtf: You disturb me.

That's not necessarily a bad thing though.  :)
Title: Re: AI, repeat events and creating a toggle effect
Post by: diamondgeezer on March 08, 2007, 03:29:12 pm
Quote from: an0n
DG, you scare me with your oddness

:)

OK, so everything now seems to be more or less peachy... but I must profess my dislike of fighters and bombers entering the landing pattern at any old angle of roll. This happens with AI fighters, my own under AI control, the lot. I was wondering if there was a method of maybe rolling myself 'upright', parallel to a landing strip of known location and orientation, using the existing coordinate manipulation SEXPs or if this is a job for the lovely SCP chaps...