Victoria 3

Victoria 3

Infamy Bank
Script optimizations
Hello, I did some tweaking on the script for my game and though I might share it for you if you want to integrate it.

The main changes are:
  • The `immediate` clause sets the variable to zero, instead of 10. It previously caused interference with the progress bar, as the min / max values are only evaluated once after the immediate clause. As the old clause initialized the variable to 1, the min on the progress bar was set to 1, instead of 0.
  • The "infamy" withdrawal logic from the bank has been simplified to a single `if` condition that calculates the amount of infamy above 10, and attempts to withdraw as much, clamped to the total amount of saved infamy. This allows precise pulls instead of in chunks of 10 up to 50. If needed it can be clamped further.
  • The variable `infamy_bank_var` has been modified to store the precise number of saved infamy, instead of in multiples of 10. This is semi-save compatible. It will reduce the amount of previously saved infamy 10 fold due to the change in scale.

Take care.

Script file: https://gist.github.com/Dimi1010/da7bea4911e6f4fded8406bf6b6f833c

Important parts of the script:

Immediate effect:
immediate = { set_variable = { name = infamy_bank_var value = 0 } }

Monthly pulse:
on_monthly_pulse = { effect = { if = { limit = { infamy < 5 } change_variable = { name = infamy_bank_var add = 10 } change_infamy = 10 } else_if = { limit = { infamy > 15 var:infamy_bank_var > 0 } set_local_variable = { name = infamy_reduction # If the infamy is above 15, it should be reduced until it reaches 10 again or until the bank is empty. value = { # The amount of infamy above 10. add = infamy subtract = 10 # Clamps the value to the amount of infamy in the bank. max = var:infamy_bank_var } } change_infamy = { subtract = local_var:infamy_reduction } change_variable = { name = infamy_bank_var subtract = local_var:infamy_reduction } } } }
Last edited by Dimi; 12 hours ago