Author Topic: [Documentation] OXCE Y-Script examples  (Read 14087 times)

Offline Yankes

  • Commander
  • *****
  • Posts: 3185
    • View Profile
Re: [Documentation][y-script] OXCE Script examples
« Reply #15 on: March 25, 2022, 10:38:17 am »
Global fix for soldiers armors that have more than 3 death frames, assumes that all armors with more death frames shifted all surfaces graphic too.
Fix for problem: https://openxcom.org/forum/index.php/topic,10392.0.html

Code: [Select]
extended:
  scripts:
    selectUnitSprite:
      - offset: -2
        code: |
          var int drawingRoutine;
          var int deathFrames;
         
          if or
            eq blit_part blit_torso
            eq blit_part blit_legs
          ;
            var ptr RuleArmor armor;
            unit.getRuleArmor armor;
            armor.getDrawingRoutine drawingRoutine;
            armor.getDeathFrames deathFrames;
            if and
              eq drawingRoutine 0
              gt sprite_index 264  #bigger than first death frame
              gt deathFrames 3
            ;
              sub deathFrames 3;
              add sprite_index deathFrames;
            end;
          end;
          return sprite_index;

Offline Yankes

  • Commander
  • *****
  • Posts: 3185
    • View Profile
Re: [Documentation][y-script] OXCE Script examples
« Reply #16 on: April 09, 2022, 03:40:05 pm »
More idea than implementation:

In recent OXCE nighty I added option for blocking item move (by making move cost bigger than available TU) and switching move type of unit.
Most critical consequence of this features is that you can create "jet pack" item that can be equipped before battle and when game start it change unit to flying one.
To prevent exploits cost of removing item will be so big that can't be done during mission.

Offline Delian

  • Colonel
  • ****
  • Posts: 240
    • View Profile
Re: [Documentation][y-script] OXCE Script examples
« Reply #17 on: April 09, 2022, 04:32:53 pm »
Wouldn't that mean that if the unit is knocked unconscious, it drops the jetpack and can't pick it up anymore? That doesn't make logical sense tho.

Offline Yankes

  • Commander
  • *****
  • Posts: 3185
    • View Profile
Re: [Documentation][y-script] OXCE Script examples
« Reply #18 on: April 09, 2022, 05:54:44 pm »
Jet pack break down and is not usable any more, this is logical :>

As for more serious answer script have option to increase and decrease cost, you could make more complex scripts to handle it better but still be some corner cases hard to handle.

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11401
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: [Documentation][y-script] OXCE Script examples
« Reply #19 on: April 10, 2022, 12:59:35 pm »
Hmm, why prevent this unit from taking off the jetpack? Is it to prevent it from throwing it away in mid-air?

Offline Yankes

  • Commander
  • *****
  • Posts: 3185
    • View Profile
Re: [Documentation][y-script] OXCE Script examples
« Reply #20 on: April 10, 2022, 01:39:15 pm »
Item move cost, new feature I added, you can make that item will cost 1000 TU to move from inventory.

Offline krautbernd

  • Commander
  • *****
  • Posts: 1116
    • View Profile
Re: [Documentation][y-script] OXCE Script examples
« Reply #21 on: April 10, 2022, 04:30:29 pm »
Item move cost, new feature I added, you can make that item will cost 1000 TU to move from inventory.
Doesn't inventoryMoveCost already accomplish the same thing?

Offline Yankes

  • Commander
  • *****
  • Posts: 3185
    • View Profile
Re: [Documentation][y-script] OXCE Script examples
« Reply #22 on: April 10, 2022, 04:36:17 pm »
Doesn't inventoryMoveCost already accomplish the same thing?
I was referring exactly to this, only details is that script can alter it, this mean item can be movable during one turn but unmovable on another.
If item should be equipable only during briefing then only item config change is required.

Offline Yankes

  • Commander
  • *****
  • Posts: 3185
    • View Profile
Re: [Documentation][y-script] OXCE Script examples
« Reply #23 on: December 30, 2022, 03:29:28 pm »
Script that show HK ufo from longer distance that normally when they are in "hunt" mode.
Distance on what HK is visible is `base_radar_range + hk_radar_range + small_bonus`
Code: [Select]
extended:
  scripts:
    detectUfoFromBase:
      - offset: 10
        code: |
          var int maxDistanceHK;
          var int radarRangeHK;
          var int hunter;
         
          ufo.Stats.getRadarRange radarRangeHK;
          set maxDistanceHK radar_max_distance;
          add maxDistanceHK 300;
          add maxDistanceHK radarRangeHK;
         
          ufo.isHunting hunter;
          if and eq hunter 1 lt distance maxDistanceHK;
            var int temp_chanc 30;
            if gt temp_chanc detection_chance;
              set detection_chance temp_chanc;
            end;
          end;
         
          return detection_type detection_chance;

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11401
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: [Documentation][y-script] OXCE Script examples
« Reply #24 on: December 30, 2022, 03:55:07 pm »
Many thanks, Yankes.

Would it be possible to write that script that for certain UFOs displays full info, even if you don't have the Hyper-Wave Decoder? I'd like to mark some Earth vehicles like that.

Offline Yankes

  • Commander
  • *****
  • Posts: 3185
    • View Profile
Re: [Documentation][y-script] OXCE Script examples
« Reply #25 on: December 30, 2022, 05:00:18 pm »
Script that make some ufo permanently HW decoded but invisible until normal radar find it.
Code: [Select]
extended:
  tags:
    RuleUfo:
      PUBLIC_HYPERWAVE_DATA: int
  scripts:
    detectUfoFromBase:
      - offset: 10
        code: |
          var int showHwData;
         
          ufo.getTag showHwData Tag.PUBLIC_HYPERWAVE_DATA;
         
          if eq showHwData 1;
            var int temp DETECTION_HYPERWAVE;
            bit_xor temp DETECTION_RADAR; # remove from HW radar detection bit, it leave only HW data flag
            bit_or detection_type temp; # add only HW falag to detection
          end;
         
          return detection_type detection_chance;
ufos:
  - type: STR_SMALL_SCOUT
    tags:
      PUBLIC_HYPERWAVE_DATA: 1

Offline MaxMahem

  • Captain
  • ***
  • Posts: 60
    • View Profile
Re: [Documentation] OXCE Y-Script examples
« Reply #26 on: March 12, 2023, 07:27:19 am »
Guard "Function" to check if an item is in the proper slot to be "active" (or otherwise proceed with the script). Uses an "ACTIVE_IN" tag which is a "flag enum" containing a bitmask of all the locations where an item should be active in. If this tag does not have a value (or if the value is set to 0 for some reason, maybe a sub-mod override) then this test will always pass. Otherwise the script will proceed only if the item is in a slot notated by the bitfield.

Code: [Select]
tags:
    RuleItem:
      ACTIVE_IN: int
          # Flag Enum
          # 0 = always active/NA?
          # 1 = L. Hand
          # 2 = R. Hand
          # 4 = Belt
          # 8 = R. Legt
          # 16 = L. Leg
          # 32 = R. Shoulder
          # 64 = L. Shoulder
          # 128 = Backpack
          # 256 = Quick Draw
          # 512 = Worn
          # 1024 = Jewlery
          # 2048 = Hat
          # 3 = R & L hands
          # 4095 = everywhere

scripts:
  newTurnItem:
    - override: ITEM_RESISTANCE_SCRIPT
      offset: 2
      code: |
        var ptr RuleItem itemRuleset;
        var int activeInEnum;
       
        item.getRuleItem itemRuleset;
        itemRuleset.getTag activeInEnum Tag.ACTIVE_IN;

        # activeInEnum has a value so we need to test it.
        if neq activeInEnum 0;
          var ptr RuleInventory itemInventory;
          var text inventoryId;
          var int testMask;

          item.getSlot itemInventory;
          itemInventory.getId inventoryId;
       
          # build a bitmask to test based on where we know the item is:
          if eq inventoryId "STR_LEFT_HAND";
            set testMask 1;
          end;
          if eq inventoryId "STR_RIGHT_HAND";
            set testMask 2;
          end;
          if eq inventoryId "STR_BELT";
            set testMask 4;
          end;
          if eq inventoryId "STR_RIGHT_LEG";
            set testMask 8;
          end;
          if eq inventoryId "STR_LEFT_LEG";
            set testMask 16;
          end;
          if eq inventoryId "STR_RIGHT_SHOULDER";
            set testMask 32;
          end;
          if eq inventoryId "STR_LEFT_SHOULDER";
            set testMask 64;
          end;
          if eq inventoryId "STR_BACK_PACK";
            set testMask 128;
          end;
          if eq inventoryId "STR_QD_SLOT";
            set testMask 256;
          end;
          if eq inventoryId "STR_WEAR";
            set testMask 512;
          end;
          if eq inventoryId "STR_WEAR_JEWELRY";
            set testMask 1024;
          end;
          if eq inventoryId "STR_WEAR_HAT";
            set testMask 2048;
          end;

          bit_and testMask activeInEnum;
          if eq testMask 0;
            debug_log "Item:" item " passed no tests:" testMask "enum:" activeInEnum;
            return;
          end;
          debug_log "Item:" item "passed the tests!:" testMask "enum:" activeInEnum;
        end;
       
        # script proceeds normally from here.