aliens

Author Topic: [Solved]Skip Player first turn (battlescape) per mission (boolean)  (Read 2479 times)

Offline thusky

  • Sergeant
  • **
  • Posts: 29
    • View Profile
Hello,

Been a while since I last posted and worked on my mod, I'm back one year later and working on a script I worked on before. The idea of this script would be to skip the player's first turn only for certain mission, as such I'd like to be able to control this boolean (true/false) per mission.

I had a previously working prototype of the script which "Filip H" (discord) helped me make, however this version didn't allow me to control when I wanted this feature to be active, it was basically always active.

The old version:

Code: [Select]
# Script allowing Xcom: Rising from the deep to always skip first turn in battlescape and let the unit regain TU for the second turn.
extended:
  scripts:
    newTurnUnit:
      - offset: 21
        code: |
          var int isPlayerUnit;
          var int maxUnitTu;
          var int isEnemyTurn;

          unit.getFaction isPlayerUnit;
          unit.getTimeUnitsMax maxUnitTu;
          battle_game.getTurnSide isEnemyTurn;

          if eq turn 1;
            if eq isPlayerUnit 0;
            unit.setTimeUnits 0 ;
              if eq isEnemyTurn 1;
              unit.setTimeUnits maxUnitTu;
              end;
            end;
          end;
          return;

In the new version, I'm trying to add an item through the alienDeployments.rul with [ExtraRandomItems], however that wouldn't work on the long run, there surely is a better way to make a boolean to control the skip first turn per mission.

The new (WIP) version, which currently doesn't work:

Code: [Select]
#------DUMMY ITEM FOR BATTLETURN SKIP
items:
  - type: STR_TURN_SKIP
    categories: [STR_LOGIC]
    tags:
      SKIP_TAG: 1
# Script allowing Xcom: Rising from the deep to always skip first turn in battlescape and let the unit regain TU for the second turn.
extended:
  tags:
    BattleGame:
     SKIP_TAG: int

  scripts:
  #---Check if SKIP_TAG is present to skip first turn or not
    createItem:
      - offset: 21
        code: |
          var int isSkipTurn;

          item.getTag isSkipTurn Tag.SKIP_TAG;

          return;

  #---Skip First Turn
    newTurnUnit:
      - offset: 22
        code: |
          var int isPlayerUnit;
          var int maxUnitTu;
          var int isEnemyTurn;
          var int isSkipTurnPointer;
         
          unit.getFaction isPlayerUnit;
          unit.getTimeUnitsMax maxUnitTu;
          battle_game.getTurnSide isEnemyTurn;
          battle_game.getTag isSkipTurnPointer Tag.isSkipTurn;

          if eq isSkipTurnPointer 1;
            if eq turn 1;
              if eq isPlayerUnit 0;
              unit.setTimeUnits 0 ;
                if eq isEnemyTurn 1;
                unit.setTimeUnits maxUnitTu;
                end;
              end;
            end;
          end;
          return;

So all in all, a way to enable/disable skip first turn per mission.


EDIT:
Solution Down Below.
« Last Edit: October 14, 2023, 02:41:02 am by thusky »

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [Question]Skip Player first turn (battlescape) per mission (boolean)
« Reply #1 on: October 13, 2023, 05:19:07 pm »
What exactly is a question? What do not work (and how)?

Offline thusky

  • Sergeant
  • **
  • Posts: 29
    • View Profile
Re: [Question]Skip Player first turn (battlescape) per mission (boolean)
« Reply #2 on: October 13, 2023, 05:34:07 pm »
The first script works but doesn't allow me to turn it on/off on demand, which is a problem.

The second script doesn't work as nothing happens, I still have my first turn as the player whereas all my units should all have 0 TU until the second turn.

The question is "How can I make this script work?" basically, or what other kind of designs could I go for to create something similar to a boolean using the old script.

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [Question]Skip Player first turn (battlescape) per mission (boolean)
« Reply #3 on: October 13, 2023, 05:47:00 pm »
Do you check logs and see if there are some information?

Offline thusky

  • Sergeant
  • **
  • Posts: 29
    • View Profile
Re: [Question]Skip Player first turn (battlescape) per mission (boolean)
« Reply #4 on: October 13, 2023, 06:58:42 pm »
I did and this is what I got:

[13-10-2023_17-30-08]   [ERROR]   Can't match overload for operator 'BattleItem.getTag' for:
[13-10-2023_17-30-08]   [ERROR]     [ptre BattleItem] [var int] [BattleGame.Tag]
[13-10-2023_17-30-08]   [ERROR]   Expected:
[13-10-2023_17-30-08]   [ERROR]     [ptr BattleItem] [var int] [RuleItem.Tag]
[13-10-2023_17-30-08]   [ERROR]     [ptr BattleItem] [var int] [BattleItem.Tag]
[13-10-2023_17-30-08]   [ERROR]   Error in parsing script 'createItem' for 'Global Event Script': invalid operation in line: 'item.getTag isSkipTurn Tag.SKIP_TAG;'
[13-10-2023_17-30-08]   [ERROR]   Unknown argument 'Tag.isSkipTurn'
[13-10-2023_17-30-08]   [ERROR]   Error in matching arguments for operator 'BattleGame.getTag'
[13-10-2023_17-30-08]   [ERROR]   Error in parsing script 'newTurnUnit' for 'Global Event Script': invalid operation in line: 'battle_game.getTag isSkipTurnPointer Tag.isSkipTurn;'
[13-10-2023_17-30-08]   [ERROR]   Error in tags: 'SKIP_TAG' unknown tag name not defined in current file


I've been trying different things to remove the errors but aside from reverting to the old code which works 100% of the time I'm a tad lost. Still I'll keep trying then.

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [Question]Skip Player first turn (battlescape) per mission (boolean)
« Reply #5 on: October 13, 2023, 07:03:30 pm »
It clearly say what is wrong you try use `[BattleGame.Tag]` (tag for battle game) in place where `[RuleItem.Tag]` or `[BattleItem.Tag]` (tags for items) is possible.
Why you use `item.getTag` there?

Offline thusky

  • Sergeant
  • **
  • Posts: 29
    • View Profile
Re: [Question]Skip Player first turn (battlescape) per mission (boolean)
« Reply #6 on: October 13, 2023, 07:10:23 pm »
I'm pretty much a novice and really dumstruck when it comes to anything script related (that involves any logic), I mostly spend my days drawing, creating 3D art and pixel art.

As such I'd say that's pretty much the reason why some things that might seem clear aren't to me ahah.

Thanks though I'll get right on it then, I hope this is the only issue with the script!

So yep, no particular reason why I used item.getTag aside from lack of logic/patience when it comes to anything script related.

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [Question]Skip Player first turn (battlescape) per mission (boolean)
« Reply #7 on: October 13, 2023, 08:31:05 pm »
btw remember to use `debug_log "some message" item;` to track what your script do and what vales have given variable.
This will allow you to track that script do and why.

Offline thusky

  • Sergeant
  • **
  • Posts: 29
    • View Profile
Re: [Question]Skip Player first turn (battlescape) per mission (boolean)
« Reply #8 on: October 13, 2023, 08:40:47 pm »
Got it,

Do you think this is the best approach? To create a dummy item to give to units when battle start to "simulate" a boolean?

Or is there some other way I could trigger this script on and off on demand? The old one I mean (it works without issues).

Offline Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: [Question]Skip Player first turn (battlescape) per mission (boolean)
« Reply #9 on: October 13, 2023, 09:10:30 pm »
No, your approach could work, but you mixup two different things, tags on item it self that work as "trigger" and global battle tag that is used to notify all other what should be done. You need two separate tags one on whole battle object and another on item, and on item creation init tag on battle object.

Offline thusky

  • Sergeant
  • **
  • Posts: 29
    • View Profile
Re: [Question]Skip Player first turn (battlescape) per mission (boolean)
« Reply #10 on: October 13, 2023, 09:24:06 pm »
Thanks! With this I'll go in that direction then, I'll report back whenever I hit a hard wall, I'm likely gonna try and try again until it works.

Offline thusky

  • Sergeant
  • **
  • Posts: 29
    • View Profile
Re: [Solved]Skip Player first turn (battlescape) per mission (boolean)
« Reply #11 on: October 14, 2023, 02:51:04 am »
Thanks to you Yankes and Filip H from the I.D.T Discord server I learnt a lot and the script is complete!

This script sets the player's units to 0 TU on their first turn and back to their max TU on the enemy turn!

Best to place the dummy item to enable the script in aliendeployments.rul

The snippet:

Code: [Select]
#------Dummy item to place in the battlescape for the script to work
items:
  - type: STR_TURN_SKIP
    categories: [STR_LOGIC]
    tags:
      ITEM_SKIP_TAG: 1

# Script allowing Xcom: Rising from the deep to set the player's units TU to 0 in battlescape and let the unit regain TU for the second turn.
extended:
  tags:
    BattleGame:
      BATTLE_SKIP_TAG: int
    RuleItem:
      ITEM_SKIP_TAG: int

  scripts:
  #---If there is an item with skip first turn tag, then set the battlescape tag to skip first turn.
    createItem:
      - offset: 21
        code: |
          var int isSkipItem;
          var int battleGameObject;

          item.getTag isSkipItem Tag.ITEM_SKIP_TAG;

          if eq isSkipItem 1;
          battle_game.setTag Tag.BATTLE_SKIP_TAG 1;
          end;
          return;


  #---Check if it's the 1st turn, check if the units are from the player, check if the dummy item is present on the map, then set the units to 0 TU, enemy turn set them to their max TU.
    newTurnUnit:
      - offset: 22
        code: |
          var int isPlayerUnit;
          var int maxUnitTu;
          var int isEnemyTurn;
          var int battleGameObject;

          unit.getFaction isPlayerUnit;
          unit.getTimeUnitsMax maxUnitTu;
          battle_game.getTurnSide isEnemyTurn;
          battle_game.getTag battleGameObject Tag.BATTLE_SKIP_TAG;

          if eq turn 1;
            if eq battleGameObject 1;
              if eq isPlayerUnit 0;
              unit.setTimeUnits 0 ;
                if eq isEnemyTurn 1;
                unit.setTimeUnits maxUnitTu;
                end;
              end;
            end;
          end;
          return;

PS:
Again this script wouldn't have been possible without you guys, thank you so much!