Source-Python-Dev-Team / Source.Python

This plugin aims to use boost::python and create an easily accessible wrapper around the Source Engine API for scripter use.
http://forums.sourcepython.com
GNU General Public License v3.0
164 stars 32 forks source link

Property "desired_player_class" doesn't work for "dod" #475

Closed dronelektron closed 1 year ago

dronelektron commented 1 year ago

I want to get "desired_player_class" using the following code:

from commands import CommandReturn
from commands.client import ClientCommand
from players.entity import Player

@ClientCommand('sp_desired_class')
def print_desired_class(command, index):
    player = Player(index)
    desired_class = player.desired_player_class

    print(f'[DEBUG] Desired player class - {desired_class}')

    return CommandReturn.BLOCK

But I get the error:

[Source.Python]
[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\commands\auth.py", line 44, in __call__
    return self.callback(*args)
  File "..\addons\source-python\plugins\dod_desired_class\dod_desired_class.py", line 9, in print_desired_class
    desired_class = player.desired_player_class

ValueError: Unable to find property 'm_Shared.m_iDesiredPlayerClass'.

I guess it's because of this:

https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/src/core/modules/players/players_entity.cpp#L746

Then I've tried to add this property to this file:

https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/data/source-python/entities/orangebox/dod/CDODPlayer.ini

Like this:

[property]

    ragdoll = m_hRagdoll
    # DOD:S has another path to "desired player class"
    desired_player_class = m_Shared.dodsharedlocaldata.m_iDesiredPlayerClass

    [[eye_angle]]
        name = m_angEyeAngles[0]
        type = QAngle

But this property doesn't work either, looks like SP won't override it

CookStar commented 1 year ago

I have added a fix (#477) for this problem, but if you rewrite the ini to something like dod_desired_player_class, then you should be able to use the desired_player_class(i.e. Player.dod_desired_player_class) without requiring the fix.

dronelektron commented 1 year ago

Yea, I've tested this already (using different name in the .ini file) but desired_player_class is more preferable.

Also, this file also contains player_class and desired_player_class, but do those properties read from .ini or are they also taken from C++ code? Maybe they are useless too? Just wondering.

https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/data/source-python/entities/orangebox/tf/CTFPlayer.ini

CookStar commented 1 year ago

The ini is a remnant before C++ native was implemented.