Welcome, Guest! Login | Register

Controlling Player Speeds [Print this Article]
Posted by: omega
Date posted: Aug 31 2003
User Rating: 5 out of 5.0
Number of views: 3924
Number of comments: 1
Description: by Fireball
From the Editor: I've modified this tutorial, and simplified it. For those of you who may have seen the original tutorial, there was a section on adding a message for speed; this message isn't needed, and the same task can be accomplished an easier way (which will not be covered in this tutorial anymore, since most of you will not need it for the purpose of this tutorial.)

This tutorial shows how to enable you to set what speeds the player can go, and force them to remain at those speeds. Most of the setting and checking is done on the client side, so there should be no noticable increase in network traffic. The system used should easily be altered to make use of any player class system or take into account any special items that can alter someone's speed.
File names are shown in red. Existing code is shown in purple. Additions you have to make are shown in green.

First, we must modify the server to send the speed information to the client. Let's start by adding a variable to the player class so the server knows when it needs to send an update to the client, as well as a function to determine what the speed of the player should be:
 CODE  

PLAYER.H (near the bottom):
void SetCustomDecalFrames( int nFrames );
 int GetCustomDecalFrames( void );


 int PlayerSpeed() {return 270;}  //The max speed the player can move

};

Change 270 to whatever speed you want, or perform any calculations such as determining speed based on the player's class or equipment, etc.


Now we'll set the server-side limitation on speed:
 CODE  

PLAYER.CPP
(in CBasePlayer::Spawn)

 g_engfuncs.pfnSetClientMaxspeed( ENT( pev ), PlayerSpeed() );

 g_pGameRules->PlayerSpawn( this );
}



That's it! Hopefully everything compiles, and you now have very rigid player speeds that can't be modified. Some issues not covered in this tutorial are the numbers used by Half-Life for determining things such as when to show the player as running or walking, and how loud and frequently to play footstep noises. Search for "step" in PM_SHARED.C and you'll see what I mean. You should be able to base these off the PlayerSpeed() function instead of the existing hard-coded values pretty easily.
From the Editor: the easiest way to do this is to set a physics key when you set the speed of the player; look in items.cpp for the way it sets the physicskey when you get the longjump module
Fireball

Rate This Article
This article is currently rated: 5 out of 5.0 (2 Votes)

You have to register to rate this article.
User Comments Showing comments 1-1

Posted By: _jc on Sep 02 2003 at 14:57:42
I would suggest poking the players speed into fuser4 and using this to overide pmove->maxspeed, otherwise your wonderful speed system can get screwed up by the wonder of the maxspeed engince cvar.


You must register to post a comment. If you have already registered, you must login.

Latest Articles
3rd person View in Multiplayer
Half-Life 2 | Coding | Client Side Tutorials
How to enable it in HL2DM

By: cct | Nov 13 2006

Making a Camera
Half-Life 2 | Level Design
This camera is good for when you join a map, it gives you a view of the map before you join a team

By: slackiller | Mar 04 2006

Making a camera , Part 2
Half-Life 2 | Level Design
these cameras are working monitors that turn on when a button is pushed.

By: slackiller | Mar 04 2006

Storing weapons on ladder
Half-Life 2 | Coding | Snippets
like Raven Sheild or BF2

By: British_Bomber | Dec 24 2005

Implementation of a string lookup table
Half-Life 2 | Coding | Snippets
A string lookup table is a set of functions that is used to convert strings to pre-defined values

By: deathz0rz | Nov 13 2005


Latest Comments
Spinning Corpses Simple Fix
Half-Life | Coding | Snippets
By: darkPhoenix | Sep 05 2008
 
Where do we go from here
General | News
By: MIFUNE | Jun 09 2008
 
The Input/Output system
Half-Life 2 | Level Design
By: nazitaco | Dec 23 2007
 
Where do we go from here
General | News
By: Rob_F | Nov 22 2007
 
Rescaling Half-Life
Half-Life | Coding | Shared Tutorials
By: christoph | Nov 12 2007
 
GameUI
Half-Life 2 | Coding | Client Side Tutorials
By: Evil_j | Oct 29 2007
 
3 State Zoom For Any Weapon
Half-Life 2 | Coding | Server Side Tutorials
By: Ennuified | Oct 18 2007
 
Storing weapons on ladder
Half-Life 2 | Coding | Snippets
By: cct | Sep 07 2007
 
CTF Gameplay Part 1
Half-Life | Coding | Shared Tutorials
By: DarkNight | Aug 28 2007
 
CTF Gameplay Part 1
Half-Life | Coding | Shared Tutorials
By: deedok | Aug 20 2007
 

Site Info
296 Approved Articless
5 Pending Articles
3940 Registered Members
0 People Online (12 guests)
About - Credits - Contact Us

Wavelength version: 3.0.0.9
Valid XHTML 1.0! Valid CSS!