Author Topic: Python script/scheme/source exchange  (Read 20592 times)

Yoshiboy

  • Guest
Python script/scheme/source exchange
« on: January 12, 2007, 01:21:20 PM »
This topic is for posting any python code that you wish to share with other modders. Code posted will be added to this first post for others to use.

Mod Sources

(please note that some mod sources may be out of date)

Recruit from your prisoners

Dead Of Dunharrow

Craftmod

Pirates!

Maw's murder mod

Fantasy Mod

The Island

Dionsia

Darkmod

Knights and Merchants

Guardians Mod

H&B 808c

If your source is not here (i've missed it or something) and you would like me to add it just PM me or post in this thread.

Other Pyton Scripts

By Popular request: The Calendar script!
This was written for .711, but the format hasn't changed any, so it should be .730/.731 friendly

The solar year version:

Code: [Select]
(0.0, 0, ti_once, [], [(assign,"$day",1), (assign,"$month",7), (assign,"$year",1)]),

(0.0, 24, 0, [(lt, "$day", 31)], [(val_add,"$day",1)]),
(0.0, 0, 0.0, [(eq,"$day",31),(lt,"$month",13)], [(val_add,"$month",1), (assign,"$day",1)]),
(0.0, 0, 0.0, [(eq,"$month",13)], [(val_add,"$year",1), (assign,"$month",1)]),

and the lunar year version:

Code: [Select]
(0.0, 0, ti_once, [], [(assign,"$day",1), (assign,"$month",7), (assign,"$year",1)]),

(0.0, 24, 0, [(lt, "$day", 29)], [(val_add,"$day",1)]),
(0.0, 0, 0.0, [(eq,"$day",29),(lt,"$month",14)], [(val_add,"$month",1), (assign,"$day",1)]),
(0.0, 0, 0.0, [(eq,"$month",14)], [(val_add,"$year",1), (assign,"$month",1)]),

The initial values of $day, $month, and $year can be whatever you want them to be. Enjoy!

EDIT: I also have a script that allows merchant-type characters to sell goods on the open market (so to speak) and not to city merchants, if any one is interested.

Code: [Select]
  [anyone,"prisoner_chat", [], "What? You've already put me in chains, what more do you want to do?", "prisoner_chat_2",[]],
  [anyone|plyr,"prisoner_chat_2", [], "Well, as it happens, you look rather tasty . . . Let's have a bite.", "prisoner_chat_3",[]],
  [anyone|plyr,"prisoner_chat_2", [], "Nothing.", "close_window",[]],
  [anyone,"prisoner_chat_3", [], "No! Nooooooooo!", "prisoner_chat_4",
[
(store_conversation_troop,reg(3)),
(remove_troops_from_prisoners,reg(3),1),
(try_begin),
(store_free_inventory_capacity,reg(4),"trp_player"),
(ge,reg(4),1),
(troop_add_item,"trp_player","itm_dried_meat"),
(end_try),
]],
  [anyone|plyr,"prisoner_chat_4", [], "There. Someone bring me my boning knife!", "close_window",[]],

Because the people in the Suggestions forum kept asking for it. Anyone who wants it, feel free.

Wastefully,
Winter

For conditionally adding Marnid and/or Borcha to a scene depending on if they're in your party:

Code: [Select]
(modify_visitors_at_site,"scn_<your scene here>"),
(reset_visitors),
(try_begin),
(main_party_has_troop,"trp_borcha"),
(set_visitor,<mission template entry number>,"trp_borcha"),
(end_try),
(try_begin),
(main_party_has_troop,"trp_marnid"),
(set_visitor,<different mission template entry number>,"trp_marnid"),
(end_try),

Electrically,
Winter

Python to make missions end when you reach a certain point on the map, regardless of whatever else is going on.  This is basically just the code already in Vanilla in the mission template for the "sneak into town" mission, it's just commented out (because it doesn't work, although that's probably not the reason it wasn't included.)

In mission_templates change this:
Code: [Select]
     
(0.1, 0, 0, [],
       [
#           (neg|main_hero_fallen),
#           (get_player_agent_no, reg(1)),
#           (agent_get_position, 1, reg(1)),
#           (entry_point_get_position,2,31),
#           (get_distance_between_positions, reg(10), 1, 2),
#           (lt, reg(10), 500), #Our distance to exit is less than 4m.
#           (jump_to_menu,"mnu_sneak_into_town_caught_ran_away"),
#           (finish_mission,1),
        ]),
    ],

To this:

Code: [Select]

#Set "$test_thirty_midgets" to something other than one prior to here;
#(ti_before_mission_start, 0, 0, [], [(assign,"$test_thirty_midgets",0)]),
#works well.

    (0.1, 0, 0, [(neg|main_hero_fallen),(neq,"$test_thirty_midgets",1)],
       [
           #A Shameless Copy From Above
           (get_player_agent_no, reg(1)),
           (agent_get_position, 1, reg(1)),
           (entry_point_get_position,2,31),
           (get_distance_between_positions, reg(10), 1, 2),
           (lt, reg(10), 500), #Our distance to exit is less than 4m.
           (jump_to_menu,"mnu_frogs_taste_like_chicken"),
           (assign,"$test_thirty_midgets",1),
           (finish_mission,1),
        ]),
    ],


Basically, this just ends the mission if the player ever gets to within 4m of entry point number thirty-one, and initiates the indicated menu.  Not exactly original, as it's mostly just a shameless copy from native, but oh well.


I have edited this post in response to jamoecw's post below. Just like jamoecw states, the formula in http://forums.taleworlds.net/index.php/topic,8652.msg336742.html#msg336742 assumes the battlefield is square. This was intended as a feature since all of the battlefields in native I'm aware of are square, and the resulting formulas are a bit more elegant. Unfortunately the module system doesn't have an operator to calculate the square root so this "simplification" actually makes things more complicated... What I overlooked is that the first part of my simplified formula can also be used to calculate the x coordinate if a third entry point is used, and as a bonus the shape of the battle field does not matter.

Below is the updated the script like jamoecw suggested:

In order for this to work you need to place new entry points on the battlefield. This usually means modifying random_scene, used for all non-arena/trainer/seige battles in native that I am aware of. Simply place the three new entry points (numbered 20, 21 and 22 in my script) in the corners of random_scene in clockwise order from the player starting position (see crappy ASCII figure below).

Code: [Select]
21-------22
|         |
|         |
|  Start  |
|    *    |
20--------+

Code: [Select]
# Calculate the coordinates of $agent on the battle field
("triangulate",
[
  (agent_get_position,43,"$agent"), # P
  (entry_point_get_position,40,20), # A
  (entry_point_get_position,41,21), # B
  (entry_point_get_position,42,22), # C
 
  # Measure size of map
  (get_distance_between_positions,reg(6),40,41),  # A to B
  (get_distance_between_positions,reg(7),41,42),  # B to C
 
  # Measure distance to agent
  (get_distance_between_positions,reg(8),40,43),  # A to P
  (get_distance_between_positions,reg(9),41,43),  # B to P
  (get_distance_between_positions,reg(10),42,43), # C to P
 
  # ab^2
  (assign,reg(1),reg(6)),
  (val_mul,reg(1),reg(1)),
 
  # bc^2
  (assign,reg(2),reg(7)),
  (val_mul,reg(2),reg(2)),
 
  # ap^2
  (assign,reg(3),reg(8)),
  (val_mul,reg(3),reg(3)),
 
  # bp^2
  (assign,reg(4),reg(9)),
  (val_mul,reg(4),reg(4)),
 
  # cp^2
  (assign,reg(5),reg(10)),
  (val_mul,reg(5),reg(5)),
 
  # x = ( bc^2 - cp^2 + bp^2 ) / 2bc
  (assign,"$pos_x",reg(2)),
  (val_sub,"$pos_x",reg(5)),
  (val_add,"$pos_x",reg(4)),
  (val_mul,reg(7),2),
  (val_div,"$pos_x",reg(7)),
 
  # y = ( ab^2 - bp^2 + ap^2 ) / 2ab
  (assign,"$pos_y",reg(1)),
  (val_sub,"$pos_y",reg(4)),
  (val_add,"$pos_y",reg(3)),
  (val_mul,reg(6),2),
  (val_div,"$pos_y",reg(7)),
]),

Using this script it is possible to figure out the rough placement of units on the battlefield. I was hoping this could be used to steer enemy infantry units to the location they are needed the most, decide if they should cluster together or if they should attack at will, but I have not had the time to even begin to think about exactly how this would be done. But I have a feeling that, should this script actually be useful in any way, the community will find it.

Couldn't find it anywhere here, but I assume it's been done before by others. However, I just finished work on a script that lets you give money to heroes in your party, so they have no excuse for not paying you for the stuff you give them. I'm partway through testing, but it should work on both 0.751 and 0.806.

Increments (denars):
5
10
20
50
100
200
500
1000

Worked it out, oddly, by adapting the betting system and combining it with a small portion of Dionisia code. I can't entirely confirm that it works quite yet, but I'll post the code here and any holes you find can be fixed quickly. However, I can't see anything wrong with it - it should work.

Code: [Select]
  [anyone|plyr,"member_talk", [[store_troop_gold,reg(0)],[ge,reg(0),5]],
   "Here, let me give you some money to pay your way.", "member_money",[]],
  [anyone|plyr,"member_money", [[store_troop_gold,reg(0)],[ge,reg(0),5]],
   "[Give five denars]", "member_finish_money",[(troop_add_gold,reg(3),5),(troop_remove_gold,"trp_player",5)]],
  [anyone|plyr,"member_money", [[store_troop_gold,reg(0)],[ge,reg(0),10]],
   "[Give ten denars]", "member_finish_money",[(troop_add_gold,reg(3),10),(troop_remove_gold,"trp_player",10)]],
  [anyone|plyr,"member_money", [[store_troop_gold,reg(0)],[ge,reg(0),20]],
   "[Give twenty denars]", "member_finish_money",[(troop_add_gold,reg(3),20),(troop_remove_gold,"trp_player",20)]],
  [anyone|plyr,"member_money", [[store_troop_gold,reg(0)],[ge,reg(0),50]],
   "[More]", "member_money_more",[]],
  [anyone|plyr,"member_money", [],
   "[Cancel]", "member_money_reconsider",[]],
  [anyone|plyr,"member_money_more", [[store_troop_gold,reg(0)],[ge,reg(0),50]],
   "[Give fifty denars]", "member_finish_money",[(troop_add_gold,reg(3),50),(troop_remove_gold,"trp_player",50)]],
  [anyone|plyr,"member_money_more", [[store_troop_gold,reg(0)],[ge,reg(0),100]],
   "[Give one hundred denars]", "member_finish_money",[(troop_add_gold,reg(3),100),(troop_remove_gold,"trp_player",100)]],
  [anyone|plyr,"member_money_more", [[store_troop_gold,reg(0)],[ge,reg(0),200]],
   "[Give two hundred denars]", "member_finish_money",[(troop_add_gold,reg(3),200),(troop_remove_gold,"trp_player",200)]],
  [anyone|plyr,"member_money", [[store_troop_gold,reg(0)],[ge,reg(0),500]],
   "[More]", "member_money_more_more",[]],
  [anyone|plyr,"member_money_more", [],
   "[Less]", "member_money",[]],
  [anyone|plyr,"member_money_more_more", [[store_troop_gold,reg(0)],[ge,reg(0),500]],
   "[Give five hundred denars]", "member_finish_money",[(troop_add_gold,reg(3),500),(troop_remove_gold,"trp_player",500)]],
  [anyone|plyr,"member_money_more_more", [[store_troop_gold,reg(0)],[ge,reg(0),1000]],
   "[Give one thousand denars]", "member_finish_money",[(troop_add_gold,reg(3),1000),(troop_remove_gold,"trp_player",1000)]],
  [anyone|plyr,"member_money_more_more", [],
   "[Less]", "member_money_more",[]],
  [anyone|plyr,"member_money_reconsider", [],
   "Actually, I reconsidered.", "member_talk",[]],
  [anyone|plyr,"member_finish_money", [],
   "I'm done for now.", "member_talk",[]],
  [anyone|plyr,"member_finish_money", [[store_troop_gold,reg(0)],[ge,reg(0),5]],
   "[Give more]", "member_money",[]],

Hmm... how about another version where you can take money from them? I might have to do that...


EDIT: Recruiting prisoners

This code I know for a fact works like a beauty. I know it's easy to figure out, but I thought I'd share it to save you the bother of working it out for yourself.

EDIT again: I've improved it again.
This will now work much better. It stores the conversation troop's relation with the player, then generates a number between that number and good relations. The prisoner will join you if that random number is above 0, so the worse their relation with you, the wider the range for the random number, so the less likely it is to be between 0 and 3.

EDIT: It seems to be unstable. Best to leave it until I fix it.

EDIT once more: Wasn't the problem, but fisheye pointed out a slight niggle that I've now fixed. Should now work perfectly. Enjoy.

Code: [Select]
  [anyone|plyr,"prisoner_chat", [[store_conversation_troop,reg(2)],[store_troop_faction,reg(3),reg(2)],[store_relation,reg(4),reg(3),"fac_player_faction"]], "Don't try running away or trying something stupid. I will be watching you.", "prisoner_chat_2",
   [[store_random_in_range,reg(5),reg(4),4]]],
  [anyone,"prisoner_chat_2", [], "No, I swear I won't.", "prisoner_chat_3",[]],
  [anyone|plyr,"prisoner_chat_3", [], "Good. You're not stupid like the rest of these scum.", "prisoner_chat_4",[]],
  [anyone|plyr,"prisoner_chat_4", [], "[End the conversation]", "prisoner_chat_5",[]],
  [anyone|plyr,"prisoner_chat_5", [], "I hope you're looking forward to life as a slave, scum.", "close_window",[]],
  [anyone|plyr,"prisoner_chat_4", [], "[Try to recruit the prisoner]", "prisoner_chat_6",[]],
  [anyone|plyr,"prisoner_chat_6", [], "Listen, scum, you have one last chance to redeem yourself before I sell you to the slave-traders.\
  Drop all your previous allegiances and swear to fight for me and obey my every order to the letter, and you'll be paid, fed and equipped.\
   If you don't....well, let's just say that life as a slave will be seemingly unending years of agony, malnutrition and beatings.\
   I'd advise you to think very, very carefully before refusing.", "prisoner_chat_7",[]],
  [anyone,"prisoner_chat_7", [[lt,reg(5),0]], "I'll show you what I think of your offer! (The prisoner spits at your feet) There. Now get lost, I'm not interested.", "prisoner_chat_8",[]],
  [anyone|plyr,"prisoner_chat_8", [], "[Kill the prisoner]", "prisoner_chat_14",[]],
  [anyone|plyr,"prisoner_chat_8", [], "[Sell the prisoner]", "prisoner_chat_10",[]],
  [anyone|plyr,"prisoner_chat_9", [], "(You advance on the prisoner with your weapon drawn)", "prisoner_chat_11",[]],
  [anyone|plyr,"prisoner_chat_4", [], "[Kill the prisoner]", "prisoner_chat_9",[]],
  [anyone|plyr,"prisoner_chat_10", [], "We have found a roaming slave trader. It's time for us to part ways. Goodbye, it was nice not to know you.", "close_window",
   [[store_conversation_troop,reg(2)],[remove_troops_from_prisoners,reg(2),1],[troop_add_gold,"trp_player",20]]],
  [anyone,"prisoner_chat_11", [], "Please, {sir/madam}, don't kill me. I am a defenceless prisoner. Surely you're not that cruel?", "prisoner_chat_12",[]],
  [anyone|plyr,"prisoner_chat_12", [], "[Kill the prisoner]", "prisoner_chat_13",[]],
  [anyone|plyr,"prisoner_chat_13", [], "Yes, idiot. I am that cruel. Prepare to die.", "prisoner_chat_14",[]],
  [anyone|plyr,"prisoner_chat_14", [], "(The prisoner struggles against his shackles, desperate to free himself and escape you, but to no avail. You slit his throat with a knife and watch, satisfied, as his corpse sags to the floor.)", "close_window",
   [[store_conversation_troop,reg(2)],[remove_troops_from_prisoners,reg(2),1]]],
  [anyone|plyr,"prisoner_chat_12", [], "[Let him live]", "prisoner_chat_15",[]],
  [anyone|plyr,"prisoner_chat_15", [], "Very well, I'll let you live. I hope you enjoy life as a slave.", "prisoner_chat_16",[]],
  [anyone,"prisoner_chat_16", [], "Oh, thank you, {sir/madam}.", "close_window",[]],
  [anyone,"prisoner_chat_7", [[ge,reg(5),0]], "Thank you for your mercy, {sir/madam}. I promise to drop all allegiances to serve you in any way I can.","prisoner_chat_17",[]],
  [anyone|plyr,"prisoner_chat_17", [], "Good. Now, I'll make the rules clear to you. There will be no discrimination against other soldiers in my army because they were once on the opposing side or were bandits. They fight for me now, as do you. Their ties with the past are broken. Think you can handle it?", "prisoner_chat_18",[]],
  [anyone,"prisoner_chat_18", [], "Yes, {sir/madam}. I will obey the rules.", "prisoner_chat_19",[]],
  [anyone|plyr, "prisoner_chat_19", [[neg|hero_can_join]],"Oh. There isn't enough room in my party for you. I will be back when I have made room.", "close_window",
   [[store_conversation_troop,reg(0)],[troop_set_slot,reg(0),slot_prisoner_agreed,1]]],
  [anyone|plyr, "prisoner_chat_19", [[hero_can_join]], "Excellent. From now on, you fight alongside these men. Help them when they need it, and they'll do the same for you. Get equipped and fed. We'll head out as soon as you're done.", "close_window",
   [[store_conversation_troop,reg(0)],[troop_join,reg(0)],[remove_troops_from_prisoners,reg(0),1]]],
  [anyone|plyr,"prisoner_chat", [[store_conversation_troop,reg(0)],[troop_get_slot,reg(1),reg(0),slot_prisoner_agreed],[eq,reg(1),1],[hero_can_join]], "All right, I have made room for you to join my party. Welcome aboard.", "close_window",
   [[store_conversation_troop,reg(0)],[troop_join,reg(0)],[remove_troops_from_prisoners,reg(0),1]]],
  [anyone|plyr,"prisoner_chat", [[store_conversation_troop,reg(0)],[troop_get_slot,reg(1),reg(0),slot_prisoner_agreed],[neg|reg(1),1],[eq,hero_can_join]], "I am sorry, I still have no room for you. You'll have to wait a while longer, I'm afraid.", "close_window",[]],

Here is a little trick for "try_for_range". For example, you want to check all Heroes for a condition. You need a try_for_range for the first hero in module_troops.py to the last hero. Put all of the Heroes between two fake hero records ("first_npc" and "last_npc"):

Code: [Select]
["first_npc","First NPC","First NPC",tf_female|tf_hero, 0, reserved, .......
["Marnid","Marnid","Marnid", tf_hero, scn_the_happy_boar|entry(4),reserved, .......
["borcha","Borcha","Borcha",tf_hero, scn_town_13_castle|entry(6),reserved, .......
["ymira","Ymira","Ymira",tf_female|tf_hero, scn_zendar_merchant_ymira|entry(1), reserved, .......

# Add more Heroes here.

["last_npc","Last NPC","Last NPC",tf_female|tf_hero, 0, reserved, .......

Now, you can safely use in your scripts the following:
Code: [Select]
(try_for_range,":this_hero","trp_first_npc","trp_last_npc"),
# Your code here.
(end_try,0),

No matter how many Heroes you add, just add them between trp_first_npc and trp_last_npc and your code will continue to work. You can also simplify this further by adding into header_operations.py the following:
Code: [Select]
try_for_heroes = try_for_range,":this_hero","trp_first_npc","trp_last_npc"

Then, you can simply try for a the range of Heroes like this:
Code: [Select]
(try_for_heroes),
    # Your code here.
    # The local variable ":this_hero" is still useable!
(end_try,0),

Follow the same principle anywhere you want to easily categorize your code. For example, you can make a try_for_blunts, try_for_armor, try_for_swadian_towns, etc, etc.

Script (v0.8xx) to match a horse to his rider during combat.

This code is for Schattenlander, so I know in advance that my party size is max 5 and that they'll all be companions.  If you're interested in checking for a different subset of characters, or just the PC or whatever, obviously those details will need to be changed.  In this case the code is being created to record whether a companion dismounted during the fight, or fought on horse; we check advancement for different skills in the two cases.  You'll see that in the <fought_mounted> slot setting on the PC.  Depending on your application a different record may need to be created.

In module_scripts.py:
Code: [Select]
("associate_PCs_with_their_horses",  # Need this to find out if they fought mounted or not.  Call within the mission template, time zero, ti_once.
[
(try_for_range, ":Char", 0, 5),  # Schattenlander party stacks - one per character as they're all companions.
(party_stack_get_troop_id, ":Rider", "p_main_party", ":Char"),  # Get the actual troop IDs of the member in that spot in the party.
(ge, ":Rider", 0),  # Break out now if there's no one in that spot in the party.

(try_for_agents, ":CheckThisAgent"),
(agent_get_troop_id, ":CheckThisID", ":CheckThisAgent"),
(eq, ":Rider", ":CheckThisID"),
(assign, ":RiderAgent", ":CheckThisAgent"),
(try_end),
(agent_set_slot, ":RiderAgent", 12, -1),  # Slot 12 on the agent is used to record their steed's agent-ID.

(troop_set_slot, ":Rider", fought_mounted, 0),
(try_for_range, ":Horse", horses_begin, horses_end),
(troop_has_item_equipped, ":Rider", ":Horse"),
(troop_set_slot, ":Rider", fought_mounted, 1),
(try_end),
(troop_slot_eq, ":Rider", fought_mounted, 1),

(agent_get_position, 10, ":RiderAgent"),
(try_for_agents, ":CheckThisHorse"),
(neg|agent_is_human, ":CheckThisHorse"),
(agent_get_position, 11, ":CheckThisHorse"),
(get_distance_between_positions, ":Dist", 10, 11),
(lt, ":Dist", 1),
(agent_set_slot, ":RiderAgent", 12, ":CheckThisHorse"),
(try_end),
(try_end),
]),

("check_if_PCs_are_mounted",  # Call this from a trigger within the mission template, time 5 (or thereabouts).
[
(try_for_range, ":Char", 0, 5),
(party_stack_get_troop_id, ":Rider", "p_main_party", ":Char"),
(ge, ":Rider", 0),
(troop_slot_eq, ":Rider", fought_mounted, 1),

(try_for_agents, ":CheckThisAgent"),
(agent_get_troop_id, ":CheckThisID", ":CheckThisAgent"),
(eq, ":Rider", ":CheckThisID"),
(assign, ":RiderAgent", ":CheckThisAgent"),
(try_end),

(agent_get_slot, ":RidersHorse", ":RiderAgent", 12),  # Agent ID of the character's horse, from script "associate_PCs_with_their_horses"
(try_begin),
(ge, ":RidersHorse", 0),
(agent_get_position, 10, ":RiderAgent"),
(agent_get_position, 11, ":RidersHorse"),
(get_distance_between_positions, ":Dist", 10, 11),
(gt, ":Dist", 10),  # Nice generous 10cm margin to handle unusual cases.
(troop_set_slot, ":Rider", fought_mounted, 0),
(try_end),
(try_end),
]),

In module_constants.py you'll need values for horses_begin, horses_end, and fought_mounted.  I assume if you're able to make any use at all of this script that you'll know exactly how to set those up.  Watch for overlap between fought_mounted and any other modding of your troops' slots.

In module_mission_templates.py, in each mission form where you want to measure this (lead_charge, charge_with_allies, others as required), in the triggers section of the mission add:
Code: [Select]
(0, 0, ti_once, [],[(call_script, "script_associate_PCs_with_their_horses")]),
(5, 0, 0, [], [(call_script, "script_check_if_PCs_are_mounted")]),

The basic revelation here, from testing, is that a rider's agent position and his horse's agent position are identical - they're 0cm apart.


Here is a way to avoid showing the tutorial question in your mod. Simply replace the "tutorial_question" menu entry with the following:

Code: [Select]
  (
    "tutorial_question",mnf_auto_enter,
    "Starting the game. Please wait.",
    "none",
    [
    ],
    [
      ("tutorial_question_no",[],"_",[(change_screen_return)]),
    ]
  ),

Programmatically,
Winter

Script for sorting a given troop's inventory by price.

Usage example: (call_script, "script_sort_inventory", "trp_temp_troop"),

Note: "script_get_item_imod" gets the imod of an item given the item's ID and modified price. The details of that is left as an exercise for the reader. (Hint: read this post: http://mbx.streetofeyes.com/index.php?topic=50.0)

Code: [Select]
("sort_inventory", [
(store_script_param_1, ":source_troop"),

(troop_get_inventory_capacity, ":inv_cap", ":source_troop"),
(assign, ":num_items", 0),
# record the item IDs
(try_for_range, ":i_slot", 0, ":inv_cap"),
(troop_get_inventory_slot, ":item_id", ":source_troop", ":i_slot"),
(ge, ":item_id", 0),
(troop_set_slot, "trp_temp_array_a", ":num_items", ":item_id"),
(val_add, ":num_items", 1),
(try_end),
(assign, ":total_cost", 0),
# remove items and record the costs
(try_for_range, ":i_slot", 0, ":num_items"),
(troop_get_slot, ":item_id", "trp_temp_array_a", ":i_slot"),
(troop_remove_items, ":source_troop", ":item_id", 1),
(assign, ":item_cost", reg0),
(val_add, ":total_cost", ":item_cost"),
(troop_set_slot, "trp_temp_array_b", ":i_slot", ":item_cost"),
(end_try),
# bubble-sort by cost
(try_for_range, ":i_slot", 1, ":num_items"),
(try_for_range_backwards, ":j_slot", ":i_slot",":num_items"),
(try_begin),
(store_sub, ":prev_slot", ":j_slot", 1),
(troop_get_slot, ":item_cost_j", "trp_temp_array_b", ":j_slot"),
(troop_get_slot, ":item_cost_prev", "trp_temp_array_b", ":prev_slot"),
(lt, ":item_cost_prev", ":item_cost_j"),
# out of order; do the swap
(troop_set_slot, "trp_temp_array_b", ":j_slot", ":item_cost_prev", ),
(troop_set_slot, "trp_temp_array_b", ":prev_slot", ":item_cost_j"),
(troop_get_slot, ":item_id_j", "trp_temp_array_a", ":j_slot"),
(troop_get_slot, ":item_id_prev", "trp_temp_array_a", ":prev_slot"),
(troop_set_slot, "trp_temp_array_a", ":j_slot", ":item_id_prev", ),
(troop_set_slot, "trp_temp_array_a", ":prev_slot", ":item_id_j"),
(try_end),
(try_end),
(try_end),
# replace them on the troop, most expensive first
(try_for_range, ":i_slot", 0, ":num_items"),
(troop_get_slot, ":item_id", "trp_temp_array_a", ":i_slot"),
(troop_get_slot, ":item_cost", "trp_temp_array_b", ":i_slot"),
(call_script, "script_get_item_imod", ":item_id", ":item_cost"),
# reg0 is imod
(troop_add_item, ":source_troop", ":item_id", reg0),
(try_end),
(assign, reg0, ":total_cost"),
]),


Not Python, exactly, but a trick worth showing people.  Extremely useful, even if you're not tearing down and rebuilding the skill system as heavily as I have.

Renaming a skill.
(Giving it new statistical effects, and living with or negating its old ones, is up to you.)
Same technique can be used to rename a currency, alter hints, and so forth.

With thanks to Highlander & Fisheye.

1) Open M&B, start a game (any mod or Native). Use Alt+Enter to put M&B into windowed mode.
2) Off the toolbar, select File > New Language.
3) This creates the subdirectory "/new language" off your M&B directory.  It's got all kinds of tasty things in there, all in csv (comma-separated-value, basically a text spreadsheet) format.
4) Under your mod, create the subdirectory "MyMod/languages/en".  Anything in here will be seen by all English-language players.  Obviously you can repeat this technique for other languages, too.
5) Copy some or all of the files from "/new language" into your new English-language directory.  If renaming skills, you want (surprise, surprise) skills.csv.
6) Edit the stuff on any line after the | character to whatever you want.  Leave the stuff before the | alone. 

It can't accept variables or registers or anything, and some of them have length limits (formal or simply font-becomes-too-tiny) you'll have to be careful of, but other than that I haven't yet found any issues with any changes I've made here.

When editing, I suggest using text editors rather than spreadsheet programs, even though .csv would normally be spreadsheet fodder.  OpenOffice, at the very least, put all my strings between double quotes, even before the | character - do you see any double quotes in the original?  And thus nothing showed up in play, until I checked the actual text of the files and found those.  Grr.

- Hellequin

Different proficiencies for ranged/melee. I bet everyone has something similar already, but I'm posting mine here for people to use.

In module_troops.py. Put this after the definition for wp(x) and before the knows_common definition.

# BoW: separate melee and ranged proficiencies 
def wp2(x,y):
  n = 0
  r = 10 + int(x / 10)
  n |= wp_one_handed(x + random.randrange(r))
  n |= wp_two_handed(x + random.randrange(r))
  n |= wp_polearm(x + random.randrange(r))
  r = 10 + int(y / 10)
  n |= wp_archery(y + random.randrange(r))
  n |= wp_crossbow(y + random.randrange(r))
  n |= wp_throwing(y + random.randrange(r))
  return n


Example usage: Give Swadian sharpshooter around 90 melee and 140 ranged proficiencies

  ["swadian_sharpshooter","Swadian Sharpshooter","Swadian_sharpshooters",tf_guarantee_ranged|tf_mounted|tf_guarantee_boots|tf_guarantee_armor|tf_guarantee_helmet,0,0,fac_swadians,   [itm_bolts,itm_arrows,itm_heavy_crossbow,itm_heavy_crossbow,itm_arming_sword,itm_arming_sword,itm_mail_shirt,itm_mail_shirt,itm_leather_boots,itm_leather_boots,itm_kettle_hat,itm_kettle_hat,itm_leather_gloves,itm_leather_gloves],
   def_attrib|str_14|level(24),wp2(90,140),knows_common|knows_power_draw_3|knows_ironflesh_1,swadian_face1, swadian_face2],



Other Scripts

(mainly ones too long to put in the post)

Winter's depleting arrow script

Highlander's formation script

Sin-1 and Cosine-1 Arrays (for any trig people want to do)


Great thanks to Everyone who has contributed!
« Last Edit: September 17, 2007, 09:57:35 AM by Yoshiboy »

Offline Fisheye

  • Blues Brother
  • Moderator
  • *****
  • Posts: 427
  • My scalp's so bright, I gotta wear shades.
    • View Profile
Re: Python script/scheme/source exchange
« Reply #1 on: January 12, 2007, 08:26:33 PM »
Script for sorting a given troop's inventory by price. You need an additional troop: temp_array_c (just copy temp_array_a) in module_troops.py.

Usage example: (call_script, "script_sort_inventory", "trp_temp_troop"),

To get sorted loot for player: in module_game_menus.py, under the menu "total_victory". Look for:

          (change_screen_loot, "trp_temp_troop"),

And put the call right before it:

        (call_script, "script_sort_inventory", "trp_temp_troop"),
        (change_screen_loot, "trp_temp_troop"),

Code (for module_scripts.py) is below:

Code: [Select]
#####################################################################
# BoW: gets an item's value
# Param1: item ID
# Param2: item modifier
#####################################################################
("get_item_value_with_imod", [  # returns the sell price based on the item's money value and its imod
(store_script_param, ":item", 1),
(store_script_param, ":imod", 2),
(store_item_value, ":score", ":item"),
(try_begin),
(eq, ":imod", imod_lame),
(val_mul, ":score", 30),
(else_try),
(this_or_next|eq, ":imod", imod_tattered),
(eq, ":imod", imod_cracked),
(val_mul, ":score", 40),
(else_try),
(this_or_next|eq, ":imod", imod_rusty),
(eq, ":imod", imod_swaybacked),
(val_mul, ":score", 50),
(else_try),
(this_or_next|eq, ":imod", imod_ragged),
(eq, ":imod", imod_bent),
(val_mul, ":score", 60),
(else_try),
(this_or_next|eq, ":imod", imod_chipped),
(eq, ":imod", imod_battered),
(val_mul, ":score", 65),
(else_try),
(this_or_next|eq, ":imod", imod_poor),
(eq, ":imod", imod_crude),
(val_mul, ":score", 80),
(else_try),
(this_or_next|eq, ":imod", imod_old),
(eq, ":imod", imod_stubborn),
(val_mul, ":score", 90),
(else_try),
(eq, ":imod", imod_plain),
(val_mul, ":score", 100),
(else_try),
(eq, ":imod", imod_heavy),
(val_mul, ":score", 135),
(else_try),
(eq, ":imod", imod_large_bag),
(val_mul, ":score", 190),
(else_try),
(eq, ":imod", imod_temperate),
(val_mul, ":score", 140),
(else_try),
(eq, ":imod", imod_sturdy),
(val_mul, ":score", 130),
(else_try),
(eq, ":imod", imod_thick),
(val_mul, ":score", 160),
(else_try),
(eq, ":imod", imod_spirited),
(val_mul, ":score", 240),
(else_try),
(eq, ":imod", imod_balanced),
(val_mul, ":score", 170),
(else_try),
(eq, ":imod", imod_hardened),
(val_mul, ":score", 180),
(else_try),
(eq, ":imod", imod_watered_steel),
(val_mul, ":score", 290),
(else_try),
(eq, ":imod", imod_reinforced),
(val_mul, ":score", 250),
(try_end),

(assign, reg0, ":score"),
]),

#####################################################################
# BoW: sorts a troops inventory by price
# Param1: source troop
#####################################################################
("sort_inventory", [
(store_script_param_1, ":source_troop"),

(troop_get_inventory_capacity, ":inv_cap", ":source_troop"),
(assign, ":num_items", 0),
# record the item IDs
(try_for_range, ":i_slot", 0, ":inv_cap"),
(troop_get_inventory_slot, ":item_id", ":source_troop", ":i_slot"),
(ge, ":item_id", 0),
(troop_set_slot, "trp_temp_array_a", ":num_items", ":item_id"),
(troop_get_inventory_slot_modifier, ":item_imod", ":source_troop", ":i_slot"),
(troop_set_slot, "trp_temp_array_b", ":num_items", ":item_imod"),
(troop_inventory_slot_get_item_amount, ":item_amount", ":source_troop", ":i_slot"),
(troop_set_slot, "trp_temp_array_c", ":num_items", ":item_amount"),
(val_add, ":num_items", 1),
(try_end),
# bubble-sort by cost
(try_for_range, ":i_slot", 1, ":num_items"),
(try_for_range_backwards, ":j_slot", ":i_slot",":num_items"),
(try_begin),
(store_sub, ":prev_slot", ":j_slot", 1),
(troop_get_slot, ":item_j", "trp_temp_array_a", ":j_slot"),
(troop_get_slot, ":item_prev", "trp_temp_array_a", ":prev_slot"),
(troop_get_slot, ":item_imod_j", "trp_temp_array_b", ":j_slot"),
(troop_get_slot, ":item_imod_prev", "trp_temp_array_b", ":prev_slot"),
(troop_get_slot, ":item_amt_j", "trp_temp_array_c", ":j_slot"),
(troop_get_slot, ":item_amt_prev", "trp_temp_array_c", ":prev_slot"),
(call_script, "script_get_item_value_with_imod", ":item_j", ":item_imod_j"),
(assign, ":item_cost_j", reg0),
(call_script, "script_get_item_value_with_imod", ":item_prev", ":item_imod_prev"),
(assign, ":item_cost_prev", reg0),
(lt, ":item_cost_prev", ":item_cost_j"),
# out of order; do the swap
(troop_set_slot, "trp_temp_array_a", ":j_slot", ":item_prev", ),
(troop_set_slot, "trp_temp_array_a", ":prev_slot", ":item_j"),
(troop_set_slot, "trp_temp_array_b", ":j_slot", ":item_imod_prev", ),
(troop_set_slot, "trp_temp_array_b", ":prev_slot", ":item_imod_j"),
(troop_set_slot, "trp_temp_array_c", ":j_slot", ":item_amt_prev", ),
(troop_set_slot, "trp_temp_array_c", ":prev_slot", ":item_amt_j"),
(try_end),
(try_end),
(try_end),
# remove items
(troop_clear_inventory, ":source_troop"),
(try_for_range, ":i_slot", 0, 10),
(troop_set_inventory_slot, ":source_troop", ":i_slot", -1),
(end_try),
# replace them on the troop, most expensive first
(try_for_range, ":i_slot", 0, ":num_items"),
(troop_get_slot, ":item_id", "trp_temp_array_a", ":i_slot"),
(troop_get_slot, ":item_imod", "trp_temp_array_b", ":i_slot"),
(troop_get_slot, ":item_amount", "trp_temp_array_c", ":i_slot"),
(troop_add_item, ":source_troop", ":item_id", ":item_imod"),
(try_begin),
(is_between, ":item_id", morale_boosters_begin, morale_boosters_end),
(store_add, ":inv_slot", ":i_slot", 10),
(troop_inventory_slot_set_item_amount, ":source_troop", ":inv_slot", ":item_amount"),
(try_end),
(try_end),
]),
« Last Edit: October 22, 2007, 03:05:27 PM by Fisheye »

Offline Hellequin

  • Journeyman
  • ***
  • Posts: 254
    • View Profile
Re: Python script/scheme/source exchange
« Reply #2 on: January 19, 2007, 11:37:13 AM »
Not Python, exactly, but a trick worth showing people.  Extremely useful, even if you're not tearing down and rebuilding the skill system as heavily as I have.

Renaming a skill.
(Giving it new statistical effects, and living with or negating its old ones, is up to you.)
Same technique can be used to rename a currency, alter hints, and so forth.

With thanks to Highlander & Fisheye.

1) Open M&B, start a game (any mod or Native). Use Alt+Enter to put M&B into windowed mode.
2) Off the toolbar, select File > New Language.
3) This creates the subdirectory "/new language" off your M&B directory.  It's got all kinds of tasty things in there, all in csv (comma-separated-value, basically a text spreadsheet) format.
4) Under your mod, create the subdirectory "MyMod/languages/en".  Anything in here will be seen by all English-language players.  Obviously you can repeat this technique for other languages, too.
5) Copy some or all of the files from "/new language" into your new English-language directory.  If renaming skills, you want (surprise, surprise) skills.csv.
6) Edit the stuff on any line after the | character to whatever you want.  Leave the stuff before the | alone. 

It can't accept variables or registers or anything, and some of them have length limits (formal or simply font-becomes-too-tiny) you'll have to be careful of, but other than that I haven't yet found any issues with any changes I've made here.

When editing, I suggest using text editors rather than spreadsheet programs, even though .csv would normally be spreadsheet fodder.  OpenOffice, at the very least, put all my strings between double quotes, even before the | character - do you see any double quotes in the original?  And thus nothing showed up in play, until I checked the actual text of the files and found those.  Grr.

- Hellequin
« Last Edit: January 19, 2007, 11:38:47 AM by Hellequin »

Offline Fisheye

  • Blues Brother
  • Moderator
  • *****
  • Posts: 427
  • My scalp's so bright, I gotta wear shades.
    • View Profile
Re: Python script/scheme/source exchange
« Reply #3 on: January 19, 2007, 11:59:58 AM »
Different proficiencies for ranged/melee. I bet everyone has something similar already, but I'm posting mine here for people to use.

In module_troops.py. Put this after the definition for wp(x) and before the knows_common definition.

# BoW: separate melee and ranged proficiencies 
def wp2(x,y):
  n = 0
  r = 10 + int(x / 10)
  n |= wp_one_handed(x + random.randrange(r))
  n |= wp_two_handed(x + random.randrange(r))
  n |= wp_polearm(x + random.randrange(r))
  r = 10 + int(y / 10)
  n |= wp_archery(y + random.randrange(r))
  n |= wp_crossbow(y + random.randrange(r))
  n |= wp_throwing(y + random.randrange(r))
  return n


Example usage: Give Swadian sharpshooter around 90 melee and 140 ranged proficiencies

  ["swadian_sharpshooter","Swadian Sharpshooter","Swadian_sharpshooters",tf_guarantee_ranged|tf_mounted|tf_guarantee_boots|tf_guarantee_armor|tf_guarantee_helmet,0,0,fac_swadians,   [itm_bolts,itm_arrows,itm_heavy_crossbow,itm_heavy_crossbow,itm_arming_sword,itm_arming_sword,itm_mail_shirt,itm_mail_shirt,itm_leather_boots,itm_leather_boots,itm_kettle_hat,itm_kettle_hat,itm_leather_gloves,itm_leather_gloves],
   def_attrib|str_14|level(24),wp2(90,140),knows_common|knows_power_draw_3|knows_ironflesh_1,swadian_face1, swadian_face2],

« Last Edit: January 19, 2007, 12:01:36 PM by Fisheye »

Manitas

  • Guest
Re: Python script/scheme/source exchange
« Reply #4 on: January 29, 2007, 06:56:54 AM »
INTEGER SQUARE ROOT:
returns the nearest integer value to square root of any positive integer.
Note that because of absence of 'while' loop I had to use recursion, so I'm not sure if it wont crash with very large numbers, it's up to you to find out.

usage: (call_script, "script_sqrt", value)                      Never set the second param!!!!
$return global variable yields the result.

MoBo syntax:
Code: [Select]
("sqrt",[#mobo#
   store_script_param_1 :var
   store_script_param_2 :flag
   {
       :flag == 0
       :var += 1
       :var /= 2
       $return = 0
       }
  {
      :var > $return
      :var -= $return
      $return += 1
      call_script "script_sqrt" :var 1
      }
   #mobo#
   ]),

Na(t)ive syntax:
Code: [Select]
("sqrt",[
      (store_script_param_1,':var'),
      (store_script_param_2,':flag'),
      (try_begin),
        (eq,':flag',0),
        (val_add,':var',1),
        (val_div,':var',2),
        (assign,'$return',0),
      (try_end),
      (try_begin),
        (gt,':var','$return'),
        (val_sub,':var','$return'),
        (val_add,'$return',1),
        (call_script,"script_sqrt",':var',1),
      (try_end),
   ]),

for those of you interested, C syntax ;):
Code: [Select]
x = (x+1) >> 1;
for(r=0; x>r; x-=r++);

Offline Hellequin

  • Journeyman
  • ***
  • Posts: 254
    • View Profile
Re: Python script/scheme/source exchange
« Reply #5 on: February 09, 2007, 01:10:14 PM »
Full 365-day calendar with days of the week

In scripts:
Code: [Select]
("generate_date_strings",  # Takes input parameter [:Date], outputs {s39} for the full date, {s40} without day of the week.
[
(store_script_param_1, ":Date"),
(try_begin),
(eq, ":Date", 0), # Date = 0 -> Generate strings for the current date.  Date 1-365 -> Generate strings for that date.
(store_current_day, ":Date"),
(val_add, ":Date", "$DateOffset"), # A random start date (0-364) determined when beginning a new game.
(val_mod, ":Date", 365),
(val_add, ":Date", 1),
(try_end),

(assign, ":Day_of_week", ":Date"),
(val_mod, ":Day_of_week", 7),
(val_add, ":Day_of_week", "str_Sunday"),
(str_store_string, 34, ":Day_of_week"),

(assign, ":EndOfMonth", 0),
(try_begin),
(store_sub, reg(36), ":Date", ":EndOfMonth"),(val_add, ":EndOfMonth", 31),(le, reg(36), 31),(str_store_string, 35, "str_January"),
(else_try),
(store_sub, reg(36), ":Date", ":EndOfMonth"),(val_add, ":EndOfMonth", 28),(le, reg(36), 28),(str_store_string, 35, "str_February"),
(else_try),
(store_sub, reg(36), ":Date", ":EndOfMonth"),(val_add, ":EndOfMonth", 31),(le, reg(36), 31),(str_store_string, 35, "str_March"),
(else_try),
(store_sub, reg(36), ":Date", ":EndOfMonth"),(val_add, ":EndOfMonth", 30),(le, reg(36), 30),(str_store_string, 35, "str_April"),
(else_try),
(store_sub, reg(36), ":Date", ":EndOfMonth"),(val_add, ":EndOfMonth", 31),(le, reg(36), 31),(str_store_string, 35, "str_May"),
(else_try),
(store_sub, reg(36), ":Date", ":EndOfMonth"),(val_add, ":EndOfMonth", 30),(le, reg(36), 30),(str_store_string, 35, "str_June"),
(else_try),
(store_sub, reg(36), ":Date", ":EndOfMonth"),(val_add, ":EndOfMonth", 31),(le, reg(36), 31),(str_store_string, 35, "str_July"),
(else_try),
(store_sub, reg(36), ":Date", ":EndOfMonth"),(val_add, ":EndOfMonth", 31),(le, reg(36), 31),(str_store_string, 35, "str_August"),
(else_try),
(store_sub, reg(36), ":Date", ":EndOfMonth"),(val_add, ":EndOfMonth", 30),(le, reg(36), 30),(str_store_string, 35, "str_September"),
(else_try),
(store_sub, reg(36), ":Date", ":EndOfMonth"),(val_add, ":EndOfMonth", 31),(le, reg(36), 31),(str_store_string, 35, "str_October"),
(else_try),
(store_sub, reg(36), ":Date", ":EndOfMonth"),(val_add, ":EndOfMonth", 30),(le, reg(36), 30),(str_store_string, 35, "str_November"),
(else_try),
(store_sub, reg(36), ":Date", ":EndOfMonth"),(val_add, ":EndOfMonth", 31),(le, reg(36), 31),(str_store_string, 35, "str_December"),
(try_end),

(str_store_string, 39, "str_full_date"),
(str_store_string, 40, "str_simple_date"),
]
),

In strings:
Code: [Select]
("January", "January"),
("February", "February"),
("March", "March"),
("April", "April"),
("May", "May"),
("June", "June"),
("July", "July"),
("August", "August"),
("September", "September"),
("October", "October"),
("November", "November"),
("December", "December"),
("Sunday","Sunday"),
("Monday","Monday"),
("Tuesday","Tuesday"),
("Wednesday","Wednesday"),
("Thursday","Thursday"),
("Friday","Friday"),
("Saturday","Saturday"),
("full_date", "{s34}, {s35} {reg36}"),
("simple_date", "{s35} {reg36}"),

Usage: Call the script, then insert your choice of s39 or s40 into a display string, menu option, etc.  If you want just the month, day of the week, or day of the month, those are available as well.

If you're really going for true accuracy you'd need to add a year, and a day-of-week correction so that January 1 is not always Monday, but these should be trivial.  I leave insertion of leap-years as an exercise for the truly obsessive.

Enjoy!

Offline fujiwara

  • Master
  • *****
  • Posts: 858
    • View Profile
Re: Python script/scheme/source exchange
« Reply #6 on: February 10, 2007, 09:41:57 AM »
A script to determine the most expensive weapon in a player's inventory and remove it:

Code: [Select]
              (assign,':index',0),
              (try_for_range,reg1,0,100),
                  (troop_set_slot,'trp_last_troop',reg1,-1), # initalize the array
              (try_end),
              (try_for_range,reg1,<start_item>,<end_item>),
                  (player_has_item,reg1),
                  (troop_set_slot,'trp_last_troop',':index',reg1), # store any weapons carried by the player
                  (val_add,':index',1),
              (try_end),
              (try_for_range,reg2,0,100),
                  (troop_slot_eq,'trp_last_troop',reg2,-1), #gets the array length
                  (assign,':index',reg2),
              (try_end),
              (assign,':item_val_1',0),
              (assign,':item_val_2',0),
              (assign,':current_item',0),
              (try_for_range,reg3,0,':index'), #compares item values in player inventory
                  (troop_get_slot,reg4,'trp_last_troop',reg3),
                  (store_item_value,':item_val_1',reg4),
                  (gt,':item_val_1',':item_val_2'),
                  (assign,':item_val_2',':item_val_1'),
                  (assign,':current_item',reg3),
              (try_end),
              (troop_remove_item,0,':current_item'),

Could be useful as a punishment for losing a fight, duel, etc. (how it's used in Onin no Ran). Requires a trp_last_troop to exist in the module_troops file.
« Last Edit: February 10, 2007, 11:02:37 PM by fujiwara »

The horses tend to get their legs caught in the catapult rather than being properly launched.

Offline Hellequin

  • Journeyman
  • ***
  • Posts: 254
    • View Profile
Re: Python script/scheme/source exchange
« Reply #7 on: February 10, 2007, 10:05:43 AM »
Though note that the above script doesn't notice the value modifiers of imods.  It'll remove a rusty greatsword before a balanced bastard sword.  Not a big deal, but you should be aware it exists.

Offline fujiwara

  • Master
  • *****
  • Posts: 858
    • View Profile
Re: Python script/scheme/source exchange
« Reply #8 on: February 10, 2007, 11:03:32 PM »
You have a good point. I didn't have a chance to read Fisheye's above script before writing this one. I'll be adding the imod in.

The horses tend to get their legs caught in the catapult rather than being properly launched.

Offline Hellequin

  • Journeyman
  • ***
  • Posts: 254
    • View Profile
Re: Python script/scheme/source exchange
« Reply #9 on: February 11, 2007, 12:14:29 PM »
Trouble is that then you'll be unequipping everything the player owns, in order to remove the one weapon.  Very annoying to the player; I just ran into this in my own code two days ago.  I'd suggest it's not worth it, and you should just leave it "imod-blind" until Armagan gives us better imod-recognition support.

Offline fujiwara

  • Master
  • *****
  • Posts: 858
    • View Profile
Re: Python script/scheme/source exchange
« Reply #10 on: February 18, 2007, 01:55:15 AM »
Others may or may not have implemented a system of array handling scripts/functions, but I offer these up anyway. These came out of a conversation at Taleworlds with Neophyte. Arrays are 0-based, since they come out of the slot system. They're free to do with as you please, but a mention would be nice :)

The functions:

array_init: creates a new array of user-determined length, later stored in the array itself. Also initializes the array to the value array_value_null. Returns to $return. Takes a length value as input
array_clear: clears the input array of all values, returning them to array_value_null. Returns the array to $return. Takes an array as input
array_push: pushes the input value onto the top of the array (highest available, non-null index). Stores the pushed value to array_value_last_pushed. Takes an array and the value to be pushed as input
array_pop: pops the value off the top of array and removes it from the array (value replaced with array_value_null), Stores value at array_value_last_popped. Returns to $return. Takes an array as input
array_peek: returns the value at the given index without removing it from the array. Takes an array and an index as input
array_queue: returns and removes the value at the bottom of the array, then shifts all other values left/down one index. Assigns queued value to array_value_last_queued and $return. Takes an array as input
array_remove_if_ge: resets any values in the array to array_value_null that is >= the test value. Written as a proof of concept, since the whole suite of comparator functions can be easily implemented. Takes an array and a test value as input

Notes: in this implementation, the first five slots of the array are reserved, and inputted index values are offset by 5 . Obviously, if you need more reserved slots, the index offset should be changed.

Required:

module_constants:
array_value_null = -100
array_value_length = 0
array_value_last_popped = 1
array_value_last_pushed = 2
array_value_last_queued = 3
array_value_high_index = 4

module_party_templates:
('array','array',pf_disabled,0,fac_neutral,0,[]),

module_scripts:
Code: [Select]
("array_init",
   [
       (store_script_param_1,":array_length"),
       (store_random_in_range,reg1,cities_begin,cities_end),
       (set_spawn_radius,20),
       (spawn_around_party,reg1,'pt_array'),
       (val_add,':array_length',5),
       (call_script,'script_array_clear',reg0),
       ]),
  ('array_clear',
   [
       (store_script_param_1,':input_array'),
       (party_get_slot,':array_length',':input_array',array_value_length),
       (try_for_range,reg1,1,':array_length'),
           (party_set_slot,':input_array',reg1,array_value_null),
       (try_end),
       (party_set_slot,':input_array',array_value_length,':array_length'),
       (party_set_slot,':input_array',array_value_high_index,5),
       (assign,'$return',':input_array'),
       ]),
  ('array_push',
   [
       (store_script_param_1,':input_array'),
       (store_script_param_2,':input_value'),
       (party_get_slot,reg1,':input_array',array_value_high_index),
       (val_add,reg1,1),
       (party_set_slot,':input_array',reg1,':input_value'),
       (party_set_slot,':input_array',array_value_high_index,reg1),
       (party_set_slot,':input_array',array_value_last_pushed,':input_value'),
       ]),
  ('array_pop',
   [
       (store_script_param_1,':input_array'),
       (party_get_slot,reg1,':input_array',array_value_high_index),
       (party_get_slot,reg2,':input_array',reg1),
       (party_set_slot,':input_array',reg1,-1),
       (party_set_slot,':input_array',array_value_last_popped,reg2),
       (try_begin),
           (gt,reg1,5),
           (val_sub,reg1,1),
       (try_end),
       (party_set_slot,':input_array',array_value_high_index,reg1),
       (assign,'$return',reg2),
       ]),
  ('array_peek',
   [
       (store_script_param_1,':input_array'),
       (store_script_param_2,':input_index'),
       (val_add,':input_index',5),
       (party_get_slot,reg1,':input_array',':input_index'),
       (assign,'$return',reg1),
       ]),
  ('array_queue',
   [
       (store_script_param_1,':input_array'),
       (party_get_slot,reg1,':input_array',5),
       (assign,'$return',reg1),
       (party_set_slot,':input_array',array_value_last_queued,reg1),
       (call_script,'script_array_shift_left',':input_array'),
       ]),
  ('array_shift_left',
   [
       (store_script_param_1,':input_array'),
       (party_get_slot,':array_length',':input_array',array_value_length),
       (try_for_range,reg1,5,':array_length'),
           (store_add,reg2,reg1,1),
           (party_get_slot,reg3,':input_array',reg2),
           (party_set_slot,':input_array',reg1,reg3),
       (try_end),
       (party_set_slot,':input_array',':array_length',array_value_null),
       ]),
  ('array_remove_if_ge',
   [
       (store_script_param_1,':input_array'),
       (store_script_param_2,':test_value'),
       (party_get_slot,reg1,':input_array',array_value_high_index),
       (try_for_range,reg2,5,reg1),
           (party_get_slot,reg3,':input_array',reg2),
           (ge,reg3,':test_value'),
           (party_set_slot,':input_array',reg2,array_value_null),
       (try_end),
       ]),

If any notices any glaring errors, please let me know :)

EDIT: fixed some typos.

Discussion of the script has been moved here due to length considerations:
http://mbx.streetofeyes.com/index.php?topic=310.0

-- Fisheye
« Last Edit: February 23, 2008, 02:29:42 PM by fujiwara »

The horses tend to get their legs caught in the catapult rather than being properly launched.

Neophyte

  • Guest
Re: Python script/scheme/source exchange
« Reply #11 on: February 19, 2007, 07:13:53 AM »
Figured this might be the correct place to discuss the script *itself*, and use the other thread for discussions on uses for it.

Anyway, there's an error in the "initialize_array" script:
Code: [Select]
(store_random_in_range,reg1,cities_begin,cities_end),this should be
Code: [Select]
(store_random_in_range,reg1,towns_begin,towns_end),

Also, though this is personal preference rather than anything else, I would probably namel that function "array_initialize" rather than "initialize_array" purely so that all array-related scripts have names starting with "array_".

Highlander

  • Guest
Re: Python script/scheme/source exchange
« Reply #12 on: April 20, 2007, 08:37:16 AM »
nothing spectacular, but a usefull trick:
When you copy "0" from notepad or similar programmes, go to the terrain editor and press "paste", the hill height will be lower than you get it by just dragging the button. That's the only way to get absolutely NO hills; very useful in some cases.

Offline Cartread

  • Craftsman
  • **
  • Posts: 110
    • View Profile
Re: Python script/scheme/source exchange
« Reply #13 on: May 27, 2007, 04:31:07 AM »
I put my H&B 808c source up on the Repository.  It's the same as the one included in the mod download.

Yoshiboy: All but recruit from prisoners, craftmod & pirates! are direct linked!

Yoshiboy

  • Guest
Re: Python script/scheme/source exchange
« Reply #14 on: May 27, 2007, 06:23:33 AM »
Ok, added yours and hopefully they are not direct anymore. (at least the ones on the repository)

Highlander

  • Guest
Re: Python script/scheme/source exchange
« Reply #15 on: July 07, 2007, 10:17:07 AM »
Getting a parties map coordinates.

in module_parties:
  ("x70y-70","collective_enemy",pf_disabled, no_menu, pt_none, fac_neutral,0,ai_bhvr_hold,0,(70,-70),[]),
  ("x70y70","collective_enemy",pf_disabled, no_menu, pt_none, fac_neutral,0,ai_bhvr_hold,0,(70,70),[]),

in module_scripts:
("sqrt",[
      (store_script_param_1,':var'),
      (store_script_param_2,':flag'),
      (try_begin),
        (eq,':flag',0),
        (val_add,':var',1),
        (val_div,':var',2),
        (assign,'$return',0),
      (try_end),
      (try_begin),
        (gt,':var','$return'),
        (val_sub,':var','$return'),
        (val_add,'$return',1),
        (call_script,"script_sqrt",':var',1),
      (try_end),
   ]),
# Calculate the coordinates of party on the map
("calculate_coords",
[
(store_distance_to_party_from_party,reg(6),"p_x70y70","p_x70y-70"),
(store_distance_to_party_from_party,reg(9),"p_x70y-70","p_main_party"),
(store_distance_to_party_from_party,reg(10),"p_x70y70","p_main_party"),

(store_mul,":ph2",reg(6),reg(6)),
(store_mul,":bh2",reg(9),reg(9)),
(store_mul,":ah2",reg(10),reg(10)),
(store_add,":pm2",reg(6),reg(6)),

(store_sub,reg(11),":ph2",":bh2"),
(store_add,reg(12),reg(11),":ah2"),
(val_div,reg(12),":pm2"),

(assign,"$pos_x",reg(12)),

(store_mul,":xh2","$pos_x","$pos_x"),

(store_sub,reg(11),":ah2",":xh2"),

(call_script,"script_sqrt",reg(11)),

(assign,"$pos_y",'$return'),

(val_sub,"$pos_y",70),
(val_sub,"$pos_x",70),
(val_mul,"$pos_y",-1),
(val_mul,"$pos_x",-1),

]),

change the red numbers to the map's max_y and the blue one to the map's min_y. It does only work on quadratic maps, but with some work it would work on others as well.
Not all the credit go to me, since the square root script is by Manitas and the whole thing is inspirated by Amarillo's Agent coordination script.

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: Python script/scheme/source exchange
« Reply #16 on: October 14, 2007, 11:23:23 PM »
Here's a little script I wrote as a shortcut to lots of tedious manual looping:

  ("loop_input_script",
   [
   (store_script_param, ":input_script",1),
   (store_script_param, ":input_loops",2),
   (store_script_param, ":input_script_range_low",3),
   (store_script_param, ":input_script_range_high",4),
   (store_script_param, ":input_script_param_1",5),
   (store_script_param, ":input_script_param_2",6),
   (store_script_param, ":input_script_param_3",7),
   (store_script_param, ":input_script_param_4",8),
   (store_script_param, ":input_script_param_5",9),
   (store_script_param, ":input_script_param_6",10),

   (assign,"$output",-1),
   (assign, ":loops", 1),
      (try_for_range,":unused",0,":loops"),
      (lt,":loops",":input_loops"),
      (call_script,":input_script",":input_script_param_1",":input_script_param_2",":input_script_param_3",":input_script_param_4",":input_script_param_5",":input_script_param_6"),
      (assign,"$output",reg0),
      (neg|is_between,"$output",":input_script_range_low",":input_script_range_high"),
      (val_add,":loops",1),
      (try_end),
   ]),


It can be called like in this example:    (call_script,"script_loop_input_script","script_cf_select_random_center_with_faction",100,towns_begin,castles_end,":faction",0,0,0,0,0),


This script calls an input script for a number of times up to the value of ":input_loops" or until success of the input script. It will work for any input script that outputs to reg0 and whose output is a single integer or range.

I imagine it could be made somewhat more elegant with some effort, but I'm not in the mood for it just now.
« Last Edit: October 14, 2007, 11:25:54 PM by Winter »

Offline Hellequin

  • Journeyman
  • ***
  • Posts: 254
    • View Profile
Re: Python script/scheme/source exchange
« Reply #17 on: October 15, 2007, 02:36:26 PM »
Note on Winter's above script - one elegant feature of the parameters system is that it auto-fills zeroes if there are fewer parameters than requested*.  So in Winter's example, it would be more cleanly expressed with the five zeroes at the end omitted - just the trailing ) after ":faction".

* Caveat - not yet tested on (store_script_param), this is 0.808 behaviour from (store_script_param_1) and its twin, not to mention all of the header_operations ops.

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: Python script/scheme/source exchange
« Reply #18 on: October 15, 2007, 03:21:26 PM »
Note on Winter's above script - one elegant feature of the parameters system is that it auto-fills zeroes if there are fewer parameters than requested*.  So in Winter's example, it would be more cleanly expressed with the five zeroes at the end omitted - just the trailing ) after ":faction".

* Caveat - not yet tested on (store_script_param), this is 0.808 behaviour from (store_script_param_1) and its twin, not to mention all of the header_operations ops.

I added the zeroes because I've been having trouble with 'illegal script param' error messages in-game, and I didn't want to put a possibly buggy script up here.

Highlander

  • Guest
Re: Python script/scheme/source exchange
« Reply #19 on: November 05, 2007, 12:34:03 PM »
To get the rotation around x (can be also used for y in a slightly modified version).
input: 20 is the position you want the information from.
output: reg(1) is the rotation around x.
     (init_position,21),
     (position_copy_origin,21,20),
     (position_get_rotation_around_z,reg(1),20),
     (position_rotate_z,21,reg(1)),
     (position_rotate_y,21,90),
     (position_transform_position_to_local,22,21,20),
     (position_get_rotation_around_z,reg(1),22),

Offline KON_Air

  • Craftsman
  • **
  • Posts: 110
    • View Profile
Re: Python script/scheme/source exchange
« Reply #20 on: December 29, 2007, 06:56:52 PM »
Not enough bandits? Go spawn bandits! This simple script when fed with a value will spawn a party from template. For villages press 1... ok that's stupid, for villages it spawns a random bandit party of two preset types, same for towns but for castles the script checks the faction of the castle and spawns a faction specific bandit (deserters for example).

Code: [Select]
  #script_spawn_random_center_bandit:
  # INPUTS:
  #":centersize"
  # 1 village, 2 castle, 3 town
  #OUTPUT:
  # bandits
 ("spawn_random_center_bandit",
   [
   (store_script_param_1, ":center_size"),
    # (display_message, "str_ran"),
(assign, ":bandit_party", -1),
(try_begin),
(eq, ":center_size", 1),
(store_random_in_range, ":random_center", villages_begin, villages_end),
(set_spawn_radius,2),

(store_random_in_range, ":bandit_type", 1, 5),
(try_begin),
(eq, ":bandit_type", 1),
    (spawn_around_party,":random_center","pt_peasant_rebels"),
(else_try),
(spawn_around_party,":random_center","pt_village_bandits"),
(try_end),
(assign, ":bandit_party", reg0),
(party_set_slot, ":bandit_party", slot_party_type, spt_random_bandit),
# (str_store_party_name, s1, ":random_center"),
# (display_message, "str_ran1"),

(else_try),
(eq, ":center_size", 2),
(store_random_in_range, ":random_center", towns_begin, towns_end),
(set_spawn_radius,2),

(store_random_in_range, ":bandit_type2", 1, 10),
(try_begin),
(eq, ":bandit_type2", 1),
(spawn_around_party,":random_center","pt_city_bandits1"),
(else_try),
(spawn_around_party,":random_center","pt_city_bandits2"),
(try_end),

(assign, ":bandit_party", reg0),
(party_set_slot, ":bandit_party", slot_party_type, spt_random_bandit),
# (str_store_party_name, s1, ":random_center"),
# (display_message, "str_ran2"),

(else_try),
(eq, ":center_size", 3),
(store_random_in_range, ":random_center", castles_begin, castles_end),
(store_faction_of_party, ":center_faction", ":random_center"),
(try_begin),
(eq, ":center_faction", "fac_kingdom_1"),
(set_spawn_radius,2),
    (spawn_around_party,":random_center","pt_fac1_bandits"),
(assign, ":bandit_party", reg0),
(party_set_slot, ":bandit_party", slot_party_type, spt_random_bandit),
# (str_store_party_name, s1, ":random_center"),
# (display_message, "str_ran3"),
(else_try),
(eq, ":center_faction", "fac_kingdom_2"),
(set_spawn_radius,2),
    (spawn_around_party,":random_center","pt_fac2_bandits"),
(assign, ":bandit_party", reg0),
(party_set_slot, ":bandit_party", slot_party_type, spt_random_bandit),
# (display_message, "str_ran3"),
(else_try),
(eq, ":center_faction", "fac_kingdom_3"),
(set_spawn_radius,2),
    (spawn_around_party,":random_center","pt_fac3_bandits"),
(assign, ":bandit_party", reg0),
(party_set_slot, ":bandit_party", slot_party_type, spt_random_bandit),
# (display_message, "str_ran3"),
(else_try),
(eq, ":center_faction", "fac_kingdom_4"),
(set_spawn_radius,2),
    (spawn_around_party,":random_center","pt_fac4_bandits"),
(assign, ":bandit_party", reg0),
(party_set_slot, ":bandit_party", slot_party_type, spt_random_bandit),
# (display_message, "str_ran3"),
(else_try),
(eq, ":center_faction", "fac_kingdom_5"),
(set_spawn_radius,2),
    (spawn_around_party,":random_center","pt_fac5_bandits"),
(assign, ":bandit_party", reg0),
(party_set_slot, ":bandit_party", slot_party_type, spt_random_bandit),
# (display_message, "str_ran3"),
(try_end),
(try_end),
# (display_message, "str_ranb"),
 ]),

Recommended to use with such trigger (given all party templates have same spt assigned);

Code: [Select]
(0, 0, 72, [], [
(call_script, "script_count_parties_of_faction_and_party_type", "fac_outlaws", spt_random_bandit),
(assign, ":random_bandit_count", reg0),
(try_begin),
(lt, ":random_bandit_count", 10),
(call_script,"script_spawn_random_center_bandit", 1),
(call_script,"script_spawn_random_center_bandit", 2),
(call_script,"script_spawn_random_center_bandit", 3),
....etc.
« Last Edit: December 29, 2007, 06:59:09 PM by KON_Air »

Offline KON_Air

  • Craftsman
  • **
  • Posts: 110
    • View Profile
Re: Python script/scheme/source exchange
« Reply #21 on: December 30, 2007, 09:18:36 PM »
Bank stuff, loan, interest and account, not thoroughly tested

Notes; it is a wee bit messy, "$sperk_bcstmr" is a perk (remove its try), trp_pawn_merc was supposed to be a pawn shop owner but became banker etc, etc... bank_clerk is to be used for branches in other towns (I made a single scene, single troop for that, so you can make scenes for all 14 town and still use one troop)... Script is just a mess, but I kinda like it that way, 2500 is good enough for early on with skills and renown players can withdraw ridiculous amounts of money for kicks (thought I'll have inane monetary requirements for some stuff in my mod).

Scripts;

Code: [Select]
#script_credit_calculation
#changes the value of "$lend_max" when called. And is called via dialouge whenever plyr asks for loan
("credit_calculation",[
(try_begin),
(ge, "$bank_account", 0),
(assign, "$lend_max", "$bank_account"),
(else_try),
(eq, "$bank_account", 0),
(assign, "$lend_max", 500),
(try_end),
(troop_get_slot, ":troop_renown", "trp_player", slot_troop_renown),
(store_skill_level, ":skl_trade", "skl_trade", "trp_player"),
(store_skill_level, ":skl_persuade", "skl_persuasion", "trp_player"),
(store_add, ":skill_bonus", ":skl_trade"),
(val_add, ":skill_bonus", ":skl_persuade"),
(val_div, ":troop_renown", 100),
(val_div, ":skill_bonus", 2),

(val_mul, ":skill_bonus", ":troop_renown"),
(val_mul, "$lend_max", ":skill_bonus"),
#Then of course no points in skills may result in a 0 lend_max, thus we make sure player gets at least 2500 denars minimum
(try_begin),
(lt, "$lend_max", 2500),
(assign, "$lend_max", 2500),
(else_try),
#This is the extra boost thingy for lend_max
(val_mul, "$lend_max", 125),
(val_div, "$lend_max", 100),
(try_end),
]),

Triggers;

Code: [Select]
  (24.0 * 7, 0.0, 0.0,
   [],
   [
       (val_mul,"$bank_debt",105),
       (val_div,"$bank_debt",100),
   (try_begin),
   (eq, "$debt_bank_over_due", 1),
       (val_mul,"$bank_debt",102),
       (val_div,"$bank_debt",100),
   (try_end),
    ]
   ),
  (24.0 * 7, 0.0, 0.0,
   [],
   [
       (val_mul,"$bank_account",103),
       (val_div,"$bank_account",100),
   (try_begin),
   (eq, "$sperk_bcstmr", 1),
       (val_mul,"$bank_account",102),
       (val_div,"$bank_account",100),
   (try_end),
    ]
   ),
   
  (0.1, 24.0 * 30, 0.0,
   [(gt, "$bank_debt", 1)],
   [
(assign, "$debt_bank_over_due",1)
    ]
   ),

Dialogues;

Code: [Select]
   [trp_pawn_merc,"start",[],
   "Hello {sir/madam}, how can I help you?", "banker_list",[]],
   [trp_pawn_merc|plyr,"banker_list",[],
   "I would like to review my account.", "banker_account",[]],
   [trp_pawn_merc|plyr,"banker_list",[],
   "I would like buy some precious metals and gems.", "banker_trade",[]],
   [trp_pawn_merc|plyr,"banker_list",[],
   "I was just here to check my safe.", "banker_chat",[]],
    [trp_pawn_merc,"banker_chat", [], "Of course {sir/madam}, it is upstairs first door.", "close_window",[]],
   [trp_pawn_merc,"banker_trade", [], "Ah, of course we have the purest gold and silver and other valuables.", "banker_restart",[[change_screen_trade]]],
 
   
#Tell account Status
   [anyone,"banker_account", [
   (assign, reg1, "$bank_account"),
   (assign, reg2, "$bank_debt"),
   (try_begin),
   (eq, "$bank_account", 0),
   (str_store_string, s1, "@You don't have any money in your account."),
   (else_try),
   (str_store_string, s1, "@You have {reg1} denars in your account."),
   (try_end),
   (try_begin),
   (eq, "$bank_debt", 0),
   (str_store_string, s2, "@_"),
   (else_try),
   (eq, "$debt_bank_over_due", 1),
   (str_store_string, s2, "@You also have a debt of {reg2} denars, which you should pay as soon as possible because I am afraid Trade Guild has blacklisted you."),
   (else_try),
   (str_store_string, s2, "@You also have a debt of {reg2} denars."),
   (try_end),
   ], "{s1} {s2}", "banker_actions",[]],
   
   [anyone|plyr,"banker_actions",[],
   "I would like to deposit money into my account.", "banker_chat_actions_1",[]],
   [anyone|plyr,"banker_actions",[(gt, "$bank_account", 0)],
   "I would like to take money from my account.", "banker_chat_actions_2",[]],
   
   [anyone,"banker_chat_actions_1",[],
   "Sure {sir/madam}, how much would you like to deposit? You will have an interest rate of three percent per week.", "banker_actions_1",[]],
   [anyone,"banker_chat_actions_2",[],
   "Sure {sir/madam}, how much would you like to draw?", "banker_actions_2",[]],
   
   [anyone|plyr,"banker_actions",[(eq, "$bank_debt", 0)],
   "I need a loan.", "banker_chat_actions_3",[]],
   
   [anyone|plyr,"banker_actions",[(gt, "$bank_debt", 1)],
   "I'd like to pay my debt.", "banker_chat_actions_4",[]],
   
   [anyone|plyr,"banker_actions",[],
   "That's all I needed to know.", "banker_restart",[]],
   [anyone,"banker_restart",[],
   "Well {sir/madam}, do you need anything else?", "banker_list",[]],
   
   [anyone|plyr,"banker_actions",[],
   "Goodbye.", "close_window",[]],
   
#Add money to account
   [anyone|plyr,"banker_actions_1",[[store_troop_gold,reg(0)],[ge,reg(0),500]],
   "I would like to add 500 denars to account.", "banker_add_money",[(assign, "$money_diff", 500)]],
   [anyone|plyr,"banker_actions_1",[[store_troop_gold,reg(0)],[ge,reg(0),1000]],
   "I would like to add 1000 denars to account.", "banker_add_money",[(assign, "$money_diff", 1000)]],
   [anyone|plyr,"banker_actions_1",[[store_troop_gold,reg(0)],[ge,reg(0),2500]],
   "I would like to add 2500 denars to account.", "banker_add_money",[(assign, "$money_diff", 2500)]],
#Add all money
   [anyone|plyr,"banker_actions_1",[[store_troop_gold,reg2], (ge, reg2, 100)],
   "I have {reg2} denars I'd like to deposit all of it.", "banker_add_money",[(assign, "$money_diff", reg2)]],
   [anyone,"banker_add_money",[],
   "Sure {Sir/Madam} {playername}, right away", "banker_account",[
   (troop_remove_gold, "trp_player", "$money_diff"),
   (val_add, "$bank_account", "$money_diff"),
   ]],
   [anyone|plyr,"banker_actions_1",[],
   "Let me think of something else.", "banker_restart",[]],
#Take money from account
   [anyone|plyr,"banker_actions_2",[(gt, "$bank_account", 499)],
   "I would like to withdraw 500 denars from account.", "banker_take_money",[(assign, "$money_diff", 500)]],
   [anyone|plyr,"banker_actions_2",[(gt, "$bank_account", 999)],
   "I would like to withdraw 1000 denars from account.", "banker_take_money",[(assign, "$money_diff", 1000)]],
   [anyone|plyr,"banker_actions_2",[(gt, "$bank_account", 2499)],
   "I would like to withdraw 2500 denars from account.", "banker_take_money",[(assign, "$money_diff", 2500)]],
#Take all money
   [anyone|plyr,"banker_actions_2",[(assign, reg2, "$bank_account")],
   "I'd like to withdraw all {reg2} denars.", "banker_take_money",[(assign, "$money_diff", reg2)]],
   [anyone,"banker_take_money",[],
   "Sure {Sir/Madam} {playername}, right away", "banker_account",[
   (troop_add_gold, "trp_player", "$money_diff"),
   (val_sub, "$bank_account", "$money_diff"),
   ]],
   [anyone|plyr,"banker_actions_2",[],
   "Let me think of something else.", "banker_restart",[]],
#Take a loan
   [anyone,"banker_chat_actions_3",[],
   "Let me see how much we can give you...", "banker_think_actions_3",[
   (call_script, "script_credit_calculation"),
   ]],
   [anyone,"banker_think_actions_3",[(assign, reg3, "$lend_max")],
   "Well {sir/madam} {playername}, we can give you {reg3} and expect you to pay within thirty days. If you don't pay within thirty days the Trade Guild will blacklist you, which will prevent you from trading with merchants. Don't worry thought we will still buy valuables and other stuff from you to make the money you need. Also, well, if they have money, the villages will continue to trade with you too. Are you sure you can make {reg3} denars in a month with an interest rate of five percent? Also when your debt is over due there will be an additional two percent interest.", "banker_actions_3",[]],
   [anyone|plyr,"banker_actions_3",[],
   "I'll take all of it.", "banker_lend_money",[(assign, "$money_diff", "$lend_max")]],
   [anyone|plyr,"banker_actions_3",[],
   "I just need half of it.", "banker_lend_money",[
   (val_div, "$lend_max", 2),
   (assign, "$money_diff", "$lend_max")]],
   [anyone|plyr,"banker_actions_3",[],
   "Let me think of something else.", "banker_restart",[
      (assign, "$bank_debt_end", 0),
  # (assign, "$bank_debt_start", 0),
   ]],
#Set up triggers and other stuff about loan
   [anyone,"banker_lend_money",[
   (store_current_day, "$bank_debt_end"),
 (val_add, "$bank_debt_end", 30),
 (str_store_date, s2, "$bank_debt_end"),
   ],
   "Sure {Sir/Madam} {playername}, right away. Let me see you should pay at {s2}. Other wise you know what can happen.", "banker_account",[
   (troop_add_gold, "trp_player", "$money_diff"),
   (assign, "$bank_debt", "$money_diff"),
   ]],
   
 
#Pay debt
   [anyone,"banker_chat_actions_4",[],
   "Let me see how much you us...", "banker_think_actions_4",[]],
   [anyone,"banker_think_actions_4",[(assign, reg6, "$bank_debt"),
   (str_store_date, s2, "$bank_debt_end"),
   (try_begin),
   (eq, "$debt_bank_over_due", 1),
   (str_store_string, s1, "@and it is overdue, you should pay it as soon as you can."),
   (else_try),
   (eq, "$debt_bank_over_due", 0),
   (str_store_string, s1, "@you still have some time untill the dead line which is {s2}."),
   (try_end),
   ],
   "You owe {reg6} denars {s1}", "banker_actions_4",[]],
   
   [anyone|plyr,"banker_actions_4",[[store_troop_gold,reg(0)],[ge,reg(0),"$bank_debt"]],
   "I'd like to pay all of it and close my debt.", "banker_pay_debt",[]],
   
   [anyone,"banker_pay_debt",[],
   "Oh, great put the money over there and I am writing it down... and your signature here... done. Now you don't owe us any money, any more.", "banker_list",[
      (troop_remove_gold, "trp_player", "$bank_debt"),
  (assign, "$debt_bank_over_due", 0),   
  (assign, "$bank_debt", 0),
  (assign, "$bank_debt_end", 0),
   ]],
   
      [anyone|plyr,"banker_actions_4",[],
   "Let me think of something else.", "banker_restart",[]],   
   
   [trp_bank_clerk,"start",[],
   "Hello {sir/madam}, how may I serve you?", "banker_list",[]],
   [trp_bank_clerk|plyr,"banker_list",[],
   "I would like to review my account.", "banker_account",[]],
   [trp_bank_clerk|plyr,"banker_list",[],
   "I am just looking around.", "close_window",[]],

dunde

  • Guest
Re: Python script/scheme/source exchange
« Reply #22 on: February 09, 2009, 04:56:04 AM »
I would like to share my code for injuried system, hoping for response and opinions.
This injuried system I use in my module I'm building.

In module_mission_template :

# Dunde's Wounded System Start --------------------------------

wounded_system_init = (
  ti_before_mission_start, 0, 0, [],
  [
    (call_script, "script_do_init_wounded_system"),   
    ])


wounded_system_tick = (
  0.1, 0, 0, [],
  [
    (call_script, "script_do_check_is_any_body_injured"), 
    ])

# Dunde's Wounded System End ----------------------------------

Adding :
wounded_system_init,
wounded_system_tick,

for any mission use wounded system.

in module_script.py :
#-- Dunde'sBegin


  #initialization 
  ("do_init_wounded_system",
   [
       (try_for_range, ":cur_troop", wounded_heroes_begin, wounded_heroes_end),        # Check all Heroes, yeah may be isn't effective, but a hero may comes as reinforcement, might he not?
          (assign,":troop_id", ":cur_troop"),
          (try_begin),
              (eq, ":cur_troop", "trp_kingdom_heroes_including_player_begin"),
              (assign,":troop_id", "trp_player"),     
          (try_end),
          (store_troop_health,":troop_health", ":troop_id", 0),   
          (troop_set_slot, ":troop_id", slot_troop_hp, ":troop_health"),       # Initial points.
       (try_end),
   ]),

  #in battle simulation
  ("do_check_simulated_batle_injuried",
   [
       (store_script_param, ":party_id", 1),
       (try_for_range, ":troop_no", wounded_heroes_begin, wounded_heroes_end),        # Check all Heroes, yeah may be isn't effective, but a hero may comes as reinforcement, might he not?
          (assign,":troop_id", ":troop_no"),
          (try_begin),
              (eq, ":troop_no", "trp_kingdom_heroes_including_player_begin"),
              (assign,":troop_id", "trp_player"),     
          (try_end),
          (troop_get_slot, ":old_hp", ":troop_id", slot_troop_hp), 
          (store_troop_health,":hit_points", ":troop_id", 0),   
          (troop_set_slot, ":troop_id", slot_troop_hp, ":hit_points"),
          (store_sub, ":wound", ":old_hp", ":hit_points"),
          (gt, ":wound", 0),
          (str_clear, s1), (str_clear, s2), (str_clear, s3),
          # DUNDE : Ironflesh has effect too... 
          (store_skill_level, ":skl", "skl_ironflesh", ":troop_id"),
          (val_sub, ":wound", ":skl"),                 
          # DUNDE : Add random number...
          # Yeach, sometime luck can produce unpredictable result in war.
          # Comment lines betwen RANDOM BEGIN and RANDOM END if you don't like it, and prefer exact and predictable formula!
          # RANDOM BEGIN ----------------------------------------------------- 
          (assign,":min_bond",-10), 
          # Dunde's Luck Begin
          (troop_get_slot,":luck", ":troop_id", slot_troop_luck),       
          (store_div, ":luck_factor", ":luck", 10),
          (val_sub, ":luck_factor", 5),
          (val_add, ":min_bond", ":luck_factor"),
          # Dunde's Luck End
          (store_random_in_range, ":mod", ":min_bond", 11),
          (val_add, ":wound", ":mod"),
          # RANDOM END -------------------------------------------------------
          (assign, ":penalty", ":wound"),
          (party_get_skill_level, ":skl", "skl_first_aid", ":party_id"),        # First Aid may be help...
          (val_mul, ":skl", 3),                                                 # Double it for your favour...
          # Random end -----     
          (try_begin),                                                          # OK, let's start counting how bad is the blow destroy your hero!
             (lt, ":wound",  25),                                               # less then  25% HP, it's no big deal, just scretch
             (assign, ":penalty", 0), 
          (else_try),
             (lt, ":wound", 50),                                                #     25% - 50% HP, it's begin hurt ( 2.5 -  5 hours recovery)
             # do nothing
          (else_try),
             (lt, ":wound", 75),                                                #     50% - 75% HP, it's big blow   ( 25 - 50 hours recovery) 
             (val_sub, ":penalty",25),
             (val_mul, ":penalty", 10),
          (else_try),
             (lt, ":wound", 90),                                                #     40% - 60% HP, it's tereble much  (175 - 250 hours recovery)
             (val_sub, ":penalty", 40),                                         # Death may be come from this kind of blow..
             (val_mul, ":penalty", 50),
             (str_store_string, s2, "str_serious"),
             (store_random_in_range, ":mod",":luck",101),                       # OK!!! Your last chance to survive in 75% died, except for lucky one             
             (val_add, ":mod", ":skl"),                                         # mmm, wait, may be your party member can do first aid for you!!! Not much help, but why not try...
             (lt, ":mod", 25),
             (assign, ":penalty", -1),
          (else_try),                                                           # more then 95% HP, oh, no! A deadly blow.. No body can survive from that!!! Your luck can't help you anymore...   
             (val_sub, ":penalty", 40),                                         # 1000 - 1200 hours recovery for survivors
             (val_mul, ":penalty", 200),         
             (str_store_string, s2, "str_deadly"),
             (store_random_in_range, ":mod",0,101),                             # OK!!! Your last chance to survive in 50-50 dice!             
             (val_add, ":mod", ":skl"),                                         # mmm, wait, may be your party member can do first aid for you!!! Not much help, but why not try...
             (lt, ":mod", 25),
             (assign, ":penalty", -1),
          (try_end),     
          (str_store_troop_name, s1, ":troop_id"),
          (troop_get_type, reg3,":troop_id"),           
          (try_begin),
             (lt, ":penalty", 0),
             (agent_set_hit_points, ":troop_id", 0, 0),
             (troop_set_slot, ":troop_id", slot_troop_death, 1),               # Death
          (else_try),
             (gt, ":penalty", 0),
             (val_sub, ":penalty", ":skl"),               # First Aid 
             (val_max, ":penalty", 1),                    # Even best healer can't do immediate heal or make a hit occurs positive effect.   
             (try_begin),
                (lt, ":wound", 80),                       # Big Blow is on head or torso only
                (store_random_in_range, ":mod", 1, 7),    # Part of body that hit.     
             (else_try),
                (store_random_in_range, ":mod", 1, 3),    # Head or torso.. 
             (try_end),
             (try_begin),
                (eq, ":mod", 1),
                (troop_get_slot, ":wound", ":troop_id", slot_troop_head_injuried),
                (val_add, ":wound", ":penalty"),   
                (troop_set_slot, ":troop_id", slot_troop_head_injuried,":wound"),   
             (else_try),
                (eq, ":mod", 2),
                (troop_get_slot, ":wound", ":troop_id", slot_troop_torso_injuried),
                (val_add, ":wound", ":penalty"),   
                (troop_set_slot, ":troop_id", slot_troop_torso_injuried,":wound"),   
             (else_try),
                (eq, ":mod", 3),
                (troop_get_slot, ":wound", ":troop_id", slot_troop_arm1_injuried),
                (val_add, ":wound", ":penalty"),   
                (troop_set_slot, ":troop_id", slot_troop_arm1_injuried,":wound"),   
             (else_try),
                (eq, ":mod", 4),
                (troop_get_slot, ":wound", ":troop_id", slot_troop_arm2_injuried),
                (val_add, ":wound", ":penalty"),   
                (troop_set_slot, ":troop_id", slot_troop_arm2_injuried,":wound"),   
             (else_try),
                (eq, ":mod", 5),
                (troop_get_slot, ":wound", ":troop_id", slot_troop_leg1_injuried),
                (val_add, ":wound", ":penalty"),   
                (troop_set_slot, ":troop_id", slot_troop_leg1_injuried,":wound"),   
             (else_try),
                (troop_get_slot, ":wound", ":troop_id", slot_troop_leg2_injuried),
                (val_add, ":wound", ":penalty"),   
                (troop_set_slot, ":troop_id", slot_troop_leg2_injuried,":wound"),   
             (try_end),
           (try_end),
      (try_end),       
   ]),   

  #tick to check 
  ("do_check_is_any_body_injured",   
   [
       (try_for_agents, ":agent_id"),                                            # Search in battlefield
          (agent_get_troop_id, ":troop_id", ":agent_id"),                        # Get his Troop ID
          (assign, ":mod", 0),
          (try_begin),
             (ge, ":troop_id", wounded_heroes_begin),                            # He must be Wounded System's target.
             (lt, ":troop_id", wounded_heroes_end),
             (assign, ":mod", 1),
          (else_try),
              (eq, ":troop_id", "trp_player"),
              (assign, ":mod", 1),
          (end_try),
          (gt, ":mod", 0),
          (troop_get_slot, ":old_hp", ":troop_id", slot_troop_hp),
          (store_agent_hit_points, ":hit_points", ":agent_id", 0),
          (troop_set_slot, ":troop_id", slot_troop_hp, ":hit_points"),
          (store_sub, ":wound", ":old_hp", ":hit_points"),
          (gt, ":wound", 0),
          (str_clear, s1), (str_clear, s2), (str_clear, s3),
          # DUNDE : Ironflesh has effect too... 
          (store_skill_level, ":skl", "skl_ironflesh", ":troop_id"),
          (val_sub, ":wound", ":skl"),                 
          # DUNDE : Add random number...
          # Yeach, sometime luck can produce unpredictable result in war.
          # Comment lines betwen RANDOM BEGIN and RANDOM END if you don't like it, and prefer exact and predictable formula!
          # RANDOM BEGIN ----------------------------------------------------- 
          (assign,":min_bond",-10), 
          # Dunde's Luck Begin
          (troop_get_slot,":luck", ":troop_id", slot_troop_luck),       
          (store_div, ":luck_factor", ":luck", 10),
          (val_sub, ":luck_factor", 5),
          (val_add, ":min_bond", ":luck_factor"),
          # Dunde's Luck End
          (store_random_in_range, ":mod", ":min_bond", 11),
          (val_add, ":wound", ":mod"),
          # RANDOM END -------------------------------------------------------
          (assign, ":penalty", ":wound"),
          (agent_get_party_id, ":party", ":agent_id"),
          (party_get_skill_level, ":skl", "skl_first_aid", ":party"),           # First Aid may be help...
          (val_mul, ":skl", 3),                                                 # Double it for your favour...
          # Random end -----     
          (try_begin),                                                          # OK, let's start counting how bad is the blow destroy your hero!
             (lt, ":wound",  10),                                               # less then  10% HP, it's no big deal, just scretch
             (assign, ":penalty", 0), 
          (else_try),
             (lt, ":wound", 25),                                                #     10% - 25% HP, it's begin hurt ( 1 -  5 hours recovery)
             (val_sub, ":penalty", 5),
             (str_store_string, s2, "str_hurting"),
          (else_try),
             (lt, ":wound", 40),                                                #     25% - 40% HP, it's big blow   ( 20 - 30 hours recovery) 
             (val_sub, ":penalty",10),
             (val_mul, ":penalty", 10),
             (str_store_string, s2, "str_big"),
          (else_try),
             (lt, ":wound", 60),                                                #     40% - 60% HP, it's tereble much  (100 - 200 hours recovery)
             (val_sub, ":penalty", 20),                                         # Death may be come from this kind of blow..
             (val_mul, ":penalty", 50),
             (str_store_string, s2, "str_serious"),
             (store_random_in_range, ":mod",":luck",101),                       # OK!!! Your last chance to survive in 75% died, except for lucky one             
             (val_add, ":mod", ":skl"),                                         # mmm, wait, may be your party member can do first aid for you!!! Not much help, but why not try...
             (lt, ":mod", 50),
             (assign, ":penalty", -1),
          (else_try),
             (lt, ":wound", 75),                                                #     60% - 75% HP, it's fatal serious (350 - 500 hours recovery)
             (val_sub, ":penalty", 25),
             (val_mul, ":penalty", 100),
             (str_store_string, s2, "str_fatal"),
             (store_random_in_range, ":mod",":luck",101),                       # OK!!! Your last chance to survive in 75% died, except for lucky one             
             (val_add, ":mod", ":skl"),                                         # mmm, wait, may be your party member can do first aid for you!!! Not much help, but why not try...
             (lt, ":mod", 75),
             (assign, ":penalty", -1),
          (else_try),                                                           # more then 95% HP, oh, no! A deadly blow.. No body can survive from that!!! Your luck can't help you anymore...   
             (val_sub, ":penalty", 40),                                         # 700 - 1800 hours recovery for survivors
             (val_mul, ":penalty", 200),         
             (str_store_string, s2, "str_deadly"),
             (store_random_in_range, ":mod",0,101),                             # OK!!! Your last chance to survive in 50-50 dice!             
             (val_add, ":mod", ":skl"),                                         # mmm, wait, may be your party member can do first aid for you!!! Not much help, but why not try...
             (lt, ":mod", 75),
             (assign, ":penalty", -1),
          (try_end),     
          (str_store_troop_name, s1, ":troop_id"),
          (troop_get_type, reg3,":troop_id"),           
          (try_begin),
             (lt, ":penalty", 0),
             (store_random_in_range, ":mod", 1, 3),
             (try_begin),
                (eq, ":mod", 1), 
                (str_store_string, s2, "str_torso"),
             (else_try),
                (str_store_string, s2, "str_head"), 
             (try_end),
             (display_message, "@{s1} 's death for being hit by (s2} at {reg3?his:her} {s3}."),
             (agent_set_hit_points, ":troop_id", 0, 0),
             (troop_set_slot, ":troop_id", slot_troop_death, 1),               # Death
          (else_try),
             (gt, ":penalty", 0),
             (val_sub, ":penalty", ":skl"),               # First Aid 
             (val_max, ":penalty", 1),                    # Even best healer can't do immediate heal or make a hit occurs positive effect.   
             (try_begin),
                (lt, ":wound", 80),                       # Big Blow is on head or torso only
                (store_random_in_range, ":mod", 1, 7),    # Part of body that hit.     
             (else_try),
                (store_random_in_range, ":mod", 1, 3),    # Head or torso.. 
             (try_end),
             (try_begin),
                (eq, ":mod", 1),
                (troop_get_slot, ":wound", ":troop_id", slot_troop_head_injuried),
                (val_add, ":wound", ":penalty"),   
                (troop_set_slot, ":troop_id", slot_troop_head_injuried,":wound"),   
                (str_store_string, s3, "str_head"),   
             (else_try),
                (eq, ":mod", 2),
                (troop_get_slot, ":wound", ":troop_id", slot_troop_torso_injuried),
                (val_add, ":wound", ":penalty"),   
                (troop_set_slot, ":troop_id", slot_troop_torso_injuried,":wound"),   
                (str_store_string, s3, "str_torso"),   
             (else_try),
                (eq, ":mod", 3),
                (troop_get_slot, ":wound", ":troop_id", slot_troop_arm1_injuried),
                (val_add, ":wound", ":penalty"),   
                (troop_set_slot, ":troop_id", slot_troop_arm1_injuried,":wound"),   
                (str_store_string, s3, "str_left_arm"),   
             (else_try),
                (eq, ":mod", 4),
                (troop_get_slot, ":wound", ":troop_id", slot_troop_arm2_injuried),
                (val_add, ":wound", ":penalty"),   
                (troop_set_slot, ":troop_id", slot_troop_arm2_injuried,":wound"),   
                (str_store_string, s3, "str_right_arm"),   
             (else_try),
                (eq, ":mod", 5),
                (troop_get_slot, ":wound", ":troop_id", slot_troop_leg1_injuried),
                (val_add, ":wound", ":penalty"),   
                (troop_set_slot, ":troop_id", slot_troop_leg1_injuried,":wound"),   
                (str_store_string, s3, "str_left_leg"),   
             (else_try),
                (troop_get_slot, ":wound", ":troop_id", slot_troop_leg2_injuried),
                (val_add, ":wound", ":penalty"),   
                (troop_set_slot, ":troop_id", slot_troop_leg2_injuried,":wound"),   
                (str_store_string, s3, "str_right_arm"), 
             (try_end),
             (display_message, "@{s1} 's {s2} hit at {reg3?his:her} {s3}."),
           (try_end),
       (try_end),     
   ]),

  #calculate how bad injuried is
  # output : reg0 = penalty
  ("calculate_injuried_penalty",
   [
      (store_script_param, ":injuried", 1),
      (try_begin),
          (lt, ":injuried", 100),
          (assign, reg0, 0),
      (else_try),
          (lt, ":injuried", 300),
          (assign, reg0, 1),
      (else_try),
          (lt, ":injuried", 700),
          (assign, reg0, 2),
      (else_try),
          (assign, reg0, 3),
      (try_end),
   ]),
 
  #calculate penalty
  # output : reg0 = penalty
  ("calculate_injuried_skill_penalty",
   [
      (store_script_param, ":troop_id", 1),
      (store_script_param, ":skill_id", 2),
      (troop_get_slot, ":temp_inj", ":troop_id", slot_troop_head_injuried), (call_script, "script_calculate_injuried_penalty", ":temp_inj"), (assign, ":head", reg0),
      (troop_get_slot, ":temp_inj",":troop_id", slot_troop_torso_injuried), (call_script, "script_calculate_injuried_penalty", ":temp_inj"), (assign, ":torso", reg0),
      (troop_get_slot, ":temp_inj", ":troop_id", slot_troop_arm1_injuried), (call_script, "script_calculate_injuried_penalty", ":temp_inj"), (assign, ":arm1", reg0),
      (troop_get_slot, ":temp_inj", ":troop_id", slot_troop_arm2_injuried), (call_script, "script_calculate_injuried_penalty", ":temp_inj"), (assign, ":arm2", reg0),
      (troop_get_slot, ":temp_inj", ":troop_id", slot_troop_leg1_injuried), (call_script, "script_calculate_injuried_penalty", ":temp_inj"), (assign, ":leg1", reg0),
      (troop_get_slot, ":temp_inj", ":troop_id", slot_troop_leg2_injuried), (call_script, "script_calculate_injuried_penalty", ":temp_inj"), (assign, ":leg2", reg0),
      (assign, reg0, 0), 
      (try_begin), # need consentration
         (this_or_next|eq, ":skill_id", "skl_trade"),    (this_or_next|eq, ":skill_id", "skl_leadership"),
         (this_or_next|eq, ":skill_id", "skl_engineer"), (this_or_next|eq, ":skill_id", "skl_first_aid"),
         (this_or_next|eq, ":skill_id", "skl_surgery"),  (this_or_next|eq, ":skill_id", "skl_wound_treatment"),
         (this_or_next|eq, ":skill_id", "skl_spotting"), (this_or_next|eq, ":skill_id", "skl_pathfinding"),
         (this_or_next|eq, ":skill_id", "skl_tactics"),  (this_or_next|eq, ":skill_id", "skl_trainer"), (eq, ":skill_id", "skl_horse_archery"),
         (val_add, reg0, ":head"),
      (try_end),
      (try_begin), # overall health
         (this_or_next|eq, ":skill_id", "skl_athletics"), (eq, ":skill_id", "skl_ironflesh"),
         (val_add, reg0, ":torso"),
      (try_end),
      (try_begin), # need booth hand minors
         (this_or_next|eq, ":skill_id", "skl_first_aid"), (this_or_next|eq, ":skill_id", "skl_wound_treatment"),
         (this_or_next|eq, ":skill_id", "skl_surgery"),  (eq, ":skill_id", "skl_horse_archery"),
         (assign, ":temp_inj", ":arm1"), (val_add, ":temp_inj", ":arm2"), (val_div, ":temp_inj", 2),
         (val_add, reg0, ":temp_inj"),
      (try_end),
      (try_begin), # need right hand more
         (this_or_next|eq, ":skill_id", "skl_power_draw"),   (this_or_next|eq, ":skill_id", "skl_power_throw"),
         (this_or_next|eq, ":skill_id", "skl_power_strike"), (eq, ":skill_id", "skl_weapon_master"),
         (assign, ":temp_inj", ":arm2"), (val_mul, ":temp_inj", 2), (val_add, ":temp_inj", ":arm1"), (val_div, ":temp_inj", 2),
         (val_add, reg0, ":temp_inj"),
      (try_end),
      (try_begin), # need left hand only
         (eq, ":skill_id", "skl_shield"),
         (assign, ":temp_inj", ":arm1"), (val_mul, ":temp_inj", 3), (val_div, ":temp_inj", 2),
         (val_add, reg0, ":temp_inj"),
      (try_end),
      (try_begin), # need legs
         (eq, ":skill_id", "skl_athletics"),
         (assign, ":temp_inj", ":leg1"), (val_add, ":temp_inj", ":leg2"),
         (val_add, reg0, ":temp_inj"),
      (try_end),
      (try_begin), # need armst & legs
         (eq, ":skill_id", "skl_riding"),
         (assign, ":temp_inj", ":leg1"), (val_add, ":temp_inj", ":leg2"), (val_add, ":temp_inj", ":arm1"), (val_add, ":temp_inj", ":arm2"), (val_div, ":temp_inj", 3),
         (val_add, reg0, ":temp_inj"),
      (try_end),
   ]),

  #treat injuried
  ("do_treat_injuried",
   [
      (store_script_param, ":troop_id", 1),
      (store_script_param, ":heal", 2),
      (try_for_range, ":injuried_type", injuried_begin, injuried_end),
         (troop_get_slot, ":injuried", ":troop_id", ":injuried_type"),
         (val_sub, ":injuried", ":heal"),
         (troop_set_slot, ":troop_id", ":injuried_type", ":injuried"),
      (try_end),
   ]),

  # script_dunde_get_injuried_text
  # input  : troop_id   ;
  # output : S1 - S6    ; injuried state in text
  ("dunde_get_injuried_text",
   [
      (store_script_param, ":troop_id", 1),
      (troop_get_type, reg13, ":troop_id"),
      (troop_get_slot, ":injuried", ":troop_id", slot_troop_head_injuried),
      (assign, reg1, ":injuried"),
      (try_begin),
         (lt, ":injuried", 100),
         (str_clear, s1),
      (else_try),
         (lt, ":injuried", 300),
         (str_store_string, s1, "@light concussion"),
      (else_try),
         (lt, ":injuried", 700),
         (str_store_string, s1, "@heavy concussion"),
      (else_try),
         (str_store_string, s1, "@cracked bone"),
      (try_end),
      (troop_get_slot, ":injuried", ":troop_id", slot_troop_torso_injuried),
      (assign, reg2, ":injuried"),
      (try_begin),
         (lt, ":injuried", 100),
         (str_clear, s2),
      (else_try),
         (lt, ":injuried", 300),
         (str_store_string, s2, "@light wound in {reg13?her:his}"),
      (else_try),
         (lt, ":injuried", 700),
         (str_store_string, s2, "@severe wound in {reg13?her:his} chest"),
      (else_try),
         (str_store_string, s2, "@tereble internal bleeding"),
      (try_end),
      (troop_get_slot, ":injuried", ":troop_id", slot_troop_arm1_injuried),
      (assign, reg3, ":injuried"),
      (try_begin),
         (lt, ":injuried", 100),
         (str_clear, s3),
      (else_try),
         (lt, ":injuried", 300),
         (str_store_string, s3, "@light wound in {reg13?her:his} left arm"),
      (else_try),
         (lt, ":injuried", 700),
         (str_store_string, s3, "@severe wound in {reg13?her:his} left arm"),
      (else_try),
         (str_store_string, s3, "@broken left arm"),
      (try_end),
      (troop_get_slot, ":injuried", ":troop_id", slot_troop_arm2_injuried),
      (assign, reg4, ":injuried"),
      (try_begin),
         (lt, ":injuried", 100),
         (str_clear, s4),
      (else_try),
         (lt, ":injuried", 300),
         (str_store_string, s4, "@light wound in {reg13?her:his} right arm"),
      (else_try),
         (lt, ":injuried", 700),
         (str_store_string, s4, "@severe wound in {reg13?her:his} right arm"),
      (else_try),
         (str_store_string, s4, "@broken right arm"),
      (try_end),
      (troop_get_slot, ":injuried", ":troop_id", slot_troop_leg1_injuried),
      (assign, reg5, ":injuried"),
      (try_begin),
         (lt, ":injuried", 100),
         (str_clear, s5),
      (else_try),
         (lt, ":injuried", 300),
         (str_store_string, s5, "@light wound in {reg3?her:his} left leg"),
      (else_try),
         (lt, ":injuried", 700),
         (str_store_string, s5, "@severe wound in {reg13?her:his} left leg"),
      (else_try),
         (str_store_string, s5, "@broken left leg"),
      (try_end),
      (troop_get_slot, ":injuried", ":troop_id", slot_troop_leg2_injuried),
      (assign, reg6, ":injuried"),
      (try_begin),
         (lt, ":injuried", 100),
         (str_clear, s6),
      (else_try),
         (lt, ":injuried", 300),
         (str_store_string, s6, "@light wound in {reg13?her:his} right leg"),
      (else_try),
         (lt, ":injuried", 700),
         (str_store_string, s6, "@severe wound in {reg13?her:his} left leg"),
      (else_try),
         (str_store_string, s6, "@broken right leg"),
      (try_end),     
   ]),

#-- Dunde's Wounded System End

dunde

  • Guest
Re: Python script/scheme/source exchange
« Reply #23 on: February 09, 2009, 04:57:50 AM »
contined from my last post :

in module_constant.py :
#-- Dunde's  Constants Begin ----
slot_troop_luck = 142
slot_troop_hp   = 143
slot_troop_head_injuried = 144
slot_troop_torso_injuried = 145
slot_troop_arm1_injuried = 146
slot_troop_arm2_injuried = 147
slot_troop_leg1_injuried = 148
slot_troop_leg2_injuried = 149
slot_troop_death = 150

then, spawning kingdom heroes in module_simple_triggers.py, changed to :
  # Respawn hero party after kingdom hero is released from captivity.
  (48,
   [
       (try_for_range, ":troop_no", kingdom_heroes_begin, kingdom_heroes_end), 
         (troop_slot_eq, ":troop_no", slot_troop_occupation, slto_kingdom_hero),                                                            # He is a hero, an a lord.
         #(troop_slot_eq, ":troop_no", slot_troop_is_prisoner, 0),
         (neg|troop_slot_ge, ":troop_no", slot_troop_prisoner_of_party, 0),                                                                 # He must not be a prisoner
         (neg|troop_slot_ge, ":troop_no", slot_troop_leaded_party, 1),                                                                      # He must not be leading a party (active)
         # Dunde's Wounded System : 
         (neg|troop_slot_ge, ":troop_no", slot_troop_death, 1),                                                                             # Death Heroes never be respawned. 
         # ---------------------------------------------------------------------------------   
         (store_troop_faction, ":cur_faction", ":troop_no"),                                                                                # DUNDE's NEW KNOWLEDGE :   
         (try_begin),                                                                                                                       # find center of his own faction
           (call_script, "script_cf_select_random_walled_center_with_faction_and_owne r_priority_no_siege", ":cur_faction", ":troop_no"),    #Can fail
           (assign, ":center_no", reg0),
           (call_script, "script_create_kingdom_hero_party", ":troop_no", ":center_no"),
           (party_attach_to_party, "$pout_party", ":center_no"),
         (else_try),
           (neg|faction_slot_eq, ":cur_faction", slot_faction_state, sfs_active),                                                           # if faction's destroyed
           (try_begin),
             (is_between, ":troop_no", kings_begin, kings_end),                                                                             # then their king become commoner
             (troop_set_slot, ":troop_no", slot_troop_change_to_faction, "fac_commoners"),
           (else_try),
             (store_random_in_range, ":random_no", 0, 100),
             (lt, ":random_no", 10),                                                                                                        # and the others, 10% chance to join another faction     
             (call_script, "script_cf_get_random_active_faction_except_player_faction_a nd_faction", ":cur_faction"),                        # 90% chance to continue hiding.   
             (troop_set_slot, ":troop_no", slot_troop_change_to_faction, reg0),
           (try_end),
         (try_end),
       (try_end),
    ]),

for luck system :
  # Dunde's Luck Begin --------------------------------------------- 
  (24,                                                  # It's that make luck wave...
   [
       (try_for_range, ":troop_no", wounded_heroes_begin, wounded_heroes_end),  # For all Heroes, let's start with about 50's
          (assign,":troop_id", ":troop_no"),
          (try_begin),
             (eq, ":troop_no", "trp_kingdom_heroes_including_player_begin"),
             (assign,":troop_id", "trp_player"),     
          (try_end),           
          (troop_get_slot, ":current_luck", ":troop_id", slot_troop_luck),
          (store_random_in_range, ":luck", -10, 11),
          (try_begin),
             (gt, ":luck",0),                                  # This loop make bad/good luck is harder to go away
             (val_mul, ":luck", ":current_luck"),
             (val_div, ":luck", 50),
          (else_try),
             (gt, ":current_luck",0),                          # avoiding division by zero
             (val_mul, ":luck", 50),
             (val_div, ":luck", ":current_luck"),
          (try_end),
          (try_begin),
             (eq, ":luck", 0), 
             (store_random_in_range, ":luck", -5, 6),          # Just in case, division make them to nol always
          (try_end),
          (val_add, ":current_luck", ":luck"),         
          (val_add, ":current_luck", ":luck"),
          (val_clamp, ":current_luck", 0, 101),                # Luck is 0 till 100 range
          (troop_set_slot, ":troop_id", slot_troop_luck, ":current_luck"),
      (try_end),   
    ]),
  # Dunde's Luck End ------------------------------------------------ 


in module_scripts.py, initialitation for luck for any heroes :
  ("game_start",
   [
      #Autoloot---
      # initialization hook
      (call_script, "script_init_item_difficulties"),
      #end Autoloot---
      (faction_set_slot, "fac_player_supporters_faction", slot_faction_state, sfs_inactive),
      # -- DUNDE BEGIN ----------------------------------------------------------------------------------
      # Let's redone Luck system
      # ORI : (assign, "$g_player_luck", 200),
      (try_for_range, ":cur_troop", wounded_heroes_begin, wounded_heroes_end),  # For all Heroes, let's start with about 50's
         (store_random_in_range, ":luck", -10, 11),
         (val_add, ":luck", 50),
         (assign,":troop_id", ":cur_troop"),
         (try_begin),
            (eq, ":cur_troop", "trp_kingdom_heroes_including_player_begin"),
            (assign,":troop_id", "trp_player"),     
         (try_end),           
         (troop_set_slot, ":troop_id", slot_troop_luck, ":luck"),
      (try_end),
      # -- DUNDE END ------------------------------------------------------------------------------------
      (troop_set_slot, "trp_player", slot_troop_occupation, slto_kingdom_hero),
      (troop_set_slot, "trp_player", slot_troop_prisoner_of_party, -1),

in module_troops.py :
I move xerina cs. so it closed to another npc so I can select by range all npc for injuried system
# Tavern minstrel.
  ["tavern_minstrel_1","Minstrel","Minstrel",tf_hero|tf_randomize_face, 0, reserved, fac_commoners,[itm_leather_jacket,itm_hide_boots],def_attrib|level(5),wp(20),knows_common,merchant_face_1,merchant_face_2],

#-- DUNDE BEGIN --
# DUNDE : New Locations for Xerina cs, this marked as wounded system begin
#         These bastard tourney champions must be included in woundes system too...
#         What for? For my future plan to redone tournament completely, and perhaps... Hey, don't you want to duel with or recruit them?
#         Btw, wow.... I never realize their level before... And now, I know  why they often beat me in tourney before...
  ["Xerina","Xerina","Xerina",tf_hero|tf_female, scn_the_happy_boar|entry(5),reserved,  fac_commoners,[itm_leather_jerkin,itm_hide_boots],def_attrib|str_15|agi_15|level(39),wp(312),knows_power_strike_5|knows_ironflesh_5|knows_riding_6|knows_power_draw_4|knows_athletics_8|knows_shield_3,0x00000001ac0820074920561d0b51e6ed00000000001d40ed0000000000000000],
  ["Dranton","Dranton","Dranton",tf_hero, scn_the_happy_boar|entry(2),reserved,  fac_commoners,[itm_leather_vest,itm_hide_boots],def_attrib|str_15|agi_14|level(42),wp(324),knows_power_strike_5|knows_ironflesh_7|knows_riding_4|knows_power_draw_4|knows_athletics_4|knows_shield_3,0x0000000a460c3002470c50f3502879f800000000001ce0a00000000000000000],
  ["Kradus","Kradus","Kradus",tf_hero, scn_the_happy_boar|entry(3),reserved,  fac_commoners,[itm_padded_leather,itm_hide_boots],def_attrib|str_15|agi_14|level(43),wp(270),knows_power_strike_5|knows_ironflesh_7|knows_riding_4|knows_power_draw_4|knows_athletics_4|knows_shield_3,0x0000000f5b1052c61ce1a9521db1375200000000001ed31b0000000000000000],
#-- DUNDE END ----


#NPC system changes begin
#Companions
  ["npc1","Borcha","Borcha",tf_hero|tf_unmoveable_in_party_window, 0, reserved, fac_commoners,[itm_khergit_armor,itm_nomad_boots,itm_knife],
   str_8|agi_7|int_12|cha_7|level(3),wp(60),knows_tracker_npc|
   knows_ironflesh_1|knows_power_strike_1|knows_pathfinding_3|knows_athletics_2|knows_tracking_1|knows_riding_2, #skills 2/3 player at that level
   0x00000004bf086143259d061a9046e23500000000001db52c000000000 0000000],
  ["npc2","Marnid","Marnid", tf_hero|tf_unmoveable_in_party_window, 0,reserved, fac_commoners,[itm_linen_tunic,itm_hide_boots,itm_club],


If battle simulation need for injuried to :
module_scripts.py
  #script_game_event_simulate_battle:
  # This script is called whenever the game simulates the battle between two parties on the map.
  # INPUT:
  # param1: Defender Party
  # param2: Attacker Party
  ("game_event_simulate_battle",
    [
       (store_script_param_1, ":root_defender_party"),
       (store_script_param_2, ":root_attacker_party"),

       (try_begin),
         (store_faction_of_party, ":defender_faction", ":root_defender_party"),
         (store_faction_of_party, ":attacker_faction", ":root_attacker_party"),
         (neq, ":defender_faction", "fac_player_faction"),
         (neq, ":attacker_faction", "fac_player_faction"),
         (store_relation, ":reln", ":defender_faction", ":attacker_faction"),
         (ge, ":reln", 0),
         (set_trigger_result, 1),
       (else_try),
         (assign, ":trigger_result", 0),

         (try_begin),
           (this_or_next|eq, "$g_battle_simulation_cancel_for_party", ":root_defender_party"),
           (eq, "$g_battle_simulation_cancel_for_party", ":root_attacker_party"),
           (assign, "$g_battle_simulation_cancel_for_party", -1),
           (assign, "$auto_enter_town", "$g_battle_simulation_auto_enter_town_after_battle"),
           (assign, ":trigger_result", 1),
         (else_try),
           (try_begin),
             (this_or_next|party_slot_eq, ":root_defender_party", slot_party_retreat_flag, 1),
             (party_slot_eq, ":root_attacker_party", slot_party_retreat_flag, 1),
             (assign, ":trigger_result", 1), #End battle!
           (try_end),
           (party_set_slot, ":root_attacker_party", slot_party_retreat_flag, 0),

  ##         (assign, ":cancel_attack", 0),

           (party_collect_attachments_to_party, ":root_defender_party", "p_collective_ally"),
           (party_collect_attachments_to_party, ":root_attacker_party", "p_collective_enemy"),

 #          (call_script, "script_party_count_fit_for_battle", "p_collective_ally"),
           (call_script, "script_party_calculate_strength", "p_collective_ally", 0),
           (assign, ":defender_strength", reg0),
#           (call_script, "script_party_count_fit_for_battle", "p_collective_enemy"),
           (call_script, "script_party_calculate_strength", "p_collective_enemy", 0),
           (assign, ":attacker_strength", reg0),

           (store_div, ":defender_strength", ":defender_strength", 20),
           (val_min, ":defender_strength", 50),
           (val_max, ":defender_strength", 1),
           (store_div, ":attacker_strength", ":attacker_strength", 20),
           (val_min, ":attacker_strength", 50),
           (val_add, ":attacker_strength", 1),
           (try_begin),
             #For sieges increase attacker casualties and reduce defender casualties.
             (this_or_next|party_slot_eq, ":root_defender_party", slot_party_type, spt_castle),
             (party_slot_eq, ":root_defender_party", slot_party_type, spt_town),
             (val_mul, ":defender_strength", 3),
             (val_div, ":defender_strength", 2),
             (val_div, ":attacker_strength", 2),
           (try_end),

# Dunde's Wounded System Initialitation point ------------------------------------------------------------------------
           (call_script,"script_do_init_wounded_system"),
# --------------------------------------------------------------------------------------------------------------------
       
           (try_begin),
             (neg|is_currently_night), #Don't fight at night
             (inflict_casualties_to_party_group, ":root_attacker_party", ":defender_strength", "p_temp_casualties"),
             (party_collect_attachments_to_party, ":root_attacker_party", "p_collective_enemy"),
           (try_end),
# Dunde's Wounded System for defender --------------------------------------------------------------------------------
           (call_script, "script_do_check_simulated_batle_injuried", "p_collective_enemy"),
# --------------------------------------------------------------------------------------------------------------------
           (call_script, "script_party_count_fit_for_battle", "p_collective_enemy", 0),
           (assign, ":new_attacker_strength", reg0),

           (try_begin),
#             (gt, ":new_attacker_strength", 0),                            COMMENTED BY DUNDE : Unfair for attacker
             (neg|is_currently_night), #Don't fight at night
             (inflict_casualties_to_party_group, ":root_defender_party", ":attacker_strength", "p_temp_casualties"),
             (party_collect_attachments_to_party, ":root_defender_party", "p_collective_ally"),
           (try_end),
# Dunde's Wounded System for attacker --------------------------------------------------------------------------------
           (call_script, "script_do_check_simulated_batle_injuried", "p_collective_ally"),
# --------------------------------------------------------------------------------------------------------------------
           (call_script, "script_party_count_fit_for_battle", "p_collective_ally", 0),
           (assign, ":new_defender_strength", reg0),

           (try_begin),
             (this_or_next|eq, ":new_attacker_strength", 0),
             (eq, ":new_defender_strength", 0),
             # Battle concluded! determine winner

             (try_begin),
               (eq, ":new_attacker_strength", 0),
               (eq, ":new_defender_strength", 0),
               (assign, ":root_winner_party", -1),
               (assign, ":root_defeated_party", -1),
               (assign, ":collective_casualties", -1),
             (else_try),
               (eq, ":new_attacker_strength", 0),
               (assign, ":root_winner_party",   ":root_defender_party"),
               (assign, ":root_defeated_party", ":root_attacker_party"),
               (assign, ":collective_casualties",    "p_collective_enemy"),
             (else_try),
               (assign, ":root_winner_party", ":root_attacker_party"),
               (assign, ":root_defeated_party",  ":root_defender_party"),
               (assign, ":collective_casualties",  "p_collective_ally"),
             (try_end),

             (try_begin),
               (ge, ":root_winner_party", 0),
               (call_script, "script_get_nonempty_party_in_group", ":root_winner_party"),
               (assign, ":nonempty_winner_party", reg0),
               (store_faction_of_party, ":faction_receiving_prisoners", ":nonempty_winner_party"),
               (store_faction_of_party, ":defeated_faction", ":root_defeated_party"),
             (else_try),
               (assign, ":nonempty_winner_party", -1),
             (try_end),

             (try_begin),
               (ge, ":collective_casualties", 0),
               (party_get_num_companion_stacks, ":num_stacks", ":collective_casualties"),
             (else_try),
               (assign, ":num_stacks", 0),
             (try_end),
             (try_for_range, ":troop_iterator", 0, ":num_stacks"),
               (party_stack_get_troop_id, ":cur_troop_id", ":collective_casualties", ":troop_iterator"),
               (troop_is_hero, ":cur_troop_id"),
               (call_script, "script_remove_troop_from_prison", ":cur_troop_id"),
               (troop_set_slot, ":cur_troop_id", slot_troop_leaded_party, -1),
               (store_random_in_range, ":rand", 0, 100),
               (str_store_troop_name_link, s1, ":cur_troop_id"),
               (str_store_faction_name_link, s2, ":faction_receiving_prisoners"),
               (store_troop_faction, ":defeated_troop_faction", ":cur_troop_id"),
               (str_store_faction_name_link, s3, ":defeated_troop_faction"),
               (try_begin),
                  (troop_get_slot, ":death", ":cur_troop_id", slot_troop_death),
                  (gt, ":death",0),
                  (display_message,"@{s1} of {s3} was defeated in battle and death... "),
               (else_try),
                 (ge, ":rand", hero_escape_after_defeat_chance),
                 #------ Ga Seru donk.... Bandit juga bisa menawan hero ------------------------------------------------------------------------       
                 #(party_stack_get_troop_id, ":leader_troop_id", ":nonempty_winner_party", 0),
                 #(is_between, ":leader_troop_id", kingdom_heroes_begin, kingdom_heroes_end), #disable non-kingdom parties capturing enemy lords
                 #------------------------------------------------------------------------------------------------------------------------------
                 (party_add_prisoners, ":nonempty_winner_party", ":cur_troop_id", 1),
                 (gt, reg0, 0),
                 #(troop_set_slot, ":cur_troop_id", slot_troop_is_prisoner, 1),
                 (troop_set_slot, ":cur_troop_id", slot_troop_prisoner_of_party, ":nonempty_winner_party"),
                 (display_log_message, "str_hero_taken_prisoner"),
               (else_try),
                 (display_message,"@{s1} of {s3} was defeated in battle but managed to escape."),
               (try_end),
               (try_begin),
                 (store_troop_faction, ":cur_troop_faction", ":cur_troop_id"),
                 (faction_slot_eq, ":cur_troop_faction", slot_faction_marshall, ":cur_troop_id"),
                 #Marshall is defeated, refresh ai.
                 (assign, "$g_recalculate_ais", 1),
               (try_end),
             (try_end),
             (try_begin),
               (ge, ":collective_casualties", 0),
               (party_get_num_prisoner_stacks, ":num_stacks", ":collective_casualties"),
             (else_try),
               (assign, ":num_stacks", 0),
             (try_end),
             (try_for_range, ":troop_iterator", 0, ":num_stacks"),
               (party_prisoner_stack_get_troop_id, ":cur_troop_id", ":collective_casualties", ":troop_iterator"),
               (troop_is_hero, ":cur_troop_id"),
               (call_script, "script_remove_troop_from_prison", ":cur_troop_id"),
               (store_troop_faction, ":cur_troop_faction", ":cur_troop_id"),
               (str_store_troop_name_link, s1, ":cur_troop_id"),
               (str_store_faction_name_link, s2, ":faction_receiving_prisoners"),
               (str_store_faction_name_link, s3, ":cur_troop_faction"),
               (display_log_message,"str_hero_freed"),
             (try_end),

             (try_begin),
               (ge, ":collective_casualties", 0),
               (party_clear, "p_temp_party"),
               (assign, "$g_move_heroes", 0), #heroes are already processed above. Skip them here.
               (call_script, "script_party_add_party_prisoners", "p_temp_party", ":collective_casualties"),
               (call_script, "script_party_prisoners_add_party_companions", "p_temp_party", ":collective_casualties"),
               (distribute_party_among_party_group, "p_temp_party", ":root_winner_party"),
               (call_script, "script_clear_party_group", ":root_defeated_party"),
                # -- NNY PATROL BEGIN --
                (call_script,"script_cf_fix_party_size", "p_temp_party",0),       
                # -- NNY PATROL END --
             (try_end),
             (assign, ":trigger_result", 1), #End battle!

             #Center captured
             (try_begin),
               (ge, ":collective_casualties", 0),
               (party_get_slot, ":cur_party_type", ":root_defeated_party", slot_party_type),
               (this_or_next|eq, ":cur_party_type", spt_town),
               (eq, ":cur_party_type", spt_castle),

               (assign, "$g_recalculate_ais", 1),

               (store_faction_of_party, ":winner_faction", ":root_winner_party"),
               (store_faction_of_party, ":defeated_faction", ":root_defeated_party"),

               (str_store_party_name, s1, ":root_defeated_party"),
               (str_store_faction_name, s2, ":winner_faction"),
               (str_store_faction_name, s3, ":defeated_faction"),
               (display_log_message, "str_center_captured"),

               (try_begin),
                    (eq, "$g_encountered_party", ":root_defeated_party"),
  ##                  (display_message, "@Player participation in siege called from g_encountered_party"),
                    (call_script, "script_add_log_entry", logent_player_participated_in_siege, "trp_player",  "$g_encountered_party", 0, "$g_encountered_party_faction"),
               (try_end),
  ##             (try_begin),
  ##                  (eq, "$g_encountered_party_2", ":root_defeated_party"),
  ##                  (display_message, "@Player participation in siege called from game_event_simulate_battle thanks to g_encountered_party"),
  ##             (try_end),
  ##             (try_begin),
  ##                  (eq, "$g_enemy_party", ":root_defeated_party"),
  ##                  (display_message, "@Player participation in siege called from game_event_simulate_battle thanks to g_encountered_party"),
  ##             (try_end),


               (try_begin),
                 (party_get_num_companion_stacks, ":num_stacks", ":root_winner_party"),
                 (gt, ":num_stacks", 0),
                 (party_stack_get_troop_id, ":leader_troop_no", ":root_winner_party", 0),
                 (is_between, ":leader_troop_no", kingdom_heroes_begin, kingdom_heroes_end),
                 (party_set_slot, ":root_defeated_party", slot_center_last_taken_by_troop, ":leader_troop_no"),
               (else_try),
                 (party_set_slot, ":root_defeated_party", slot_center_last_taken_by_troop, -1),
               (try_end),

               (call_script, "script_lift_siege", ":root_defeated_party", 0),
               (call_script, "script_give_center_to_faction", ":root_defeated_party", ":winner_faction"),
               (try_begin),
                 (eq, ":defeated_faction", "fac_player_supporters_faction"),
                 (call_script, "script_add_notification_menu", "mnu_notification_center_lost", ":root_defeated_party", ":winner_faction"),
               (try_end),
               #Reduce prosperity of the center by 5
               (call_script, "script_change_center_prosperity", ":root_defeated_party", -5),
               (call_script, "script_order_best_besieger_party_to_guard_center", ":root_defeated_party", ":winner_faction"),
               (call_script, "script_cf_reinforce_party", ":root_defeated_party"),
               (call_script, "script_cf_reinforce_party", ":root_defeated_party"),
             (try_end),
           (try_end),

           #ADD XP
           (try_begin),
             (party_slot_eq, ":root_attacker_party", slot_party_type, spt_kingdom_hero_party),
             (store_random_in_range, ":random_num",0, 100),
             (lt, ":random_num", 25),
             (gt, ":new_attacker_strength", 0),
             (call_script, "script_upgrade_hero_party", ":root_attacker_party", 1000),
           (try_end),
           (try_begin),
             (party_slot_eq, ":root_defender_party", slot_party_type, spt_kingdom_hero_party),
             (store_random_in_range, ":random_num",0, 100),
             (lt, ":random_num", 25),
             (gt, ":new_defender_strength", 0),
             (call_script, "script_upgrade_hero_party", ":root_defender_party", 1000),
           (try_end),

           (store_random_in_range, ":random_num", 0, 100),
           (try_begin),
             (lt, ":random_num", 10),
  ##           (this_or_next|lt, ":random_num", 10),
  ##           (eq, ":cancel_attack", 1),
             (assign, ":trigger_result", 1), #End battle!
           (try_end),
         (try_end),
         (set_trigger_result, ":trigger_result"),
       (try_end),
  ]),


Healing :
module_simple_triggers.py
  # Dunde's Healing
  (0.5,
   [
       (try_for_parties, ":party_id"),
          (party_get_num_companion_stacks, ":num_stacks", ":party_id"),
          # Seach between troops in parties
          (try_for_range, ":stack_no", 0, ":num_stacks"),
             (party_stack_get_troop_id, ":troop_id", ":party_id", ":stack_no"),
             (is_between, ":troop_id", wounded_heroes_begin, wounded_heroes_end),
             (troop_get_slot, ":death", ":troop_id", slot_troop_death),
             (store_troop_health,":troop_health", ":troop_id", 0),
             (eq, ":death", 0),   
             (assign, ":rest", 0),
             (assign, ":mod", 5), 
             (try_begin),
                (is_between, ":party_id", centers_begin, centers_end),
                (store_skill_level, ":treatment", "skl_wound_treatment", ":troop_id"),
                (assign, ":rest", 1),   
             (else_try), 
                (party_get_skill_level, ":treatment", ":party_id", "skl_wound_treatment"),
                (neg|map_free), (eq, ":party_id", "p_main_party"), (assign, ":rest", 1),
             (try_end),
             (try_begin),
                (eq, ":rest", 1), (val_mul, ":mod", 3),  (val_div, ":mod", 2),   
             (try_end),
             (val_mul, ":mod", ":troop_health"),
             (val_mul, ":treatment", 75),
             (val_add, ":mod", ":treatment"), 
             (val_div, ":mod", 100),
             (call_script, "script_do_treat_injuried", ":troop_id", ":mod"), 
          (try_end),
          (party_get_num_prisoner_stacks , ":num_stacks", ":party_id"),
          # Search between prisoners
          (try_for_range, ":stack_no", 0, ":num_stacks"),
             (party_prisoner_stack_get_troop_id, ":troop_id", ":party_id", ":stack_no"),           
             (is_between, ":troop_id", wounded_heroes_begin, wounded_heroes_end),
             (store_troop_health,":troop_health", ":troop_id", 0),
             (store_skill_level, ":treatment", "skl_wound_treatment", ":troop_id"),
             (assign, ":mod", 5),
             (val_mul, ":mod", ":troop_health"),
             (val_mul, ":treatment", 75),
             (val_add, ":mod", ":treatment"), 
             (val_div, ":mod", 100),
             (call_script, "script_do_treat_injuried", ":troop_id", ":mod"),
          (try_end),             
       (try_end),               # for parties
   ]),     


Hoping someone can help me testing or debugging this.
Thanks.

Dunde
« Last Edit: February 09, 2009, 05:02:47 AM by dunde »