Scripting question(s)

Users who are viewing this thread

nightstormer

Regular
I am new to Python and Warband, but I am not new to scripting as a concept as I have done mods for other games before. Though, I find it wee bit harder to get used to Python but I guess that's something I will overcome. But....I decided to start with something apparently simple, as I've read people have done it with M&B. I want to add a simple trigger to make Mills add 5% every month and not just one time. I know it has already been done, but I can't seem to find any code for it, so I do this for learning purposes and humbly ask the people here which approach (if any) is correct.

I have used the #Schools entry as a template, in simple_triggers

First option:

Code:
# Mill
  (30 * 24,
   [(try_for_range, ":cur_village", villages_begin, villages_end),
      (party_slot_eq, ":cur_village", slot_town_lord, "trp_player"),
      (party_slot_eq, ":cur_village", slot_center_has_fish_pond, 1),
      (party_get_slot, ":prosperity", ":cur_village", slot_town_prosperity),
      (val_add, ":prosperity", 5),
      (val_min, ":prosperity", 100),
      (party_set_slot, ":cur_village", slot_town_prosperity, ":prosperity"),
    (try_end),
    ]),

I am not sure, but I feel this would just add 5 every month and not 5% so next option was this:

Code:
# Mill
  (30 * 24,
   [(try_for_range, ":cur_village", villages_begin, villages_end),
      (party_slot_eq, ":cur_village", slot_town_lord, "trp_player"),
      (party_slot_eq, ":cur_village", slot_center_has_fish_pond, 1),
      (party_get_slot, ":prosperity", ":cur_village", slot_town_prosperity),
      (val_div, ":prosperity", 100),
      (val_mul, ":prosperity", 5),
      (val_min, ":prosperity", 100),
      (party_set_slot, ":cur_village", slot_town_prosperity, ":prosperity"),
    (try_end),
    ]),

In my mind, at the moment, it looks like it divides the current prosperity by 100 and multiplies that with 5. Which sounds better, but I am not familiar with how this game handles the numbers, yet.

Also, as I used #Schools as a template I still have (val_min, ":prosperity", 100), there, but I am not quite sure if it is needed or what it does?

I am sorry if this is a very trivial question, but I really would like to learn how to write scripts and mod this excellent game. I look forward, and hope, to any feedback anyone can offer. :smile:
 
GetAssista said:
X -> 0.05X  is what you coded in. Not an addition of 5%
Besides vanilla prosperity is 0-100 so add 5 is equivalent to 5% increase

So basically option one is the correct one then?
 
GetAssista said:
Oh, wait, I thought that first option was vanilla :grin:
If it is copied from vanilla templates exactly, then yes, it is the right one.

Hehe, yeah well it is the #School part adapted :smile:  But, what does the 'val_min' do for this script, or any, really? Does it need to be set as a minimum value? If I have interpreted it correctly, which is quite possible I have not. I would've rather reckoned it would've been a max-value instead, in my logic. But I am used to a slightly different, perhaps simpler, scripting language.

And, is it not possible to use a 'real' 5 % growth and/or does the game have problems with decimals and not round up/down?

I will use this thread only for my questions, so I don't clutter the board. I was looking through the modules trying to find where 'Move up' and 'Move down' buttons are controlled when you sort your army. I was hoping to duplicate it for garrisons, as I more often than not would like to sort them as well depending on what I am facing. Perhaps I can't see the forest for all the trees here, but if anyone could point me in the right direction I'd be happy. :smile:

I must say, even I am just at the very early stages of learning to script this game I am very excited as it seems the possibilities are close to endless.
 
"val_min" take the smaller of the two numbers and save it (in the variable).
(val_min, ":prosperity", 100),
in a way, it prevents prosperity from going over 100.

"val_max" will save the bigger of the 2 numbers.

And, is it not possible to use a 'real' 5 % growth and/or does the game have problems with decimals and not round up/down?
I'm not sure. The value saved might be real, but the presentation number will be rounded up.
 
Back
Top Bottom