Page 1 of 1

Weapon_indexes error

Posted: Sat Jul 25, 2015 7:37 pm
by MrMalina
Hello.
If you use the following code, sometimes an error:

Code:

Syntax: Select all

def check_weapons(index):

player = PlayerEntity(index)

if not player.dead_flag:

rest = wcs_restricted[player.index]

if rest:

# try:
weapons = player.weapon_indexes()

# except:
# weapons = set()

print(tuple(weapons))

for weapon_index in weapons:

weapon = Entity(weapon_index)

if not weapon.classname in rest:

wcs.core.strings.wcs_tell(player.index, "restrict: weapon", weapon.classname[7:])

player.drop_weapon(weapon.pointer, weapon.pointer, weapon.pointer)


Error:
The attachment Скриншот 2015-07-25 22.29.26.jpg is no longer available

http://hostingkartinok.com/show-image.php?id=aac4646894d89d320e4c9a550d8fac97

Posted: Sat Jul 25, 2015 8:11 pm
by satoon101
This error has been reported elsewhere. I am having a very difficult time in replicating it. Do you or anyone know what circumstances cause this error to occur? Could you add some debugging messages to players.weapons.__init__'s weapon_indexes method to help narrow some things down, as well? At first glance, I do notice that we really don't need to get the Entity instance, just the Edict instance. I'll make that change today and see if that fixes it. However, if you are going to get the Entity (or WeaponEntity) instance of the weapon at a later time, you will still encounter the error. So, we still need to try to figure out what is causing it.

Posted: Sat Jul 25, 2015 8:53 pm
by MrMalina

Syntax: Select all

def weapon_indexes(
self, classname=None, is_filters=None, not_filters=None):
"""Iterate over all currently held weapons by thier index."""
# Is the weapon array supported for the current game?
if _weapon_prop_length is None:
return

print("_weapon_prop_length: ", _weapon_prop_length)

# Loop through the length of the weapon array
for offset in range(_weapon_prop_length):

print("- offset: ", offset)

# Get the player's current weapon at this offset
handle = self.get_property_int(
weapon_manager.myweapons + '%03i' % offset)

print("- handle: ", handle)

# Get the weapon's index
index = index_from_inthandle(handle, raise_exception=False)

print("- index: ", index)

# Is this a valid index?
if index == INVALID_ENTITY_INDEX:

print("INVALID_ENTITY_INDEX -> CONTINUE")

# Move onto the next offset
continue


# Get the weapon's edict
edict = Entity(index)

print("- edict: ", edict)

# Get the weapon's classname
weapon_class = edict.get_class_name()

# Was a classname given and the current
# weapon is not of that classname?
if classname is not None and weapon_class != classname:

# Do not yield this index
continue

# Import WeaponClassIter to use its functionality
from filters.weapons import WeaponClassIter

# Was a weapon type given and the
# current weapon is not of that type?
if not (is_filters is None and not_filters is None):
if weapon_class not in list(WeaponClassIter(
is_filters, not_filters, 'classname')):

# Do not yield this index
continue

# Yield the index
yield index


And I added a line in entities/entity.py: print(index, edict)

I've noticed a pattern, if I play for a counter-terrorists are no errors, if I play for terrorists, everything is fine, but as soon as I spawn with a bomb appears this error:

Click

Posted: Sat Jul 25, 2015 9:59 pm
by satoon101
Could you test using this:

Syntax: Select all

def weapon_indexes(
self, classname=None, is_filters=None, not_filters=None):
"""Iterate over all currently held weapons by thier index."""
# Is the weapon array supported for the current game?
if _weapon_prop_length is None:
return

# Loop through the length of the weapon array
for offset in range(_weapon_prop_length):

# Get the player's current weapon at this offset
handle = self.get_property_int(
weapon_manager.myweapons + '%03i' % offset)

# Get the weapon's index
index = index_from_inthandle(handle, raise_exception=False)

# Is this a valid index?
if index == INVALID_ENTITY_INDEX:

# Move onto the next offset
continue

try:
# Get the weapon's edict
edict = Entity(index)

except ValueError:

from players.helpers import edict_from_index
print(edict_from_index(index).get_class_name())

# Get the weapon's classname
weapon_class = edict.get_class_name()

# Was a classname given and the current
# weapon is not of that classname?
if classname is not None and weapon_class != classname:

# Do not yield this index
continue

# Import WeaponClassIter to use its functionality
from filters.weapons import WeaponClassIter

# Was a weapon type given and the
# current weapon is not of that type?
if not (is_filters is None and not_filters is None):
if weapon_class not in list(WeaponClassIter(
is_filters, not_filters, 'classname')):

# Do not yield this index
continue

# Yield the index
yield index


Test that for a while to see what all weapon names are shown. It might encounter an error during the except portion. So, let us know about that if it happens, as well.

I have tried to replicate this on both CS:S and CS:GO, and I cannot get that error to occur. Are you adding/removing bots at different times, by chance, that could cause this? And what do you have your bot_defer_ cvar(s) set to?

Posted: Sun Jul 26, 2015 6:56 am
by MrMalina

Posted: Sun Jul 26, 2015 7:06 am
by MrMalina
Since the player has only weapon_deagle, weapon_knife and weapon_c4.
I saw that the indices weapon_deagle weapon_knife and received normally.
So error occurs when there is an attempt to get the index c4

I wrote a small plugin to get the index of the bomb:

Syntax: Select all

from entities.entity import Entity

from filters.entities import EntityIter


for entity in EntityIter():
ent = Entity(entity)

classname = ent.classname

if "c4" in classname:
print(classname, ent.index)


Function weapon_indexes looking id 536, while the index of the current round of bombs - 535.

http://hostingkartinok.com/show-image.php?id=6d3cc280cb62de59cbc6d32034fd8b33