Raised This Month: $51 Target: $400
 12% 

Best way to kill a player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
za_bullet2
Junior Member
Join Date: Jul 2006
Old 02-28-2007 , 13:32   Best way to kill a player
Reply With Quote #1

What is the best way to kill a player? I tried setting health to 0 using the Edict::GetUnknown() + Offset = 0 But that didn't work..... Any ideas? D.
za_bullet2 is offline
Knagg0
SourceMod Donor
Join Date: Dec 2005
Location: Germany
Old 02-28-2007 , 13:33   Re: Best way to kill a player
Reply With Quote #2

CBasePlayer::CommitSuicide()
Knagg0 is offline
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 03-01-2007 , 05:36   Re: Best way to kill a player
Reply With Quote #3

Quote:
Originally Posted by Knagg0 View Post
CBasePlayer::CommitSuicide()
That wouldn't really be the best as it has to go through some processes before they die, it could be overridden for instance as it is in ZombieMod.

CCSPlayer::EventKilled and CCSPlayer::EventDying
__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3
Knagg0
SourceMod Donor
Join Date: Dec 2005
Location: Germany
Old 03-01-2007 , 06:39   Re: Best way to kill a player
Reply With Quote #4

Quote:
CCSPlayer::EventKilled and CCSPlayer::EventDying
You mean *Player::Event_Killed and *Player::Event_Dying

Ok... You can only call CommitSuicide() every 5 seconds for one player.
But but otherwise its the same and easier

Code:
void CBasePlayer::CommitSuicide()
{
	if( !IsAlive() )
		return;
		
	// prevent suiciding too often
	if ( m_fNextSuicideTime > gpGlobals->curtime )
		return;

	// don't let them suicide for 5 seconds after suiciding
	m_fNextSuicideTime = gpGlobals->curtime + 5;  

	// have the player kill themself
	m_iHealth = 0;
	Event_Killed( CTakeDamageInfo( this, this, 0, DMG_NEVERGIB ) );
	Event_Dying();
}

Last edited by Knagg0; 03-01-2007 at 06:51.
Knagg0 is offline
za_bullet2
Junior Member
Join Date: Jul 2006
Old 03-02-2007 , 01:53   Re: Best way to kill a player
Reply With Quote #5

I'm clearly a complete N00B....seems I'm not getting how this is all done....

I've got something like this...

Code:
        IServerUnknown * pServerUnknown = pEdict->GetUnknown();
        CBaseEntity * pEntity = pServerUnknown ->GetBaseEntity();
        CBasePlayer * pPlayer = ToBasePlayer(pEntity);
        pPlayer->CommitSuicide();
.....nothing happens.....

What am I missing here?

D.
za_bullet2 is offline
el hippo
Member
Join Date: Jan 2006
Location: Texas
Old 03-02-2007 , 02:58   Re: Best way to kill a player
Reply With Quote #6

You'll have to use vfuncs to be able to call functions that relate to base entity stuff since the sdk's header files are not current.

Look at http://wiki.tcwonline.org/index.php/...%28SourceMM%29 for more information on this. There is a nice example on how to call CommitSuicide at the bottom of that wiki page.

And as for that 5 second delay: You could probably mess with the data desc map to set the value of m_fNextSuicideTime to sometime in the past so you can suicide that person. The data description maps are pretty useful for making the game do what you want.

Hippo
__________________

Last edited by el hippo; 03-02-2007 at 03:01.
el hippo is offline
za_bullet2
Junior Member
Join Date: Jul 2006
Old 03-02-2007 , 07:42   Re: Best way to kill a player
Reply With Quote #7

OOOOOOH I SEEEEEE!

Okay.....as I said...N00B....thanks....I'll try that and see what happens.

Shot.

D.
za_bullet2 is offline
za_bullet2
Junior Member
Join Date: Jul 2006
Old 03-02-2007 , 09:18   Re: Best way to kill a player
Reply With Quote #8

Works like a charm.....thanks....I have a side question....all the "events" in the vtable like Event_Killed? How do you hook those?

D.
za_bullet2 is offline
BAILOPAN
Join Date: Jan 2004
Old 03-02-2007 , 21:42   Re: Best way to kill a player
Reply With Quote #9

It's best just to use IGameEventManager2 as it was intended; the event you're thinking of is probably "player_death" or soemthing.

But if they're virtual you can hook them with SourceHook, if you use Metamod:Source. If you're looking for cross-mod compatibility it gets more difficult. Of course, if they're not virtual, it is much more difficult.
__________________
egg
BAILOPAN is offline
za_bullet2
Junior Member
Join Date: Jul 2006
Old 03-03-2007 , 01:33   Re: Best way to kill a player
Reply With Quote #10

I try to use the "standard" ways as much as possible, my question regarding Event_Killed, was purely for interest sake....I already capture all other events like player_hurt, player_spawn...etc etc....via the events interface.

But thanks for the info.

Shot.

D.
za_bullet2 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode