Closed xArkanEx closed 5 years ago
There's 3 ways to write items in a new format: ESS, ESP, and SP. To start of with, here's an item (Pendant of the Blood Scarab) that gives you 50 health when you buy it as well as each time you spawn:
ESS (../addons/source-python/plugins/es_emulator/eventscripts/wcs/modules/items/pendant_of_the_blood_scarab/es_pendant_of_the_blood_scarab.txt
):
block player_spawn
{
es wcs_setfx health event_var(userid) + 50 0
}
block buycmd
{
es wcs_setfx health server_var(wcs_userid) + 50 0
}
ESP (../addons/source-python/plugins/es_emulator/eventscripts/wcs/modules/items/pendant_of_the_blood_scarab/pendant_of_the_blood_scarab.py
):
def player_spawn_(event, wcsplayer):
wcsplayer.player.health += 50
def buycmd(wcsplayer):
wcsplayer.player.health += 50
SP (../addons/source-python/plugins/wcs/modules/items/pendant_of_the_blood_scarab/__init__.py
):
from ....core.modules.items.calls import ItemEvent
@ItemEvent()
def player_spawn(event, wcsplayer):
wcsplayer.player.health += 50
@ItemEvent()
def buycmd(wcsplayer):
wcsplayer.player.health += 50
You're only supposed to use 1 of these but it won't hurt if you have all 3 files, as it'll only load 1 of them. It checks (and loads if it's found) in the following order: SP -> ESP -> ESS. If none of the files are found, there'll be a warning to notify you about it (WCS will still load - the item will just be ignored).
There's 2 other files that's required: config.json
and strings.ini
, which are located (in this case) in ../addons/source-python/plugins/wcs/modules/items/pendant_of_the_blood_scarab/
. The contents of the 2 files are as follows:
strings.ini:
[name]
en = "Pendant of the Blood Scarab"
[description]
en = "Gives you +50 health upon purchase and +50 when you spawn"
config.json:
{
"cost": 0,
"required": 0,
"dab": 1,
"duration": 1,
"count": 1,
"event": "player_spawn"
}
strings.ini
contains translated information, in this case, the item name and item description. config.json
contains information such as what the item costs, the minimum required level before it can be purchased, dab (Dead Alive Both) which is when the item can be purchased, the duration (0 = 1 round, 1 = untill death), count (how many of them can be purchased), and event.
Notes: In the ESP example, you'll notice an underscore (_) after "player_spawn". This is supposed to be there, otherwise it'd be seen as a normal event, which is not what we want.
Thank you very much for giving me such a detailled answer ! Appreciate the help !
Sorry to bother you again about this. I am trying to load the SP version but it does not work. I got an error while it tries to load:
Traceback (most recent call last):
File "../addons/source-python/plugins/wcs/core/modules/base.py", line 117, in _load_categories_and_values
setting = self.load(name)
File "../addons/source-python/plugins/wcs/core/modules/items/manager.py", line 108, in load
return self._load(name, 'items', ITEM_PATH, ITEM_PATH_ES, OnPluginItemLoad)
File "../addons/source-python/plugins/wcs/core/modules/base.py", line 187, in _load
self[name].module = import_module(f'wcs.modules.{module}.{name}')
File "../addons/source-python/plugins/wcs/modules/items/amulet/__init__.py", line 3, in <module>
@ItemEvent()
TypeError: __init__() missing 1 required positional argument: 'event'
[SP] Successfully loaded plugin 'wcs'.
If I use ItemEvent instead of ItemEvent() it seems like the events are not triggered.
If i use ItemEvent('player_spawn') it gives me another error:
Traceback (most recent call last):
File "../addons/source-python/plugins/wcs/core/modules/base.py", line 117, in _load_categories_and_values
setting = self.load(name)
File "../addons/source-python/plugins/wcs/core/modules/items/manager.py", line 108, in load
return self._load(name, 'items', ITEM_PATH, ITEM_PATH_ES, OnPluginItemLoad)
File "../addons/source-python/plugins/wcs/core/modules/base.py", line 187, in _load
self[name].module = import_module(f'wcs.modules.{module}.{name}')
File "../addons/source-python/plugins/wcs/modules/items/amulet/__init__.py", line 3, in <module>
@ItemEvent('player_spawn')
File "../addons/source-python/plugins/wcs/core/modules/items/calls.py", line 41, in __call__
if 'event' not in config:
TypeError: argument of type 'ItemSetting' is not iterable
Do you have an idea ?
Sorry to bother you again about this.
No worries.
I am trying to load the SP version but it does not work. I got an error while it tries to load:
Traceback (most recent call last): File "../addons/source-python/plugins/wcs/core/modules/base.py", line 117, in _load_categories_and_values setting = self.load(name) File "../addons/source-python/plugins/wcs/core/modules/items/manager.py", line 108, in load return self._load(name, 'items', ITEM_PATH, ITEM_PATH_ES, OnPluginItemLoad) File "../addons/source-python/plugins/wcs/core/modules/base.py", line 187, in _load self[name].module = import_module(f'wcs.modules.{module}.{name}') File "../addons/source-python/plugins/wcs/modules/items/amulet/__init__.py", line 3, in <module> @ItemEvent() TypeError: __init__() missing 1 required positional argument: 'event' [SP] Successfully loaded plugin 'wcs'.
If I use ItemEvent instead of ItemEvent() it seems like the events are not triggered.
If i use ItemEvent('player_spawn') it gives me another error:
Traceback (most recent call last): File "../addons/source-python/plugins/wcs/core/modules/base.py", line 117, in _load_categories_and_values setting = self.load(name) File "../addons/source-python/plugins/wcs/core/modules/items/manager.py", line 108, in load return self._load(name, 'items', ITEM_PATH, ITEM_PATH_ES, OnPluginItemLoad) File "../addons/source-python/plugins/wcs/core/modules/base.py", line 187, in _load self[name].module = import_module(f'wcs.modules.{module}.{name}') File "../addons/source-python/plugins/wcs/modules/items/amulet/__init__.py", line 3, in <module> @ItemEvent('player_spawn') File "../addons/source-python/plugins/wcs/core/modules/items/calls.py", line 41, in __call__ if 'event' not in config: TypeError: argument of type 'ItemSetting' is not iterable
Do you have an idea ?
Update to the newest version, and those issues should be fixed.
Thank you it works now. Could you tell me where i could find a description of the many argument passed to the function (event, wcsplayer ...). And a list of arguments for each events ?
Thank you it works now. Could you tell me where i could find a description of the many argument passed to the function (event, wcsplayer ...). And a list of arguments for each events ?
Right now, there's next to no documentation about it, however, if you're comfortable with Python, you can try looking at the source code. You can search for ".notify(", and it'd give you a (some what) readable list of what events there's available. The arguments depends on what you're hooking and from what. For items, it can have no arguments, "wcsplayer" or "event" and "wcsplayer". For races, you can have the same as the items except for skills, as they also provide a "variables" argument.
These questions are likely more suited in the forum thread, so I'd recommend you to ask them there, or create a new issue for each question (if they're around the same topic, just a single one is fine) you may have to make it easier to get an overview of things. Feel free to still make an issue here or in said thread, though.
Hi, Thank you for this mod. Could you provide an item example code in order to grasp the way to code them ?
Thank you !