Posted by: -+Arcadian+-
Date posted: Jun 16 2003 User Rating: 5 out of 5.0 | Number of views: 3692 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. 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 #endif //---------------------------------------------------- |
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. -+Arcadian+- |
|
User Comments
Showing comments 1-2
|
hehehe very nice i may change sum stuff to make it so that u can freeze pplz :p |
|
|
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.
|