Author Topic: Problems with FREDed cloaking  (Read 2128 times)

0 Members and 1 Guest are viewing this topic.

Offline Dragon

  • Citation needed
  • 212
  • The sky is the limit.
Problems with FREDed cloaking
I'm working on a cloaking system in FS engine and archived success with making a fighter invisible ,but I have a problem.
Every time I cloak and decloak ,my secondary (and primary ,though they are not a problem now ,because I changed all weapons on a cloaking fighter to energy dependant) banks reset.
This wouldn't be a problem with cloaking on autopiloting or other specific moments in mission ,because I would simply load secondary bank ammo into variable and restore them after decloak ,linking it to specific event ,but with "combat cloaking" I'm working on ,this doesn't seem to work.
This is a pair of events which control cloaking and decloaking ,I would like to know what I'm doing wrong.
Code: [Select]
$Formula: ( every-time
   ( and
      ( key-pressed "1" )
      ( is-ship-class
         "Assasin"
         "Alpha 1"
      )
   )
   ( change-ship-class
      "Assasin#Cloaked"
      "Alpha 1"
   )
   ( ship-stealthy "Alpha 1" )
   ( lock-primary-weapon "Alpha 1" )
   ( lock-secondary-weapon "Alpha 1" )
   ( lock-afterburner "Alpha 1" )
   ( key-reset "2" )
   ( turret-lock-all "Alpha 1" )
   ( protect-ship "Alpha 1" )
   ( modify-variable
      @SAmmo1[0]
      ( get-secondary-ammo "Alpha 1" 0 )
   )
   ( modify-variable
      @SAmmo2[0]
      ( get-secondary-ammo "Alpha 1" 1 )
   )
   ( modify-variable
      @SAmmo3[0]
      ( get-secondary-ammo "Alpha 1" 2 )
   )
   ( modify-variable
      @SAmmo4[0]
      ( get-secondary-ammo "Alpha 1" 3 )
   )
)
+Name: Cloak
+Repeat Count: 1
+Interval: 1
+Team: 0

$Formula: ( every-time
   ( and
      ( key-pressed "2" )
      ( is-ship-class
         "Assasin#Cloaked"
         "Alpha 1"
      )
   )
   ( change-ship-class
      "Assasin"
      "Alpha 1"
   )
   ( ship-unstealthy "Alpha 1" )
   ( unlock-primary-weapon "Alpha 1" )
   ( unlock-secondary-weapon "Alpha 1" )
   ( unlock-afterburner "Alpha 1" )
   ( key-reset "1" )
   ( turret-free-all "Alpha 1" )
   ( unprotect-ship "Alpha 1" )
   ( set-secondary-ammo
      "Alpha 1"
      0
      @SAmmo1[0]
   )
   ( set-secondary-ammo
      "Alpha 1"
      1
      @SAmmo2[0]
   )
   ( set-secondary-ammo
      "Alpha 1"
      2
      @SAmmo3[0]
   )
   ( set-secondary-ammo
      "Alpha 1"
      3
      @SAmmo4[0]
   )
)
+Name: Decloak
+Repeat Count: 1
+Interval: 1
+Team: 0
Player is able to cloak anytime in the mission ,is ignored by all enemy ships and his weapons ,afterburners and turret are locked.
The only issue are those ammunition resets (and maybe lack of cloaking animation ,but it's not a serious problem).

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Problems with FREDed cloaking
Code: [Select]
$Formula: ( every-time
   ( and
      ( key-pressed "2" )
      ( is-ship-class
         "Assasin#Cloaked"
         "Alpha 1"
      )
   )

SNIP

( key-reset "1" )


I suspect that's the real problem. Why are your key resets the wrong way round?
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Dragon

  • Citation needed
  • 212
  • The sky is the limit.
Re: Problems with FREDed cloaking
What exactly is wrong with them?
The event itself works and triggers as expected ,it's only the number of missiles that's getting reset every time the ship's class changes.

 

Offline headdie

  • i don't use punctuation lol
  • 212
  • Lawful Neutral with a Chaotic outook
    • Skype
    • Twitter
    • Headdie on Deviant Art
Re: Problems with FREDed cloaking
hows this for a suggestion for a later SCP build

in the Ships table you can set an $altPOF / $CloakedPOF

when in game the player pressed the bound key and it does one of 2 things

1 - the players (or scripted ship / missile) switches to the listed ship file which is identical to the original except the skin is set invisible with all current settings/stats transferred over.

2 - the ship/missile switches to a generic WCS style ghost file which is able to be set with the previously listed data.

I imagine WCS would like either for making stealth fighters and skipper missiles easier to implement.
Minister of Interstellar Affairs Sol Union - Retired
quote General Battuta - "FRED is canon!"
Contact me at [email protected]
My Release Thread, Old Release Thread, Celestial Objects Thread, My rubbish attempts at art

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Problems with FREDed cloaking
We'll do cloaking properly at some point, there's no need to hack it into the code in this fashion.

Hacking it in via FRED on the other hand is encouraged.

 
What exactly is wrong with them?
The event itself works and triggers as expected ,it's only the number of missiles that's getting reset every time the ship's class changes.

Yeah, I took another look at it and you're right, I'd have expected that to work even if your resets are a little unconventional for my liking (I believing in always resetting a key press in the event you test it in rather than hoping the rest of your SEXP logic will keep you safe so I would have reset both). I'm a little mystified as to why this isn't working so I suggest that you try it in a test mission using only FS2 ships. If you can make it fail there you've basically made this my number 1 priority (I absolutely hate having bugs in my code! :D )
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Problems with FREDed cloaking
So what happened with this?
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Dragon

  • Citation needed
  • 212
  • The sky is the limit.
Re: Problems with FREDed cloaking
I put cloaking aside for a while because of work on BP, but now I checked it with retail files and missiles still reset.
Tested on latest nightly ,using "no mods" setting in launcher.
I hope you can either point me what I did wrong ,or fix it in code if there's a bug.

[attachment deleted by MSC

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Problems with FREDed cloaking
As I said, if there is a bug it's in my code. Which makes it top priority for me. :D

I'll look tonight.

EDIT : I took a look and I can see the cause of your problem. It doesn't actually lie in the get and set SEXPs themselves in the end at all.

Due to the way change-ship-class works it resets the ammo to maximum when it is used. The problem is that you are using it before the get-secondary-ammo SEXPs so the values you are storing are obviously borked now. Cut and paste the change-ship-class SEXP to the end of the table and you'll immediately fix this problem (although the numbers in cloaked mode are wrong, the correct values will be written back from the value immediately upon uncloaking).

I'm pretty sure you can figure out how to cure that minor problem anyway. :D
« Last Edit: June 30, 2009, 04:14:08 pm by karajorma »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Dragon

  • Citation needed
  • 212
  • The sky is the limit.
Re: Problems with FREDed cloaking
Works flawlessly, great thanks Kajorama.
Is that possible to make something happen 3 seconds after each time player cloaks?
(I was thinking of making invisible texture with animated -glow map, then deactivate this map to render fighter fully invisible. 3 seconds is a lenght of my cloaking sound.)

  

Offline FUBAR-BDHR

  • Self-Propelled Trouble Magnet
  • 212
  • Master Drunk
    • 165th Beer Drinking Hell Raisers
Re: Problems with FREDed cloaking
Without thinking too hard Kara might have some new code in 3.6.11 that will make what you are trying to do easy.  Otherwise you could set a variable each time the ship cloaks to mission_time and have another looping event that checks for mission_time + 3 being greater then that variable which does what you want and sets the variable back to it's default of 999999999.
No-one ever listens to Zathras. Quite mad, they say. It is good that Zathras does not mind. He's even grown to like it. Oh yes. -Zathras