Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /var/sites/a/ on line 20
Wavelength | Your Game Editing Resource | Controlling Player Speeds
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: 8998
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:

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:

(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

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 20: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 05 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
knock knock
General | News
By: MIFUNE | Dec 31 2017
knock knock
General | News
By: omega | Dec 22 2016
knock knock
General | News
By: MIFUNE | Oct 10 2015
New HL HUD Message System
Half-Life | Coding | Shared Tutorials
By: chbrules | Dec 31 2011
knock knock
General | News
By: Whistler | Nov 05 2011
Particle Engine tutorial part 4
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 18 2010
Particle Engine tutorial part 2
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
Particle Engine tutorial part 3
Half-Life | Coding | Client Side Tutorials
By: darkPhoenix | Feb 11 2010
Game Movement Series #2: Analog Jumping and Floating
Half-Life 2 | Coding | Shared Tutorials
By: mars3554 | Oct 26 2009
Particle Engine tutorial part 5
Half-Life | Coding | Client Side Tutorials
By: Deadpool | Aug 02 2009

Site Info
297 Approved Articless
8 Pending Articles
3940 Registered Members
0 People Online (3 guests)
About - Credits - Contact Us

Wavelength version:
Valid XHTML 1.0! Valid CSS!