Hard Light Productions Forums

Modding, Mission Design, and Coding => The Modding Workshop => Topic started by: Black Wolf on September 28, 2011, 10:24:10 pm

Title: Can model animations be triggered by Sexp?
Post by: Black Wolf on September 28, 2011, 10:24:10 pm
Well, can they? I know they can be scripted, but I don't know any LUA at all, and for a few meshes I have planned a sexp based implementation would be immensely useful (And don't tell me to learn LUA, my brain isn't set up to program and I really don't have the time).
Title: Re: Can model animations be triggered by Sexp?
Post by: Cyborg17 on September 28, 2011, 10:34:35 pm
You can adjust rotating subsystems.  Start them, stop them and adjust their speed and direction (clockwise, counter-clockwise).  That may be it, though.
Title: Re: Can model animations be triggered by Sexp?
Post by: Nuke on September 29, 2011, 09:57:47 pm
i think you can trigger one of the tabled animations with a sexp, if you can get the system to work that is. i usually just cheat and use scripting to change a submodel's orientation matrix.
Title: Re: Can model animations be triggered by Sexp?
Post by: zookeeper on September 30, 2011, 12:55:26 am
You can trigger a tabled animation, yes. Unfortunately, you can't (yet) choose which one: every such animation the ship has will be triggered.

The Lua code to do it is as simple as this:
Code: [Select]
shiphandle:triggerAnimation("scripted", 0, true)Use false instead of true if you want to play the animation(s) backwards.

The animation tabling needs these:
Code: [Select]
  $animation:                 triggered
  $type:                      scripted

And the subobject needs to have these props:
Code: [Select]
$special=subsystem
$triggered:
Title: Re: Can model animations be triggered by Sexp?
Post by: Black Wolf on September 30, 2011, 01:20:05 am
You can trigger a tabled animation, yes. Unfortunately, you can't (yet) choose which one: every such animation the ship has will be triggered.

The Lua code to do it is as simple as this:
Code: [Select]
shiphandle:triggerAnimation("scripted", 0, true)Use false instead of true if you want to play the animation(s) backwards.

The animation tabling needs these:
Code: [Select]
  $animation:                 triggered
  $type:                      scripted

And the subobject needs to have these props:
Code: [Select]
$special=subsystem
$triggered:

Triggering everything isn't ideal, but it shouldn't be a gamebreaker either.

This part:
Code: [Select]
shiphandle:triggerAnimation("scripted", 0, true)
I'm assuming goes into scripting.tbl, somehow? Or can it be done directly with script-eval?

Complete scripting novice here - I've only ever used it for gravity and that's about it.  :nervous:
Title: Re: Can model animations be triggered by Sexp?
Post by: zookeeper on September 30, 2011, 02:36:08 am
This part:
Code: [Select]
shiphandle:triggerAnimation("scripted", 0, true)
I'm assuming goes into scripting.tbl, somehow? Or can it be done directly with script-eval?

Complete scripting novice here - I've only ever used it for gravity and that's about it.  :nervous:

Yes, you can use script-eval, and probably what you should do if you're not comfortable with scripting.

Use this as your scripting.tbl, or as whatever-sct.tbm, or just add everything except the first and last line to an existing file:
Code: [Select]
#Conditional Hooks

$Application: FS2_Open

$On Game Init: [

    trigger_anim = function(shipname)
        mn.Ships[shipname]:triggerAnimation("scripted", 0, true)
    end
   
    trigger_anim_reverse = function(shipname)
        mn.Ships[shipname]:triggerAnimation("scripted", 0, false)
    end

]

#End

Then, you can call those functions with script-eval like this:
Code: [Select]
( script-eval "trigger_anim('Alpha 1')" )
Yes, the argument to give is literally "trigger_anim('Alpha 1')". It's a bit of a hassle, since if you don't want to hardcode the ship name in every call, you'll have to concatenate the argument string from "trigger_anim('", the ship's name and "')". I'm sure you can also pass the boolean value as a second argument instead of defining two functions somehow, but I haven't tested that.
Title: Re: Can model animations be triggered by Sexp?
Post by: Black Wolf on September 30, 2011, 05:53:49 am
Awesome. I will have a use for this very soon. Thanks heaps. :)
Title: Re: Can model animations be triggered by Sexp?
Post by: Nuke on September 30, 2011, 09:22:16 am
you should probably idiotproof those functions though. like make sure the ship handles are valid. this is why i really wish we could embed scripts in missions, so you could distribute scripted missions without needing any tables or mod directories.
Title: Re: Can model animations be triggered by Sexp?
Post by: Aardwolf on October 01, 2011, 11:29:28 am
this is why i really wish we could embed scripts in missions, so you could distribute scripted missions without needing any tables or mod directories.

:yes: from me
Title: Re: Can model animations be triggered by Sexp?
Post by: JCDNWarrior on October 01, 2011, 11:40:51 am
Would be amazing to see this being improved, though great that the current method's already posted. All I need now is a carrier with animated opening/closing doors and cutscenes will look much better to me. ;)