aliens

Author Topic: [SUGGESTION] item category check for y-scripts  (Read 142 times)

Offline Finnik

  • Colonel
  • ****
  • Posts: 139
    • View Profile
[SUGGESTION] item category check for y-scripts
« 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

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`
« Last Edit: July 26, 2020, 06:47:46 pm by Finnik »

Offline Meridian

  • Global Moderator
  • Commander
  • ***
  • Posts: 6319
  • Aaand we're back!
    • View Profile
    • My Wiki
Re: [SUGGESTION] item category check for y-scripts
« Reply #1 on: July 26, 2020, 10:06:10 am »
Isn't this the same functionality as already provided by tags?

Offline Finnik

  • Colonel
  • ****
  • Posts: 139
    • View Profile
Re: [SUGGESTION] item category check for y-scripts
« Reply #2 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.

Offline Yankes

  • Moderator
  • Commander
  • ***
  • Posts: 2336
    • View Profile
Re: [SUGGESTION] item category check for y-scripts
« Reply #3 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.

Offline Meridian

  • Global Moderator
  • Commander
  • ***
  • Posts: 6319
  • Aaand we're back!
    • View Profile
    • My Wiki
Re: [SUGGESTION] item category check for y-scripts
« Reply #4 on: July 26, 2020, 05:18:37 pm »
Merged.

Method 'getHaveCategory' was renamed to 'hasCategory'.

Offline Finnik

  • Colonel
  • ****
  • Posts: 139
    • View Profile
Re: [SUGGESTION] item category check for y-scripts
« Reply #5 on: July 26, 2020, 06:48:21 pm »
^ _ ^