PYTHON SCRIPT/SCHEME EXCHANGE

Users who are viewing this thread

I've done some thinking about how the shield bashing could work, and these are my ideas thus far:

For player:
ti_on_whatever_pressed calls the following script:

Code:
(get_player_agent_no,":player"),
(agent_get_position,1,":player"),
(assign,":mindist",100),
(assign,":shield_equipped",0),
(try_for_range,":shield",shields_begin,shields_end), #fill in the appropriate item names
(agent_has_item_equipped,":shield",":player"),
(assign,":shield_equipped",1),
(neq,":shield",0),
(try_for_agents,":agent"),
    (agent_is_alive,":agent"),
    (agent_is_human,":agent"),
    (neg|agent_is_ally,":agent"),
    (agent_get_position,2,":agent"),
    (neg|position_is_behind_position,2,1),
    (get_distance_between_positions,":dist",1,2),
    (lt,":dist",":mindist"),
    (assign,":mindist",":dist"),
    (assign,":chosen",":agent"),
(end_try),
(agent_set_animation, ":player", anim_shield_bash),  # someone would have to make this animation.
(agent_set_animation, ":chosen", anim_strike_fall_back_rise),
(agent_store_health,":health",":chosen"),
(val_sub,":health",10),
(agent_set_health,":chosen",":health"),

For ai:
Every second during battle call the following script:
Code:
(get_player_agent_no,":player"),
(try_for_agents,":basher"),
    (agent_is_human,":basher"),
    (agent_is_alive,":basher"),
    (neq,":player",":basher"),
    (assign,":shield_equipped",0),
    (try_for_range,":shield",shields_begin,shields_end), #fill in the appropriate item names
        (agent_has_item_equipped,":shield",":basher"),
        (assign,":shield_equipped",1),
    (end_try),
    (neq,":shield_equipped",0),
    (try_begin),
          (agent_is_ally,":basher"),
          (agent_get_position,1,":basher"),
          (assign,":mindist",100),
          (try_for_agents,":agent"),
                (agent_is_alive,":agent"),
                (agent_is_human,":agent"),
                (neg|agent_is_ally,":agent"),
                (agent_get_position,2,":agent"),
                (neg|position_is_behind_position,2,1),
                (get_distance_between_positions,":dist",1,2),
                (lt,":dist",":mindist"),
                (assign,":mindist",":dist"),
                (assign,":chosen",":agent"),
           (end_try),
           (store_random_in_range,":random",1,10),
           (eq,":random",7),                                          #this line and the one before it would keep to agents from simultaneously shield bashing one another save in rare instances.
           (agent_set_animation, ":basher", anim_shield_bash),  # someone would have to make this animation.
           (agent_set_animation, ":chosen", anim_strike_fall_back_rise),
           (agent_store_health,":health",":chosen"),
           (val_sub,":health",10),
           (agent_set_health,":chosen",":health"),
    (else_try),
          (neg|agent_is_ally,":basher"),
          (agent_get_position,1,":basher"),
          (assign,":mindist",100),
          (try_for_agents,":agent"),
                (agent_is_alive,":agent"),
                (agent_is_human,":agent"),
                (agent_is_ally,":agent"),
                (agent_get_position,2,":agent"),
                (neg|position_is_behind_position,2,1),
                (get_distance_between_positions,":dist",1,2),
                (lt,":dist",":mindist"),
                (assign,":mindist",":dist"),
                (assign,":chosen",":agent"),
           (end_try),
           (store_random_in_range,":random",1,10),
           (eq,":random",7),                                          #this line and the one before it would keep to agents from simultaneously shield bashing one another save in rare instances.
           (agent_set_animation, ":basher", anim_shield_bash),  # someone would have to make this animation.
           (agent_set_animation, ":chosen", anim_strike_fall_back_rise),
           (agent_store_health,":health",":chosen"),
           (val_sub,":health",10),
           (agent_set_health,":chosen",":health"),
    (end_try),
(end_try),


There are most likely some variables in the wrong order, and someone would have to make a shield-bash animation and put it in game but otherwise this should work.
 
We'd have to wait for BRF Edit's animation support to be fully operational though, and to be able to add new animations instead of altering/replacing old ones.
 
well i used the slash animation and it worked the poor river pirate fall into the ground but i also used it whit a crosbow and a spear :razz:
 
(try_for_range,":shield",shields_begin,shields_end), #fill in the appropriate item names
(agent_has_item_equipped,":shield",":player"),

Shouldn't the above part have stopped that happening? Or did you have a shield equipped, but not used?
 
i have the shield on the back the agent has iten equiped don't mean that we need to have on hand?
 
No it doesn't have to be in hand, just in one of the four weapon slots. No way around that.

Out of curiosity, did you test the ai version of the code, too? And were any variables in the wrong order?



I never tested the script, you see, the first time I typed it up was onto the forums.
 
well it worked but i don't know what the number i have tho change to make it caled at every second
ps: the river pirate worked even whitout shield i think there are any variable in wrong order this is very anoyng have a knitgh getin pnwed by a river pirate
 
In that case it should be more like this:

For player:
ti_on_whatever_pressed calls the following script:

Code:
(get_player_agent_no,":player"),
(agent_get_position,1,":player"),
(assign,":mindist",100),
(assign,":shield_equipped",0),
(try_for_range,":shield",shields_begin,shields_end), #fill in the appropriate item names
   (agent_has_item_equipped,":player",":shield"),
   (assign,":shield_equipped",1),
(end_try),
(neq,":shield",0),
(try_for_agents,":agent"),
    (agent_is_alive,":agent"),
    (agent_is_human,":agent"),
    (neg|agent_is_ally,":agent"),
    (agent_get_position,2,":agent"),
    (neg|position_is_behind_position,2,1),
    (get_distance_between_positions,":dist",1,2),
    (lt,":dist",":mindist"),
    (assign,":mindist",":dist"),
    (assign,":chosen",":agent"),
(end_try),
(agent_set_animation, ":player", anim_shield_bash),  # someone would have to make this animation.
(agent_set_animation, ":chosen", anim_strike_fall_back_rise),
(agent_store_health,":health",":chosen"),
(val_sub,":health",10),
(agent_set_health,":chosen",":health"),

For ai:
Every second during battle call the following script:
Code:
(get_player_agent_no,":player"),
(try_for_agents,":basher"),
    (agent_is_human,":basher"),
    (agent_is_alive,":basher"),
    (neq,":player",":basher"),
    (assign,":shield_equipped",0),
    (try_for_range,":shield",shields_begin,shields_end), #fill in the appropriate item names
        (agent_has_item_equipped,":basher",":shield"),
        (assign,":shield_equipped",1),
    (end_try),
    (neq,":shield_equipped",0),
    (try_begin),
          (agent_is_ally,":basher"),
          (agent_get_position,1,":basher"),
          (assign,":mindist",100),
          (try_for_agents,":agent"),
                (agent_is_alive,":agent"),
                (agent_is_human,":agent"),
                (neg|agent_is_ally,":agent"),
                (agent_get_position,2,":agent"),
                (neg|position_is_behind_position,2,1),
                (get_distance_between_positions,":dist",1,2),
                (lt,":dist",":mindist"),
                (assign,":mindist",":dist"),
                (assign,":chosen",":agent"),
           (end_try),
           (store_random_in_range,":random",1,10),
           (eq,":random",7),                                          #this line and the one before it would keep to agents from simultaneously shield bashing one another save in rare instances.
           (agent_set_animation, ":basher", anim_shield_bash),  # someone would have to make this animation.
           (agent_set_animation, ":chosen", anim_strike_fall_back_rise),
           (agent_store_health,":health",":chosen"),
           (val_sub,":health",10),
           (agent_set_health,":chosen",":health"),
    (else_try),
          (neg|agent_is_ally,":basher"),
          (agent_get_position,1,":basher"),
          (assign,":mindist",100),
          (try_for_agents,":agent"),
                (agent_is_alive,":agent"),
                (agent_is_human,":agent"),
                (agent_is_ally,":agent"),
                (agent_get_position,2,":agent"),
                (neg|position_is_behind_position,2,1),
                (get_distance_between_positions,":dist",1,2),
                (lt,":dist",":mindist"),
                (assign,":mindist",":dist"),
                (assign,":chosen",":agent"),
           (end_try),
           (store_random_in_range,":random",1,10),
           (eq,":random",7),                                          #this line and the one before it would keep to agents from simultaneously shield bashing one another save in rare instances.
           (agent_set_animation, ":basher", anim_shield_bash),  # someone would have to make this animation.
           (agent_set_animation, ":chosen", anim_strike_fall_back_rise),
           (agent_store_health,":health",":chosen"),
           (val_sub,":health",10),
           (agent_set_health,":chosen",":health"),
    (end_try),
(end_try),


That would fix it, unless you forgot to fill in the correct items for shields_begin and shields_end.

Highlander said:
I'm pretty sure it has to be in hand.
I've never played around with the command. You're probably right.


EDIT: fixed an error in the player script.

EDIT2: DarkAnd, did it succsessfully take ten hit points from you when you were bashed?
 
Lets you talk to a party member to fight any troop or edit any scene.


http://forums.taleworlds.com/index.php/topic,25794.0.html
 
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!

Code:
#script_party_prisoners_to_naked
# INPUT: Party-id from which prisoners will be removed.
# This script loots prisoners of a party, giving the loot to the player and heroes, then replaces them with naked prisoners 
  
  ("party_prisoners_to_naked",
   [
      (store_script_param_1,":party"), #Source Party_id
      (party_get_num_companion_stacks,":troop_stacks",":party"),#count number of companion stacks      
      (party_get_num_prisoner_stacks,":num_prisoner_stacks",":party"),#count number of prisoner stacks
      (try_for_range_backwards,":stack_no", 0,":num_prisoner_stacks"),#start cycling        
        (party_prisoner_stack_get_troop_id,":stack_troop",":party",":stack_no"),#get troop_id for prisoner
        (party_prisoner_stack_get_size,":stack_size",":party",":stack_no"),#count instances for prisoner troop_id          
        (try_for_range,":prisoner_in_stack",0,":stack_size"),#this will loot every instance of the same troop stack
          (try_for_range,":item_id",1,270),# this will give every single item_id
            (store_item_kind_count,reg(1),":item_id",":stack_troop"),
            (neq,reg(1),0),#if the troop has at least one item of the kind
            (store_free_inventory_capacity,reg(2),"trp_player"),#check if the player has enough inventory space
            (try_begin),
              (ge,reg(2),reg(1)),#if player's inventory has enough space
              (assign,":dest_troop","trp_player"),#player becomes destination troop
            (else_try), 
              (try_for_range,":position",0,":troop_stacks"),#cycle through companion troop stacks
                (neq,":dest_found",1),#until it's found a destination troop
                (party_stack_get_troop_id,":comp_troop",":party",":position"),#companion troop id
                (try_begin),# I want the cycle to only select heroes
                  (troop_is_hero,":comp_troop"),#if the troop is a hero
                  (store_free_inventory_capacity,reg(3),":comp_troop"),#get its inventory capacity
                  (try_begin),
                    (gt,reg(3),reg(1)),#if hero has space
                    (assign,":dest_troop",":comp_troop"),#he/she becomes destination
                    (assign,":dest_found",1), 
                  (try_end),
                (try_end),#if the troop isn't a hero OR all heroes don't have free space the cycle won't do anything  
              (try_end),
            (try_end),  
            (call_script,"script_equipment_quality",":item_id"),#randomly gives an imod to the object, according to its type          
            (troop_add_item,":dest_troop",":item_id",reg(5)),#assign it to destination troop
            (assign,":dest_found",0),#reset the variable 
          (try_end),
        (try_end),     
        (party_remove_prisoners,":party",":stack_troop",":stack_size"),#removes reg(0) prisoners 
        (party_add_prisoners,":party","trp_male_prisoner",reg(0)),#adds a male_prisoner for every troop removed        
      (try_end),      
    ]),

#script_equipment_quality
#INPUT: the item to assign a random imod to
   ("equipment_quality",
    [
        (store_script_param_1,":item_looted"),
        (store_random_in_range,":dice_roll",1,1000),  
        (call_script,"script_get_item_type",":item_looted"),#call a script that identifies the item kind
        
        (try_begin),#is it a misc item?
          (eq,"$loot_misc",1),
          (assign,reg(5),0),#plain 
          (assign,"$loot_misc",0),
        (try_end),

        (try_begin),#is it a horse?
          (eq,"$loot_horse",1),
          (try_begin),
            (is_between,":dice_roll",1,15),#15 out of 1000
            (assign,reg(5),22),#spirited horse
            (assign,"$loot_horse",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",16,60),#45 out of 1000
            (assign,reg(5),21),#temperate horse
            (assign,"$loot_horse",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",61,100),#40 out of 1000
            (assign,reg(5),11),#heavy horse
            (assign,"$loot_horse",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",101,300),#200 out of 1000
            (assign,reg(5),20),#stubborn horse
            (assign,"$loot_horse",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",301,500),#200 out of 1000
            (assign,reg(5),19),#swaybacked horse
            (assign,"$loot_horse",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",501,800),#300 out of 1000
            (assign,reg(5),18),#lame horse
            (assign,"$loot_horse",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",801,1000),#200 out of 1000
            (assign,reg(5),0),#plain horse
            (assign,"$loot_horse",0),
          (try_end),
        (try_end),#horse end 
        
        (try_begin),#is it ammo?
          (eq,"$loot_ammo",1),
          (try_begin),
            (is_between,":dice_roll",1,250),#250 out of 1000
            (assign,reg(5),1),#cracked ammo
            (assign,"$loot_ammo",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",251,700),#450 out of 1000
            (assign,reg(5),3),#bent ammo
            (assign,"$loot_ammo",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",701,950),#250 out of 1000
            (assign,reg(5),0),#plain ammo
            (assign,"$loot_ammo",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",951,1000),#50 out of 1000
            (assign,reg(5),23),#large bag of ammo
            (assign,"$loot_ammo",0),
          (try_end),            
        (try_end), #ammo end  

        (try_begin),#is it thrown?
          (eq,"$loot_thrown",1),
          (try_begin),
            (is_between,":dice_roll",1,250),#250 out of 1000
            (assign,reg(5),1),#cracked thrown
            (assign,"$loot_thrown",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",251,700),#450 out of 1000
            (assign,reg(5),3),#bent thrown
            (assign,"$loot_thrown",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",701,950),#250 out of 1000
            (assign,reg(5),0),#plain thrown
            (assign,"$loot_thrown",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",951,1000),#50 out of 1000
            (assign,reg(5),23),#large bag of thrown
            (assign,"$loot_thrown",0),
          (try_end),            
        (try_end), #thrown end 

        (try_begin),#is it ranged??
          (eq,"$loot_range",1),
          (try_begin),
            (is_between,":dice_roll",1,300),#300 out of 1000
            (assign,reg(5),1),#cracked ranged
            (assign,"$loot_range",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",301,750),#450 out of 1000
            (assign,reg(5),3),#bent ranged
            (assign,"$loot_range",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",751,1000),#250 out of 1000
            (assign,reg(5),0),#plain ranged
            (assign,"$loot_range",0),
          (try_end),                     
        (try_end), #ranged end   


        (try_begin),#is it melee weapon?
          (eq,"$loot_melee",1),
          (try_begin),
            (is_between,":dice_roll",1,150),#150 out of 1000
            (assign,reg(5),4),#chipped melee
            (assign,"$loot_melee",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",151,350),#200 out of 1000
            (assign,reg(5),2),#rusty melee
            (assign,"$loot_melee",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",351,535),#180 out of 1000
            (assign,reg(5),0),#plain melee
            (assign,"$loot_melee",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",536,635),#100 out of 1000
            (assign,reg(5),3),#bent melee
            (assign,"$loot_melee",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",636,835),#200 out of 1000
            (assign,reg(5),7),#crude melee
            (assign,"$loot_melee",0),
          (try_end), 
          (try_begin),
            (is_between,":dice_roll",836,885),#50 out of 1000
            (assign,reg(5),9),#balanced melee
            (assign,"$loot_melee",0),
          (try_end), 
          (try_begin),
            (is_between,":dice_roll",886,985),#100 out of 1000
            (assign,reg(5),11),#heavy melee
            (assign,"$loot_melee",0),
          (try_end), 
          (try_begin),
            (is_between,":dice_roll",986,1000),#15 out of 1000
            (assign,reg(5),10),#watered-steel melee
            (assign,"$loot_melee",0),
          (try_end),         
        (try_end), #melee end

        (try_begin),#is it armor?
          (eq,"$loot_armor",1),
          (try_begin),
            (is_between,":dice_roll",1,150),#150 out of 1000
            (assign,reg(5),1),#cracked armor
            (assign,"$loot_armor",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",151,350),#200 out of 1000
            (assign,reg(5),2),#rusty armor
            (assign,"$loot_armor",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",351,535),#180 out of 1000
            (assign,reg(5),0),#plain armor
            (assign,"$loot_armor",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",536,635),#100 out of 1000
            (assign,reg(5),5),#battered armor
            (assign,"$loot_armor",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",636,850),#215 out of 1000
            (assign,reg(5),12),#tattered armor
            (assign,"$loot_armor",0),
          (try_end), 
          (try_begin),
            (is_between,":dice_roll",851,920),#70 out of 1000
            (assign,reg(5),13),#ragged armor
            (assign,"$loot_armor",0),
          (try_end), 
          (try_begin),
            (is_between,":dice_roll",921,970),#50 out of 1000
            (assign,reg(5),14),#sturdy armor
            (assign,"$loot_armor",0),
          (try_end), 
          (try_begin),
            (is_between,":dice_roll",971,985),#15 out of 1000
            (assign,reg(5),15),#thick armor
            (assign,"$loot_armor",0),
          (try_end), 
          (try_begin),
            (is_between,":dice_roll",986,995),#10 out of 1000
            (assign,reg(5),16),#hardened armor
            (assign,"$loot_armor",0),
          (try_end), 
          (try_begin),
            (is_between,":dice_roll",996,1000),#5 out of 1000
            (assign,reg(5),17),#reinforced armor
            (assign,"$loot_armor",0),
          (try_end),         
        (try_end), #armor end  

        (try_begin),#is it a shield?
          (eq,"$loot_shield",1),
          (try_begin),
            (is_between,":dice_roll",1,150),#150 out of 1000
            (assign,reg(5),1),#cracked shield
            (assign,"$loot_shield",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",151,350),#200 out of 1000
            (assign,reg(5),2),#rusty shield
            (assign,"$loot_shield",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",351,535),#180 out of 1000
            (assign,reg(5),0),#plain shield
            (assign,"$loot_shield",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",536,635),#100 out of 1000
            (assign,reg(5),5),#battered shield
            (assign,"$loot_shield",0),
          (try_end),
          (try_begin),
            (is_between,":dice_roll",636,850),#215 out of 1000
            (assign,reg(5),12),#tattered shield
            (assign,"$loot_shield",0),
          (try_end), 
          (try_begin),
            (is_between,":dice_roll",851,920),#70 out of 1000
            (assign,reg(5),13),#ragged shield
            (assign,"$loot_shield",0),
          (try_end), 
          (try_begin),
            (is_between,":dice_roll",921,970),#50 out of 1000
            (assign,reg(5),14),#sturdy shield
            (assign,"$loot_shield",0),
          (try_end), 
          (try_begin),
            (is_between,":dice_roll",971,985),#15 out of 1000
            (assign,reg(5),15),#thick shield
            (assign,"$loot_shield",0),
          (try_end), 
          (try_begin),
            (is_between,":dice_roll",986,995),#10 out of 1000
            (assign,reg(5),16),#hardened shield
            (assign,"$loot_shield",0),
          (try_end), 
          (try_begin),
            (is_between,":dice_roll",996,1000),#5 out of 1000
            (assign,reg(5),17),#reinforced shield
            (assign,"$loot_shield",0),
          (try_end),         
        (try_end), #shield end   
             
            
   ]),

#script_get_item_type
#INPUT: the item_id of the item to class
#this script (used with script_equipment_quality) checks the item_id against the list in header_item_modifiers.py
#so that the proper imod can be added to the item (no watered-steel horses or large bags of black armor today, sorry!)
   ("get_item_type",
    [
        (store_script_param_1,reg(4)),
        (try_begin),
          (is_between,reg(4),19,34),
          (assign,"$loot_misc",1),
        (try_end), 
        (try_begin),
          (is_between,reg(4),46,52),
          (assign,"$loot_horse",1),
        (try_end),
        (try_begin),
          (is_between,reg(4),53,59),
          (assign,"$loot_ammo",1),
        (try_end),
        (try_begin),
          (is_between,reg(4),60,137),
          (assign,"$loot_armor",1),
        (try_end),
        (try_begin),
          (is_between,reg(4),247,270),
          (assign,"$loot_armor",1),
        (try_end),       
        (try_begin),
          (is_between,reg(4),138,198),
          (assign,"$loot_melee",1),
        (try_end), 
        (try_begin),
          (is_between,reg(4),199,220),
          (assign,"$loot_shield",1),
        (try_end), 
        (try_begin),
          (is_between,reg(4),221,226),
          (assign,"$loot_thrown",1),
        (try_end), 
        (try_begin),
          (is_between,reg(4),227,239),
          (assign,"$loot_range",1),
        (try_end), 
        
   ]),
 
Neat script, and a really good idea imho. But how about defining some constants rather than using numbers to refer to items? And how do you avoid getting a rusty leather armor or a water-steeled club?
 
Amarillo said:
But how about defining some constants rather than using numbers to refer to items?
Could you give me an example? I'm not sure I understand...

And how do you avoid getting a rusty leather armor or a water-steeled club?
For now, I don't...  :oops:
Apart from separating non-metal weapons and armor from the rest (surely NOT neat), I can't figure out how to do it..
 
Golcondio said:
And how do you avoid getting a rusty leather armor or a water-steeled club?
For now, I don't...  :oops:
Apart from separating non-metal weapons and armor from the rest (surely NOT neat), I can't figure out how to do it..

You can define imodbits groups: Define one for your looted items that is basics like heavy/poor/reinforced/old  stuff that can apply equally to leather, steel, or wood.  Use only that one in your script.
 
Back
Top Bottom