Page 1 of 1

Changes to the engine?

Posted: Sat Jun 18, 2016 5:12 pm
by iPlayer
Hey there,

I've noticed that some previously working code started throwing exceptions and I'm not sure if there were changes made to the engine (Counter-Strike: Source) or these changes are SP-related

For example,

Syntax: Select all

player.set_property_int('m_lifeState', 512)    # Part of the old respawning code

now raises the following exception
TypeError: Property 'm_lifeState' is of type uchar not int


Okay, it got replaced with

Syntax: Select all

player.life_state = LifeState.ALIVE

though I don't know what old '512' even meant, I couldn't find in LifeState enum.

Then,

Syntax: Select all

weapon.ammoprop

suprisingly fails with the following exception:
Image
I believe type_name contains something invalid and raises when getting concatenated to 'get_'.

Then,

Syntax: Select all

player.set_property_int('m_iTeamNum', 2)

fails similarly to the m_lifeState:
TypeError: Property 'm_iTeamNum' is of type char not int


Note that I can't use player.team because despite being defined in data files for CBaseEntity, for player entities it gets overridden by property(get_team, set_team):

Syntax: Select all

def get_team(self):
"""Return the player's team.

:rtype: int
"""
return self.playerinfo.team

def set_team(self, value):
"""Set the players team."""
self.playerinfo.team = value

team = property(get_team, set_team)

And playerinfo's team is a different thing. I need to be able to switch player without him dying and without class selection screen.

Any news? What had happened? These are 3 bits I've discovered, but the plugin doesn't work at all, so I guess fixing these will get me to new bugs.

Re: Changes to the engine?

Posted: Sat Jun 18, 2016 5:20 pm
by iPlayer
I feel being trolled

Syntax: Select all

player.set_property_char('m_iTeamNum', 2)
AttributeError: Attribute 'set_property_char' not found

Re: Changes to the engine?

Posted: Sat Jun 18, 2016 5:47 pm
by satoon101
We made some changes a couple/few months ago to fix issues with all SendProps of type int to actually get/set using their proper type (char, uchar, short, ushort, int, and bool).
https://github.com/Source-Python-Dev-Te ... es.py#L270

The 'char' methods of the Entity class were never added to the master branch, but they are on the player_weapons_update2 branch. That's an easy fix, though when someone has the chance to update it.

I am not sure about the ammoprop stuff, and am unable to test, currently.

Re: Changes to the engine?

Posted: Sat Jun 18, 2016 5:53 pm
by iPlayer
Few months ago?.. Weird, I had a feeling it was all stable in the end of May. Must be me again.

m_iTeamNum can be retrieved/set for all non-Player entities by using <Entity>.team

Yeah, I thought of maybe doing

Syntax: Select all

Entity.__setattr__(player, 'team', 2)


Edit: I get why it was all stable in the end of May - I believe I just hadn't updated my SP for a while.

Re: Changes to the engine?

Posted: Sat Jun 18, 2016 6:01 pm
by satoon101
I removed my edit after I reread your original post, as it was obvious you already knew that.

As for the ammoprop error, that 'might' be fixed in the player_weapons_update2 branch, but I cannot confirm that for at least another 2 weeks. I hope to be able to get back working on that branch at that point so that we can get it tested and merged fairly soon.

Re: Changes to the engine?

Posted: Sat Jun 18, 2016 6:07 pm
by iPlayer
Thanks. Good luck with that. :)

For now I will try to investigate the ammoprop error - maybe I was accessing entities that didn't exist.

PS. As for m_iTeamNumber, this works:

Syntax: Select all

Entity(player.index).team = 2


and this doesn't:

Syntax: Select all

Entity.__setattr__(player, 'team', 2)

The latter still treats player as a Player, not an Entity. Although it would make possible to avoid creating extra Entity instance every time.

Re: Changes to the engine?

Posted: Sat Jun 18, 2016 7:08 pm
by iPlayer
I think there might be confusion between:
1. 'ammoprop' in entities/CBaseCombatWeapon.ini
2. 'ammoprop' entries in weapons/cstrike.ini

Re: Changes to the engine?

Posted: Mon Jun 20, 2016 8:19 pm
by satoon101
Actually, they 'should' return the same values (typically). We provide the data in ../weapons/ for use when you don't actually have a weapon entity (WeaponClassIter use, for example). If you have a weapon, you should be using the ../entities/ one. Either way, you will want to join it with the other ammoprop from the properties section of the ../weapons/ data file:

Syntax: Select all

from weapons.manager import weapon_manager

...

weapon = Entity(index)

return self.get_property_int(
weapon_manager.ammoprop + '%03d' % weapon.ammoprop)


The above is NOT true for CS:GO, which does not use the normal reserver ammo convention. It instead uses a new property, m_iPrimaryReserveAmmoCount, to store the value. This is one issue that the player_weapons_update2 branch is trying to fix:
https://github.com/Source-Python-Dev-Te ... /issues/50