Posted by: X-0ut
Date posted: Apr 28 2003 User Rating: 5 out of 5.0 | Number of views: 3860 Number of comments: 2 | Description: |
This tutorial will show you how to setup a new key and console command, which can then be used in game to make the player sprint when holding the key, for simplicity I did not add stamina to the code, this is something you should work on to stop the player from always sprinting. Maybe I will make an extension to this tutorial in the future for stamina with clientside hud sprite depicting the stamina status, and perhaps even a pm_shared version.
First we can't just go and create new keys like IN_JUMP and IN_DUCK because there is a limit to 16 bits, to work around this we have to override a key thats not in use, for this tutorial we will override the IN_ALT1 key.
Open up in_buttons.h (common folder) and comment out the IN_ALT1 key, your code should look something like this:
| | | #define IN_RELOAD (1 << 13) //////////////////////////// // we comment out IN_ALT1 // // because we cant define // // new keys // //////////////////////////// //#define IN_ALT1 (1 << 14) #define IN_DASH (1 << 14) //////////////////////////// #define IN_SCORE (1 << 15) // Used by client.dll for when scoreboard is held down
|
Client DLL Specific Changes: Now in input.cpp we must comment out every reference to the IN_ALT1 key and replace it with our new IN_DASH key. Near the top of the file you will see a list of all the default keys like in_jump, in_duck etc, you need to alter the code so its like this:
| | | kbutton_t in_reload; //remember we are using alt1 as our new key// //kbutton_t in_alt1; kbutton_t in_dash; /////////////////// kbutton_t in_score;
|
A little further down the file you will see a bunch of functions that detect if the key is down or up, alter it so its like this:
| | | void IN_ReloadDown(void) {KeyDown(&in_reload);} void IN_ReloadUp(void) {KeyUp(&in_reload);} //we must replace every alt1 with our dash// //void IN_Alt1Down(void) {KeyDown(&in_alt1);} //void IN_Alt1Up(void) {KeyUp(&in_alt1);} void IN_DashDown(void) {KeyDown(&in_dash);} void IN_DashUp(void) {KeyUp(&in_dash);} //////////////////////////////////////// void IN_GraphDown(void) {KeyDown(&in_graph);} void IN_GraphUp(void) {KeyUp(&in_graph);}
|
We need to make two more adjustments in the CL_ButtonBits function, firstly:
| | | //again just replacing alt1 with dash// /* if (in_alt1.state & 3) { bits |= IN_ALT1; } */ if (in_dash.state & 3) { bits |= IN_DASH; } ////////////////////////////// if ( in_score.state & 3 ) { bits |= IN_SCORE; }
|
And secondly at the bottom of the function:
| | | in_reload.state &= ~2; ///nearly there// // in_alt1.state &= ~2; in_dash.state &= ~2; //////////////////// in_score.state &= ~2;
|
Finally we have one more piece of code to alter, go down to the bottom of the file , in the InitInput function where the console commands are added, make it like so:
| | | gEngfuncs.pfnAddCommand ("-reload", IN_ReloadUp); ///here we make the +dash command so we can bind it ingame// // gEngfuncs.pfnAddCommand ("+alt1", IN_Alt1Down); // gEngfuncs.pfnAddCommand ("-alt1", IN_Alt1Up); gEngfuncs.pfnAddCommand ("+dash", IN_DashDown); gEngfuncs.pfnAddCommand ("-dash", IN_DashUp); ////////////////////////////////////////////////// gEngfuncs.pfnAddCommand ("+score", IN_ScoreDown);
|
Shared Changes Open up pm_shared.c and find the PM_WalkMove function, at the top of the function you'll find a bunch of varaible declarations C style, we need to add a bool, and check if the client has pressed the IN_DASH button, we can do that like so:
| | | float downdist, updist; pmtrace_t trace; ///if we are dashing (ooo)/// qboolean bIsDashing; if ( pmove->cmd.buttons & IN_DASH ) { pmove->oldbuttons |= IN_DASH; bIsDashing = true; } else { pmove->oldbuttons &= ~IN_DASH; bIsDashing = false; } ///////////////////////////// // Copy movement amounts fmove = pmove->cmd.forwardmove; smove = pmove->cmd.sidemove;
|
Im sure you can see whats happening there, if the key is pressed, the boolean is set true, otherwise its set false. Now a little further down the function you will find this code:
| | | for (i=0; i<2; i++) // Determine x and y parts of velocity wishvel[i] = pmove->forward[i]*fmove + pmove->right[i]*smove;
|
What that is doing is copying the velocity into wishvel, we just need to alter it slightly so that it adds more speed if our boolean is true, like so:
| | | for (i=0; i<2; i++){ // Determine x and y parts of velocity if(bIsDashing && (! ( pmove->flags & FL_DUCKING))) wishvel[i] = pmove->forward[i]*(fmove*200)+ pmove->right[i]*smove; else wishvel[i] = pmove->forward[i]*fmove + pmove->right[i]*smove; }
|
Ok, so same as before the velocity is being copied into wishvel, except now if our boolean is true it copies a greater amount ((fmove*200)) . Still one more thing to do, even further down the function the speed is capped off to the server maxspeed, we need to alter it to allow for our dash to work, find this code:
| | | if (wishspeed > pmove->maxspeed) { VectorScale (wishvel, pmove->maxspeed/wishspeed, wishvel); wishspeed = pmove->maxspeed; }
|
And alter it like so:
| | | if(bIsDashing && (! ( pmove->flags & FL_DUCKING))) { if (wishspeed > pmove->maxspeed + 200) { VectorScale (wishvel, (pmove->maxspeed+200)/wishspeed, wishvel); wishspeed = pmove->maxspeed + 200; } } else { if (wishspeed > pmove->maxspeed) { VectorScale (wishvel, pmove->maxspeed/wishspeed, wishvel); wishspeed = pmove->maxspeed; } }
|
What that is doing is checking our boolean once again, if its true it checks the wishspeed against the maxspeed + 200 and caps it off, if not the wishspeed is checked against the normal maxspeed - and capped.
Thats it we are all done, you will need to compile both server and client workspaces for the effect to work, you will also need a delta.lst (found in the valve folder) You'll need to bind the dash command which you can do by opening up the console and binding it to a key like this:
Also, you will need to alter the servers maxspeed which you can do with the sv_maxspeed cvar:
Thats it for this tutorial. |
|
User Comments
Showing comments 1-2
I was playing with keys recently and discovered that IN_RUN 1 << 12 also appears unused.. every now and then it's nice to find we have ONE extra bit we need as modders.. :p.
Also, you can subjugate IN_SCORE if you'd like, anything IMPORTANT to do with scoreboards are clientside only, so no need to use up precious pev->button bits for that. (you'll have to modify one bit of code in the PlayerDeathThink for this to work).
Nice little tutorial btw, succinct and to the point, explained well :).Edited by sluggo on Sep 14 2003, 22:45:40
|
|
|
Messing around with my mod (we'd used all the available bits) I was able to get some extra manuvering room by making one of our bits a "LEFT/RIGHT" bit. Ie, if the bit was set it meant that motions were supposed to go left, otherwise right. This turned MOVELEFT/MOVERIGHT into MOVE, and LEFT/RIGHT into TURN. (giving one extra bit). We also had LEANLEFT/LEANRIGHT, which turned into LEAN (giving another extra bit). This was enough for dash and prone. |
|
You must register to post a comment. If you have already registered, you must login.
|
296 Approved Articless
5 Pending Articles
3940 Registered Members
0 People Online (15 guests)
|
|