PDA

View Full Version : How to get the player below the other?


Ricksk
07-25-2007, 02:49 PM
I have this piece of code, in the gamemovement.cpp, CheckJump:
if ( ( player->m_Local.m_bDucking ) || ( player->GetFlags() & FL_DUCKING ) )
{
if (mv->m_nButtons & IN_SPEED && SUIT > MORPHEUS_NEED) // We are Sprinting!
{
// Morpheus Jump!
#ifndef CLIENT_DLL
CHL2_Player *pHLPlayer = assert_cast<CHL2_Player*>( player );

pHLPlayer->SuitPower_Drain( MORPHEUS_NEED-JUMP_NEED ); //drain stamina for the jump
#else
C_BaseHLPlayer *pHLPlayer = assert_cast<C_BaseHLPlayer*>( player );

pHLPlayer->m_HL2Local.m_flSuitPower = max( SUIT - (MORPHEUS_NEED-JUMP_NEED), 0 ); //drain stamina for the jump
#endif
mv->m_vecVelocity[2] = flGroundFactor * flMul * MORPHEUS_HEIGHT_MULTIPLY; // 2 * gravity * height * MORPHEUS_HEIGHT_MULTIPLY
}

It's all okey, but I need to kill who is below the player, how can I do that? I have to kill when the player reach the ground (other player) again... But.. how!? :D
I thinked in make a bool to the MorphJump, so I can use the Friction() to check if theres a player below the jumperkid :D, but I dont know how to check if there is someone down, and how to kill him... How can I use "if (player->GetGroundEntity() == )" to compare the GroundEntity to the Players Entity?

Ricksk
07-26-2007, 01:32 PM
Someone? :D

Winston
07-26-2007, 02:47 PM
I would do a UTIL_Traceline straight down from pHLPlayer's origin, setting the ignore entity to pHLPlayer.

Then you should be able to get the player they land on (if there is one), and kill them, by:

if ( tr.m_pEnt && tr.m_pEnt->IsPlayer() )
{
tr.m_pEnt->TakeDamage( CTakeDamageInfo( this, this, 250, DMG_CRUSH ) );
}

Edit:
Actually, that would kill them immediately when you start to do your Morpheus jump ... if you want to wait til they land before killing, why not add a boolean, m_bCrushing to the player class, set it to false when the player spawns.
In the code you have above, set pHLPlayer->m_bCrushing = true;
Then, at the start of WalkMove, (which is only run when they're standing on something), do

if ( player->m_bCrushing )
{
player->m_bCrushing = false;
// do the trace, and the killing code here
}

noob cannon lol
07-27-2007, 09:47 AM
No need to do traces, GetGroundEntity() works fine. To get at when the player lands on someone, I would put that conditional and everything else you want to do in PhysicsStartGroundContact() in physics_main_shared.cpp. All of what the player lands on should be handled correctly by the existing code.

Winston
07-27-2007, 11:05 AM
this /\
:)

Ricksk
07-27-2007, 11:33 AM
Thanks, I will try :D

Ricksk
07-27-2007, 04:48 PM
Sorry, but I dont find any PhysicsStartGroundContact() in the SDK (I'm using the HL2MP)...
Actually I'm checking if what is below the jumper is a player, but I don't know how to 'catch' him and kill him... I could use a trace, but how do I set the trace down? And kill the ???????? :D

Winston
07-28-2007, 02:01 AM
A problem like this has no one precisely correct solution, but many possibilities, some slightly better or worse than the others. We're confusing you by talking about different implementations!

Try this: First, ignore what we've said previously.
In that fragment you've given us, after the line mv->m_vecVelocity[2] = flGroundFactor * flMul * MORPHEUS_HEIGHT_MULTIPLY; add player->m_bCrushing = true;

Now go to player.h and add bool m_bCrushing; to a public section of the player class declaration.

Open up player.cpp, and find CBasePlayer::Spawn. Add to this: m_bCrushing = false;

At the very start of void CBasePlayer::Touch (still player.cpp, ~line 4115), put:

if ( pOther->IsPlayer() && pOther == GetGroundEntity() && m_bCrushing )
{
m_bCrushing = false;
pOther->TakeDamage( CTakeDamageInfo( this, this, 250, DMG_CRUSH ) );
}

Change the 250 to the damage you want this jump to deal.
That should be it! It would be more "proper" to make these changes to the CHL2MP_Player class rather than CBasePlayer, so feel free to do that if you want, that just adds some slight complexity getting it working with gamemovement.cpp that I don't remember the details of right now.

Ricksk
07-28-2007, 02:50 PM
Sorry, but where exactly should I declare the m_bCrushing in player.h? I've tryied in all the public places, but dont seems to work =x

Winston
07-28-2007, 03:49 PM
Hmm, strange. Its definately in the CBasePlayer class and not CPlayerInfo?
I've probably got it wrong, but I can't see how. What error messages is it giving? Can't find m_bCrushing as part of CBasePlayer?

Ricksk
07-28-2007, 05:16 PM
I've only tried to declare in the player.h and then acess by player.cpp, but I couldnt find the m_bCrushing... Can you say the line to declare the bool?
(and, only to be sure, I'ts bool m_bCrushing = false; right?)

Marine
07-28-2007, 05:19 PM
You have to BUILD your files before Intellisense will show up your variables (C++ you have to do this :P)

Ricksk
07-30-2007, 08:54 AM
Uops! Sorry :D Im trying right now, sorry for that mistake #)

edit: Well, no errors, but when I use the ctrl+space to browse the m_bCrushing, it is not here :o I can acess it in the player.cpp, but I cant find it o.Ô

Ricksk
07-30-2007, 09:43 AM
Im doing something wrong... the gamemovement.cpp cant find the bool...
Please, where exactly should I declare? Tell me the line or the text near the declaration of the bool (in player.h)...

Winston
07-31-2007, 10:53 AM
Ah, sorry, my bad (again).

gamemovement.cpp is used on both sever and client.
To get this to work, you'll have to EITHER put the following defines around the "crushing" code: #ifndef CLIENT_DLL
<your code here>
#endif OR add the bool to the client player class also (c_baseplayer.h).

I suspect the second option would be the way to go, but I couldn't tell you for sure without actually doing it.

Ricksk
07-31-2007, 03:49 PM
Thanks! It's working now! :D
Hohoho now I can kill in morpheus style!
(but in Matrix he never hit someone when jump...)