lfnetwork.com mark read register faq members calendar

Thread: TUTORIAL: Melee Button
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 01-11-2009, 10:30 PM   #1
-=*Raz0r*=-
Rookie
 
-=*Raz0r*=-'s Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 243
Lightbulb 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.








Files edited
- bg_pmove.c (cgame and game)
- q_shared.h (global)
- g_active (game)








Step 1
Open up bg_pmove.c
Within the PM_Weapon function, do a search for this code:

Code:
	if (PM_CanSetWeaponAnims())
	{
		if (pm->ps->weapon == WP_THERMAL ||
			pm->ps->weapon == WP_TRIP_MINE ||
			pm->ps->weapon == WP_DET_PACK)
Before all of this, insert the following code:
Code:
	//[MeleeButton]
	if ((pm->cmd.buttons & BUTTON_MELEE))
	{ //ok, try a kick I guess.
		if (!BG_KickingAnim(pm->ps->torsoAnim) &&
			!BG_KickingAnim(pm->ps->legsAnim))
		{
			int kickMove = LS_KICK_F;
			if (kickMove != -1)
			{
				int kickAnim = saberMoveData[kickMove].animToUse;

				if (kickAnim != -1)
				{
					PM_SetAnim(SETANIM_BOTH, kickAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD, 0);
					if (pm->ps->legsAnim == kickAnim)
					{
						pm->ps->weaponTime = pm->ps->legsTimer;
						return;
					}
				}
			}
			//if got here then no move to do so put torso into leg idle or whatever
			if (pm->ps->torsoAnim != pm->ps->legsAnim)
			{
				PM_SetAnim(SETANIM_BOTH, pm->ps->legsAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD, 0);
			}
			pm->ps->weaponTime = 0;
			return;
		}
	}
	//[/MeleeButton]
This basically says; if we can do a kick, then do it.








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
Code:
//[MeleeButton]
//extern int PM_KickMoveForConditions(void);
//[/MeleeButton]
(2) Inside PM_Weapon function
Code:
			//[MeleeButton]
			//Raz - may aswell remove this then
			/*
			else if (pm->debugMelee &&
				(pm->cmd.buttons & BUTTON_ALT_ATTACK))
			{ //kicks
				if (!BG_KickingAnim(pm->ps->torsoAnim) &&
					!BG_KickingAnim(pm->ps->legsAnim))
				{
					int kickMove = PM_KickMoveForConditions();
					if (kickMove == LS_HILT_BASH)
					{ //yeah.. no hilt to bash with!
						kickMove = LS_KICK_F;
					}

					if (kickMove != -1)
					{
						if ( pm->ps->groundEntityNum == ENTITYNUM_NONE )
						{//if in air, convert kick to an in-air kick
							float gDist = PM_GroundDistance();
							//let's only allow air kicks if a certain distance from the ground
							//it's silly to be able to do them right as you land.
							//also looks wrong to transition from a non-complete flip anim...
							if ((!BG_FlippingAnim( pm->ps->legsAnim ) || pm->ps->legsTimer <= 0) &&
								gDist > 64.0f && //strict minimum
								gDist > (-pm->ps->velocity[2])-64.0f //make sure we are high to ground relative to downward velocity as well
								)
							{
								switch ( kickMove )
								{
								case LS_KICK_F:
									kickMove = LS_KICK_F_AIR;
									break;
								case LS_KICK_B:
									kickMove = LS_KICK_B_AIR;
									break;
								case LS_KICK_R:
									kickMove = LS_KICK_R_AIR;
									break;
								case LS_KICK_L:
									kickMove = LS_KICK_L_AIR;
									break;
								default: //oh well, can't do any other kick move while in-air
									kickMove = -1;
									break;
								}
							}
							else
							{ //off ground, but too close to ground
								kickMove = -1;
							}
						}
					}

					if (kickMove != -1)
					{
						int kickAnim = saberMoveData[kickMove].animToUse;

						if (kickAnim != -1)
						{
							PM_SetAnim(SETANIM_BOTH, kickAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD, 0);
							if (pm->ps->legsAnim == kickAnim)
							{
								pm->ps->weaponTime = pm->ps->legsTimer;
								return;
							}
						}
					}
				}

				//if got here then no move to do so put torso into leg idle or whatever
				if (pm->ps->torsoAnim != pm->ps->legsAnim)
				{
					PM_SetAnim(SETANIM_BOTH, pm->ps->legsAnim, SETANIM_FLAG_OVERRIDE|SETANIM_FLAG_HOLD, 0);
				}
				pm->ps->weaponTime = 0;
				return;
			}
			*/
			//[/MeleeButton]







Step 3
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








Step 4
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:

Code:
	//[MeleeButton]
	else if (buttons & BUTTON_MELEE)
	{
		return qtrue;
	}
	//[/MeleeButton]







You're done!
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!








!BUGS!
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.




Other information
Feel free to contact me about any bugs/glitches/etc
Xfire: friedjawa101
Email: raz0r@arbmodding.co.cc


Last edited by -=*Raz0r*=-; 06-23-2009 at 03:51 AM. Reason: Updated
-=*Raz0r*=- is offline   you may: quote & reply,
Old 01-12-2009, 01:22 PM   #2
-=*Raz0r*=-
Rookie
 
-=*Raz0r*=-'s Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 243
EDIT: Merged with first post.


Last edited by -=*Raz0r*=-; 04-18-2009 at 10:00 AM.
-=*Raz0r*=- is offline   you may: quote & reply,
Old 04-18-2009, 10:03 AM   #3
-=*Raz0r*=-
Rookie
 
-=*Raz0r*=-'s Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 243
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

-=*Raz0r*=- is offline   you may: quote & reply,
Old 04-18-2009, 02:26 PM   #4
Tinny
 
Tinny's Avatar
 
Join Date: Apr 2002
Posts: 1,188
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!


Redeemed!

An old school mod for jedi academy.
Tinny is offline   you may: quote & reply,
Old 04-18-2009, 02:45 PM   #5
-=*Raz0r*=-
Rookie
 
-=*Raz0r*=-'s Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 243
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!


Last edited by -=*Raz0r*=-; 11-19-2009 at 06:31 PM.
-=*Raz0r*=- is offline   you may: quote & reply,
Old 04-18-2009, 03:13 PM   #6
Tinny
 
Tinny's Avatar
 
Join Date: Apr 2002
Posts: 1,188
Hey dude, I was just watching the videos of Jedi Knight Galaxies and it looks sweeet!! You're motivating me to complete my mod!


Redeemed!

An old school mod for jedi academy.
Tinny is offline   you may: quote & reply,
Old 04-18-2009, 03:15 PM   #7
-=*Raz0r*=-
Rookie
 
-=*Raz0r*=-'s Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 243
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

-=*Raz0r*=- is offline   you may: quote & reply,
Old 04-18-2009, 03:29 PM   #8
Tinny
 
Tinny's Avatar
 
Join Date: Apr 2002
Posts: 1,188
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.


Redeemed!

An old school mod for jedi academy.
Tinny is offline   you may: quote & reply,
Old 04-18-2009, 03:47 PM   #9
-=*Raz0r*=-
Rookie
 
-=*Raz0r*=-'s Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 243
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)

-=*Raz0r*=- is offline   you may: quote & reply,
Old 04-24-2009, 06:43 PM   #10
-=*Raz0r*=-
Rookie
 
-=*Raz0r*=-'s Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 243
Updated.

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

-=*Raz0r*=- is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > JediKnight Series > Editing Central > JA Coding > TUTORIAL: Melee Button

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:31 PM.

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