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 | Freezing a Player
Welcome, Guest! Login | Register

Freezing a Player [Print this Article]
Posted by: -+Arcadian+-
Date posted: Jun 16 2003
User Rating: 5 out of 5.0
Number of views: 5901
Number of comments: 2
Description: While shooting a weapon (easy)
This article explains one way of freezing the player while shooting a weapon. x-0ut explained how to make it work in irc so he deserves the credit for it. user posted image I'm going to do this with the MP5 as an example.

#1. In the definition of your weapon's class (usually in weapons.h), add this variable into the private section:
float m_flFreezeTime;   // Arc - Freeze Player Timer

This just sets up a variable for your timer.. it will equal the current time plus 2 (or any amount of time you choose to freeze the player.

#2. Now in your weapon's C++ file (mp5.cpp in this case), add the following to its Spawn( ) function:
void CMP5::Spawn( )

    m_flFreezeTime = 0;

#3. Next, add this to its PrimaryAttack() function:
void CMP5::PrimaryAttack()

    // Arc - Freeze Player for a few seconds

#ifndef CLIENT_DLL  // Have to use #ifndef so the client dll will compile.
    //The code between the #ifndef directive and the #endif directive is only
    //compiled if the constant name that is specified has not been defined previously.
    //(this was copied from the hl source)

    m_flFreezeTime = gpGlobals->time + 2;  // m_flFreezeTime = current time + 2  ( 2 = how long to freeze the player)
    m_pPlayer->EnableControl(false);      // this freezes the player ... simple enough
#endif   // end the #ifndef CLIENT_DLL

#4. Then lastly add the following to its WeaponIdle( void ) function:
void CMP5::WeaponIdle( void )

    // Arc - Freeze Player for a few...

#ifndef CLIENT_DLL
    if (m_flFreezeTime && gpGlobals->time > m_flFreezeTime)    // Check if we're timing and if the freeze time is up
        m_pPlayer->EnableControl(true);      // unfreeze player

Thats all. Now when a player fires the gun he will be frozen for a few seconds unable to move.
Of course you could freeze a player anywhere at anytime you want. user posted image -+Arcadian+-

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-2

Posted By: GuTeR on Oct 15 2003 at 03:28:10
hehehe very nice i may change sum stuff to make it so that u can freeze pplz :p

Posted By: MIFUNE on May 11 2005 at 18:00:55
I have implemented it into my mod Zion Warcry. Thanks Arcadian. Nice tutorial!! :)

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 (6 guests)
About - Credits - Contact Us

Wavelength version:
Valid XHTML 1.0! Valid CSS!