OpenXcom Forum

Modding => OXCE Support => OpenXcom Extended => OXCE Support Y-scripts => Topic started by: zhorov on June 12, 2022, 10:29:28 pm

Title: [Solved] Drugs that restore / give time (tu)
Post by: zhorov on June 12, 2022, 10:29:28 pm
Hello. I decided to change the preparation in XPiratez so that it would add time.
For some reason no one added this except the creator of x-files mod (Zephyr serum), and this thing really makes you try to get it and not use it like other things. But why? There are many items that give energy, morale, mana, even health but not time? Why not add a few items that would give a little time and not be so valuable? This is the question I think about a lot. Why not add pills or serum that would give 20 tu. 6-10 to drag to hand and 1 to use. There would be 13-9 left that would be enough to use the first aid kit or simply leave the aisle. Also add a valuable drug that would immediately give 100 tu.
It's simple, isn't it? It should also be interesting and varied. But I saw it only in x-files and only 1 time. I want to fix this, at least for myself anyway, but I hope somebody help me.
Since the game is full of other drugs that give anything, but not the time, I decided to fix it.

I decided to edit combat drugs.
items:
  - type: STR_COMBAT_DRUGS
    medikitActionName: STR_INJECT
    costUse:
      time: 1
      health: 1  (We will lost 1 hp for each use)
      stun: -50
      morale: -50
      mana: -50
    costThrow:
      energy: 6
      time: 40
    flatRate: true
    isConsumable: true
    flatUse:
      time: true
      health: true
    recoveryPoints: 1
tags:  (The tag is what the script will use)
      WM_IS_WACKY: 1

Here is the script from x-files
 code: |
          var int temp;

          item.getTag temp Tag.WM_IS_WACKY;

          if neq temp 0;
            # debug_log "healUnit: applying wacky medikit, skip normal effects completely";
            set medikit_action_type 0;

            target.getTimeUnits temp;
            add temp 55;
            target.setTimeUnits temp;

            target.getEnergy temp;
            add temp 50;
            target.setEnergy temp;

            return;
          end;

          # debug_log "healUnit: not wacky...";
          return;

I tried to add this to my script file and to the Yankes_Scripts. It just doesn't work. Why? I dont know. I never wrote scripts, I never made mods until yesterday.
Title: Re: Drugs that restore / give time (tu)
Post by: Filip H on June 17, 2022, 01:55:18 am
I see two issues with the script.
Firstly the scripthook is missing (i.e. the part that determines when the script runs). I presume the script you grabbed used the healUnit: hook, you need to add it one line above code: |. Note that if you're adding it to a file with multiple existing scripts, there might already be a healUnit: hook, in which case you only need to add the script after it (adding the hook again will not work).
Secondly the Tag required by the script most likely isn't defined which means you need to add that too. Here is an example on how it should look like:
Code: [Select]
extended:
  tags:
    RuleItem:
      WM_IS_WACKY: int
If the RuleItem section already exists in the file you can just add WM_IS_WACKY: int among the existing tags.

One pitfall to avoid is that you need to add tags to an item in the same file as where the tags are defined, otherwise the script may not work.
The easiest way to achieve what you're trying to do would be to just to create a new .rul file and add the new script and item, it should look something like this
Code: [Select]
items:
  - type: STR_COMBAT_DRUGS
    medikitActionName: STR_INJECT
    costUse:
      time: 1
      health: 1  (We will lost 1 hp for each use)
      stun: -50
      morale: -50
      mana: -50
    costThrow:
      energy: 6
      time: 40
    flatRate: true
    isConsumable: true
    flatUse:
      time: true
      health: true
    recoveryPoints: 1
    tags:  (The tag is what the script will use)
      WM_IS_WACKY: 1

extended:
  tags:
    RuleItem:
      WM_IS_WACKY: int
  scripts:
    healUnit:
    code: |
          var int temp;

          item.getTag temp Tag.WM_IS_WACKY;

          if neq temp 0;
            # debug_log "healUnit: applying wacky medikit, skip normal effects completely";
            set medikit_action_type 0;

            target.getTimeUnits temp;
            add temp 55;
            target.setTimeUnits temp;

            target.getEnergy temp;
            add temp 50;
            target.setEnergy temp;

            return;
          end;

          # debug_log "healUnit: not wacky...";
          return;
Title: Re: Drugs that restore / give time (tu)
Post by: krautbernd on June 21, 2022, 12:09:38 pm
One pitfall to avoid is that you need to add tags to an item in the same file as where the tags are defined, otherwise the script may not work.

 :o

May I ask where you got this information from? Because that's literally not how scripts are implemented in every modpack I've come across and they work fine, including this one (which also works fine in a stand-alone mod). I already pointed OP to how this needs to implemented in an earlier thread (https://openxcom.org/forum/index.php/topic,4595.msg146774.html#msg146774).
Title: Re: Drugs that restore / give time (tu)
Post by: Yankes on June 21, 2022, 12:33:50 pm
:o

May I ask where you got this information from? Because that's literally not how scripts are implemented in every modpack I've come across and they work fine, including this one (which also works fine in a stand-alone mod). I already pointed OP to how this needs to implemented in an earlier thread (https://openxcom.org/forum/index.php/topic,4595.msg146774.html#msg146774).
It work only because of in what order files are loaded. Usually game load in same order and it work fine but other times (different OS or load from zip) it change and break mods that used it.

At least I planed that this feature work exactly as Filip H said, aka, every file that use tag it should have declared them too in same file.
Right now only when next sub mod is load list of declared tags is reseted but it should be for each rule file too, I probably can't fix it now as it would break too many mods.
Title: Re: Drugs that restore / give time (tu)
Post by: krautbernd on June 21, 2022, 01:58:36 pm
Thanks for the clarification Yankes, I wasn't aware that the feature was meant to work differently :D
Title: Re: Drugs that restore / give time (tu)
Post by: N7Kopper on July 12, 2022, 12:25:53 am
It work only because of in what order files are loaded. Usually game load in same order and it work fine but other times (different OS or load from zip) it change and break mods that used it.

At least I planed that this feature work exactly as Filip H said, aka, every file that use tag it should have declared them too in same file.
Right now only when next sub mod is load list of declared tags is reseted but it should be for each rule file too, I probably can't fix it now as it would break too many mods.
Why not deprecate it for a few editions, and warn modders (and users) on startup. before switching to "lmao no I won't load this crap" in a few updates?

This screams of undefined behavour, and that could be bad bad bad if the programming stars align in all the wrong ways. Even if it doesn't give ACE within OCXE's privilege layer (not implying that that's in any way likely, but tweezers have done more) it would ultimately save modders a crapton of headaches when someone with an esoteric setup eventually breaks something.