Page 1 of 1

TF2 - Player class id / name?

Posted: Sat Mar 31, 2018 5:27 pm
by Zeus
Theres a few things id like to be able to do with players that requires me to know what class they're playing.

As far as i can tell, Player does not have a tf2 class property or any way to find that?

Edit:
I found this: https://github.com/alliedmodders/source ... s.inc#L383

This code here can actually get and set class.

Syntax: Select all

def set_class(self, classid):
self.set_property_uchar('m_Shared.m_iDesiredPlayerClass', classid)

def get_class(self):
return self.get_property_uchar('m_PlayerClass.m_iClass')


Is it possible to have this be part of the player object in a more convienant form, or even make a tf2player subclass?

Re: TF2 - Player class id / name?

Posted: Sun Apr 01, 2018 12:55 am
by satoon101
Once build #647 is ready, you should be able to use the following:

Syntax: Select all

# To set the player's class
<Player>.player_class = classid

# If persistence needed, as in the SM link
<Player>.desired_player_class = classid

# To get the player's class
player_class = <Player>.player_class


Here is the commit I made to add these attributes to the Player class:
https://github.com/Source-Python-Dev-Te ... 868aa49009

If you wish to add more, please feel free to look at this post I made a while back:
viewtopic.php?f=8&t=972

Re: TF2 - Player class id / name?

Posted: Sun Apr 01, 2018 4:47 am
by Zeus
great! thanks for doing that :)

I'll be sure to open a PR if i have others :)