TF2 - Player class id / name?

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Zeus
Member
Posts: 52
Joined: Sat Mar 24, 2018 5:25 pm
Location: Chicago
Contact:

TF2 - Player class id / name?

Postby Zeus » Sat Mar 31, 2018 5:27 pm

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?
Last edited by Ayuto on Sun Apr 01, 2018 2:12 pm, edited 1 time in total.
Reason: code -> python
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: TF2 - Player class id / name?

Postby satoon101 » Sun Apr 01, 2018 12:55 am

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
Image
User avatar
Zeus
Member
Posts: 52
Joined: Sat Mar 24, 2018 5:25 pm
Location: Chicago
Contact:

Re: TF2 - Player class id / name?

Postby Zeus » Sun Apr 01, 2018 4:47 am

great! thanks for doing that :)

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

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 13 guests