Author Topic: checking tithes available in owned fiefs  (Read 645 times)

0 Members and 1 Guest are viewing this topic.

ssallen

  • Regular
  • *
    • View Profile
  • Faction: Neutral
checking tithes available in owned fiefs
« on: August 16, 2008, 04:41:34 PM »
Hello everyone,

I read a message a couple weeks ago about creating a "tax collector" of sorts for collecting your tithes.  I haven't mod'd M&B before so I thought this might be a small starter project to get my feet wet.  I have successfully
added the new NPC in the game and have built his entire dialog set... my problem comes in when I want to check the individual fifes the character owns for the tithes available.  I am a fairly experienced coder - just not in Python.  It can be a strange little language when you come from C based languages. Anyways, I have located several scripts where the tithes are calculated, I just can't seem to find an easy way to access the center data.  Is there
a global (or at least public) list of center classes I can just loop through? I really just want to do this:

Code: [Select]
for i to length(towns)
  if town.ownd then
    money += town.taxes_collected
  end if
end for


It seems nothing can be that simple with this bizarre language. :)
Any ideas from you experienced guys to approach this?

Thanks!

KON_Air

  • Master Knight
  • *
    • View Profile
  • Faction: Neutral
  • MP nick: KON_Air
  • M&BWB
Re: checking tithes available in owned fiefs
« Reply #1 on: August 16, 2008, 11:54:51 PM »
Code: [Select]
for i to length(towns)
  if town.ownd then
    money += town.taxes_collected
  end if
end for


Hmm... I needed something like that...

let's roll the kopi/pasta machine

Code: [Select]
(try_for_range, ":current_town", centers_begin, centers_end),

          (party_slot_eq, ":current_town", slot_town_lord, "trp_player"),
          (party_get_slot, ":accumulated_rents", ":current_town", slot_center_accumulated_rents),
          (party_get_slot, ":accumulated_tariffs", ":current_town", slot_center_accumulated_tariffs),
          (store_add, ":total_tax", ":accumulated_rents", ":accumulated_tariffs"),
          (assign, reg1, ":total_tax"),
          (call_script, "script_troop_add_gold", "trp_player", ":total_tax"),
          (party_set_slot, ":current_town", slot_center_accumulated_rents, 0),
          (party_set_slot, ":current_town", slot_center_accumulated_tariffs, 0),

(try_end),

Will give all the tariffs and rents from all owned fiefs. (castles, towns and villages).
Comparing Fallout 3 and 1-2 is like comparing an apple to a mutated apple which is trying to bite your face.

KON_Air

  • Master Knight
  • *
    • View Profile
  • Faction: Neutral
  • MP nick: KON_Air
  • M&BWB
Re: checking tithes available in owned fiefs
« Reply #2 on: August 17, 2008, 12:17:40 AM »
Argh... Double Post...

Okay, that script is not what you want, it seems I have subconsiously dismissed the horror of going into dialouges.

Here is what you need,

Code: [Select]
[anyone|plyr|repeat_for_parties,"list_fiefs_owned_to_tax", [
(store_repeat_object, ":center_no"),
(this_or_next|party_slot_eq,":current_town",slot_party_type, spt_castle),
(this_or_next|party_slot_eq,":ccurrent_town",slot_party_type, spt_town),
(party_slot_eq,":current_town",slot_party_type, spt_village),
(neq, ":current_town", "$g_encountered_party"), #given you auto collect whenever you enter a fief
(party_slot_eq, ":current_town", slot_town_lord, "trp_player"),
(str_store_party_name, s1, ":current_town"),
(party_get_slot, ":accumulated_rents", ":current_town", slot_center_accumulated_rents),
(party_get_slot, ":accumulated_tariffs", ":current_town", slot_center_accumulated_tariffs),
(store_add, ":total_tax", ":accumulated_rents", ":accumulated_tariffs"),
(gt, ":total_tax", 0),
(str_store_string, s2, ":total_tax")
],
   "Go collect taxes from {s1}, they should pay {s2}.", "list_fiefs_owned_to_tax_execute",[(store_repeat_object, "$fief_to_tax")]],

This will list dialouge options for every fief owned that has taxes greater then 0.

Code: [Select]
[anyone,"list_fiefs_owned_to_tax_execute", [(str_store_party_name, 1, "$fief_to_tax")],
"Very well, I'll collect taxes from {s1}.", "another_dialouge_state",
[(call_script, "script_collect_taxes", "$fief_to_tax")... or something else...]],

This is next the step for any of the listed options with $fief_to_tax is the fief from the list as a global variable...

Should work... I guess...
Comparing Fallout 3 and 1-2 is like comparing an apple to a mutated apple which is trying to bite your face.

ssallen

  • Regular
  • *
    • View Profile
  • Faction: Neutral
Re: checking tithes available in owned fiefs
« Reply #3 on: August 17, 2008, 01:45:14 AM »
Thanks for the help!

As kind of a learning example could you take a look at the following (try to avoid spewing a beverage out your nose during the ensuing laughing fit) and tell me where I went wrong?  I'm not entirely sure if I should be abusing the registers like this but, well, yeah... :)

Code: [Select]
(troop_slot_eq, "$g_talk_troop", slot_troop_met_previously, 2),
], "Good day to you, {your immenseness/your girthiness}.", "pillbus_collect_1",[
(call_script, "script_get_number_of_hero_centers", "trp_player"),
(assign, ":no_centers", reg0),
(assign, reg10, 0),
(assign, reg11, 0),
(try_begin),
(gt, ":no_centers", 0),
(try_for_range, ":i_center", 0, ":no_centers"),
(assign, ":total_tax", 0),
(call_script, "script_troop_get_leaded_center_with_index", "trp_player", ":i_center"),
(assign, ":cur_center", reg0),
(str_store_party_name, s12, ":cur_center"),
(assign, s66, s12),
(str_clear, s3),
(try_begin),
(party_slot_eq, s66, slot_town_lord, "trp_player"),
(party_get_slot, ":accumulated_rents", s66, slot_center_accumulated_rents),
(party_get_slot, ":accumulated_tariffs", s66, slot_center_accumulated_tariffs),
(store_add, ":total_tax", ":accumulated_rents", ":accumulated_tariffs"),
(assign, reg1, ":total_tax"),
(val_mul, reg13, reg1, .2),
(try_begin),
(gt, reg13, 50),
##### (val_add, reg11, round(reg13, 0)),
##### (val_sub, ":total_tax", round(reg13, 0)),
(val_add, reg11, reg13),
(val_sub, ":total_tax", reg13),
(party_set_slot, s66, slot_center_accumulated_rents, 0),
(party_set_slot, s66, slot_center_accumulated_tariffs, 0),
(else_try),
(lt, reg1, 50),

(else_try),
(val_sub, ":total_tax", 50),
(val_add, reg11, 50),
(party_set_slot, s66, slot_center_accumulated_rents, 0),
(party_set_slot, s66, slot_center_accumulated_tariffs, 0),
(try_end),

(try_end),
(val_add, reg10, ":total_tax"),
(str_store_string, s9, reg10),
(try_begin),
(eq, ":i_center", 0),
(str_store_party_name, s8, ":cur_center"),
(else_try),
(eq, ":i_center", 1),
(str_store_party_name, s7, ":cur_center"),
(str_store_string, s8, "@{s7} and {s8}"),
(else_try),
(str_store_party_name, s7, ":cur_center"),
(str_store_string, s8, "@{s7}, {s8}"),
(try_end),
(try_end),
(add_gold_to_party, "trp_player", reg10),
(try_end), ]],

Some of it is completely inane because I got the idea that it wasn't converting to strings properly.  The rest is inane because I'm an idiot apparently. :)

Friggin Python...

Thanks again!  Seriously.
« Last Edit: August 17, 2008, 01:56:37 AM by ssallen »

KON_Air

  • Master Knight
  • *
    • View Profile
  • Faction: Neutral
  • MP nick: KON_Air
  • M&BWB
Re: checking tithes available in owned fiefs
« Reply #4 on: August 17, 2008, 06:14:37 PM »
I didn't read all of it but here is your first problem;
script_get_number_of_hero_centers gives the NUMBER of centers owned by hero, not the NUMERIC VALUE of said centers from ID_Parties.
Thus;
(try_for_range, ":i_center", 0, ":no_centers"),
tries NUMERIC VALUES between 0 and ":no_center", which in turn is a completely unrelated stack (see ID_parties).

usage of s66 wrong, since they are string registers, not global or local :P Try to stay away from Reg(x) and Regx unless you are editing something that already uses it. I recommend using ":local" and "$global" variables, makes easier to track.

And there is a stupid mistake on my example,
Code: [Select]
[anyone|plyr|repeat_for_parties,"list_fiefs_owned_to_tax", [
(store_repeat_object, ":center_no"),
(this_or_next|party_slot_eq,":current_town",slot_party_type, spt_castle),
(this_or_next|party_slot_eq,":ccurrent_town",slot_party_type, spt_town),
... bla bla...

Should be;

Code: [Select]
[anyone|plyr|repeat_for_parties,"list_fiefs_owned_to_tax", [
(store_repeat_object, ":current_town"),
(this_or_next|party_slot_eq,":current_town",slot_party_type, spt_castle),
(this_or_next|party_slot_eq,":ccurrent_town",slot_party_type, spt_town),
... bla bla...
Comparing Fallout 3 and 1-2 is like comparing an apple to a mutated apple which is trying to bite your face.