TUTORIAL: Melee Button
so, I'm not sure if I'm supposed to/allowed to do this, but I might as-well start writing little tutorials to help out beginner coders add some fun features.
What you will achieve
The purpose of this modification is to allow the player to perform a melee attack (kick) regardless of the weapon selected.
Before we get started
I would like to point out, we will be adding a new button to the game (the buttons are defined in q_shared.h), so you must make sure you have not already reached your limit of buttons.
- bg_pmove.c (cgame and game)
- q_shared.h (global)
- g_active (game)
Open up bg_pmove.c
Within the PM_Weapon function, do a search for this code:
Step 2 (optional)
Well, we have a melee button, so why do we want another button to kick with the 'melee' weapon?
You can remove this by going into bg_pmove.c and commenting this code:
(1) Above PM_Weapon function
Time to actually make the button (BUTTON_MELEE) that the game will understand!
Open up q_shared.h and search for #define BUTTON_FORCE_DRAIN
Underneath this line, add #define BUTTON_MELEE 4096
Now to make sure the game knows we're pressing an 'action' button, insert this nifty piece of code below.
Open up g_active.c and search for qboolean G_ActionButtonPressed(int buttons)
Inside there, insert this code:
Now you can compile your code, and try it out!
type /bind x +button12 and press x to perform a kick regardless of your weapon!
Yes, I'm afraid there is one small bug.
If you use a weapon and hold the 'melee button', it works fine...
However, if you use a saber and hold the 'melee button', your animations will screw up after the first time you kick.
This is due to being dependent on the 'weaponTime' value to say if we can kick or not.
If I can fix it, or if anyone can help me, I will update this tutorial.
Feel free to contact me about any bugs/glitches/etc
EDIT: Merged with first post.
I know it seems like a triple post, but I've just updated this tutorial and stamped out some bugs.
Also, take note of the dates. ;o
Hey Raz0r, thanks for the tutorial! I've been meaning to add this functionality so this is awesome. I've always been wary of touching the q_shared.h file since you can easily break the game if you edit it but I think your tutorial irons out the kinks, thanks again!
TINNY GIVING ME PRAISE?!?! o_o...
Man, you're like a legend to me.
Playing OldSchool is like what got me into modding. o_O!
Seriously, you're awesome and thanks for the feedback!
Hey dude, I was just watching the videos of Jedi Knight Galaxies and it looks sweeet!! You're motivating me to complete my mod!
I'm not actually a part of JKG dev-team, just a community member. o_O
I offer my help if they ever need it (including promoting in my sig :P) as they have helped me too.
But yeah, that will be an epic mod once it's made. o_O
Hey, that's still cool. Glad to see the modding community is still alive, there's so much that can be done with this game. Just wish some of the code hidden away from us could be a bit more optimized and flexible otherwise its a great engine. Its still really helpful that you've posted this about melee, i thought oh noes another feature i want to implement that will take some time. Maybe we all could start having a repository of tutorials, that would be epic.
That's what I plan to do, create tutorials for all the fun features like these!
Of-course each mod should be unique, but this should help those newbies that want to learn to be cool like us! (heh)
My bad, I said search for 'if (PM_CanSetWeaponAnims())' and it turns out there was 4 instances of that in bg_pmove.c, all in the PM_Weapon() function.
So I included some more code so you know where to look now. ;o
|All times are GMT -4. The time now is 10:12 AM.|
Powered by vBulletin®
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.
LFNetwork, LLC ©2002-2011 - All rights reserved.