Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: bomb3rman on February 03, 2018, 07:14:21 am

Title: Get loadout of secondary banks to modify loadout-variable
Post by: bomb3rman on February 03, 2018, 07:14:21 am
Hello, sadly I need some more help...

I want to use missiles from a specific amount. If there are some of them left at the end of the mission, I want them to "get back to the amount".

At the beginning of the mission, I want FRED to check the loadout in the secondary banks of the player's ship, e.g. if it's armed with a trebuchet and the number of missiles in it. Then I'd like Fred to substract the number found from the corresponding loadout-variable ("loadout_Trebuchet"). So that the missiles are taken out of the available stock you can choose from.

At the end of the mission I'd like FRED to check again if there are any missiles left in the secondary bankds and add them back to the corrensponding variable...

But it seems I'm stuck here. I know that I have to tell FRED somehow to "get" the data from the ship and then it's just

- modify variable
--  Loadout_Trebuchet
-- -
--- INSERT DATA I WANT TO GET

and at the end it's just

- modify variable
-- Loadout_Trebuchet
-- +
--- INSERT DATA I WANT TO GET

In short: How can I tell FRED to gather the information  :) ?

Thank you!
Title: Re: Get loadout of secondary banks to modify loadout-variable
Post by: karajorma on February 03, 2018, 07:39:39 am
I had planned to add SEXPs for doing this stuff when I created the team-loadout changes but when no one used it, I moved on to other things. I didn't bother because I knew it was technically possible to do it, but the FREDding is rather complicated. Are you planning on doing this just for the player or for all their wingmen too?

Title: Re: Get loadout of secondary banks to modify loadout-variable
Post by: bomb3rman on February 03, 2018, 07:43:44 am
No it's just for the player. The campaign should keep the focus on the player and his ship, the wingmen will do their thing and get their own ships from the mission, not the player. I think this way it will be easier to keep the missions balanced since I just have to think about one ship and its loadout, not entire wings :)

I'm quite surprised that I seem to be the only one using the team-loadout changes right now... Didn't Bem Cavalgar use this stuff too? These missions seem to keep track on primaries, ships and secondaries as well...

EDIT: I found the secondary-fired-since SEXP... Is there a way to use this with the "every-time" conditional to repeatedly substract "1" if the player fired a missile? I think this might get problematic when you switch to double mode...
Title: Re: Get loadout of secondary banks to modify loadout-variable
Post by: karajorma on February 03, 2018, 08:50:26 am
Personally I would wait until mission end and then take a tally of what is still unused rather than trying to keep track of which missiles get fired. You'll need two kinds of events. One at t=0 which subtracts all the missiles the player has loadedout. Then at the end of the mission you add back in all the missiles that haven't be fired.

The best solution for this involves SEXP Containers but they're still an experimental feature so unfortunately you can't use them. Because of that, you'll need one SEXP like this for every type of missile you are keeping track of. You'll need a second set of SEXPs at the end of the mission to tally up what is left unfired.

when
- true
- when
-- has-secondary-weapon
--- Alpha 1
--- 0   <------------------------- weapons in the first bank
--- Trebuchet
-- modify-variable
--- Loadout_Trebuchet
--- -
---- Loadout_Trebuchet
---- get-secondary-ammo
----- Alpha 1
----- 0  <------------------------- weapons in the first bank
- when
-- has-secondary-weapon
--- Alpha 1
--- 0   <------------------------- weapons in the second bank
--- Trebuchet
etc.

To be honest, without SEXP Containers I'd probably ask someone for a script to do the same thing as this is rather unwieldy.
Title: Re: Get loadout of secondary banks to modify loadout-variable
Post by: 0rph3u5 on February 03, 2018, 08:56:18 am
EDIT: I found the secondary-fired-since SEXP... Is there a way to use this with the "every-time" conditional to repeatedly substract "1" if the player fired a missile? I think this might get problematic when you switch to double mode...

Careful, every-time doesn't do what you think it does... (there is topic about it and I am too lazy to search)



So, I experimented with replacing Red-Alert (because you know sliding in perspective changes/cutscenes/what-have-you into a campaign doesn't gel well with how Red-Alert is supposed to work) and did something similar.

Firstly, the check of ships load-out is actually pretty simple if you use string variables with the weapons clear name or a reference tables for a number variable.

The clear name method would look like this:
Code: [Select]
$Formula: ( when
   ( is-event-true-delay
      "campaign-logic-switch"
      0
   )
   ( modify-variable
      @Zeta2-s1-ammo[100]
      ( get-secondary-ammo "Zeta 2" 0 )
   )
   ( modify-variable
      @Zeta2-s2-ammo[100]
      ( get-secondary-ammo "Zeta 2" 1 )
   )
   ( modify-variable
      @Zeta2-s3-ammo[100]
      ( get-secondary-ammo "Zeta 2" 2 )
[...]
   )
   ( when
      ( has-secondary-weapon
         "Zeta 2"
         "0"
         "Rockeye"
      )
      ( modify-variable
         "@Zeta2-s1-name[Tempest]"
         "Rockeye"
      )
   )
   ( when
      ( has-secondary-weapon
         "Zeta 2"
         "1"
         "Rockeye"
      )
      ( modify-variable
         "@Zeta2-s2-name[Tempest]"
         "Rockeye"
      )
   )
   ( when
      ( has-secondary-weapon
         "Zeta 2"
         "2"
         "Rockeye"
      )
      ( modify-variable
         "@Zeta2-s3-name[Tempest]"
         "Rockeye"
      )
   )
   ( when
      ( has-secondary-weapon
         "Zeta 2"
         "0"
         "Tempest"
      )
      ( modify-variable
         "@Zeta2-s1-name[Tempest]"
         "Tempest"
      )
   )
   ( when
      ( has-secondary-weapon
         "Zeta 2"
         "1"
         "Tempest"
      )
      ( modify-variable
         "@Zeta2-s2-name[Tempest]"
         "Tempest"
      )
   )
   ( when
      ( has-secondary-weapon
         "Zeta 2"
         "2"
         "Tempest"
      )
      ( modify-variable
         "@Zeta2-s3-name[Tempest]"
         "Tempest"
      )
   )
   ( when
      ( has-secondary-weapon
         "Zeta 2"
         "0"
         "Hornet"
      )
      ( modify-variable
         "@Zeta2-s1-name[Tempest]"
         "Hornet"
      )
   )
   ( when
      ( has-secondary-weapon
         "Zeta 2"
         "1"
         "Hornet"
      )
      ( modify-variable
         "@Zeta2-s2-name[Tempest]"
         "Hornet"
      )
   )
   ( when
      ( has-secondary-weapon
         "Zeta 2"
         "2"
         "Hornet"
      )
      ( modify-variable
         "@Zeta2-s3-name[Tempest]"
         "Hornet"
      )
   )
   ( when
      ( has-secondary-weapon
         "Zeta 2"
         "0"
         "Harpoon"
      )
      ( modify-variable
         "@Zeta2-s1-name[Tempest]"
         "Harpoon"
      )
   )
   ( when
      ( has-secondary-weapon
         "Zeta 2"
         "1"
         "Harpoon"
      )
      ( modify-variable
         "@Zeta2-s2-name[Tempest]"
         "Harpoon"
      )
   )
   ( when
      ( has-secondary-weapon
         "Zeta 2"
         "2"
         "Harpoon"
      )
      ( modify-variable
         "@Zeta2-s1-name[Tempest]"
         "Harpoon"
      )
   )
[...]
Notes:
- Yes that's a that a when with its operators replaced by additional whens;
- the "campaign logic switch"-variable is just there to ensure this doesn't trigger outside a campaign-setting, basically treat it like has-time-elapsed "1" for the purpose of this;
- "[...]" means I cut something out of the original Notepad output;
- if a ship that is eligible to be picked as more than 3 secondary banks you may have to expand that to accomidate, this example was made for a mission in which the Loki, Ulysses and Zeus are eligible picks.

In a reference-table version of the same you wouldn't have string variables but a set of numbers which correspond to the weapons, makes it less prone to typos but also requires you to have the reference table on hand at all times.


Secondly, the check at the end of mission is a bit of tricky part because you have to select a point in time when FRED should save the data; It can't safe the stuff after the player has departed (as in moved on to the debriefing) because at that point no longer runs events. That's a sweet spot you have to find.

For the example above the save-point is when the mission critical ship departs, which also triggers a force-warp 10 seconds later; this might cause the missiles fired in the final 10 seconds to not count.

To view:
Code: [Select]
$Formula: ( when
   ( has-departed-delay 0 "Vindicator" )
   ( modify-variable
      @Zeta2-s1-ammo[100]
      ( get-secondary-ammo "Zeta 2" 0 )
   )
   ( modify-variable
      @Zeta2-s2-ammo[100]
      ( get-secondary-ammo "Zeta 2" 1 )
   )
   ( modify-variable
      @Zeta2-s3-ammo[100]
      ( get-secondary-ammo "Zeta 2" 2 )
   )
[...]
Note:
- This has a corresponding "recall event" in the next mission;
- "[...]" means I cut something out of the original Notepad output;
- if a ship that is eligible to be picked as more than 3 secondary banks you may have to expand that to accomidate, this example was made for a mission in which the Loki, Ulysses and Zeus are eligible picks.


Does that help?
Title: Re: Get loadout of secondary banks to modify loadout-variable
Post by: bomb3rman on February 03, 2018, 09:07:50 am
Thank you both for the quick answers, I now have a clue on what to do :)

I don't think it's that much of work. I only have to do this once for all 3 banks and missiles, then I can copy and paste the stuff via editor to all future missions.

Thanks for your help!

During the campaign, the player will sometimes be forced into the cockpit of other ships of other factions, but since they use different weapons this won't mess with the variables and I thought about locking the ships and weapons in these missions anyway :) So I think this is pretty save to use.

EDIT: Just two more questions:

1. So I can put several "when" conditions into one event? I thought I had to do one event for one check of a bank at a time (for example: Alpha 1 Bank 1 Harpoon check = one event, Alpha 1 Bank 2 Harpoon check = second event...)
-> So I can put several checks into one event and they can trigger individualy?

2. The only thing that bothers me is the use of support ships since this might screw up the whole thing... but I think I might just not allow support ships at all  ;7
Title: Re: Get loadout of secondary banks to modify loadout-variable
Post by: bomb3rman on February 04, 2018, 06:17:01 am
Sorry for double-post, but just wanted to tell that I answered my last questions by myself. Yes, you can put several checks into one event and they can trigger individualy and yes I might not use a support ship at all  :D

So thanks to all!
Title: Re: Get loadout of secondary banks to modify loadout-variable
Post by: karajorma on February 04, 2018, 07:32:24 am
If you do this

When
-trigger 1
-when
-- trigger 2
-when
-- trigger 3

Trigger 1 MUST evaluate to true or nothing will happen. After that, the other triggers will be evaluated independently of each other.

You can even do the same with when-argument but be warned that unless you save the argument to a string variable, there is no way to get at the outermost argument.
Title: Re: Get loadout of secondary banks to modify loadout-variable
Post by: bomb3rman on February 04, 2018, 11:34:35 am
Ok, now it's clear, thanks :)