Golcondio said:This is my first "serious" script with M&B's system, so I thought it'd be cool to share...
It's a script that loots prisoners (based on prisoner troops' inventory) and gives items to the player; if the player's inventory is full, the script will target heroes.
Item quality is randomized (since all items in non-hero troops' inventories have no imods), based on another script you'll find here...
You can put the scripts in your own mod as they are: you just need a trigger or a conversation that activates the script.
Hope you enjoy!
Why? Because I'm new at scripting (when I say new, I mean "never written a line of code before"), so my aim was to make it work, not finesse...Winter said:Why a massively complicated bunch of scripts like this? Try copying and adjusting the Native looting mechanisms to use player party prisoners. That would allow you to do everything in just one small script, removes the need for custom item identification or imod scripts, removes the need for extra troop types, and even solves the problem of inappropriate imods.
Sedentarily,
Winter
change_screen_loot
troop_loot_troop
Golcondio said:Why? Because I'm new at scripting (when I say new, I mean "never written a line of code before"), so my aim was to make it work, not finesse...
I actually TRIED using the looting mechanisms but I can't manage to understand how I'm supposed to use operations likeandCode:change_screen_loot
: I tried putting them in triggers (I tested every bit of my script that way) but nothing happened...Code:troop_loot_troop
Thanks! knowing this beforehand would have saved me a lot of crosschecking, but I still learned something...Winter said:I believe that looting requires you to be in an encounter for it to work, and possibly even requires being called from a game menu, so it would indeed fail when used in a trigger. Instead I'd test it by: 1) starting an encounter with a dummy party or using a variable condition, which 2) dumps the player to a menu that redirects to the loot screen, and finally 3) leave_encounter and change_screen_return.
Also, just a note, in your item scripts you can actually use item entries and imods directly. You don't have to use their numbers. For example, (is_between,":range","itm_horse_meat","itm_practice_sword"), works equally well as (is_between,":range",1,2),. You can also address imods directly by using the constants defined in header_item_modifiers. For example, instead of (assign,reg(5),16),#hardened armor you can use (assign,reg(5),imod_hardened),#hardened armor
Sunderedly,
Winter
Golcondio said:Thanks! knowing this beforehand would have saved me a lot of crosschecking, but I still learned something...
I'll try the encounter thing, which means: Back To Coding!!! (I actually spent more time in the past weeks coding and browsing the forum for answers than playing...)
Winter said:Also, Amman de Stazia, what you're suggesting doesn't work. troop_add_item ignores the list of imodbits, something which I've frequently exploited for Craftmod.
Sedentarily,
Winter
Amman de Stazia said:(troop_add_item, "trp_player","itm_steel_bolts",0)
change zero to some other numbers.... go on
the number references an imodbit. If you cross-check the list of modifiers (complete) with the list of modifiers applicable to that item, you can select from the correct spread of numbers, thus adding an item with a modifier.
locomotively
Amman
Amman de Stazia said:that's actually pretty cool, because in addition it lets you do things like take your weapon to the smith and have it improved. The only script needed would be to (quality+1) on the weapon currently equipped. Right?
Here's another way of working inside the imodbit system:
[assign,reg(10),imod_tattered],
[assign,reg(11),imod_reinforced],
[assign,reg(12),imod_thick],
[assign,reg(13),imod_ragged],
(store_random_in_range,reg(0),reg(10),reg(14)), (troop_remove_item,0,"itm_padded_cloth"),(troop_add_item,"trp_marnid","itm_padded_cloth",reg(0)),
Highlander said:You could use
(store_random_in_range,reg(1),10,14)
(troop_remove_item,0,"itm_padded_cloth"),(troop_add_item,"trp_marnid","itm_padded_cloth",reg(reg(1))),
I'm not 100% sure, but if I remember correct, I've successfully used something like that before. Just try it.
Hellequin said:Making a version which did the same thing the other direction would be much the same affair. I believe Craftmod does it similarly as well.
Manitas has a good point except that imods have the advantage of a great deal of user-visible content in a relatively compact manner. To simply replicate Native's level of detail using that scheme would multiply the number of items five- to seven-fold. Construction of items (all items) using an adjective plus a noun, or indeed simply from two strings if you chose to break the standard grammar, is an extremely powerful tool. Right now it's an extremely powerful tool with strong limitations. Someday, however, Armagan may be good enough to give us the ability to define our own imod lists and their effects. At which point, look out, it's a whole 'nother ball game.
(Here's a thought - just use the same format as module_items objects for the newly defined modifiers. That is, a now-nonexistent module_item_modifiers.py would contain tupes identical to item tuples, which are added to the items in-game once an imod has been assigned. The name portion gets added on the front of the item's name (rendering the header_item_modifiers.csv file obsolete). The numerical values such as speed, weight, or damage get added to the item's stats, and default to zero [no change] where not specified. The mesh field would be unused in most cases, although the possibility exists to define a mesh here which will also be drawn every time the imod is present (perhaps a sickly green aura); mostly, meshes would continue to be associated with the item, and be able to include alternates associated with specific imods, just as now.)
#THE RANDOM CHARACTER
("start_xplrar",[(eq, "$clss_chc", 24),
(store_random_in_range, "$strdice", 0, 6),
(store_random_in_range, "$agidice", 0, 6),
(store_random_in_range, "$intdice", 0, 6),
(store_random_in_range, "$chrdice", 0, 6),
(store_random_in_range, "$skl1dice", 0, 4),
(store_random_in_range, "$skl2dice", 0, 3),
(store_random_in_range, "$skl3dice", 0, 3),
(store_random_in_range, "$skl4dice", 0, 2),
(store_random_in_range, "$goldice", 100, 1200),
(store_random_in_range, "$itmdice", 0, 6),
(store_random_in_range, "$wpndice", 0, 7),
],"Accept.",[
(troop_raise_attribute, "trp_player",ca_strength,"$strdice"),
(troop_raise_attribute, "trp_player",ca_agility,"$agidice"),
(troop_raise_attribute, "trp_player",ca_intelligence,"$intdice"),
(troop_raise_attribute, "trp_player",ca_charisma,"$chrdice"),
#skills c/p from somewhere else so value/dice added later
(troop_raise_skill, "trp_player","skl_trade","$skl4dice"),
(troop_raise_skill, "trp_player","skl_leadership","$skl1dice"),
(troop_raise_skill, "trp_player","skl_prisoner_management","$skl1dice"),
(troop_raise_skill, "trp_player","skl_engineer","$skl2dice"),
(troop_raise_skill, "trp_player","skl_first_aid","$skl2dice"),
(troop_raise_skill, "trp_player","skl_surgery","$skl3dice"),
(troop_raise_skill, "trp_player","skl_wound_treatment","$skl3dice"),
(troop_raise_skill, "trp_player","skl_inventory_management","$skl1dice"),
(troop_raise_skill, "trp_player","skl_spotting","$skl2dice"),
(troop_raise_skill, "trp_player","skl_pathfinding","$skl2dice"),
(troop_raise_skill, "trp_player","skl_tactics","$skl3dice"),
(troop_raise_skill, "trp_player","skl_tracking","$skl3dice"),
(troop_raise_skill, "trp_player","skl_trainer","$skl2dice"),
(troop_raise_skill, "trp_player","skl_horse_archery","$skl3dice"),
(troop_raise_skill, "trp_player","skl_riding","$skl1dice"),
(troop_raise_skill, "trp_player","skl_athletics","$skl4dice"),
(troop_raise_skill, "trp_player","skl_shield","$skl2dice"),
(troop_raise_skill, "trp_player","skl_weapon_master","$skl2dice"),
(troop_raise_skill, "trp_player","skl_power_draw","$skl4dice"),
(troop_raise_skill, "trp_player","skl_power_throw","$skl4dice"),
(troop_raise_skill, "trp_player","skl_power_strike","$skl4dice"),
(troop_raise_skill, "trp_player","skl_ironflesh","$skl1dice"),
#itm dice all copy pasted from other classes :P
(try_begin),
(eq, "$itmdice",0),
(eq, "$character_gender",1),
(troop_add_item, "trp_player","itm_dress",imod_sturdy),
(troop_add_item, "trp_player","itm_wimple_with_veil",imod_sturdy),
(troop_add_item, "trp_player","itm_woolen_hose",0),
(else_try),
(eq, "$itmdice",0),
(troop_add_item, "trp_player","itm_ragged_outfit",imod_sturdy),
(troop_add_item, "trp_player","itm_ankle_boots",0),
(else_try),
(eq, "$itmdice",1),
(eq, "$character_gender",1),
(troop_add_item, "trp_player","itm_lady_dress_ruby",imod_sturdy),
(troop_add_item, "trp_player","itm_turret_hat_ruby",imod_sturdy),
(troop_add_item, "trp_player","itm_woolen_hose",0),
(else_try),
(eq, "$itmdice",1),
(troop_add_item, "trp_player","itm_nobleman_outfit",imod_sturdy),
(troop_add_item, "trp_player","itm_woolen_hose",0),
(else_try),
(eq, "$itmdice",2),
(eq, "$character_gender",1),
(troop_add_item, "trp_player","itm_peasant_dress",imod_sturdy),
(troop_add_item, "trp_player","itm_wimple_a",imod_sturdy),
(troop_add_item, "trp_player","itm_woolen_hose",0),
(else_try),
(eq, "$itmdice",2),
(troop_add_item, "trp_player","itm_straw_hat",imod_sturdy),
(troop_add_item, "trp_player","itm_linen_tunic",imod_sturdy),
(troop_add_item, "trp_player","itm_woolen_hose",0),
(else_try),
(eq, "$itmdice",3),
(troop_add_item, "trp_player","itm_wine",0),
(troop_add_item, "trp_player","itm_bread",0),
(troop_add_item, "trp_player","itm_robe",0),
(troop_add_item, "trp_player","itm_black_hood",0),
(else_try),
(eq, "$itmdice",4),
(troop_add_item, "trp_player","itm_tabard",imod_sturdy),
(troop_add_item, "trp_player","itm_leather_boots",0),
(else_try),
(eq, "$itmdice",5),
(troop_add_item, "trp_player","itm_leather_armor",0),
(troop_add_item, "trp_player","itm_skullcap",0),
(troop_add_item, "trp_player","itm_ankle_boots",0),
(try_end),
#All Hail Might Apple acting as a seperator
(troop_add_item, "trp_player","itm_apples",0),
#The only part I wrote;
(try_begin),
(eq, "$wpndice", 0),
(troop_raise_proficiency, "trp_player",0,35),
(troop_add_item, "trp_player","itm_sword_medieval_a",0),
(troop_add_item, "trp_player","itm_round_shield",0),
(else_try),
(eq, "$wpndice", 1),
(troop_raise_proficiency, "trp_player",1,35),
(troop_add_item, "trp_player","itm_axe",0),
(troop_add_item, "trp_player","itm_round_shield",0),
(else_try),
(eq, "$wpndice", 2),
(troop_raise_proficiency, "trp_player",2,35),
(troop_add_item, "trp_player","itm_spear",0),
(troop_add_item, "trp_player","itm_round_shield",0),
(else_try),
(eq, "$wpndice", 3),
(troop_raise_proficiency, "trp_player",3,35),
(troop_add_item, "trp_player","itm_hunting_bow",0),
(troop_add_item, "trp_player","itm_arrows",0),
(else_try),
(eq, "$wpndice", 4),
(troop_raise_proficiency, "trp_player",4,35),
(troop_add_item, "trp_player","itm_hunting_crossbow",0),
(troop_add_item, "trp_player","itm_bolts",0),
(else_try),
(eq, "$wpndice", 5),
(troop_raise_proficiency, "trp_player",5,35),
(troop_add_item, "trp_player","itm_throwing_daggers",0),
(troop_add_item, "trp_player","itm_dagger",0),
(troop_add_item, "trp_player","itm_round_shield",0),
(else_try),
(eq, "$wpndice", 6),
(troop_raise_proficiency, "trp_player",6,50),
(troop_add_item, "trp_player","itm_dagger",0),
(troop_add_item, "trp_player","itm_flintlock_pistol",0),
(troop_add_item, "trp_player","itm_cartridges",0),
(try_end),
(troop_add_gold, "trp_player", "$goldice"),
(change_screen_return, 0),
]),
store_random_in_range = 2136 # gets random number in range [range_low,range_high] excluding range_high
# (store_random_in_range,<destination>,<range_low>,<range_high>),
(try_for_range, ":troop_iterator", 0, ":num_stacks"),
(party_stack_get_troop_id, ":cur_troop_id", ":root_winner_party", ":troop_iterator"),
(troop_is_hero, ":cur_troop_id"),
(troop_set_slot, ":cur_troop_id", slot_troop_is_prisoner, 0),
(troop_set_slot, ":cur_troop_id", slot_troop_leaded_party, -1),
(troop_get_slot,":cur_troop_ranka",":cur_troop_id",slot_troop_renown),
(party_get_num_companion_stacks, ":num_stacks", ":collective_casualties"),
(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"),
(troop_set_slot, ":cur_troop_id", slot_troop_is_prisoner, 0),
(troop_set_slot, ":cur_troop_id", slot_troop_leaded_party, -1),
(troop_get_slot,":cur_troop_rank",":cur_troop_id",slot_troop_renown),
(try_begin),
(ge, ":cur_troop_ranka", ":cur_troop_rank"),
(party_add_prisoners, ":nonempty_winner_party", ":cur_troop_id", 1),
(gt, reg0, 0),
(troop_set_slot, ":cur_troop_id", slot_troop_is_prisoner, 1),
(str_store_troop_name, s1, ":cur_troop_id"),
(str_store_faction_name, s2, ":faction_receiving_prisoners"),
(str_store_faction_name, s3, ":defeated_faction"),
(display_log_message,"str_hero_taken_prisoner"),
(else_try),
(str_store_troop_name, s1, ":cur_troop_id"),
(str_store_faction_name, s2, ":faction_receiving_prisoners"),
(str_store_faction_name, s3, ":defeated_faction"),
(display_log_message,"@{s1} of {s3} was defeated in battle but managed to escape."),
(try_end),
eljeffe418 said:(try_for_range, ":troop_iterator", 0, ":num_stacks"),
(party_stack_get_troop_id, ":cur_troop_id", ":root_winner_party", ":troop_iterator"),
(troop_is_hero, ":cur_troop_id"),
(troop_set_slot, ":cur_troop_id", slot_troop_is_prisoner, 0),
(troop_set_slot, ":cur_troop_id", slot_troop_leaded_party, -1),
(troop_get_slot,":cur_troop_ranka",":cur_troop_id",slot_troop_renown),
(party_get_num_companion_stacks, ":num_stacks", ":collective_casualties"),
(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"),
(troop_set_slot, ":cur_troop_id", slot_troop_is_prisoner, 0),
(troop_set_slot, ":cur_troop_id", slot_troop_leaded_party, -1),
(troop_get_slot,":cur_troop_rank",":cur_troop_id",slot_troop_renown),
(try_begin),
(ge, ":cur_troop_ranka", ":cur_troop_rank"),
(party_add_prisoners, ":nonempty_winner_party", ":cur_troop_id", 1),
(gt, reg0, 0),
(troop_set_slot, ":cur_troop_id", slot_troop_is_prisoner, 1),
(str_store_troop_name, s1, ":cur_troop_id"),
(str_store_faction_name, s2, ":faction_receiving_prisoners"),
(str_store_faction_name, s3, ":defeated_faction"),
(display_log_message,"str_hero_taken_prisoner"),
(else_try),
(str_store_troop_name, s1, ":cur_troop_id"),
(str_store_faction_name, s2, ":faction_receiving_prisoners"),
(str_store_faction_name, s3, ":defeated_faction"),
(display_log_message,"@{s1} of {s3} was defeated in battle but managed to escape."),
(try_end),
Modified source code to make it so lords can capture each other. I think it was originally in the source but the variable to see if they can be captured wasn't declared, I think. There's already a string for the lord getting captured. I changed it so that it's based on difference of renown.