Author Topic: Scripting basics  (Read 1006 times)

Offline Kzer-Za

  • Colonel
  • ****
  • Posts: 138
    • View Profile
Re: Scripting basics
« Reply #30 on: August 24, 2019, 11:07:27 pm »
How can I trigger accuracyMultiplierBonusStats only for soldiers? I tried using tags, but neither

Code: [Select]
soldiers:
  - type: XCOM
    armor: STR_NONE_UC
    tags:
      SOLDIER: 1

nor

Code: [Select]
units:
  - type: XCOM
    armor: STR_NONE_UC
    tags:
      SOLDIER: 1

works.

Also I would like it to apply to all weapons except psionic ones, and I can't get item rulesets from within accuracyMultiplierBonusStats. Could you advise something about it?

Online Meridian

  • Global Moderator
  • Commander
  • ***
  • Posts: 5207
  • Aaand we're back!
    • View Profile
    • My Wiki
Re: Scripting basics
« Reply #31 on: August 25, 2019, 12:01:01 am »
what do you want to do?

accuracy and damage can be modded to oblivion also without scripts, have you checked the existing ruleset attributes?

Offline Yankes

  • Moderator
  • Commander
  • ***
  • Posts: 2128
    • View Profile
Re: Scripting basics
« Reply #32 on: August 25, 2019, 03:04:14 am »
There is separate attack on psi-amp that do weapon damage. Aliens can use it too.

Offline Kzer-Za

  • Colonel
  • ****
  • Posts: 138
    • View Profile
Re: Scripting basics
« Reply #33 on: August 25, 2019, 07:35:27 am »
what do you want to do?

accuracy and damage can be modded to oblivion also without scripts, have you checked the existing ruleset attributes?

Yes, they can, but I want to give soldiers a penalty to accuracy when they are flying, and that does not seem to be doable without scripts. The script for reducing the accuracy is already working, here it is:

Code: [Select]
    accuracyMultiplierBonusStats:
      - offset: 10
        code: |
          var int unitFloating;
          var int unitSoldier;
          var ptr RuleItem itemRuleset;

          unit.isFloating unitFloating;
          if eq unitFloating 1;
            muldiv bonus 8 10;
          end;
         
          debug_log 1 bonus;
          debug_log 2 unitFloating;
         
          return bonus;

Now I only need to insert a check for whether a unit is a soldier or not, since I don't want to affect other flying units. (Since soldiers in flying suits are affected by not having a foothold, while for massive hovertanks and cyberdiscs it is not such an issue, and flying aliens should be adapted to it, since flying is their natural means of locomotion).

Offline Kzer-Za

  • Colonel
  • ****
  • Posts: 138
    • View Profile
Re: Scripting basics
« Reply #34 on: August 25, 2019, 07:41:37 am »
There is separate attack on psi-amp that do weapon damage. Aliens can use it too.

Really? Can I combine it with the regular attacks? I wanted Mind Control to inflict minor damage (say, 2-3 HP). It is insignificant from one attack, but with repeated attacks it would take its toll.

Offline Yankes

  • Moderator
  • Commander
  • ***
  • Posts: 2128
    • View Profile
Re: Scripting basics
« Reply #35 on: August 25, 2019, 01:13:12 pm »
This work different, You can have panic, MC and use action on psi-amp that will use weapon hit behavior. And they are separate options.

For penalty for only soldiers, you check if unit is not 2x2 (`getSize` in armor rule) and have soldier object `getGeoscapeSoldier` (if soldier have big armor then we assume it have stabilizers).

Offline Kzer-Za

  • Colonel
  • ****
  • Posts: 138
    • View Profile
Re: Scripting basics
« Reply #36 on: August 25, 2019, 05:41:06 pm »
Thanks, but how do I declare the variable for holding "getGeoscapeSoldier"? I tried this:

Code: [Select]
          var ptr BattleUnit isSoldier;
         
          unit.getGeoscapeSoldier isSoldier;
          if neq isSoldier null;
            debug_log 0 12345;
          end;

But I get an error "Conflicting overloads for operator 'clear'". If I try "var ptr GeoscapeSoldier isSoldier;", I get "invalid type" error.
« Last Edit: August 25, 2019, 08:57:12 pm by Kzer-Za »

Offline Shiroi Bara

  • Colonel
  • ****
  • Posts: 146
    • View Profile
Re: Scripting basics
« Reply #37 on: August 25, 2019, 06:13:06 pm »
A few questions:
1. How to nerf psi attack skills of enemy? Should I reduce parameter psiSkill in units.rul file?
2. What formulas used to calculate Psi (M.C.) attack in both UFO and TFTD based games?
3. Is it possible generate alien mission when only proper research finished and if yes how to do it?
Answers with examples will be great.

Offline Kzer-Za

  • Colonel
  • ****
  • Posts: 138
    • View Profile
Re: Scripting basics
« Reply #38 on: August 25, 2019, 06:29:54 pm »
I think it would be better to create a separate theme for these questions for readability sake, since they are not related to scripting (mission scripts are a different kind of scripts, not the one discussed here).

PS I answered your questions briefly in a private message, to keep this theme about scripts.
« Last Edit: August 25, 2019, 06:42:33 pm by Kzer-Za »

Offline Kzer-Za

  • Colonel
  • ****
  • Posts: 138
    • View Profile
Re: Scripting basics
« Reply #39 on: August 25, 2019, 09:03:46 pm »
I would also like to have tags on soldiers as BattleUnits for other purposes, is there a way for it? As I said, neither

Code: [Select]
soldiers:
  - type: XCOM
    tags:
      SOLDIER: 1

nor

Code: [Select]
units:
  - type: XCOM
    tags:
      SOLDIER: 1

is working. (By not working I mean that when I try to get the tag, the result is 0).

Offline ohartenstein23

  • Commander
  • *****
  • Posts: 1661
  • Flamethrowers fry cyberdisk circuits
    • View Profile
Re: Scripting basics
« Reply #40 on: August 25, 2019, 10:49:20 pm »
Does your mod have a soldier or unit type called "XCOM"? If you haven't specifically added that unit or soldier, the standard X-Com soldier is called "STR_SOLDIER" internally.

Offline Kzer-Za

  • Colonel
  • ****
  • Posts: 138
    • View Profile
Re: Scripting basics
« Reply #41 on: August 25, 2019, 11:15:37 pm »
(Banging my head on the wall) I have copied it from somewhere and didn't change the type. Thanks!

Offline Kzer-Za

  • Colonel
  • ****
  • Posts: 138
    • View Profile
Re: Scripting basics
« Reply #42 on: August 26, 2019, 10:13:56 am »
But after the correction of the mistake above, I still get zeroes. Probably another stupid mistake on my part, but I don't see it :( Here's the code:

Code: [Select]
extended:
  tags:
    BattleUnit:
      LAST_HIT_FRAME: int
      IS_SOLDIER: int
  scripts:
    accuracyMultiplierBonusStats:
      - offset: 10
        code: |
          var int unitFloating;
          var int unitSoldier;
          unit.getTag unitSoldier Tag.IS_SOLDIER;
          debug_log 96580879 unitSoldier;
          return bonus;
units:
  - type: STR_SOLDIER
    tags:
      IS_SOLDIER: 1

And after clicking on a weapon in the Battlescape I get this in the log:
Code: [Select]
[26-08-2019_10-00-05] [DEBUG] Script debug log at     0x2d: 96580879 0

I can't see what am I doing wrong now.

Online Meridian

  • Global Moderator
  • Commander
  • ***
  • Posts: 5207
  • Aaand we're back!
    • View Profile
    • My Wiki
Re: Scripting basics
« Reply #43 on: August 26, 2019, 10:40:38 am »
vanilla STR_SOLDIER is under soldiers: not units:

Offline Kzer-Za

  • Colonel
  • ****
  • Posts: 138
    • View Profile
Re: Scripting basics
« Reply #44 on: August 26, 2019, 10:57:21 am »
I thought it should be in "units" because if I define it in "soldiers" I get an error. The rest of the code is the same as above, only "units" are replaced with "soldiers":

Code: [Select]
soldiers:
  - type: STR_SOLDIER
    tags:
      IS_SOLDIER: 1

Code: [Select]
[ERROR] Error in tags: 'IS_SOLDIER' unknown tag name not defined in current file