From ac67b5373731b9a7acca11e92d58f0d065058fb9 Mon Sep 17 00:00:00 2001 From: Stephen Toon Date: Wed, 5 Oct 2016 23:47:31 -0400 Subject: [PATCH 01/14] Added weapons to csgo weapon data that do not have their own entity classnames. Added item_definition_index to all weapons in csgo weapon data to help differentiate between weapons. Changed maxammo for all non-grenade weapons in csgo weapon data to hard code the value instead of using the ConVars. The ConVars seem to no longer work, as changing their values does not affect the reserver ammo for the weapons. --- .../data/source-python/weapons/csgo.ini | 188 +++++++++++++++--- 1 file changed, 159 insertions(+), 29 deletions(-) diff --git a/addons/source-python/data/source-python/weapons/csgo.ini b/addons/source-python/data/source-python/weapons/csgo.ini index 368fd0b0d..f31069c14 100644 --- a/addons/source-python/data/source-python/weapons/csgo.ini +++ b/addons/source-python/data/source-python/weapons/csgo.ini @@ -30,241 +30,306 @@ # Snipers [[awp]] slot = 1 - maxammo = "ammo_338mag_max" + maxammo = 30 ammoprop = 6 clip = 10 cost = 4750 + item_definition_index = 9 tags = "all,primary,rifle,sniper" [[g3sg1]] slot = 1 - maxammo = "ammo_762mm_max" + maxammo = 90 ammoprop = 2 clip = 20 cost = 5000 + item_definition_index = 11 tags = "all,primary,rifle,sniper" [[scar20]] slot = 1 - maxammo = "ammo_762mm_max" + maxammo = 90 ammoprop = 2 clip = 20 cost = 5000 + item_definition_index = 38 tags = "all,primary,rifle,sniper" [[ssg08]] slot = 1 - maxammo = "ammo_762mm_max" + maxammo = 90 ammoprop = 2 clip = 10 cost = 1700 + item_definition_index = 40 tags = "all,primary,rifle" # Assault Rifles [[ak47]] slot = 1 - maxammo = "ammo_762mm_max" + maxammo = 90 ammoprop = 2 clip = 30 cost = 2700 + item_definition_index = 7 tags = "all,primary,rifle" [[aug]] slot = 1 - maxammo = "ammo_762mm_max" + maxammo = 90 ammoprop = 2 clip = 30 cost = 3300 + item_definition_index = 8 tags = "all,primary,rifle" [[famas]] slot = 1 - maxammo = "ammo_556mm_max" + maxammo = 90 ammoprop = 3 clip = 25 cost = 2250 + item_definition_index = 10 tags = "all,primary,rifle" [[galilar]] slot = 1 - maxammo = "ammo_556mm_max" + maxammo = 90 ammoprop = 3 clip = 35 cost = 2000 + item_definition_index = 13 tags = "all,primary,rifle" [[m4a1]] slot = 1 - maxammo = "ammo_556mm_max" + maxammo = 90 ammoprop = 3 clip = 30 cost = 3100 + item_definition_index = 16 tags = "all,primary,rifle" + [[m4a1_silencer]] + slot = 1 + maxammo = 40 + ammoprop = 4 + clip = 20 + cost = 3100 + item_definition_index = 60 + tags = "all,secondary,rifle" + [[sg556]] slot = 1 - maxammo = "ammo_556mm_max" + maxammo = 90 ammoprop = 3 clip = 30 cost = 3000 + item_definition_index = 39 tags = "all,primary,rifle" # SMGs [[bizon]] slot = 1 - maxammo = "ammo_9mm_max" + maxammo = 120 ammoprop = 7 clip = 64 cost = 1400 + item_definition_index = 26 tags = "all,primary,smg" [[mac10]] slot = 1 - maxammo = "ammo_45acp_max" + maxammo = 100 ammoprop = 9 clip = 30 cost = 1050 + item_definition_index = 17 tags = "all,primary,smg" [[mp7]] slot = 1 - maxammo = "ammo_9mm_max" + maxammo = 120 ammoprop = 7 clip = 30 cost = 1700 + item_definition_index = 33 tags = "all,primary,smg" [[mp9]] slot = 1 - maxammo = "ammo_9mm_max" + maxammo = 120 ammoprop = 7 clip = 30 cost = 1250 + item_definition_index = 34 tags = "all,primary,smg" [[p90]] slot = 1 - maxammo = "ammo_57mm_max" + maxammo = 100 ammoprop = 13 clip = 50 cost = 2350 + item_definition_index = 19 tags = "all,primary,smg" [[ump45]] slot = 1 - maxammo = "ammo_45acp_max" + maxammo = 100 ammoprop = 9 clip = 25 cost = 1200 + item_definition_index = 24 tags = "all,primary,smg" # Shotguns [[mag7]] slot = 1 - maxammo = "ammo_buckshot_max" + maxammo = 32 ammoprop = 8 clip = 5 cost = 1800 + item_definition_index = 27 tags = "all,primary,shotgun" [[nova]] slot = 1 - maxammo = "ammo_buckshot_max" + maxammo = 32 ammoprop = 8 clip = 8 cost = 1200 + item_definition_index = 35 tags = "all,primary,shotgun" [[sawedoff]] slot = 1 - maxammo = "ammo_buckshot_max" + maxammo = 32 ammoprop = 8 clip = 7 cost = 1200 + item_definition_index = 29 tags = "all,primary,shotgun" [[xm1014]] slot = 1 - maxammo = "ammo_buckshot_max" + maxammo = 32 ammoprop = 8 clip = 7 cost = 2000 + item_definition_index = 25 tags = "all,primary,shotgun" # Heavy Machine Gun [[m249]] slot = 1 - maxammo = "ammo_556mm_box_max" + maxammo = 200 ammoprop = 5 clip = 100 cost = 5200 + item_definition_index = 14 tags = "all,primary,machinegun" [[negev]] slot = 1 - maxammo = "ammo_556mm_box_max" + maxammo = 200 ammoprop = 5 clip = 150 cost = 5700 + item_definition_index = 28 tags = "all,primary,machinegun" # ========================================================================= # SECONDARY WEAPONS # ========================================================================= + [[cz75a]] + slot = 2 + maxammo = 12 + ammoprop = 12 + clip = 12 + cost = 500 + item_definition_index = 63 + tags = "all,secondary,pistol" + [[deagle]] slot = 2 - maxammo = "ammo_50AE_max" + maxammo = 35 ammoprop = 1 clip = 7 cost = 700 + item_definition_index = 1 tags = "all,secondary,pistol" [[elite]] slot = 2 - maxammo = "ammo_9mm_max" + maxammo = 120 ammoprop = 7 clip = 30 cost = 500 + item_definition_index = 2 tags = "all,secondary,pistol" [[fiveseven]] slot = 2 - maxammo = "ammo_57mm_max" + maxammo = 100 ammoprop = 13 clip = 20 cost = 500 + item_definition_index = 3 tags = "all,secondary,pistol" [[glock]] slot = 2 - maxammo = "ammo_9mm_max" + maxammo = 120 ammoprop = 7 clip = 20 cost = 200 + item_definition_index = 4 tags = "all,secondary,pistol" [[hkp2000]] slot = 2 - maxammo = "ammo_357sig_small_max" + maxammo = 24 ammoprop = 10 clip = 12 cost = 200 + item_definition_index = 32 tags = "all,secondary,pistol" [[p250]] slot = 2 - maxammo = "ammo_357sig_p250_max" + maxammo = 26 ammoprop = 20 clip = 13 cost = 300 + item_definition_index = 36 + tags = "all,secondary,pistol" + + [[revolver]] + slot = 2 + maxammo = 8 + ammoprop = 1 + clip = 8 + cost = 850 + item_definition_index = 64 tags = "all,secondary,pistol" [[tec9]] slot = 2 - maxammo = "ammo_9mm_max" + maxammo = 120 ammoprop = 7 clip = 32 cost = 500 + item_definition_index = 30 + tags = "all,secondary,pistol" + + [[usp_silencer]] + slot = 2 + maxammo = 24 + ammoprop = 11 + clip = 12 + cost = 200 + item_definition_index = 61 tags = "all,secondary,pistol" # ========================================================================= @@ -272,10 +337,67 @@ # ========================================================================= [[knife]] slot = 3 + item_definition_index = 42 + tags = "all,knife,melee" + + [[knife_boyonet]] + slot = 3 + item_definition_index = 500 + tags = "all,knife,melee" + + [[knife_butterfly]] + slot = 3 + item_definition_index = 515 + tags = "all,knife,melee" + + [[knife_falchion]] + slot = 3 + item_definition_index = 512 + tags = "all,knife,melee" + + [[knife_flip]] + slot = 3 + item_definition_index = 505 + tags = "all,knife,melee" + + [[knife_gut]] + slot = 3 + item_definition_index = 506 + tags = "all,knife,melee" + + [[knife_karambit]] + slot = 3 + item_definition_index = 507 + tags = "all,knife,melee" + + [[knife_m9_bayonet]] + slot = 3 + item_definition_index = 508 + tags = "all,knife,melee" + + [[knife_push]] + slot = 3 + item_definition_index = 516 + tags = "all,knife,melee" + + [[knife_survival_bowie]] + slot = 3 + item_definition_index = 514 + tags = "all,knife,melee" + + [[knife_t]] + slot = 3 + item_definition_index = 59 + tags = "all,knife,melee" + + [[knife_tactical]] + slot = 3 + item_definition_index = 509 tags = "all,knife,melee" [[knifegg]] slot = 3 + item_definition_index = 0 tags = "all,knife,melee" [[taser]] @@ -284,6 +406,7 @@ ammoprop = 19 clip = 1 cost = 400 + item_definition_index = 31 tags = "all,melee" # ========================================================================= @@ -294,6 +417,7 @@ maxammo = "ammo_grenade_limit_default" ammoprop = 18 cost = 50 + item_definition_index = 47 tags = "all,grenade" [[flashbang]] @@ -301,6 +425,7 @@ maxammo = "ammo_grenade_limit_flashbang" ammoprop = 15 cost = 200 + item_definition_index = 43 tags = "all,grenade" [[hegrenade]] @@ -308,6 +433,7 @@ maxammo = "ammo_grenade_limit_default" ammoprop = 14 cost = 300 + item_definition_index = 44 tags = "all,grenade,explosive" [[incgrenade]] @@ -315,6 +441,7 @@ maxammo = "ammo_grenade_limit_default" ammoprop = 17 cost = 600 + item_definition_index = 48 tags = "all,grenade,incendiary" [[molotov]] @@ -322,6 +449,7 @@ maxammo = "ammo_grenade_limit_default" ammoprop = 17 cost = 400 + item_definition_index = 46 tags = "all,grenade,incendiary" [[smokegrenade]] @@ -329,6 +457,7 @@ maxammo = "ammo_grenade_limit_default" ammoprop = 16 cost = 300 + item_definition_index = 45 tags = "all,grenade" # ========================================================================= @@ -336,4 +465,5 @@ # ========================================================================= [[c4]] slot = 5 + item_definition_index = 49 tags = "all,objective" From a4d74a92d0cd27b366eb1650ff62875cb694d009 Mon Sep 17 00:00:00 2001 From: Stephen Toon Date: Fri, 7 Oct 2016 09:09:09 -0400 Subject: [PATCH 02/14] Issue #153. Added the ini ConfigObj to the weapon_manager instance. --- .../packages/source-python/weapons/manager.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/addons/source-python/packages/source-python/weapons/manager.py b/addons/source-python/packages/source-python/weapons/manager.py index b96749480..3eff68e6a 100644 --- a/addons/source-python/packages/source-python/weapons/manager.py +++ b/addons/source-python/packages/source-python/weapons/manager.py @@ -46,10 +46,10 @@ def __init__(self): super().__init__() # Get the ConfigObj instance of the file - ini = ConfigObj(_gamepath, unrepr=True) + self.ini = ConfigObj(_gamepath, unrepr=True) # Get the "properties" - properties = ini['properties'] + properties = self.ini['properties'] # Get the game's weapon prefix self._prefix = properties['prefix'] @@ -61,22 +61,24 @@ def __init__(self): self._myweapons = properties['myweapons'] # Store any special names - self._special_names = ini.get('special names', {}) + self._special_names = self.ini.get('special names', {}) # Store projectile names - self._projectiles = ini.get('projectiles', {}) + self._projectiles = self.ini.get('projectiles', {}) # Store tags as a set self._tags = set() # Loop through all weapons - for basename in ini['weapons']: + for basename in self.ini['weapons']: # Get the weapon's full name name = self._format_name(basename) # Add the weapon to the dictionary - self[name] = WeaponClass(name, basename, ini['weapons'][basename]) + self[name] = WeaponClass( + name, basename, self.ini['weapons'][basename] + ) # Add the weapon's tags to the set of tags self._tags.update(self[name].tags) From 62bce07c72eb4e3b108ed4247f4755048e80d2fc Mon Sep 17 00:00:00 2001 From: Stephen Toon Date: Fri, 7 Oct 2016 09:10:41 -0400 Subject: [PATCH 03/14] Issue #153. Added Weapon.get_weapon_name to the base Weapon class and CS:GO specific. --- .../packages/source-python/weapons/_base.py | 4 ++++ .../weapons/engines/csgo/__init__.py | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/addons/source-python/packages/source-python/weapons/_base.py b/addons/source-python/packages/source-python/weapons/_base.py index 1b08dce6a..a2d9f5a76 100644 --- a/addons/source-python/packages/source-python/weapons/_base.py +++ b/addons/source-python/packages/source-python/weapons/_base.py @@ -151,3 +151,7 @@ def set_secondary_fire_ammo(self, value): secondary_fire_ammo = property( get_secondary_fire_ammo, set_secondary_fire_ammo, doc="""Property to get/set the weapon's secondary fire ammo.""") + + def get_weapon_name(self): + """Return the full class name of the weapon.""" + return self.classname diff --git a/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py b/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py index 0c89df66c..66fb6e6f3 100644 --- a/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py +++ b/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py @@ -10,6 +10,15 @@ from weapons.manager import weapon_manager +# ============================================================================= +# >> GLOBAL VARIABLES +# ============================================================================= +_item_definition_indexes = { + values['item_definition_index']: weapon + for weapon, values in weapon_manager.ini['weapons'].items() +} + + # ============================================================================= # >> CLASSES # ============================================================================= @@ -29,7 +38,6 @@ def get_ammo(self): ) ) - def set_ammo(self, value): """Set the player's ammo property for the weapon.""" # Is the weapon not a grenade? @@ -46,8 +54,14 @@ def set_ammo(self, value): value, ) - # Set the "ammo" property methods ammo = property( get_ammo, set_ammo, doc="""Property to get/set the weapon's ammo.""") + + def get_weapon_name(self): + """Return the full class name of the weapon.""" + return _item_definition_indexes.get( + self.item_definition_index, + self.classname, + ) From 4ada7d757c59b153a461a31db09b9b4296e0c5fe Mon Sep 17 00:00:00 2001 From: Stephen Toon Date: Fri, 7 Oct 2016 09:11:25 -0400 Subject: [PATCH 04/14] Issue #153. Added CEconEntity data for CS:GO. --- .../data/source-python/entities/csgo/CEconEntity.ini | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 addons/source-python/data/source-python/entities/csgo/CEconEntity.ini diff --git a/addons/source-python/data/source-python/entities/csgo/CEconEntity.ini b/addons/source-python/data/source-python/entities/csgo/CEconEntity.ini new file mode 100644 index 000000000..5d6de7f2b --- /dev/null +++ b/addons/source-python/data/source-python/entities/csgo/CEconEntity.ini @@ -0,0 +1,3 @@ +[property] + + item_definition_index = m_AttributeManager.m_Item.m_iItemDefinitionIndex From 1f41f83ca7020404cc6e39fdac6152f8f5696cc0 Mon Sep 17 00:00:00 2001 From: Stephen Toon Date: Fri, 7 Oct 2016 09:17:32 -0400 Subject: [PATCH 05/14] Issue #153. Fixed issue with weapon_knifegg. --- addons/source-python/data/source-python/weapons/csgo.ini | 1 - .../packages/source-python/weapons/engines/csgo/__init__.py | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/source-python/data/source-python/weapons/csgo.ini b/addons/source-python/data/source-python/weapons/csgo.ini index f31069c14..7a37d4778 100644 --- a/addons/source-python/data/source-python/weapons/csgo.ini +++ b/addons/source-python/data/source-python/weapons/csgo.ini @@ -397,7 +397,6 @@ [[knifegg]] slot = 3 - item_definition_index = 0 tags = "all,knife,melee" [[taser]] diff --git a/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py b/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py index 66fb6e6f3..9ee2f271c 100644 --- a/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py +++ b/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py @@ -14,8 +14,9 @@ # >> GLOBAL VARIABLES # ============================================================================= _item_definition_indexes = { - values['item_definition_index']: weapon + values.get('item_definition_index'): weapon for weapon, values in weapon_manager.ini['weapons'].items() + if values.get('item_definition_index') } From b7a0b649c0a2f20ef2d1994eba36e194721aa97d Mon Sep 17 00:00:00 2001 From: Stephen Toon Date: Thu, 20 Oct 2016 08:36:11 -0400 Subject: [PATCH 06/14] Added parent_class to CS:GO weapons that are not members of dumpentityfactories. Fixed name of one CS:GO weapon. --- .../data/source-python/weapons/csgo.ini | 17 ++++++++++++++++- .../entities/{entity.py => _base.py} | 0 2 files changed, 16 insertions(+), 1 deletion(-) rename addons/source-python/packages/source-python/entities/{entity.py => _base.py} (100%) diff --git a/addons/source-python/data/source-python/weapons/csgo.ini b/addons/source-python/data/source-python/weapons/csgo.ini index 7a37d4778..e0dc5fa19 100644 --- a/addons/source-python/data/source-python/weapons/csgo.ini +++ b/addons/source-python/data/source-python/weapons/csgo.ini @@ -117,6 +117,7 @@ clip = 20 cost = 3100 item_definition_index = 60 + parent_class = "weapon_m4a1" tags = "all,secondary,rifle" [[sg556]] @@ -249,6 +250,7 @@ clip = 12 cost = 500 item_definition_index = 63 + parent_class = "weapon_p250" tags = "all,secondary,pistol" [[deagle]] @@ -312,6 +314,7 @@ clip = 8 cost = 850 item_definition_index = 64 + parent_class = "weapon_deagle" tags = "all,secondary,pistol" [[tec9]] @@ -330,6 +333,7 @@ clip = 12 cost = 200 item_definition_index = 61 + parent_class = "weapon_hkp2000" tags = "all,secondary,pistol" # ========================================================================= @@ -340,59 +344,70 @@ item_definition_index = 42 tags = "all,knife,melee" - [[knife_boyonet]] + [[knife_bayonet]] slot = 3 item_definition_index = 500 + parent_class = "weapon_knife" tags = "all,knife,melee" [[knife_butterfly]] slot = 3 item_definition_index = 515 + parent_class = "weapon_knife" tags = "all,knife,melee" [[knife_falchion]] slot = 3 item_definition_index = 512 + parent_class = "weapon_knife" tags = "all,knife,melee" [[knife_flip]] slot = 3 item_definition_index = 505 + parent_class = "weapon_knife" tags = "all,knife,melee" [[knife_gut]] slot = 3 item_definition_index = 506 + parent_class = "weapon_knife" tags = "all,knife,melee" [[knife_karambit]] slot = 3 item_definition_index = 507 + parent_class = "weapon_knife" tags = "all,knife,melee" [[knife_m9_bayonet]] slot = 3 item_definition_index = 508 + parent_class = "weapon_knife" tags = "all,knife,melee" [[knife_push]] slot = 3 item_definition_index = 516 + parent_class = "weapon_knife" tags = "all,knife,melee" [[knife_survival_bowie]] slot = 3 item_definition_index = 514 + parent_class = "weapon_knife" tags = "all,knife,melee" [[knife_t]] slot = 3 item_definition_index = 59 + parent_class = "weapon_knife" tags = "all,knife,melee" [[knife_tactical]] slot = 3 item_definition_index = 509 + parent_class = "weapon_knife" tags = "all,knife,melee" [[knifegg]] diff --git a/addons/source-python/packages/source-python/entities/entity.py b/addons/source-python/packages/source-python/entities/_base.py similarity index 100% rename from addons/source-python/packages/source-python/entities/entity.py rename to addons/source-python/packages/source-python/entities/_base.py From 65636533f554ce782bc0fb86134b6336663c11d3 Mon Sep 17 00:00:00 2001 From: Stephen Toon Date: Thu, 20 Oct 2016 08:37:59 -0400 Subject: [PATCH 07/14] Changed entities.entity to be engine/game specific. Implemented changes to Entity.find and Entity.create for csgo engine. --- .../packages/source-python/entities/_base.py | 22 +------ .../entities/engines/__init__.py | 3 + .../entities/engines/csgo/__init__.py | 57 ++++++++++++++++++ .../packages/source-python/entities/entity.py | 59 +++++++++++++++++++ 4 files changed, 121 insertions(+), 20 deletions(-) create mode 100644 addons/source-python/packages/source-python/entities/engines/__init__.py create mode 100644 addons/source-python/packages/source-python/entities/engines/csgo/__init__.py create mode 100644 addons/source-python/packages/source-python/entities/entity.py diff --git a/addons/source-python/packages/source-python/entities/_base.py b/addons/source-python/packages/source-python/entities/_base.py index eb44dab29..a3bc40b3f 100644 --- a/addons/source-python/packages/source-python/entities/_base.py +++ b/addons/source-python/packages/source-python/entities/_base.py @@ -1,4 +1,4 @@ -# ../entities/entity.py +# ../entities/_base.py """Provides a base class to interact with a specific entity.""" @@ -20,19 +20,18 @@ from engines.trace import Ray from engines.trace import TraceFilterSimple # Entities +from _entities._entity import BaseEntity from entities import BaseEntityGenerator from entities import TakeDamageInfo from entities.classes import server_classes from entities.constants import DamageTypes from entities.constants import RenderMode -from entities.helpers import edict_from_index from entities.helpers import index_from_inthandle from entities.helpers import index_from_pointer from entities.helpers import wrap_entity_mem_func # Filters from filters.weapons import WeaponClassIter # Memory -from memory import get_object_pointer from memory import make_object # Players from players.constants import HitGroup @@ -41,23 +40,6 @@ from studio.constants import INVALID_ATTACHMENT_INDEX -# ============================================================================= -# >> FORWARD IMPORTS -# ============================================================================= -# Source.Python Imports -# Entities -from _entities._entity import BaseEntity - - -# ============================================================================= -# >> ALL DECLARATION -# ============================================================================= -# Add all the global variables to __all__ -__all__ = ('BaseEntity', - 'Entity', - ) - - # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= diff --git a/addons/source-python/packages/source-python/entities/engines/__init__.py b/addons/source-python/packages/source-python/entities/engines/__init__.py new file mode 100644 index 000000000..51c945f50 --- /dev/null +++ b/addons/source-python/packages/source-python/entities/engines/__init__.py @@ -0,0 +1,3 @@ +# ../entities/engines/__init__.py + +"""Provides engine specific Entity based functionality.""" diff --git a/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py b/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py new file mode 100644 index 000000000..1d832f088 --- /dev/null +++ b/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py @@ -0,0 +1,57 @@ +# ../engines/engines/csgo/__init__.py + +"""Provides CS:GO specific Entity based functionality.""" + +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Source.Python Imports +from entities._base import Entity as _Entity +from weapons.manager import weapon_manager + + +# ============================================================================= +# >> GLOBAL VARIABLES +# ============================================================================= +_weapon_names_for_definition = { + weapon_manager[weapon].name: values.get('item_definition_index') + for weapon, values in weapon_manager.ini['weapons'].items() + if values.get('item_definition_index') +} +_weapon_parents = { + weapon_manager[weapon].name: values.get('parent_class') + for weapon, values in weapon_manager.ini['weapons'].items() + if values.get('parent_class') +} +_parent_weapons = set(_weapon_parents.values()) + + +# ============================================================================= +# >> CLASSES +# ============================================================================= +class Entity(_Entity): + """Class used to interact directly with entities.""" + + @classmethod + def create(cls, classname): + index = _weapon_names_for_definition.get(classname) + if classname in _weapon_parents and index is not None: + entity = super().create(_weapon_parents[classname]) + entity.item_definition_index = index + else: + entity = super().create(classname) + return entity + + @classmethod + def find(cls, classname): + from filters.entities import EntityIter + index = _weapon_names_for_definition.get(classname) + if classname in _weapon_parents and index is not None: + for entity in EntityIter(_weapon_parents[classname]): + if entity.item_definition_index == index: + return entity + elif classname in _parent_weapons: + for entity in EntityIter(classname): + if entity.item_definition_index in (index, 0): + return entity + return super().find(classname) diff --git a/addons/source-python/packages/source-python/entities/entity.py b/addons/source-python/packages/source-python/entities/entity.py new file mode 100644 index 000000000..a1d2413fc --- /dev/null +++ b/addons/source-python/packages/source-python/entities/entity.py @@ -0,0 +1,59 @@ +# ../entities/entity.py + +"""Provides a class used to interact with a specific entity.""" + +# ============================================================================= +# >> IMPORTS +# ============================================================================= +from importlib import import_module +from core import GAME_NAME +from core import SOURCE_ENGINE +from paths import SP_PACKAGES_PATH + + +# ============================================================================= +# >> FORWARD IMPORTS +# ============================================================================= +# Source.Python Imports +# Entities +from _entities._entity import BaseEntity + + +# ============================================================================= +# >> ALL DECLARATION +# ============================================================================= +__all__ = ('BaseEntity' + 'Entity', + ) + + +# ============================================================================= +# >> GLOBAL VARIABLES +# ============================================================================= +if SP_PACKAGES_PATH.joinpath( + 'entities', 'engines', SOURCE_ENGINE, GAME_NAME + '.py' +).isfile(): + + # Import the game-specific 'Entity' class + Entity = import_module( + 'entities.engines.{engine}.{game}'.format( + engine=SOURCE_ENGINE, + game=GAME_NAME, + ) + ).Entity + +elif SP_PACKAGES_PATH.joinpath( + 'entities', 'engines', SOURCE_ENGINE, '__init__.py' +).isfile(): + + # Import the engine-specific 'Entity' class + Entity = import_module( + 'entities.engines.{engine}'.format( + engine=SOURCE_ENGINE, + ) + ).Entity + +else: + + # Import the base 'Entity' class + from entities._base import Entity From 3204c578af2bc123e7e1f7798b7f0bbad49365f3 Mon Sep 17 00:00:00 2001 From: Stephen Toon Date: Thu, 20 Oct 2016 08:39:22 -0400 Subject: [PATCH 08/14] Fixed setting _item_definition_index values to the basename instead of the classname of the weapons. --- .../packages/source-python/weapons/engines/csgo/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py b/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py index 9ee2f271c..6d9f3efb2 100644 --- a/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py +++ b/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py @@ -14,7 +14,7 @@ # >> GLOBAL VARIABLES # ============================================================================= _item_definition_indexes = { - values.get('item_definition_index'): weapon + values.get('item_definition_index'): weapon_manager[weapon].name for weapon, values in weapon_manager.ini['weapons'].items() if values.get('item_definition_index') } From 397a65d6595330b6dbed96d0ad521f52b4f13337 Mon Sep 17 00:00:00 2001 From: Stephen Toon Date: Sun, 4 Dec 2016 12:30:19 -0500 Subject: [PATCH 09/14] Added 'earned' tags for knives that must be earned/purchased. These weapons should never be given to players that have not earned/purchased them as any server doing so could be banned. --- .../data/source-python/weapons/csgo.ini | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/addons/source-python/data/source-python/weapons/csgo.ini b/addons/source-python/data/source-python/weapons/csgo.ini index e0dc5fa19..7c7369623 100644 --- a/addons/source-python/data/source-python/weapons/csgo.ini +++ b/addons/source-python/data/source-python/weapons/csgo.ini @@ -348,55 +348,55 @@ slot = 3 item_definition_index = 500 parent_class = "weapon_knife" - tags = "all,knife,melee" + tags = "all,knife,melee,earned" [[knife_butterfly]] slot = 3 item_definition_index = 515 parent_class = "weapon_knife" - tags = "all,knife,melee" + tags = "all,knife,melee,earned" [[knife_falchion]] slot = 3 item_definition_index = 512 parent_class = "weapon_knife" - tags = "all,knife,melee" + tags = "all,knife,melee,earned" [[knife_flip]] slot = 3 item_definition_index = 505 parent_class = "weapon_knife" - tags = "all,knife,melee" + tags = "all,knife,melee,earned" [[knife_gut]] slot = 3 item_definition_index = 506 parent_class = "weapon_knife" - tags = "all,knife,melee" + tags = "all,knife,melee,earned" [[knife_karambit]] slot = 3 item_definition_index = 507 parent_class = "weapon_knife" - tags = "all,knife,melee" + tags = "all,knife,melee,earned" [[knife_m9_bayonet]] slot = 3 item_definition_index = 508 parent_class = "weapon_knife" - tags = "all,knife,melee" + tags = "all,knife,melee,earned" [[knife_push]] slot = 3 item_definition_index = 516 parent_class = "weapon_knife" - tags = "all,knife,melee" + tags = "all,knife,melee,earned" [[knife_survival_bowie]] slot = 3 item_definition_index = 514 parent_class = "weapon_knife" - tags = "all,knife,melee" + tags = "all,knife,melee,earned" [[knife_t]] slot = 3 @@ -408,7 +408,7 @@ slot = 3 item_definition_index = 509 parent_class = "weapon_knife" - tags = "all,knife,melee" + tags = "all,knife,melee,earned" [[knifegg]] slot = 3 From 586738cc2def78d1f4e2f60d9632b8c37d60230e Mon Sep 17 00:00:00 2001 From: Stephen Toon Date: Tue, 6 Dec 2016 08:41:45 -0500 Subject: [PATCH 10/14] Fixed slowness in Entity.find for CS:GO. --- .../entities/engines/csgo/__init__.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py b/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py index 1d832f088..44eaf43a4 100644 --- a/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py +++ b/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py @@ -44,14 +44,22 @@ def create(cls, classname): @classmethod def find(cls, classname): - from filters.entities import EntityIter + from filters.entities import BaseEntityIter index = _weapon_names_for_definition.get(classname) if classname in _weapon_parents and index is not None: - for entity in EntityIter(_weapon_parents[classname]): - if entity.item_definition_index == index: - return entity + for entity in BaseEntityIter(_weapon_parents[classname]): + if not entity.is_networked(): + continue + if entity.get_network_property_int( + 'm_AttributeManager.m_Item.m_iItemDefinitionIndex' + ) == index: + return cls(entity.index) elif classname in _parent_weapons: - for entity in EntityIter(classname): - if entity.item_definition_index in (index, 0): - return entity + for entity in BaseEntityIter(classname): + if not entity.is_networked(): + continue + if entity.get_network_property_int( + 'm_AttributeManager.m_Item.m_iItemDefinitionIndex' + ) in (index, 0): + return cls(entity.index) return super().find(classname) From 70454254349131792eac0360938435878b50d690 Mon Sep 17 00:00:00 2001 From: Stephen Toon Date: Tue, 6 Dec 2016 08:46:20 -0500 Subject: [PATCH 11/14] Changed Weapon.get_weapon_name() method to Weapon.weapon_name property. --- addons/source-python/packages/source-python/weapons/_base.py | 3 ++- .../packages/source-python/weapons/engines/csgo/__init__.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/source-python/packages/source-python/weapons/_base.py b/addons/source-python/packages/source-python/weapons/_base.py index a2d9f5a76..4af903f1b 100644 --- a/addons/source-python/packages/source-python/weapons/_base.py +++ b/addons/source-python/packages/source-python/weapons/_base.py @@ -152,6 +152,7 @@ def set_secondary_fire_ammo(self, value): get_secondary_fire_ammo, set_secondary_fire_ammo, doc="""Property to get/set the weapon's secondary fire ammo.""") - def get_weapon_name(self): + @property + def weapon_name(self): """Return the full class name of the weapon.""" return self.classname diff --git a/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py b/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py index 6d9f3efb2..6b1b2898e 100644 --- a/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py +++ b/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py @@ -60,7 +60,8 @@ def set_ammo(self, value): get_ammo, set_ammo, doc="""Property to get/set the weapon's ammo.""") - def get_weapon_name(self): + @property + def weapon_name(self): """Return the full class name of the weapon.""" return _item_definition_indexes.get( self.item_definition_index, From 75c5c2d56860f3b3211a537222183a762687729c Mon Sep 17 00:00:00 2001 From: Stephen Toon Date: Tue, 6 Dec 2016 22:59:27 -0500 Subject: [PATCH 12/14] Improved performance of Entity.find for CS:GO. --- .../source-python/entities/engines/csgo/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py b/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py index 44eaf43a4..d33d7b06f 100644 --- a/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py +++ b/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py @@ -5,7 +5,8 @@ # ============================================================================= # >> IMPORTS # ============================================================================= -# Source.Python Imports +# Source.Python +from entities import BaseEntityGenerator from entities._base import Entity as _Entity from weapons.manager import weapon_manager @@ -44,10 +45,12 @@ def create(cls, classname): @classmethod def find(cls, classname): - from filters.entities import BaseEntityIter index = _weapon_names_for_definition.get(classname) if classname in _weapon_parents and index is not None: - for entity in BaseEntityIter(_weapon_parents[classname]): + parent_classname = _weapon_parents[classname] + for entity in BaseEntityGenerator(): + if entity.classname != parent_classname: + continue if not entity.is_networked(): continue if entity.get_network_property_int( @@ -55,7 +58,9 @@ def find(cls, classname): ) == index: return cls(entity.index) elif classname in _parent_weapons: - for entity in BaseEntityIter(classname): + for entity in BaseEntityGenerator(): + if entity.classname != classname: + continue if not entity.is_networked(): continue if entity.get_network_property_int( From b25a5d6e9a01f3fa2843abfcbcba44779acc923e Mon Sep 17 00:00:00 2001 From: Stephen Toon Date: Wed, 7 Dec 2016 19:44:34 -0500 Subject: [PATCH 13/14] More speed improvements for Entity.find for CS:GO. --- .../source-python/entities/engines/csgo/__init__.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py b/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py index d33d7b06f..2d0c2d4e5 100644 --- a/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py +++ b/addons/source-python/packages/source-python/entities/engines/csgo/__init__.py @@ -48,9 +48,7 @@ def find(cls, classname): index = _weapon_names_for_definition.get(classname) if classname in _weapon_parents and index is not None: parent_classname = _weapon_parents[classname] - for entity in BaseEntityGenerator(): - if entity.classname != parent_classname: - continue + for entity in BaseEntityGenerator(parent_classname, True): if not entity.is_networked(): continue if entity.get_network_property_int( @@ -58,9 +56,7 @@ def find(cls, classname): ) == index: return cls(entity.index) elif classname in _parent_weapons: - for entity in BaseEntityGenerator(): - if entity.classname != classname: - continue + for entity in BaseEntityGenerator(classname, True): if not entity.is_networked(): continue if entity.get_network_property_int( From c576a5e580e32eb9628447231afb5a0e62ebccb2 Mon Sep 17 00:00:00 2001 From: Ayuto22 Date: Sat, 10 Dec 2016 10:47:51 +0100 Subject: [PATCH 14/14] Added return type to documentation --- .../source-python/weapons/engines/csgo/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py b/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py index 6b1b2898e..0ef935ca8 100644 --- a/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py +++ b/addons/source-python/packages/source-python/weapons/engines/csgo/__init__.py @@ -26,7 +26,10 @@ class Weapon(_Weapon): """Allows easy usage of the weapon's attributes.""" def get_ammo(self): - """Return the amount of ammo the player has for the weapon.""" + """Return the amount of ammo the player has for the weapon. + + :rtype: int + """ # Is the weapon not a grenade? if 'grenade' not in weapon_manager[self.classname].tags: return self.primary_ammo_count @@ -62,7 +65,10 @@ def set_ammo(self, value): @property def weapon_name(self): - """Return the full class name of the weapon.""" + """Return the full class name of the weapon. + + :rtype: str + """ return _item_definition_indexes.get( self.item_definition_index, self.classname,