Author Topic: Limiting Stat Gains with scripting  (Read 690 times)

Online Nirran

  • Captain
  • ***
  • Posts: 94
    • View Profile
Limiting Stat Gains with scripting
« on: October 29, 2023, 10:47:58 am »
hello

       im trying to limit stam tu and hp gains,unfortunatly this script snip doesnt work,and way of doing this with scripting some other way or with a rul file?

Code: [Select]
          #limit TimeUnits
          statChange.getTimeUnits changeTimeUnits; #how much TimeUnits was incresed by exp
          soldier.Stats.getTimeUnits origTimeUnits; #current TimeUnits (alredy with bonsu value from exp)
          battle_game.randomRange value valueMin valueMax;
          add currTimeUnits value; #effective 1-2 points
          soldier.Stats.setTimeUnits currTimeUnits;  
         
          #limit Stamina
          statChange.getStamina changeStamina; #how much Stamina was incresed by exp
          soldier.Stats.getStamina origStamina; #current Stamina (alredy with bonsu value from exp)
          battle_game.randomRange value valueMin valueMax;
          add currStamina value; #effective 1-2 points
          soldier.Stats.setStamina currStamina;

          #limit Health
          statChange.getHealth changeHealth; #how much Health was incresed by exp
          soldier.Stats.getHealth origHealth; #current Health (alredy with bonsu value from exp)
          battle_game.randomRange value valueMin valueMax;
          add currHealth value; #effective 1-2 points
          soldier.Stats.setHealth currHealth;

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8597
    • View Profile
Re: Limiting Stat Gains with scripting
« Reply #1 on: October 29, 2023, 01:57:44 pm »
Here's a simple example to set your custom TU increase after a mission:

Code: [Select]
extended:
  scripts:
    returnFromMissionUnit:
      - offset: 10
        code: |
          var int statFromGame;
          var int statFromGameDiff;
          var int statByModder;

          soldier.Stats.getTimeUnits statFromGame;   # new soldier TU
          statChange.getTimeUnits statFromGameDiff;  # how much TU was gained this mission

          set statByModder statFromGame;             # let's take the new soldier TU
          sub statByModder statFromGameDiff;         # and remove the gain to get the old soldier TU
          add statByModder 42;                       # add whatever custom amount you want

          soldier.Stats.setTimeUnits statByModder;   # set the newly calculated amount
          return;

This is just for illustration, in a real script, you will need to consider stat caps, whether any experience was gained or not, etc.

Online Nirran

  • Captain
  • ***
  • Posts: 94
    • View Profile
Re: Limiting Stat Gains with scripting
« Reply #2 on: October 29, 2023, 10:12:39 pm »
Here's a simple example to set your custom TU increase after a mission:

Code: [Select]
extended:
  scripts:
    returnFromMissionUnit:
      - offset: 10
        code: |
          var int statFromGame;
          var int statFromGameDiff;
          var int statByModder;

          soldier.Stats.getTimeUnits statFromGame;   # new soldier TU
          statChange.getTimeUnits statFromGameDiff;  # how much TU was gained this mission

          set statByModder statFromGame;             # let's take the new soldier TU
          sub statByModder statFromGameDiff;         # and remove the gain to get the old soldier TU
          add statByModder 42;                       # add whatever custom amount you want

          soldier.Stats.setTimeUnits statByModder;   # set the newly calculated amount
          return;

This is just for illustration, in a real script, you will need to consider stat caps, whether any experience was gained or not, etc.

tyvm Meridian,got it working!

Online Nirran

  • Captain
  • ***
  • Posts: 94
    • View Profile
Re: Limiting Stat Gains with scripting
« Reply #3 on: October 30, 2023, 10:07:45 pm »
This is just for illustration, in a real script, you will need to consider stat caps, whether any experience was gained or not, etc.

alright,does a method exist to return the .rul stat caps with a script?

and thnx for ur help again dude

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8597
    • View Profile
Re: Limiting Stat Gains with scripting
« Reply #4 on: October 31, 2023, 09:20:42 am »
alright,does a method exist to return the .rul stat caps with a script?

yes

Online Nirran

  • Captain
  • ***
  • Posts: 94
    • View Profile
Re: Limiting Stat Gains with scripting
« Reply #5 on: November 01, 2023, 03:51:33 am »
yes

thnx again

can point me to scripting .rul file docs?

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8597
    • View Profile
Re: Limiting Stat Gains with scripting
« Reply #6 on: November 01, 2023, 12:13:19 pm »
If you want to know full list of operations in script you need enable verbose logging in config, with this script will dump all meta information about every script hook to logs.

Online Nirran

  • Captain
  • ***
  • Posts: 94
    • View Profile
Re: Limiting Stat Gains with scripting
« Reply #7 on: November 01, 2023, 08:48:40 pm »
im friggin blind sometimes,sorry if i annoyed