Posted by: British_Bomber
Date posted: Dec 24 2005 User Rating: 4.5 out of 5.0 | Number of views: 14328 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
| | if ( pm.fraction == 1.0f || !OnLadder( pm ) ) return false;
|
I added
| | 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
| | if ( !LadderMove() && ( player->GetMoveType() == MOVETYPE_LADDER ) ) {
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
| | if ( !LadderMove() && ( player->GetMoveType() == MOVETYPE_LADDER ) ) { if ( m_pWeapon ) { m_pWeapon->Deploy(); }
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
| | 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( ...
| | bool CBaseCombatCharacter::Weapon_CanSwitchTo( CBaseCombatWeapon *pWeapon ) {
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
| | void CBaseCombatWeapon::ItemPostFrame( void ) { CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if (!pOwner) return;
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. |
|
User Comments
Showing comments 1-4
great thank you, i hope you make more good tutorials like this :) |
|
how to store weapon while jumping? I would like to read a tutorial like it... plz teach me :D |
|
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.
|