[CSS]Exception when reading ammo key value

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

[CSS]Exception when reading ammo key value

Postby Doldol » Sun Feb 18, 2018 9:01 am

I can set the ammo key value without any issues, and this works (gives the amount of reserve ammo the value is set to when I pick up the USP), but an exception gets raised when trying to read it.

Also, "ammo" is not in weapon_usp.keyvalues. & Reading the kv after spawn doesn't work either.

Code:

Syntax: Select all

from weapons.entity import Weapon

weapon_usp = Weapon.create("weapon_usp")

weapon_usp.set_key_value_int("ammo", 125) # Works
weapon_usp.get_key_value_int("ammo") # Exception raised

weapon_usp.spawn()


Exception:

Code: Select all

         [SP] Loading plugin 'kvtest'...
         
         [SP] Caught an Exception:
         Traceback (most recent call last):
           File "../addons/source-python/packages/source-python/plugins/command.py", line 162, in load_plugin
             plugin = self.manager.load(plugin_name)
           File "../addons/source-python/packages/source-python/plugins/manager.py", line 193, in load
             plugin._load()
           File "../addons/source-python/packages/source-python/plugins/instance.py", line 74, in _load
             self.module = import_module(self.import_name)
           File "../addons/source-python/plugins/kvtest/kvtest.py", line 6, in <module>
             weapon_usp.get_key_value_int("ammo") # Exception raised
         
         NameError: "ammo" is not a valid KeyValue for entity class "CWeaponCSBase".
         
         
         [SP] Plugin 'kvtest' was unable to be loaded.


SP info

Code: Select all

         Date          : 2018-02-18 09:00:42.103015
         OS            : Linux-4.4.0-101-generic-x86_64-with-debian-stretch-sid
         Game          : css
         SP version    : 621


What is going on? & How else can I read the value of reserve ammo that comes with a weapon spawned in the world?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CSS]Exception when reading ammo key value

Postby L'In20Cible » Sun Feb 18, 2018 11:10 am

Some key values are hard-coded and are not returning true/false on success/failure which cause our internal check to fail for them. We removed the check for the setter method and should probably remove it for the getter method as well.

EDIT: Went ahead and removed that check.
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Re: [CSS]Exception when reading ammo key value

Postby Doldol » Sun Feb 18, 2018 11:37 am

Sounds good, thanks
User avatar
Doldol
Senior Member
Posts: 200
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Re: [CSS]Exception when reading ammo key value

Postby Doldol » Mon Feb 19, 2018 1:07 pm

There still seems to be something funky going on

Code: Select all

         [SP] Caught an Exception:
         Traceback (most recent call last):
           File "../addons/source-python/packages/source-python/plugins/command.py", line 162, in load_plugin
             plugin = self.manager.load(plugin_name)
           File "../addons/source-python/packages/source-python/plugins/manager.py", line 193, in load
             plugin._load()
           File "../addons/source-python/packages/source-python/plugins/instance.py", line 74, in _load
             self.module = import_module(self.import_name)
           File "../addons/source-python/plugins/kvtest/kvtest.py", line 6, in <module>
             weapon_usp.get_key_value_int("ammo") # Exception raised
         
         ValueError: KeyValue does not seem to be an integer: 'P?x?X?x?x?x?C???'.
         
         
         [SP] Plugin 'kvtest' was unable to be loaded.


when reading as string

Code: Select all

             weapon_usp.get_key_value_string("ammo") # Exception raised
         
         UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 0: invalid continuation byte
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [CSS]Exception when reading ammo key value

Postby Ayuto » Wed Feb 21, 2018 8:20 pm

This key value is write-only. Reading is not implemented.

You got these weird values/exceptions, because we forgot to initialize an internal variable. That is now fixed with this commit:
https://github.com/Source-Python-Dev-Te ... d4ba0aff4c

If want to read the value, you need to access the variable via an offset:
CSS: 1424 (Linux), 351 (Windows)

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 23 guests