Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: Dearon on December 25, 2012, 05:36:33 pm

Title: set-object-facing problem
Post by: Dearon on December 25, 2012, 05:36:33 pm
Hello!
I am making a mission and in it there is a part where you make an in game jump to subspace, i'd like to make the player face where the end of the subspace tunnel will be before the jump happens, but as of yet i havent figured a way to make FS do it. I used Axem's tutorial for the in-game jump. I have posted my code below, i would appreciate any help. Thanks in advance. :)

Code: [Select]
#Events ;! 21 total

$Formula: ( when-argument
   ( random-multiple-of
      "Alpha 2"
      "Alpha 3"
      "Alpha 4"
   )
   ( and
      ( >
         5200
         ( distance
            "Alpha 1"
            "GTC Budapest #1"
         )
      )
      ( not
         ( has-departed-delay
            0
            "GTC Budapest #1"
         )
      )
   )
   ( change-iff "Hostile" "<argument>" )
   ( clear-goals "Alpha" )
   ( if-then-else
      ( string-equals
         "@traitor_1[Alpha 1]"
         "Alpha 1"
      )
      ( modify-variable
         "@traitor_1[Alpha 1]"
         "<argument>"
      )
      ( modify-variable
         "@traitor_2[Alpha 1]"
         "<argument>"
      )
   )
   ( add-goal
      "<argument>"
      ( ai-chase-any 89 )
   )
   ( invalidate-argument "<argument>" )
)
+Name: treason
+Repeat Count: 1
+Trigger Count: 2
+Interval: 0

$Formula: ( when-argument
   ( any-of
      "sensors"
      "communication"
      "weapons"
      "engine"
      "navigation"
      "radar01a-dish"
   )
   ( and
      ( is-destroyed-delay
         0
         "@traitor_1[Alpha 1]"
      )
      ( is-destroyed-delay
         0
         "@traitor_2[Alpha 1]"
      )
   )
   ( add-goal
      "Alpha"
      ( ai-destroy-subsystem
         "GTC Budapest #1"
         "<argument>"
         89
      )
   )
   ( good-secondary-time
      "Friendly"
      100
      "Trebuchet"
      "GTC Budapest #1"
   )
)
+Name: traitors killed
+Repeat Count: 1
+Interval: 1

$Formula: ( when
   ( and
      ( targeted "GTC Budapest #1" )
      ( is-event-true-delay "treason" 10 )
      ( not
         ( string-equals
            "@traitor_2[Alpha 1]"
            "Alpha 1"
         )
      )
   )
   ( add-goal
      "@traitor_1[Alpha 1]"
      ( ai-chase "Alpha 1" 101 )
   )
   ( add-goal
      "@traitor_2[Alpha 1]"
      ( ai-chase "Alpha 1" 101 )
   )
   ( good-secondary-time
      "Hostile"
      100
      "Trebuchet"
      "Alpha 1"
   )
   ( add-goal
      "Alpha"
      ( ai-destroy-subsystem
         "GTC Budapest #1"
         "weapons"
         101
      )
   )
)
+Name: alpha 1 doesnt care
+Repeat Count: 1
+Interval: 1

$Formula: ( every-time-argument
   ( any-of
      "sensors"
      "communication"
      "weapons"
      "navigation"
      "radar01a-dish"
   )
   ( is-subsystem-destroyed-delay
      "GTC Budapest #1"
      "<argument>"
      0
   )
   ( add-goal
      "GTC Budapest #1"
      ( ai-play-dead 101 )
   )
   ( invalidate-argument "<argument>" )
   ( modify-variable
      @malf_n[0]
      ( + @malf_n[0] 25 )
   )
)
+Name: power grid malfunction
+Repeat Count: 1
+Interval: 1

$Formula: ( when
   ( key-pressed "1" )
   ( set-subsystem-strength
      "GTC Budapest #1"
      "engine"
      0
   )
)
+Name: cheat 1
+Repeat Count: 1
+Interval: 1

$Formula: ( when
   ( < 0 @malf_n[0] )
   ( modify-variable
      @malf_n[0]
      ( - @malf_n[0] 1 )
   )
   ( every-time
      ( = @malf_n[0] 0 )
      ( clear-goals "GTC Budapest #1" )
      ( add-goal
         "GTC Budapest #1"
         ( ai-waypoints-once
            "Waypoint path 1"
            50
         )
      )
      ( add-goal
         "GTC Budapest #1"
         ( ai-warp-out 49 )
      )
   )
)
+Name: power grid restore
+Repeat Count: 1
+Trigger Count: 150
+Interval: 1

$Formula: ( when
   ( has-departed-delay
      0
      "GTC Budapest #1"
   )
   ( set-subspace-drive
      ( false )
      "Alpha 1"
   )
   ( key-reset "Alt-J" )
   ( ship-copy-damage
      "GTC Budapest #1"
      "GTC Budapest #2"
   )
)
+Name: follow GTC Budapest
+Repeat Count: 1
+Interval: 1

$Formula: ( when
   ( and
      ( >
         700
         ( distance
            "Waypoint path 2:1"
            "Alpha 1"
         )
      )
      ( key-pressed "Alt-J" )
   )
   ( player-use-ai )
   ( clear-goals "Alpha 1" )
   ( add-goal
      "Alpha 1"
      ( ai-play-dead 101 )
   )
   ( lock-afterburner "Alpha 1" )
   ( lock-primary-weapon "Alpha 1" )
   ( lock-secondary-weapon "Alpha 1" )
   ( set-object-facing
      "Alpha 1"
      5000
      0
      3700
      3000
      0
   )
)
+Name: face correctly
+Repeat Count: 1
+Interval: 1
+Chained: 0

$Formula: ( when
   ( true )
   ( lock-primary-weapon "Alpha 1" )
   ( lock-secondary-weapon "Alpha 1" )
   ( lock-afterburner "Alpha 1" )
   ( ship-lat-maneuver
      "Alpha 1"
      5000
      0
      0
      50
      ( true )
   )
   ( hud-display-gauge 4000 "warpout" )
   ( key-reset "Alt-J" )
)
+Name: Press Alt-J
+Repeat Count: 1
+Interval: 1
+Chained: 2

$Formula: ( when
   ( true )
   ( warp-effect
      ( get-object-x
         "Alpha 1"
         "<none>"
         0
         0
         100
      )
      ( get-object-y
         "Alpha 1"
         "<none>"
         0
         0
         100
      )
      ( get-object-z
         "Alpha 1"
         "<none>"
         0
         0
         100
      )
      ( get-object-x "Alpha 1" )
      ( get-object-y "Alpha 1" )
      ( get-object-z "Alpha 1" )
      100
      10
      69
      70
      0
      0
   )
)
+Name: Warp effect
+Repeat Count: 1
+Interval: 1
+Chained: 4

$Formula: ( when ( true ) ( fade-out 1000 1 ) )
+Name: fade out
+Repeat Count: 1
+Interval: 1
+Chained: 2

$Formula: ( when
   ( true )
   ( fade-in 1000 )
   ( mission-set-subspace 1 )
   ( shields-off
      "Alpha 1"
      "Alpha 2"
      "Alpha 3"
      "Alpha 4"
   )
   ( hide-jumpnode "Jump Node 0" )
   ( player-not-use-ai )
   ( unlock-primary-weapon "Alpha 1" )
   ( unlock-secondary-weapon "Alpha 1" )
   ( unlock-afterburner "Alpha 1" )
)
+Name: subspace corridor
+Repeat Count: 1
+Interval: 1
+Chained: 1

$Formula: ( when
   ( and
      ( <=
         700
         ( distance
            "Waypoint path 2:1"
            "Alpha 1"
         )
      )
      ( key-pressed "Alt-J" )
   )
   ( set-subspace-drive
      ( true )
      "Alpha 1"
   )
   ( force-jump )
)
+Name: wrong warp
+Repeat Count: 1
+Interval: 1

$Formula: ( when
   ( key-pressed "2" )
   ( set-subsystem-strength
      "GTC Budapest #1"
      "engine"
      100
   )
)
+Name: cheat 2
+Repeat Count: 1
+Interval: 1

$Formula: ( when
   ( or
      ( and
         ( is-disabled-delay
            0
            "GTC Budapest #1"
         )
         ( is-disarmed-delay
            0
            "GTC Budapest #1"
         )
      )
      ( and
         ( is-disabled-delay
            0
            "GTC Budapest #3"
         )
         ( is-disarmed-delay
            0
            "GTC Budapest #3"
         )
      )
   )
   ( change-iff
      "Friendly"
      "GTC Budapest #1"
   )
   ( change-iff
      "Friendly"
      "GTC Budapest #3"
   )
)
+Name: GTC Budapest Captured
+Repeat Count: 1
+Interval: 1

$Formula: ( when
   ( has-departed-delay
      0
      "GTC Budapest #2"
   )
   ( key-reset "Alt-J" )
   ( ship-copy-damage
      "GTC Budapest #2"
      "GTC Budapest #3"
   )
)
+Name: follow again GTC Budapest
+Repeat Count: 1
+Interval: 1

$Formula: ( when
   ( has-departed-delay
      0
      "GTC Budapest #2"
   )
   ( player-use-ai )
   ( clear-goals "Alpha 1" )
   ( add-goal
      "Alpha 1"
      ( ai-play-dead 101 )
   )
   ( lock-primary-weapon "Alpha 1" )
   ( lock-secondary-weapon "Alpha 1" )
   ( lock-afterburner "Alpha 1" )
   ( ship-lat-maneuver
      "Alpha 1"
      5000
      0
      0
      50
      ( true )
   )
   ( hud-display-gauge 4000 "warpout" )
   ( key-reset "Alt-J" )
)
+Name: Press Alt-J
+Repeat Count: 1
+Interval: 1
+Chained: 0

$Formula: ( when
   ( true )
   ( warp-effect
      ( get-object-x
         "Alpha 1"
         "<none>"
         0
         0
         100
      )
      ( get-object-y
         "Alpha 1"
         "<none>"
         0
         0
         100
      )
      ( get-object-z
         "Alpha 1"
         "<none>"
         0
         0
         100
      )
      ( get-object-x "Alpha 1" )
      ( get-object-y "Alpha 1" )
      ( get-object-z "Alpha 1" )
      100
      10
      69
      70
      0
      0
   )
)
+Name: Warp Effect
+Repeat Count: 1
+Interval: 1
+Chained: 4

$Formula: ( when ( true ) ( fade-out 1000 1 ) )
+Name: fade out
+Repeat Count: 1
+Interval: 1
+Chained: 2

$Formula: ( when
   ( true )
   ( fade-in 1000 )
   ( mission-set-subspace 0 )
   ( shields-on
      "Alpha 1"
      "Alpha 2"
      "Alpha 3"
      "Alpha 4"
   )
   ( player-not-use-ai )
   ( unlock-primary-weapon "Alpha 1" )
   ( unlock-secondary-weapon "Alpha 1" )
   ( unlock-afterburner "Alpha 1" )
   ( remove-sun-bitmap 0 )
   ( show-jumpnode "Jump Node 1" )
   ( remove-background-bitmap 0 )
   ( remove-background-bitmap 1 )
   ( remove-background-bitmap 2 )
   ( remove-background-bitmap 3 )
   ( remove-background-bitmap 4 )
   ( remove-background-bitmap 5 )
   ( remove-background-bitmap 6 )
   ( add-sun-bitmap
      "SunWhite"
      0
      0
      0
      100
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "NebulG10-Whisp"
      9
      2
      351
      500
      500
      5
      5
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "NebulH13-Whisp"
      6
      319
      357
      400
      400
      1
      1
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "NebulG1-Main"
      18
      85
      342
      600
      600
      1
      1
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "NebulG4-Whisp"
      38
      317
      320
      1000
      600
      3
      2
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "NebulH7-Whisp"
      0
      353
      20
      600
      500
      1
      1
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "NebulH6-Whisp"
      3
      21
      13
      700
      500
      1
      1
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "NebulH1-Main"
      359
      322
      15
      800
      800
      1
      1
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "NebulA2-Main"
      3
      355
      3
      500
      700
      2
      2
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "NebulG6-Whisp"
      9
      0
      324
      600
      600
      2
      2
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "NebulG5-Whisp"
      7
      351
      7
      500
      700
      1
      2
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "NebulA10-Whisp"
      11
      83
      306
      700
      700
      1
      1
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "NebulA10-Whisp"
      325
      280
      349
      800
      800
      1
      1
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "NebulB9-Whisp"
      347
      50
      346
      500
      500
      1
      1
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "dneb01"
      342
      269
      338
      500
      500
      1
      1
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "dneb01"
      345
      7
      358
      500
      500
      1
      1
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "neb03"
      14
      338
      249
      700
      700
      1
      1
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "dneb13"
      47
      0
      249
      700
      700
      1
      1
      @engine_strenght[100]
   )
   ( add-background-bitmap
      "planeta1"
      14
      338
      216
      500
      500
      1
      1
      @engine_strenght[100]
   )
)
+Name: fade in & background change
+Repeat Count: 1
+Interval: 1
+Chained: 1

$Formula: ( when
   ( true )
   ( hide-jumpnode "Jump Node 1" )
)
+Name: hide jump node 1
+Repeat Count: 1
+Interval: 1
Title: Re: set-object-facing problem
Post by: Axem on December 25, 2012, 05:59:38 pm
Hurrah, people using tutorials!

Anyhoo, I'm guessing this little area is where you're having problems?

Code: [Select]
   ( set-object-facing
      "Alpha 1"
      5000
      0
      3700
      3000
      0
   )

The best way I can describe it is set-object-facing works on a frame by frame basis. When you call set-object-facing, the game tries to rotate Alpha 1 to turn to face the point in 3000ms, but it only does it for a single frame. That doesn't actually do us a whole lot.

So you have a couple of options. First make a specialized variable and repeating event with large trigger and zero delay, and move your set-object-facing there. See the next few pics with an ideal setup.

(http://lazymodders.fsmods.net/axemart/FreeSpace/SEXPs/sexpspinning.png)

Another way you could do it is put the player under AI control, put a waypoint out around where you want him to point to, then use the facing sexp to tell when you're facing the point and continue on.
Title: Re: set-object-facing problem
Post by: Dearon on December 25, 2012, 06:37:56 pm
Thank you so much! It works! :)

By the way your tutorials are really helpful, i hope there is more where that 3 came from. :)

Merry Christmas! :)