LucasForums (
-   General Editing (
-   -   Animations and Lightsabers (

Caridorc 08-20-2008 09:14 AM

Animations and Lightsabers
Hi everybody!
I'm new for the comunity, but not for modding...anyway I was wondering if I can make the lightsaber to switch/turn off when I use a force power and then to switch/turn it on when the force power animation is finished...yes like what happens in the force unleashed videos...
to do that do I need to do some code? if yes could someone tell me if it's difficult? because i know that you need to know c/c++ to code, but I only know pascal, delphi and javascript (I'm an IT student)

thanks and sorry for bad english (I'm Italian :xp:)...bye

nizwiz 08-20-2008 02:02 PM

sp or mp?

Caridorc 08-20-2008 02:25 PM

both, if it's possible. If not tell me what is easier...
I want to make a mod that works in both sp and mp, but if it isn't possible or it's too difficult I prefere to make a first release for the easier part (sp/mp I don't know) and then when I'll be good enaugh I'll make the second release for harder part (mp/sp I don't know)

helps are welcome, it's a serious project...

nizwiz 08-21-2008 03:40 PM

sp will be tough, since you can't code for it (no source code available) and I don't think there is a way to do it without.

For mp it's certainly feasible, but it'll not be easy:

1st: acquaint yourself with C (since you're an IT student, chances are you'll have to do that anyway, eventually).
2nd: decide whether to start off base JA (a) or OJP (b).
3rd: download the JA SDK (a) or the OJP sources (b).
4th: download and install an MS Vistual Studio express version.
5th: get the sources compiled (this is a bit tricky for (a) since you'll have to do some tweaking of the source code; I'll show you how once you've got your mind settled on that option).
6th: try reading some of the code to get a feeling for it.

Once you're that far, someone might be inclined to delve into the source code to help you get going with your specific mod idea.

EDIT1: Well, you could of course ask the OJP team if they'd wanted to do that themselves for their mod, but I doubt it (they're busy enough as it is).

EDIT2: Just had an idea for sp. Maybe it'll work with some binds / console scripts. I'll try it out.

EDIT3: Yeah, I've managed to compile some binds that'll turn off the saber automatically upon using force grip, but not to turn it on automatically again once you cease gripping. So it goes like this: you start gripping, your saber goes off; you finish gripping, your saber does NOT go on automatically, but you'll have to activate it manually. That ok with you? (If not, better say so right away lest I waste my time any further).
There's only one more problem: the annoying hilt spinning that is performed upon saber de/activation is very inconvenient in this context. Luckily, I have an animation mod prepared that removes this spinning.
I'll get a package ready this weekend so you can try it out. If it suits your taste, I'll extend it to include the other force powers as well.

EDIT4: I forgot to ask - which game do you want it for, jk2 or jk3?

Caridorc 08-22-2008 08:51 AM

Wow I didn't think that someone will ever listen to me....thanks...

Anyway...I think that the option (b) is the easy way, so for now I take that;

for the grip thing, why you can't turn the lightsaber on after gripping? I mean: isn't it the same thing for turning it on, but done after the force power (the bind is one: turn on/off)...maybe you could try to explain me the problem and I could try to solve it (without the specific code, of course, because I don't know C yet)...

The last thing (jk2 or jka): if we do this first little mod for jk2, will it work for jka too? (like models I mean, because the jk2 models work in jka but not vice versa) If not, I choose jka (jk3)

nizwiz 08-24-2008 11:27 AM

Bad news: it isn't working too well, since there is a delay between switching the saber off and actually starting to grip. Unfortunately, that cannot be avoided I think.

Answering your post: There is no C involved, it's just binds (q3 console language, if you will).
Now, the simple idea behind it is, instead of using the default "bind <GRIP> +force_grip", you use "bind <GRIP> weapon 1; +force_grip" (with <GRIP> being a placeholder for the used key code), so everytime you do a grip your saber will go off. It isn't that simple, of course, since you can also grip when your saber is off (and then your saber would go on, obviously). Furthermore, if you're trying to do it the direct way, gripping will not cease after releasing the grip key.
And that's exactly where the problem is. You see, the + sign in front of force_grip indicates that the force power will be used as long as the key is pressed, and stopped upon releasing the key. This is hard-coded into the game, and as far as I can tell there is no way to specify exactly what will happen uon relasing the key;
To clarify it: if the engine would allow to bind on the events "key is pressed" and "key is released", than you could do it like that

bind +F1 weapon 1;+force_grip
bind -F2 weapon 1;-force_grip

But that's not the way it is implemented. Instead, if you do a "bind F1 +force_grip", you will have +force_grip mapped to the event "F1 is pressed" and -force_grip automatically mapped to the event "F1 is released" (also "bind F1 +force_grip; weapon 1" will not have anything mapped to the event "F1 is released", so you'll end up with force_grip being activated, but never deactivated, which is very awful to behold).
I don't see how you could overcome this problem without altering the code, which isn't really possible (no source code for sp, unfortunately).

Anyway, here's a package for you to try out:

You'll have to extract the contents to your base folder, then copy the file grip_saberoff.cfg.template and remove the ".template" extension from the copy, then edit the copy and replace the placeholders <GRIP> and <WEAPON1> with your preferred key codes for force_grip and weapon 1 (look in your jaconfig.cfg to find those key codes). Before trying it out, make a backup of your jaconfig.cfg, and restore it afterwards.
To use the binds, load a map (don't use a saved game, since that will prevent the animation changes to take effect) then enter "exec grip_saberoff" at the console (assuming the name of your copy is grip_saberoff.cfg).

EDIT: Because of the awful delay I stated above, I'd suggest you don't mod anything for sp and instead do it manually, i.e. press the grip button and the "weapon 1" button at the same time (or one immediately after the other). That looks much smoother.

Caridorc 08-24-2008 02:12 PM

mmmm...not good...but I have an idea: the taunt animation.
I like that animation for the grip and it turns off the saber too, the only thing that is not good is that the saber also it possible to build an animation that does the same thing but the rotation and so on for the rest of the force powers?:confused:

PS: I've not try your solution yet, but i'll do it soon...
PPS: if we succeed in the animation thing I think the SP problem is solved too

nizwiz 08-24-2008 02:22 PM


Originally Posted by Caridorc (Post 2515291)
mmmm...not good...but I have an idea: the taunt animation.
I like that animation for the grip and it turns off the saber too

Only in fast stance (and jk3, for that matter). That would make the binds fairly complicated, so better not try it at all.

Caridorc 08-24-2008 02:53 PM

foregive me, I think that I explained bad...I was saying to do the mod without any binds.
for example: if I edit the animation.cfg so that when you grip someone the game run the taunt animation, ingame I grip someone and the saber turns off automaticaly because of the taunt animation (but the saber will also rotate)

Well, in case I've messed up your brain, try it yoursef:D;11593979

nizwiz 08-24-2008 05:19 PM

Uhm, did you actually try your package out? 'Cause, you know, it doesn't work: saber's not going off (without binds). And that's because the saber being swichted off upon fast stance taunt is not part of the animation (you can't control something like that in animations), but hard-coded in the game.

Caridorc 08-25-2008 01:04 PM

Sorry yesterday I didn't. But I did a few days ago and I remembered that had worked....But taunt turns off the saber so how has the taunt been coded?
Isn't it possible to code force powers in the same way?

katanamaru 08-25-2008 02:21 PM

The taunt has been coded into the actual code of the SP game. The SP source code has not and probably will never be released. I don't recommend switching animations around that involve movement. They have a tendacy to look bad, function poorly, and mess with saber movement and sounds. The bind way looks to be the easiest way for SP.

With coding anything is possible in MP.

nizwiz 08-25-2008 05:24 PM

I included an animation mod that gets rid off that stupid spinning done upon saber de/activation, because, y'know, it sucks all the more in this context. Unfortunately, this animation tweak itself has a little glitch. katanamaru has nailed it exactly.
As for the taunt, you see, the sequence itself (the one that is mapped to BOTH_GESTURE1) doesn't turn the saber off (if you map this sequence to any other animation, the saber won't go off upon triggering that animation). Instead it's hard-coded into the "taunt" command that, in case the current stance is the fast stance, the saber will be turned off before playing the animation. You can't simply change it or use it elsewhere.

Caridorc 08-26-2008 06:31 AM the ways are:
1) bindings: the easy way but it is bugged and slow in animations;
2) codeing: the more difficult way but it is only for mp;

Is it difficult to code my little mod? Am I able to do that? Could someone help me? Please I have to know if I can do it because it is the starting point of a bigger mod that I want to do...(but don't worry the rest parts are very easy to do; even I can do them; there are only two other little problems that I can't solve, but they are less important for now)

nizwiz 08-26-2008 03:18 PM

It shouldn't be too difficult.
But have you completed steps 1 to 6, yet? I for one won't start looking into it before you show some serious efforts. Get yourself acquainted with C, at the very least. That won't be a waste of time in any case (considering that you're an IT student), even if you'd scrap your mod idea.

Maybe this weekend I'll find some time to try and meddle with the source code - that is, if I'm not ninjaed by someone else.

Caridorc 08-26-2008 04:48 PM

Thanks so much!!! I'll familiarize to C very soon, we have a deal!

nizwiz 08-26-2008 06:12 PM

Ok, deal.

nizwiz 09-02-2008 04:50 PM

Well, I have a first draft that works, mostly.

I've used vanilla jk3 SDK, so you'll first have to get it to compile. Go download and install MS Visual C++ 2008 Express edition, if you haven't already. Then download and apply these code fixes. Open the solution in Visual Studio (double-click on codemp\JKA_mp(SDK).sln in Windows Explorer), then try and build the whole solution. If three DLLs have been produced in codemp\Debug, you're ready to go.

Now to the actual mod:
You'll have to edit codemp\game\w_force.c (the mod is serverside; if that won't do, tell me and I'll look into it again).
So in Visual Studio, in the left hand tree view, double-click on JK2game/Source Files/w_force.c.

First, you'll have to define which force powers are supposed to switch the saber off. On top of w_force.c, right after the #include's, add the following piece of

        const int mask_SaberDeactivatingForcePowers = 0
        //        | (1 <<        FP_HEAL)
        //        | (1 << FP_LEVITATION)
        //        | (1 << FP_SPEED)
        //        | (1 << FP_PUSH)
        //        | (1 << FP_PULL)
        //        | (1 << FP_TELEPATHY)
        //        | (1 << FP_GRIP)
        //        | (1 << FP_LIGHTNING)
        //        | (1 << FP_RAGE)
        //        | (1 << FP_PROTECT)
        //        | (1 << FP_ABSORB)
        //        | (1 << FP_TEAM_HEAL)
        //        | (1 << FP_TEAM_FORCE)
        //        | (1 << FP_DRAIN)
        //        | (1 << FP_SEE)

and then remove the comment signs (//) in front of the chosen force powers.

Now we're going to switch the saber off in WP_ForcePowerStart(...).
Jump to that function (on top of the right hand edit view, there are two list boxes right under the filename thingy; the left one should read "(Global Scope)", the right one should be empty; open the right one and select said function from the list).
You'll find a lengthy "switch" construct in the function (there's only one, so that shouldn't be a problem). Right after the switch block, insert the section indicated in this


//the following section inserted by nizwiz:
        if ( self->client->ps.saberHolstered != 2
                && ((1 << forcePower) & mask_SaberDeactivatingForcePowers) != 0 )
                // store the current activation state of the sabers in self->genericValue13
                // so that we can restore it afterwards
                // (genericValue13 doesn't seem to be used elsewhere for players)
                self->genericValue13 = 2 - self->client->ps.saberHolstered;

                // now switch the sabers off

                if ( self->client->ps.saberHolstered == 1
                        && self->client->saber[1].model
                        && self->client->saber[1].model[0] )
                {//turn off second sabers
                        G_Sound( self, CHAN_WEAPON, self->client->saber[1].soundOff );
                {//turn off first
                        G_Sound( self, CHAN_WEAPON, self->client->saber[0].soundOff );

                self->client->ps.saberHolstered = 2;
//insertion ends here

        if ( duration )

(BTW, this is mostly copied from the taunt command; following your idea, I just looked it up there, copied it and it worked like a charm; then I've modified it a bit to accomodate for the automatic re-ignition later).
Well, that's it for the deactivation part.

Finally, to re-activate the saber after all saber-deactivating powers are done, you'll have to edit - guess what - right, WP_ForcePowerStop(...). So jump there, and at the end of the function, add the section indicated in the following snippet of


//the following section inserted by nizwiz:
        // if all saber deactivating force powers have been stopped,
        // and sabers had actually been forced off, switch 'em on again (if they aren't already)
        if ( (self->client->ps.fd.forcePowersActive & mask_SaberDeactivatingForcePowers) == 0
                && self->genericValue13 != 0 )
                if ( self->client->ps.saberHolstered == 2 )
                        self->client->ps.saberHolstered = 2 - self->genericValue13;
                        if ( self->client->ps.saberHolstered == 1
                                && self->client->saber[1].model
                                && self->client->saber[1].model[0] )
                        {//turn on second saber
                                G_Sound( self, CHAN_WEAPON, self->client->saber[1].soundOn );
                        {//turn on first
                                G_Sound( self, CHAN_WEAPON, self->client->saber[0].soundOn );

                self->genericValue13 = 0;
//insertion ends here


That's it. Now you'll just have to re-build the server (in the left hand tree view, right-click on "JK2game" and select "Build"), then pack the produced jampgamex86.dll up in a pk3 (you only need jampgamex86.dll since it's a serverside only mod) and put it in your base folder.

I've tried this mod with most force powers, and here's the deal:
- It doesn't seem to work at all for "heal" and "jump" (looks like WP_ForcePowerStart isn't called for these)
- For "push" and "pull" the deactivation part works, but the re-activation doesn't (WP_ForcePowerStop isn't called for these; they're kinda instant powers).
If you do want the de/re-activation for any of those force powers as well, say so and I'll look into again (otherwise I'd rather not).

What I haven't tried at all is "team heal" and "team energize". Also, I haven't tested the mod with dual sabers / staff. I'll leave that all to you.

And one more shortcoming (sort of): If you define any of the long-term force powers (see, speed, protect, absorb) as saber-deactivating, there's nothing that hinders you to activate the saber again while the force power's still active. If this is a problem, say so and I'll try to find a way around that (though that's likely more difficult to accomplish).

In case of problems, just post them here and I'll try to help.

Caridorc 09-14-2008 09:23 AM

first...forgive me for answering you only now, it's my mail's fault: it didn't tell me that there was other posts in the thread...

second...thanks for all you're doing for me...I appreciate so much...

third...basically the powers that I want to de/activate the sabers are:
lightning, grip, drain, absorb*

*only when you stand firm (not when you're walking/running) if it's possible; if not then I don't need the de/activation for this power

nizwiz 09-15-2008 03:10 PM

Hi there, I'd suggest you try it out and see if it's ok at all.
As for the footnote: as mentioned, you can re-ignite the saber after it's been turned off upon activating absorb; if that's enough, I'd rather not try to figure out ho to implement this "saber off while absorb is active, but only if standing still" behaviour - I'm not even sure I know how you'd want the mechanics to be like (when exactly should the saber be deactivated and when re-activated).

Caridorc 09-17-2008 08:45 AM

Good news: I've tryed your package and it's damn good!!!
The only thing that isn't as I wanted is absorb, but probably it's my fault because I explained myself bad...
The way that I thought for absorb is:
1)you are standing on the floor (without walk or run); you activate the absorb power; your player does a little animation (for example the push one) and while he's doing the animation the saber turns off; if you deactivate absorb or if you run out of force, the saber turns on and the player animates for returning in his original stance; if you start walking/running the saber automatically turns on.
2)you are moving around (maybe fighting with someone, who knows?) so you're walking/running; you activate absorb and all work as the game would work if there isn't any mod: as the original game.

Now, for the animations part there is no problem because I can do it; for the code part I depend on you (because even if I started looking in programming in C#, I don't learn enaught yet and now that sadly I've started to go to school :(, it is going to be more difficult); I don't even totally understand how to compile your code excetera :confused:...

nizwiz 09-19-2008 09:23 PM

Uhm, to be honest, I've lost all interest I had in coding for jk3mp (and there wasn't much to begin with - I don't even play jk3mp); so I'm afraid you're on your own.
Well, good luck with your mod, then.

Caridorc 09-21-2008 10:58 AM

Thank you
All right I understand...well thanks for all your help...
could I ask you one more favour? could you explain me how to make the same dll that you made but without the force absorb effect? :yelhelp:

nizwiz 09-21-2008 01:22 PM

You're welcome.
As for your question: I already did. It's all written there in that lengthy post of mine, right above and below the first code box.
Anyway, here's the updated package: ForceSaberOff.pk3

Caridorc 09-21-2008 04:47 PM

Many thanks...
I think that I'll achieve of finishing my mod...:thumbsup::waive1:

nizwiz 09-22-2008 02:35 PM

Good luck.

All times are GMT -4. The time now is 01:38 AM.

Powered by vBulletin®
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.
LFNetwork, LLC ©2002-2015 - All rights reserved.