OpenXcom Forum
Modding => OpenXcom Extended => OXCE Suggestions DONE => Topic started by: Finnik on July 26, 2020, 01:51:29 am
-
I would like to share my first tiny step into coding y-scripts. Many thanks to Yankes for inspiration and guidance!
https://github.com/MeridianOXC/OpenXcom/pull/72 (https://github.com/MeridianOXC/OpenXcom/pull/72)
The point here was to add a little QoL for a scripter that is working with many items. If you want to add some specific behavior to all items it one category, with that you do not have to add repeating tags to any item in the category, but add a single category check in the script itself. Let's say, we want to mod all our sniper rifles have some special behavior. Instead of adding tags to all of them defining it as a sniper rifle, you can use already most likely defined category item property.
So, an example of a script:
extended:
scripts:
damageUnit:
- offset: 1 #test category script
code: |
var ptr RuleItem itemRuleset;
var int check;
damaging_item.getRuleItem itemRuleset;
itemRuleset.hasCategory check "STR_SNIPER_RIFLES"; #returns 1 if defined category found in item's arrey; else returns 0 if the item does not belong to this category
if eq check 1;
debug_log 2 723;
# do our stuff
end;
return;
UPD: method renamed to `hasCategory`
-
Isn't this the same functionality as already provided by tags?
-
Pretty much, as I said, it is a QoL for a scripter, so you don't have to assign the same tags over and over again adding a weapon to some custom category mechanics, but use data you already imputed.
-
Isn't this the same functionality as already provided by tags?
Yes, for me Finnik motivation is not much convicting but functionality it self could be used for other thins too, and at top of this is very simple to add this.
Overall when he fix some small corner cases I will merge it.
-
Merged.
Method 'getHaveCategory' was renamed to 'hasCategory'.
-
^ _ ^