Author Topic: [Solved] Drugs that restore / give time (tu)  (Read 4059 times)

Offline zhorov

  • Sergeant
  • **
  • Posts: 41
    • View Profile
[Solved] Drugs that restore / give time (tu)
« 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.
« Last Edit: February 12, 2023, 03:20:48 pm by Meridian »

Offline Filip H

  • Squaddie
  • *
  • Posts: 7
    • View Profile
Re: Drugs that restore / give time (tu)
« Reply #1 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;
« Last Edit: June 17, 2022, 02:02:44 am by Filip H »

Offline krautbernd

  • Commander
  • *****
  • Posts: 1108
    • View Profile
Re: Drugs that restore / give time (tu)
« Reply #2 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.
« Last Edit: June 21, 2022, 12:11:15 pm by krautbernd »

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3360
    • View Profile
Re: Drugs that restore / give time (tu)
« Reply #3 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.
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.

Offline krautbernd

  • Commander
  • *****
  • Posts: 1108
    • View Profile
Re: Drugs that restore / give time (tu)
« Reply #4 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

Offline N7Kopper

  • Captain
  • ***
  • Posts: 61
    • View Profile
Re: Drugs that restore / give time (tu)
« Reply #5 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.