Welcome, Guest! Login | Register

Storing weapons on ladder [Print this Article]
Posted by: British_Bomber
Date posted: Dec 24 2005
User Rating: 4.5 out of 5.0
Number of views: 3294
Number of comments: 4
Description: like Raven Sheild or BF2
After reading on a few forums that there were some people interested in forcing players to lower their weapons while climbing ladders. Similar to Battlefield and Ravensheild. I did some messing around and got this working and since I'm not going to be using it I decided to share it here.

So to start off.

Gamemovement.cpp or whatever you are using as the movement logic in your game.

What I did was found where the player is first detected as being on a ladder.

this is in the bool CGameMovement::LadderMove( void ) function

just after the line

 CODE (C++) 
// no ladder in that direction, return
if ( pm.fraction == 1.0f || !OnLadder( pm )  )
    return false;


I added

 CODE (C++) 
//No weapon on ladders
m_pWeapon = player->GetActiveWeapon();
if( m_pWeapon )
    m_pWeapon->Holster();


So with the getting on the ladder taken care of the next thing is handling getting off the ladder.

this happens in the void CGameMovement::PlayerMove( void ) function in this if statement

 CODE (C++) 
if ( !LadderMove() && ( player->GetMoveType() == MOVETYPE_LADDER ) )
{

    // Clear ladder stuff unless player is dead or riding a train
    // It will be reset immediatly again next frame if necessary
    player->SetMoveType( MOVETYPE_WALK );
    player->SetMoveCollide( MOVECOLLIDE_DEFAULT );
}


this just checks if the player isn't moving on a ladder but their movetype indicates they are on a ladder then switch them back to walking.
that's what we want so I simply added this in there

 CODE (C++) 
if ( !LadderMove() && ( player->GetMoveType() == MOVETYPE_LADDER ) )
{
    //No Weapons on ladders
    if ( m_pWeapon )
    {
        m_pWeapon->Deploy();
    }

    // Clear ladder stuff unless player is dead or riding a train
    // It will be reset immediatly again next frame if necessary
    player->SetMoveType( MOVETYPE_WALK );
    player->SetMoveCollide( MOVECOLLIDE_DEFAULT );
}


so the last thing to do in here is to add the m_pWeapon variable to the movement class. I did that just after the player pointer in the protected section

 CODE  
CBasePlayer *player;
//No Weapons on ladders
CBaseCombatWeapon *m_pWeapon;


Now that that's done the weapon is Holstered when getting a ladder and deployed on leaving. However there are still 2 issues. When the weapon is supposedly holstered it can still fire and the player can switch to a different weapon while on the ladder.

To take care of the switching I went into basecombatcharacter_shared.cpp and add the following to Weapon_CanSwitchTo( ...

 CODE (C++) 
bool CBaseCombatCharacter::Weapon_CanSwitchTo( CBaseCombatWeapon *pWeapon )
{

    //No Weapons on ladders
    if( GetMoveType() == MOVETYPE_LADDER )
        return false;

    if( IsPlayer() )
    .
    .
    .


now that the player can't switch weapons on the ladder the shooting has to be stopped too. I did this in basecombatweapon_shared.cpp in the ItemPostFrame() function

 CODE (C++) 
void CBaseCombatWeapon::ItemPostFrame( void )
{
    CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
    if (!pOwner)
        return;

    //No Weapons on ladders
    if( pOwner->GetMoveType() == MOVETYPE_LADDER )
        return;
    .
    .
    .


what that does is stops any logic from calling any weapon functions. If you have weapons that have their own ItemPostFrame function defined, then at the begining of those either add the ladder check or just call BaseClass::ItemPostFrame();

So that's it, more me typing than acctual code but that gives you the basics. If you want to go and add your own hand climbing animations and such I'd suggest looking at how HL2 did the hand admire and just alter that to fit your hand model and call the animation when the move type is set to a ladder.

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

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

Posted By: schneider on Sep 07 2006 at 13:48:36
great thank you, i hope you make more good tutorials like this :)

Posted By: bloodyskull on Sep 09 2006 at 11:29:03
how to store weapon while jumping?
I would like to read a tutorial like it...
plz teach me :D

Posted By: slackiller on Sep 15 2006 at 12:52:25
good stuff BB

Posted By: cct on Sep 07 2007 at 13:06:46
i´m a bit out of coding but couldn´t you redo the last 2 steps for movetype_jump if that one exists?


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
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
 
Debugging your half-life 2 mod
Half-Life 2 | Coding | Articles
By: blackshark | Aug 17 2007
 

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

Wavelength version: 3.0.0.9
Valid XHTML 1.0! Valid CSS!