Posted by: X-0ut
Date posted: Jun 25 2003 User Rating: 5 out of 5.0 | Number of views: 5889 Number of comments: 3 | Description: Stamina controlled sprint |
You will need to have completed the first part of this tutorial which can be found in the shared section here Part1 This addition to the dash/sprint code requires only clientside modification, so open up your client workspace and hud.h - at the bottom of the CHud class after this line float GetSensitivity(); place this variable declaration:
| | int g_iStamina;//stores our stamina
|
We are going to store our stamina in that variable. Next open up input.cpp and find the previous code we alltered:
| | void IN_DashDown(void) {KeyDown(&in_dash);} void IN_DashUp(void) {KeyUp(&in_dash);}
|
Replace it with this slighty modified version:
| | ///Stamina/// void IN_DashDown(void) { if(gHUD.g_iStamina>0) KeyDown(&in_dash); } void IN_DashUp(void) { KeyUp(&in_dash); }
|
That simply stops the key from being pressed if we are out of stamina. Now scroll down input.cpp until you find the CL_CreateMove function, after this line static vec3_t oldangles; add this little chunk of code:
| | //alter stamina amount if(in_dash.state & 1) gHUD.g_iStamina -= gHUD.m_flTimeDelta * 300;//key is pressed - decrement stamina else gHUD.g_iStamina += gHUD.m_flTimeDelta * 100;//key is not pressed - increment stamina
if(gHUD.g_iStamina<0) { gHUD.g_iStamina =0;//cap stamina at zero so we dont have negative amounts in_alt1.state &= ~1;//release the dash button so the client cant keep sprinting } if(gHUD.g_iStamina>1000) //cap stamina at 1000 gHUD.g_iStamina = 1000;
|
Thats self explanatry im sure, but basically whats happening is if the dash key is pressed the stamina drains, if it reaches zero the key is released forcing the client to stop sprinting, if the key is not pressed the stamina slowly regains. Thats all for input.cpp, next we need somewhere to display our stamina bar - we'll use health.cpp, so open it up and find the Draw function. Near the bottom of the function you will find this line:
| | FillRGBA(x, y, iWidth , iHeight, 255, 160, 0, a);
|
Place this directly after it:
| | //draw stamina FillRGBA(XRES(10), y - gHUD.m_iFontHeight, iWidth+(gHUD.g_iStamina/10), iHeight, 0, 255, 0, 255);
|
That simply draws a green rectangle above the health/armor to the width of our current status amount.
Well thats it, a very simple tutorial - but it makes the dash/sprint effect more complete. |
|
User Comments
Showing comments 1-3
xout where it says
| | if(gHUD.g_iStamina<0) { gHUD.g_iStamina =0;//cap stamina at zero so we dont have negative amounts in_alt1.state &= ~1;//release the dash button so the client cant keep sprinting }
|
i think you mean
| | if(gHUD.g_iStamina<0) { gHUD.g_iStamina =0;//cap stamina at zero so we dont have negative amounts in_dash.state &= ~1;//release the dash button so the client cant keep sprinting }
|
otherwise, in_alt1.state come up as a unidentified modifier since its commented out also one thing i see is there is nothing to prevent stamina from decreasing if the person is standing still, lemme see if i can fix thatEdited by Bryan on Mar 15 2004, 04:31:49
|
|
To make it so they don't lose stamina unless they are moving, change the following:
To this:
| | if((in_dash.state & 1) && (in_forward.state & 1)) { |
This will make sure that they are holding down the dash key AND the forward key. You will also want to go back and edit some of the code in pm_shared.c (the areas that make sure they are on the ground) so that they can't dash backwards (pmove->cmd.buttons & IN_BACK), or if they do it goes slower than dashing forwards.
Good luck!Edited by XxAvalanchexX on Mar 09 2005, 08:05:59
|
|
That stamina code is not secured. Since its done on client side only, it would mean that its very easy to cheat to make it so you have unlimited stamina without the server knowing about it. Its better to store the player's stamina on the server and then retrieve it from the client.Edited by hagai on Jun 15 2006, 15:08:43
|
|
You must register to post a comment. If you have already registered, you must login.
|
297 Approved Articless
8 Pending Articles
3940 Registered Members
0 People Online (7 guests)
|
|