Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: freespacegundam on March 01, 2006, 03:15:52 pm

Title: FRED Help Needed (Event triggering)
Post by: freespacegundam on March 01, 2006, 03:15:52 pm
Okay, to make a long story short I'm designing a mission (I can't say what its for so bear with me) where the player is instructed to scan a group of cargo containers in order to locate three that contain a valuable resource out of thirteen available containers.  The trouble comes when I want the blasted thing to send messages.  Basically, this is how I want it to work.

First: Player finds any 1 of the cargo containers before the other two, command sends one message.

Two: Player finds one of the other two cargo containers after already finding the first one, different message.

Three: Player finds the last container after finding the first two in any order, final message sent.

The problem is that the way I've FREDed it makes all the messages display everytime any of the three containers is found.  This is how I have it set up for most of the events.

Find 1
-when
     -and
            -or
               Cargo1 is known
            -or
               Cargo 2 is known
            -or
               Cargo 3 is known
     -is-event-incomplete
       -Find 2
-send message
  -message 1

Find 2

-when
     -and
            -or
               Cargo1 is known
            -or
               Cargo 2 is known
            -or
               Cargo 3 is known
     -is-event-true
       -Find 1
-send message
  -message 2

Find 3
-when
     -and
            -or
               Cargo1 is known
            -or
               Cargo 2 is known
            -or
               Cargo 3 is known
     -is-event-true
       -Find 1
       -Find 2
-send message 3

I need to figure out a way to do this so that the messages will trigger at the right time rather than all at once.  I desperately need assistance.
Title: Re: FRED Help Needed (Event triggering)
Post by: Nuclear1 on March 01, 2006, 03:29:23 pm
This should be nice and easy to do. Easiest option here I can see would be to use variables. You would need two different sets of events for this, but it is easy.

Code: [Select]
-when
--cargo-known-delay
---Cargo 1
---0
--modify-variable
---CargoScanned
----+
----1

Make two other identical events, interchanging the cargo names for each of the special containers.

Second step:

Code: [Select]
--when
---=
----CargoScanned
----1
--send-message
---<message data>

Do this three times, but using 2 and 3 in the next two events in place of the one. When the player scans each of the containers, it will add one to the counter, and when the counter equals a certain number, a message will be played at that moment.

Hope this helps. :)
Title: Re: FRED Help Needed (Event triggering)
Post by: Shade on March 01, 2006, 03:34:17 pm
Your problem is that because the only difference between the events is that the previous events have to be true for the next one to happen, once 'Find 1' becomes true, 'Find 2' immediately becomes true, and once 'Find 2' becomes true, 'Find 3' becomes true. So all 3 messages will be displayed whenever any of the cargoes are scanned.

What you can do if you have enough events to spare, is to have 3 events for each message, dealing with only one cargo at a time instead of lumping all 3 together. The 'not' operant can help you make sure each event applies to only one possible combination of known cargo. All this is doable in retail FRED. Another possibility is to mess around with variables, which is neater, but some people have a hard time with them.
Title: Re: FRED Help Needed (Event triggering)
Post by: freespacegundam on March 01, 2006, 03:36:57 pm
Eh, yes, some people do have problems with variables, aka me.  How do I go about creating the CargoScanned part of that?  Is it just another event?
Title: Re: FRED Help Needed (Event triggering)
Post by: Nuclear1 on March 01, 2006, 03:40:54 pm
Nope. Simply right click on any event and look for "Add Variable" in the selection.

Like myeh:

[attachment deleted by admin]
Title: Re: FRED Help Needed (Event triggering)
Post by: Nuclear1 on March 01, 2006, 03:44:25 pm
And from there, you'll get this next option.

Simply replace "VariableName" with "CargoScanned" and "Default Value" with 0.



[attachment deleted by admin]
Title: Re: FRED Help Needed (Event triggering)
Post by: freespacegundam on March 01, 2006, 03:47:35 pm
Ah I see, but how do I get FRED to do + and then 1 below it?  Everytime I change it to add 1 its always add and then two zeros, or do I simply ignore the second one?
Title: Re: FRED Help Needed (Event triggering)
Post by: Shade on March 01, 2006, 03:48:49 pm
Thought that might be the case or you'd have used variables in the first place. I'll just show you how the events should look :)

Code: [Select]
Add a variable called 'scancount' and initialize it to 0

Scan1
    -when
        -is-cargo-known-delay
            -cargo 1
            -0
    -modify-variable
        -scancount
        -+
            -scancount
            -1

Scan2
    -when
        -is-cargo-known-delay
            -cargo 2
            -0
    -modify-variable
        -scancount
        -+
            -scancount
            -1

Scan3
    -when
        -is-cargo-known-delay
            -cargo 3
            -0
    -modify-variable
        -scancount
        -+
            -scancount
            -1

What this does is it adds one to the scancount variable when a cargo is scanned. So if one is scanned, regarless of which, scancount = 1, if all 3 are scanned, scancount =3. So for the messages, you simply check what scancount is and send the appropriate message.
Title: Re: FRED Help Needed (Event triggering)
Post by: freespacegundam on March 01, 2006, 03:58:23 pm
Ah, I have it now, many thanks to everyone.  Hopefully I'll have this worked out soon.
Title: Re: FRED Help Needed (Event triggering)
Post by: karajorma on March 01, 2006, 05:36:15 pm
My FAQ has a nice long explaination of how to use variables which hopefully isn't too technical. Anyone who has problems with them should check it out.

While I'm at it if you're using SCP you could replace the three events with

Scaned Crates (Repeat count 3)
when-argument
-any-of
--Cargo 1
--Cargo 2
--Cargo 3
-is-cargo-known-delay
-- < argument >
-modify-variable
--Scancount(0)
-- +
---Scancount(0)
---1
-invalidate-argument
--< argument >

Looks more complicated I know and it's probably not worth it in this case unless you fany experimenting with the new conditionals but if you wanted to add three more crates all you'd have to do is add their names below the other 3. :D
Title: Re: FRED Help Needed (Event triggering)
Post by: Shade on March 02, 2006, 08:28:23 am
Now that's handy. Knew about when-argument, but not about the invalidate argument sexp until now. That's definitely the best way of doing it :)
Title: Re: FRED Help Needed (Event triggering)
Post by: Nuclear1 on March 02, 2006, 08:58:01 am
IIRC, FG uses retail FRED, so when-argument wouldn't be applicable in his case. Still, it's a good answer, kara. I've never used any of the new conditionals myself, so I'll have to go this a try later.
Title: Re: FRED Help Needed (Event triggering)
Post by: Slasher on March 02, 2006, 09:48:32 am
Sorry for the thread hijack, but while we're on the topic of new conditionals I was wondering if anyone could help me out.  I've got an event set up like this:

Event Name
    every-time-argument
        number-of
            3
            <ship 1>
            <ship 2>
            <ship 3>
            <ship 4>
            <ship 5>
            <ship 6>
            <ship 7>
            <ship 8>
        key-pressed
            1
        add-goal
            <argument>
                 ai-warp
                      89

My goal was to make it so any 3 of the 8 ships would depart whenever the player presses the 1 key.  It has never worked.  I've tried this with a when-argument with a repeat count despite knowing it wouldn't work, and sure enough, it didn't.  I haven't even bothered trying a key-reset SEXP because on the few times I did get ships to jump out by pressing 1, they all warped out, thereby precluding pressing the 1 key again.  I'm obviously missing something, what is it?
Title: Re: FRED Help Needed (Event triggering)
Post by: Goober5000 on March 02, 2006, 10:12:58 am
My goal was to make it so any 3 of the 8 ships would depart whenever the player presses the 1 key. It has never worked. I've tried this with a when-argument with a repeat count despite knowing it wouldn't work, and sure enough, it didn't. I haven't even bothered trying a key-reset SEXP because on the few times I did get ships to jump out by pressing 1, they all warped out, thereby precluding pressing the 1 key again. I'm obviously missing something, what is it?

That ... won't work ... for so many reasons. :lol: Try using different sexps.
Title: Re: FRED Help Needed (Event triggering)
Post by: karajorma on March 02, 2006, 02:33:29 pm
Sorry for the thread hijack, but while we're on the topic of new conditionals I was wondering if anyone could help me out.  I've got an event set up like this:

Event Name
    every-time-argument
        number-of
            3
            <ship 1>
            <ship 2>
            <ship 3>
            <ship 4>
            <ship 5>
            <ship 6>
            <ship 7>
            <ship 8>
        key-pressed
            1
        add-goal
            <argument>
                 ai-warp
                      89

My goal was to make it so any 3 of the 8 ships would depart whenever the player presses the 1 key.  It has never worked.  I've tried this with a when-argument with a repeat count despite knowing it wouldn't work, and sure enough, it didn't.  I haven't even bothered trying a key-reset SEXP because on the few times I did get ships to jump out by pressing 1, they all warped out, thereby precluding pressing the 1 key again.  I'm obviously missing something, what is it?

There are quite a few problems with the SEXP. The biggest one is that you've used number-of but haven't specified any conditional to figure out how many of them have actually fulfilled the trigger conditions. As a result all of them are valid and they all jump out.

I would suggest solving the problem using the random-of SEXP like this.


Event Name
    every-time-argument
        random-of
            <ship 1>
            <ship 2>
            <ship 3>
            <ship 4>
            <ship 5>
            <ship 6>
            <ship 7>
            <ship 8>
        and
            key-pressed
                1
            <
               ShipCounter(0)
               3
        add-goal
            <argument>
                 ai-warp
                      89
        modify-variable
               ShipCounter(0)
               +
                     ShipCounter(0)
                     1
       invalidate-argument
            <argument>


The changes I've added should ensure that only 3 ships are every selected
Title: Re: FRED Help Needed (Event triggering)
Post by: Goober5000 on March 02, 2006, 03:42:00 pm
Hmm... that actually won't work.  The problem is that it's possible for random-of to choose one of the invalidated arguments and thus not do anything.  Perhaps it should only choose randomly from among the valid arguments as opposed to all of them.
Title: Re: FRED Help Needed (Event triggering)
Post by: Slasher on March 02, 2006, 03:45:47 pm
Well, I got three ships to jump out which is a big improvement over having all of them fly away, but it only worked once.  I thought a lack of a key-reset might be the culprit so I put it in the above event thinking it would reset whenever 1 was pressed but it still wouldn't come through. 

Title: Re: FRED Help Needed (Event triggering)
Post by: Goober5000 on March 02, 2006, 03:48:20 pm
Well, I got three ships to jump out which is a big improvement over having all of them fly away, but it only worked once. I thought a lack of a key-reset might be the culprit so I put it in the above event thinking it would reset whenever 1 was pressed but it still wouldn't come through.

I dunno, but key-reset won't work for that.  You'd need key-reset-multiple.
Title: Re: FRED Help Needed (Event triggering)
Post by: karajorma on March 02, 2006, 03:52:41 pm
Hmm... that actually won't work.  The problem is that it's possible for random-of to choose one of the invalidated arguments and thus not do anything.  Perhaps it should only choose randomly from among the valid arguments as opposed to all of them.

That's why I used every-time. If it picks an invalidated argument it should simply pick again next frame without incrementing the count or executing any of the other action operators. Eventually it will pick one that is valid.

As for picking a valid argument only that's definitely a good idea.

Well, I got three ships to jump out which is a big improvement over having all of them fly away, but it only worked once.  I thought a lack of a key-reset might be the culprit so I put it in the above event thinking it would reset whenever 1 was pressed but it still wouldn't come through. 

Using key reset would be a bad idea as that's part of the trigger for the event. I suppose you could try using key-reset (or key-reset-multiple) if you used it like this

Event Name
    every-time-argument
        random-of
            <ship 1>
            <ship 2>
            <ship 3>
            <ship 4>
            <ship 5>
            <ship 6>
            <ship 7>
            <ship 8>
        and
           or
                 key-pressed
                      1
                 >
                      ShipCounter(0)
                      0
            <
               ShipCounter(0)
               3
        add-goal
            <argument>
                 ai-warp
                      89
        modify-variable
               ShipCounter(0)
               +
                     ShipCounter(0)
                     1
       invalidate-argument
            <argument>
      Key-reset
             1

As for why you didn't get everything to jump out I think I'm going to have to investigate this one :)
Title: Re: FRED Help Needed (Event triggering)
Post by: Slasher on March 02, 2006, 03:54:14 pm
I take it that's an SCP job?
Title: Re: FRED Help Needed (Event triggering)
Post by: karajorma on March 02, 2006, 03:58:48 pm
Yep. :)
Title: Re: FRED Help Needed (Event triggering)
Post by: Slasher on March 02, 2006, 04:17:44 pm
Okay, thanks for the help you two.   :cool:
Title: Re: FRED Help Needed (Event triggering)
Post by: karajorma on March 02, 2006, 05:21:15 pm
Well, I got three ships to jump out which is a big improvement over having all of them fly away, but it only worked once.  I thought a lack of a key-reset might be the culprit so I put it in the above event thinking it would reset whenever 1 was pressed but it still wouldn't come through. 

Odd. I just built a mission to test that and it worked fine with both the most recent CVS (using random-multiple-of) and the 02/02-06 build (using random-of) and it worked fine with both.

Are you using a very recent CVS build? Be warned that any mission built using random-of to do this will break as soon as you start using a build that supports random-multiple-of since that does what random-of appeared to do in earlier builds. More info on the subject is here (http://www.hard-light.net/forums/index.php/topic,38643.0.html).
Title: Re: FRED Help Needed (Event triggering)
Post by: Slasher on March 02, 2006, 05:51:09 pm
I used the 2-27 build of FSO for my test.  Just to clarify, the variable was a regular number variable, there was no repeat count, and I used the first event you listed above, the one without the key-reset. 
Title: Re: FRED Help Needed (Event triggering)
Post by: karajorma on March 03, 2006, 05:39:04 pm
Give this mission a try. Press 1. Three ships should jump out.

[attachment deleted by admin]
Title: Re: FRED Help Needed (Event triggering)
Post by: Slasher on March 04, 2006, 01:52:36 pm
I've downloaded it but have yet to take a look at it.  Thanks in any event for the test mission though.  :yes:
Title: Re: FRED Help Needed (Event triggering)
Post by: karajorma on March 04, 2006, 02:11:00 pm
Shouldn't take more than a minute to test. Press 1 and see if the ships jump out :)

I'd already made the test mission anyway so I figured it's a good idea to see if you can reproduce your problem with my mission :)