OpenXcom Forum

Modding => OpenXcom Extended => OXCE Suggestions DONE => Topic started by: Finnik on July 26, 2020, 01:51:29 am

Title: [DONE][SUGGESTION] item category check for y-scripts
Post 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:
Code: [Select]
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`
Title: Re: [SUGGESTION] item category check for y-scripts
Post by: Meridian on July 26, 2020, 10:06:10 am
Isn't this the same functionality as already provided by tags?
Title: Re: [SUGGESTION] item category check for y-scripts
Post by: Finnik on July 26, 2020, 12:33:21 pm
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.
Title: Re: [SUGGESTION] item category check for y-scripts
Post by: Yankes on July 26, 2020, 02:48:19 pm
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.
Title: Re: [SUGGESTION] item category check for y-scripts
Post by: Meridian on July 26, 2020, 05:18:37 pm
Merged.

Method 'getHaveCategory' was renamed to 'hasCategory'.
Title: Re: [SUGGESTION] item category check for y-scripts
Post by: Finnik on July 26, 2020, 06:48:21 pm
^ _ ^