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

[TF2] get player class on death


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yusufali
Member
Join Date: Feb 2014
Old 09-16-2014 , 15:26   [TF2] get player class on death
Reply With Quote #1

How can one go about getting the killer's and victim's class upon the death event

I am binding to player_death, and the event only has the keys 'userid' and 'attacker'
there are 2 methods in the sourcemod api that has to do with the player class

but im not entirely sure on how it works?

Code:
stock TFClassType:TF2_GetPlayerClass(client) //what is stock?
native TFClassType:TF2_GetClass(const String:classname[]); //this doesnt seem to be a solution
__________________
yusufali is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 09-16-2014 , 15:29   Re: [TF2] get player class on death
Reply With Quote #2

You need to convert the client's UserID(which bot event ints "userid" and "attacker" have) into a client index then use TF2_GetPlayerClass on the client index.
__________________
WildCard65 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-16-2014 , 16:33   Re: [TF2] get player class on death
Reply With Quote #3

"stock" just means it's a method that will only be compiled if you actually use it.

It's really just a wrapper around a GetEntProp call.

Having said that, TF2 has a few quirks you need to know about regarding player_death...
  • it fires when Spies fake their death. You can detect if this is happening using this:
    PHP Code:
    if (GetEventInt(event"death_flags") & TF_DEATHFLAG_DEADRINGER)
    {
        return; 

    This assumes tf2_stocks is loaded.
  • TF2's player_death has a victim_entindex field, which just happens to be the player's client index.

Also, make sure attacker is > 0 and <= MaxClients. 0 means the world killed the player (fall damage, death pits) while an entity index means something else killed them (Halloween boss, etc...)
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
yusufali
Member
Join Date: Feb 2014
Old 09-16-2014 , 22:38   Re: [TF2] get player class on death
Reply With Quote #4

what type does it return, im getting tag mismatch

Code:
new victim = GetClientOfUserId(GetEventInt(event,"userid"));
new victim_role = TF2_GetPlayerClass(victim);
__________________
yusufali is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 09-16-2014 , 23:19   Re: [TF2] get player class on death
Reply With Quote #5

TF2_GetPlayerClass returns a int of type TFClassType, so you'll have to tag victim_role as such.

Last edited by bl4nk; 09-17-2014 at 15:59. Reason: TFClassType, not TFClass (i should double check stuff before posting)
bl4nk is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-16-2014 , 23:36   Re: [TF2] get player class on death
Reply With Quote #6

Quote:
Originally Posted by bl4nk View Post
TF2_GetPlayerClass returns a int of type TFClass, so you'll have to tag victim_role as such.
Unfortunately, TFClassType is defined in tf2.inc instead of tf2_stocks.inc.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 09-16-2014 , 23:43   Re: [TF2] get player class on death
Reply With Quote #7

Quote:
Originally Posted by Powerlord View Post
Unfortunately, TFClassType is defined in tf2.inc instead of tf2_stocks.inc.
Including tf2_stocks.inc automatically includes tf2.inc (but not the other way around.)

https://github.com/alliedmodders/sou...stocks.inc#L38
__________________

Last edited by ddhoward; 09-16-2014 at 23:45.
ddhoward is offline
yusufali
Member
Join Date: Feb 2014
Old 09-17-2014 , 00:35   Re: [TF2] get player class on death
Reply With Quote #8

Quote:
Originally Posted by bl4nk View Post
TF2_GetPlayerClass returns a int of type TFClass, so you'll have to tag victim_role as such.
What exactly do you mean by that? So when I'm building an insert query to a mysql database,
is it an integer? like
Code:
 ("%d", victim_role)
or something would work?
__________________
yusufali is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 09-17-2014 , 00:48   Re: [TF2] get player class on death
Reply With Quote #9

Quote:
Originally Posted by yusufali View Post
What exactly do you mean by that?
he means this:

Code:
new victim = GetClientOfUserId(GetEventInt(event,"userid"));
new TFClassType:victim_role = TF2_GetPlayerClass(victim);
__________________

Last edited by ddhoward; 09-17-2014 at 09:16.
ddhoward is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 09-17-2014 , 07:40   Re: [TF2] get player class on death
Reply With Quote #10

Quote:
Originally Posted by yusufali View Post
what type does it return, im getting tag mismatch

Code:
new victim = GetClientOfUserId(GetEventInt(event,"userid"));
new victim_role = TF2_GetPlayerClass(victim);
Infront of "victim_role" before the "new" put "TFClassType"
__________________
WildCard65 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 07:32.


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