Author Topic: [OSP] SimpleLoot  (Read 3721 times)

0 Members and 1 Guest are viewing this topic.

xenoargh

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Neutral
[OSP] SimpleLoot
« on: May 23, 2011, 10:11:24 PM »
This is code to replace script_party_calculate_loot in module_scripts.  It's short, sweet and simple.  In fact, after testing it, I haven't the foggiest why I didn't do this months ago; the looting code has always been one of the more problematic things in Warband.

Why am I sharing this one out?  If you've ever looked at that script in Native, you know that it's anything but short, sweet and simple; it relies on the calculation of party shares, which is prone to various issues, and because it uses troop_loot_troop, it doesn't give access to the full range of equipment that should be available.  This uses a very different method to iterate through the Troop items, using a random chance based on Looting skill.  No more pile of 20 worthless Rocks when you've just fought 40 Looters fighting alongside some well-equipped Deserters- that problem is fixed, amongst others.

This code could very easily be extended to allow for special treasures held by enemy Heroes and other fun things, and it allows horses to be looted just like anything else.


Code: [Select]
    #script_party_calculate_loot:
    # INPUT:
    # param1: Party-id
    # Returns num looted items in reg(0)
     ("party_calculate_loot",
      [
(store_script_param_1, ":enemy_party"), #Enemy Party_id
(troop_clear_inventory,"trp_temp_troop"),#Clear the temp troop inventory
        (assign, ":num_looted_items",0),
(assign, ":loot_slot", 10),
       
#Get looting skill
        (party_get_skill_level, ":player_party_looting", "p_main_party", "skl_looting"),
        (val_mul, ":player_party_looting", 3),
       
        (party_get_num_companion_stacks, ":num_stacks",":enemy_party"),
        (try_for_range, ":i_stack", 0, ":num_stacks"),
(lt, ":loot_slot", 40),#Don't overfill loot
          (party_stack_get_troop_id, ":stack_troop",":enemy_party",":i_stack"),
(try_for_range, ":current_inv", 0, 30),
(troop_get_inventory_slot,":my_inv",":stack_troop",":current_inv"),#Search for items
(gt, ":my_inv", 0),#We have a valid item
(store_random_in_range, ":rand", 1, 135),
(val_add, ":rand", ":player_party_looting"),
(try_begin),
(ge, ":rand", 100),
(troop_set_inventory_slot, "trp_temp_troop", ":loot_slot", ":my_inv"),
(val_add, ":loot_slot", 1),#Bump the slot upwards, so that we don't overwrite
(val_add, ":num_looted_items", 1),
(try_end),
(try_end),
(try_end),

#Add random trade goods where appropriate
        (try_begin),
(this_or_next|party_slot_eq, "$g_enemy_party", slot_party_type, spt_kingdom_caravan),
(this_or_next|party_slot_eq, "$g_enemy_party", slot_party_type, spt_bandit_lair),
(party_slot_eq, "$g_enemy_party", slot_party_type, spt_village_farmer),

(party_get_skill_level, ":player_looting", "p_main_party", "skl_looting"),
(store_random_in_range, ":plunder_amount", 1, 5),
(val_add, ":plunder_amount", ":player_looting"),
(troop_add_merchandise, "trp_temp_troop", itp_type_goods, ":plunder_amount"),
(val_add, ":num_looted_items", ":plunder_amount"),
        (try_end),  
         
         (assign, reg0, ":num_looted_items"),
      ]),

FrisianDude

  • Coitus non Awesome
  • Grandmaster Knight
  • *
  • Zis is Tshörman tärritorie!
    • View Profile
  • Faction: Neutral
  • MP nick: Liudulf Ward/Léodwulf
  • M&BWB
Re: [OSP] SimpleLoot
« Reply #1 on: May 23, 2011, 10:37:34 PM »
Interesting. Forgive the silly questions of my tired mind, but is this meant to replace native looting?
Nords ruled by King Ragnar, Khergits ruled by Sanjar Khan, Rhodoks ruled by King Graveth, Swadians ruled by King Harlaus, Vaegirs ruled by King Yaroglek. All those peoples live, fight, and die in the continent of Calradia. The Nords and Rhodoks field solely infantry and archers, the Swadians and Vaegirs have infantry, archers and cavalry and the Khergit field almost exclusively cavalry. No such things as "infarty" or "calvary" exist. Play Vikingr!

xenoargh

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Neutral
Re: [OSP] SimpleLoot
« Reply #2 on: May 23, 2011, 10:59:29 PM »
Yup.

Somebody

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Bandit
  • WBWF&S
Re: [OSP] SimpleLoot
« Reply #3 on: May 24, 2011, 12:21:36 AM »
Not sure how troop_loot_troop works (or how efficient it is), but your code doesn't take into account how many troops are in each stack (you'll get as many items from a caravan master as 100 caravan guards) and limits the inventory slot at 30 so troops with item variation above a certain point won't be counted properly. You can also remove the val_add in the loop and have something like this:
Code: [Select]
(party_get_skill_level, ":player_party_looting", "p_main_party", "skl_looting"),
(val_mul, ":player_party_looting", 3),
(val_add, ":player_party_looting", 1),
...
(store_random_in_range, ":rand", ":player_party_looting", 135),
...
(val_div, ":player_party_looting", 3),
(store_random_in_range, ":plunder_amount", ":player_party_looting", 5),

xenoargh

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Neutral
Re: [OSP] SimpleLoot
« Reply #4 on: May 24, 2011, 01:37:08 AM »
Quote
Not sure how troop_loot_troop works (or how efficient it is), but your code doesn't take into account how many troops are in each stack (you'll get as many items from a caravan master as 100 caravan guards)
This is true, but if you test it, you'll see that, on average, you get better loot, most of the time.  Of course you can always shake it down by percentages, or if the stack's really big, give a smallish chance of getting two of a thing.  I don't think it's necessary for my purposes, but I can see lots of ways that people can use it to juggle things in a different way.

Quote
limits the inventory slot at 30 so troops with item variation above a certain point won't be counted properly
I don't think there's any practical way to avoid having to make choices in that regard.  If you have 10 different troops, with merely 10 items apiece... you run out of slots pretty fast.  A sorter could be used to discard cheaper items, but it's a double-edged sword; most likely, there are reasonably-cheap things that you'd like to show up in the loot.  I may write one that goes back for a second round of randomness; I think it's better to have some cheap junk mixed up with the good stuff, because players often want to equip their Companions from looted items.


Marcolino

  • Knight
  • *
  • Fortitudinem et honorem
    • View Profile
  • Faction: Neutral
  • MP nick: Marcolino
Re: [OSP] SimpleLoot
« Reply #5 on: June 25, 2011, 01:21:03 PM »
Xenoargh

This is a pretty good script. A great improved from Native. Thanks for sharing! :D
Ego nunquam mendacio, sed sanguinarius et indomitus sum


"Quod melius est in vita? Ut conteret inimicos tuos, educ tecum, et audiunt lamenta feminarum suarum"

Robak

  • Regular
  • *
    • View Profile
  • Faction: Neutral
Re: [OSP] SimpleLoot
« Reply #6 on: January 16, 2014, 05:40:49 PM »
@xenoargh, could you pinpoint which numbers exactly in yours script code, should be edited to increase/decrease after battle loot?

Dusk Voyager

  • Grandmaster Knight
  • *
  • All the world's a bottle.
    • View Profile
    • PoP Dev Forum
  • Faction: Rhodok
Re: [OSP] SimpleLoot
« Reply #7 on: January 16, 2014, 10:27:22 PM »
(click to show/hide)
(click to show/hide)

Robak

  • Regular
  • *
    • View Profile
  • Faction: Neutral
Re: [OSP] SimpleLoot
« Reply #8 on: January 17, 2014, 03:11:54 PM »
@Dusk Voyager thanks, its working great, but i need one more thing.
How to make loot to depend also on number of soldiers in stack? For now, we get staff only from one soldier per kind as @Somebody mentioned earlier.
Any ideas?

Dusk Voyager

  • Grandmaster Knight
  • *
  • All the world's a bottle.
    • View Profile
    • PoP Dev Forum
  • Faction: Rhodok
Re: [OSP] SimpleLoot
« Reply #9 on: January 17, 2014, 04:04:29 PM »
(click to show/hide)
Beware that the number of lines has changed, so it's not save-compatible.

PS. edited once more
« Last Edit: January 20, 2014, 10:08:51 AM by Dusk Voyager »

cuts

  • Regular
  • *
    • View Profile
  • Faction: Nord
Re: [OSP] SimpleLoot
« Reply #10 on: January 21, 2014, 08:14:52 PM »
Thanks a lot xeno and Dusk! Does this also replace   «#script_calculate_main_party_shares:» or just «#script_party_calculate_loot:»?
« Last Edit: January 21, 2014, 08:26:15 PM by cuts »

Dusk Voyager

  • Grandmaster Knight
  • *
  • All the world's a bottle.
    • View Profile
    • PoP Dev Forum
  • Faction: Rhodok
Re: [OSP] SimpleLoot
« Reply #11 on: January 21, 2014, 10:15:40 PM »
Should be just the latter, because main party members have no bearing on the execution of his code.
« Last Edit: January 22, 2014, 09:56:08 AM by Dusk Voyager »

cuts

  • Regular
  • *
    • View Profile
  • Faction: Nord
Re: [OSP] SimpleLoot
« Reply #12 on: February 05, 2014, 10:46:23 PM »
Thanks again, Dusk! I've been testing the script and this much smaller code allows for much better loot, indeed! It looks way better. Short and simple. I like it.

However, I'm having a minor setback, over here. Apparently, the new code also allows for some items to be looted, items which are not supposed to. I tried flagging them as unique, changing their abundance to 0 and even removing the itp_merchandise flag, but to no avail...

Think that there might be anything else that I could try, anyone?
« Last Edit: February 06, 2014, 12:50:20 AM by cuts »

Somebody

  • Grandmaster Knight
  • *
    • View Profile
  • Faction: Bandit
  • WBWF&S
Re: [OSP] SimpleLoot
« Reply #13 on: February 05, 2014, 11:47:28 PM »
If you're referring to items marked with itp_unique, exclude them manually after (gt, ":my_inv", 0),#We have a valid item

cuts

  • Regular
  • *
    • View Profile
  • Faction: Nord
Re: [OSP] SimpleLoot
« Reply #14 on: February 06, 2014, 11:06:37 AM »
Haha! Thanks, somebody. You always seem to riddle me with your answers. I always get the feeling that I'm close, but I can never make it o:

I tried researching the forums for «itp_unique» and stuff, but no luck... It seems this issue is specific to this script.

For some reason the native looting system doesn't seem to loot «itp_unique» items, but, noob as I am, I still couldn't find out how it does it, yet. I can't see nothing on the code even slightly related. Maybe it's because it doesn't allow you to loot equipped items?

The closest I could get was «item_get_type» and the command database (http://mbcommands.ollclan.eu/) doesn't seem to help much either...

Now, if I could find out a way to get the looting system to tell apart items flagged «itp_unique» and make them unlootable that would be great! Would anyone care to point me in the right direction? :)
« Last Edit: February 06, 2014, 01:42:04 PM by cuts »