PYTHON SCRIPT/SCHEME EXCHANGE

Users who are viewing this thread

HokieBT said:
...
FYI - for those new to working with presentations, make sure you add the following before Kuba's code
Code:
 (set_fixed_point_multiplier, 1000),

WilliamBerne said:
#script_display_prsnt_coordinate
  ("display_prsnt_coordinate",
    [
        (try_begin),
        (key_clicked,key_left_control),
        (mouse_get_position, pos2),
        (position_get_x,":pos_x",pos2),
        (position_get_y,":pos_y",pos2),
        (assign,reg1,":pos_x"),
        (assign,reg2,":pos_y"),
        (display_message,"@x: {reg1}, y: {reg2}"),
        (try_end),
      ]),
hehe
but I think Kuba's is better than mine.
 
Kuba said:
Little Pos Helper
I created LPH to make designing presentations easier. It shows cursor's position in upper-left corner. Enjoy.
Installation:
1. Paste this into "ti_on_presentation_load" section:
Code:
			#Little Pos Helper by Kuba begin
			(create_text_overlay, "$g_little_pos_helper", "@00,00"),
			(overlay_set_color, "$g_little_pos_helper", 0xFFFFFFFF),
			(position_set_x, pos1, 10),
			(position_set_y, pos1, 700),
			(overlay_set_position, "$g_little_pos_helper", pos1),
			#Little Pos Helper by Kuba end
2. And this into presentation's triggers section:
Code:
		#Little Pos Helper by Kuba begin
		(ti_on_presentation_run,
		[
		(mouse_get_position, pos1),
		(position_get_x, reg1, pos1),
		(position_get_y, reg2, pos1),
		(overlay_set_text, "$g_little_pos_helper", "@{reg1},{reg2}"),
		]),
		#Little Pos Helper by Kuba end

I had made a similar stuff to help myself to implement some puzzle games with the Module System before.

Add the following into "ti_on_presentation_load".
        ####### mouse fix pos system #######
       
(create_text_overlay, "$g_presentation_obj_39", "@ ", tf_center_justify|tf_vertical_align_center),

        (create_mesh_overlay,
"$g_presentation_obj_38", "mesh_white_plane"),
        (position_set_x, pos1,
50),
        (position_set_y, pos1,
37500),
        (overlay_set_size,
"$g_presentation_obj_38", pos1),

        (create_mesh_overlay,
"$g_presentation_obj_37", "mesh_white_plane"),
        (position_set_x, pos1,
50000),
        (position_set_y, pos1,
50),
        (overlay_set_size,
"$g_presentation_obj_37", pos1),
       
####### mouse fix pos system #######

The following into "ti_on_presentation_run".
        ####### mouse fix pos system #######
       
(mouse_get_position, pos1),
        (position_get_x, reg50, pos1),
        (position_get_y, reg51, pos1),
       
        (position_set_x, pos1, reg50),
        (position_set_y, pos1,
0),
        (overlay_set_position,
"$g_presentation_obj_38", pos1),

        (position_set_x, pos1,
0),
        (position_set_y, pos1, reg51),
        (overlay_set_position,
"$g_presentation_obj_37", pos1),

        (try_begin),
          (le, reg50,
500),
          (assign,
":eek:ffset_x", 70),
        (else_try),
          (assign,
":eek:ffset_x", -70),
        (try_end),
        (try_begin),
          (le, reg51,
375),
          (assign,
":eek:ffset_y", 20),
        (else_try),
          (assign,
":eek:ffset_y", -20),
        (try_end),
        (store_add,
":pos_x", reg50, ":eek:ffset_x"),
        (store_add,
":pos_y", reg51, ":eek:ffset_x"),
        (position_set_x, pos1,
":pos_x"),
        (position_set_y, pos1,
":pos_y"),
        (overlay_set_position,
"$g_presentation_obj_39", pos1),
        (overlay_set_text,
"$g_presentation_obj_39", "@({reg50},{reg51})"),
       
####### mouse fix pos system #######

It creates a cross on the screen by the cursor's position and the cross can move along with the cursor. The coordinates' information will also follow the cursor, not at a fixed place.

Screenshot(Minesweeper I made):
54726830201003161629402137202935179_000_640.jpg
 
rubik said:
Kuba said:
Little Pos Helper
I created LPH to make designing presentations easier. It shows cursor's position in upper-left corner. Enjoy.
Installation:
1. Paste this into "ti_on_presentation_load" section:
Code:
			#Little Pos Helper by Kuba begin
			(create_text_overlay, "$g_little_pos_helper", "@00,00"),
			(overlay_set_color, "$g_little_pos_helper", 0xFFFFFFFF),
			(position_set_x, pos1, 10),
			(position_set_y, pos1, 700),
			(overlay_set_position, "$g_little_pos_helper", pos1),
			#Little Pos Helper by Kuba end
2. And this into presentation's triggers section:
Code:
		#Little Pos Helper by Kuba begin
		(ti_on_presentation_run,
		[
		(mouse_get_position, pos1),
		(position_get_x, reg1, pos1),
		(position_get_y, reg2, pos1),
		(overlay_set_text, "$g_little_pos_helper", "@{reg1},{reg2}"),
		]),
		#Little Pos Helper by Kuba end

I had made a similar stuff to help myself to implement some puzzle games with the Module System before.

Add the following into "ti_on_presentation_load".
        ####### mouse fix pos system #######
       
(create_text_overlay, "$g_presentation_obj_39", "@ ", tf_center_justify|tf_vertical_align_center),

        (create_mesh_overlay,
"$g_presentation_obj_38", "mesh_white_plane"),
        (position_set_x, pos1,
50),
        (position_set_y, pos1,
37500),
        (overlay_set_size,
"$g_presentation_obj_38", pos1),

        (create_mesh_overlay,
"$g_presentation_obj_37", "mesh_white_plane"),
        (position_set_x, pos1,
50000),
        (position_set_y, pos1,
50),
        (overlay_set_size,
"$g_presentation_obj_37", pos1),
       
####### mouse fix pos system #######

The following into "ti_on_presentation_run".
        ####### mouse fix pos system #######
       
(mouse_get_position, pos1),
        (position_get_x, reg50, pos1),
        (position_get_y, reg51, pos1),
       
        (position_set_x, pos1, reg50),
        (position_set_y, pos1,
0),
        (overlay_set_position,
"$g_presentation_obj_38", pos1),

        (position_set_x, pos1,
0),
        (position_set_y, pos1, reg51),
        (overlay_set_position,
"$g_presentation_obj_37", pos1),

        (try_begin),
          (le, reg50,
500),
          (assign,
":eek:ffset_x", 70),
        (else_try),
          (assign,
":eek:ffset_x", -70),
        (try_end),
        (try_begin),
          (le, reg51,
375),
          (assign,
":eek:ffset_y", 20),
        (else_try),
          (assign,
":eek:ffset_y", -20),
        (try_end),
        (store_add,
":pos_x", reg50, ":eek:ffset_x"),
        (store_add,
":pos_y", reg51, ":eek:ffset_x"),
        (position_set_x, pos1,
":pos_x"),
        (position_set_y, pos1,
":pos_y"),
        (overlay_set_position,
"$g_presentation_obj_39", pos1),
        (overlay_set_text,
"$g_presentation_obj_39", "@({reg50},{reg51})"),
       
####### mouse fix pos system #######

It creates a cross on the screen by the cursor's position and the cross can move along with the cursor. The coordinates' information will also follow the cursor, not at a fixed place.

Screenshot(Minesweeper I made):
54726830201003161629402137202935179_000_640.jpg
Minesweeper in M&B . Just epic
 
I had written a trigger to sort the troops in lords' parties or their towns or castles and also kingdom caravans by the level of troops every 24 hours.

Just need to add the following into module_simple_triggers.py.
Python:
(24,
    [
      (try_for_parties, ":party_no"),
        (neq, ":party_no", "p_main_party"),
        (neq, ":party_no", "p_temp_party"),
        (assign, ":continue", 0),
        (try_begin),
          (this_or_next|party_slot_eq, ":party_no", slot_party_type, spt_kingdom_hero_party),
          (party_slot_eq, ":party_no", slot_party_type, spt_kingdom_caravan),
          (party_is_active, ":party_no"),
          (assign, ":continue", 1),
          (try_begin),
            (party_stack_get_troop_id, ":cur_troop", ":party_no", 0),
            (this_or_next|troop_is_hero, ":cur_troop"),
            (eq, ":cur_troop", "trp_caravan_master"),
            (assign, ":first_stack", 1),
          (else_try),
            (assign, ":first_stack", 0),
          (try_end),
        (else_try),
          (this_or_next|party_slot_eq, ":party_no", slot_party_type, spt_castle),
          (party_slot_eq, ":party_no", slot_party_type, spt_town),
          (neg|party_slot_eq, ":party_no", slot_town_lord, "trp_player"[/COLOR][COLOR=#000000]),
          (assign, ":first_stack", 0),
          (assign, ":continue", 1),
        (try_end),
        (eq, ":continue", 1),
        (party_get_num_companion_stacks, ":num_stacks", ":party_no"),
        (gt, ":num_stacks", ":first_stack"),
        (assign, ":last_stack", ":num_stacks"),
        
        # start to sort
        (store_sub, ":num_times", ":num_stacks", ":first_stack"),
        (try_for_range, ":unused", 0, ":num_times"),
          # find highest-level troop
          (assign, ":best_stack", -1),
          (assign, ":best_level", -1),
          (try_for_range, ":cur_stack", ":first_stack", ":last_stack"),
            (party_stack_get_troop_id, ":cur_troop", ":party_no", ":cur_stack"),
            (store_character_level, ":troop_level", ":cur_troop"),
            (gt, ":troop_level", ":best_level"),
            (assign, ":best_level", ":troop_level"),
            (assign, ":best_stack", ":cur_stack"),
          (try_end),
          # move to the end
          (try_begin),
            (gt, ":best_level", -1),
            (party_stack_get_troop_id, ":stack_troop", ":party_no", ":best_stack"),
            (party_stack_get_size, ":stack_size", ":party_no", ":best_stack"),
            (party_stack_get_num_wounded, ":num_wounded", ":party_no", ":best_stack"),
            (party_remove_members, ":party_no", ":stack_troop", ":stack_size"),
            (party_add_members, ":party_no", ":stack_troop", ":stack_size"),
            (party_wound_members, ":party_no", ":stack_troop", ":num_wounded"),
            (val_sub, ":last_stack", 1),
          (try_end),
        (try_end),
      (try_end),
    ]),
 
Last edited by a moderator:
well known problem: if you add multiple races as genders, the new races are always considered female because they don't have header tf=0.

i heard there was a solution that could be a bit complicated, but i didn't find anything about the neccessary changes/coding. and i know some mods have managed to add new male races, but i don't get it.

Anybody got a clue?

Thx in advance
 
Replace all troop_get_type with script to define the gender. We can make male have least significant bit=0, and female' LSB =1.
Let's say tf_male=0, tf_female=1, tf_goblin=2. Then, Female goblin=tf_goblin|tf_female
So after call (troop_get_type,":gender", ":troop"), then call (val_and, ":gender", 1),
male will be 0, and female will be 1.
 
The code to define the gender would be great to use in my mod , but Im not much of a coder so can you explain it a little better for me as in what module file do I change and what code do I put where ?

Thanks , Del
 
i worked on a race/race script of my own, inspired by dunde's hints, when i came across a very similar script by Keedo420.
here's a link. i hope that's okay for Keedo420, but you should PM him for permission anyways.
i kind of based my race script on Keedos elgant coding for my private mod with only few changes, and it worked very well. 

for me, i luckily decided to not use different fantasy races in my private mod before i implemented the necessary dialogue and menue tweaks. several well defined skins and the race script had to be commented out. while i do like fantasy stuff (i thought about a fantasy europe in the mid-14th century), my mod is back on the purely historical track and will reincarnate in warband. alas, now the only different "race" will be plague-victims....
 
Archevious said:
This is a script I found from Cruger, props to dzorro for fixing it:

Faction Patrols

Go into module_triggers.py, and uncomment this:
Code:
##      (try_begin),
##        (store_random_in_range, ":random_no", 0, 100),
##        (lt, ":random_no", 10),
##        (call_script, "script_create_kingdom_party_if_below_limit", ":cur_kingdom", spt_patrol),
##      (try_end),

then go to module_scripts.py and uncomment this:
Code:
##        (eq, ":party_type", spt_patrol),
##        (assign, ":party_count_limit", 1),
##      (else_try),

and this
Code:
##        (eq, ":party_type", spt_patrol),
##        (assign, ":party_template", "pt_patrol_party"),
#        (assign, ":party_name_str", "str_s7_patrol"), <---- keep this outcommented
##      (else_try),

Also, uncomment this in module_constants.py:
Code:
spt_patrol             = 7

And you have faction patrols. :smile:
I just built this for WB and it compiled without error. I've yet to see in-game, though.

EDIT: At first I saw no patrols, then after a while I did see one. 0 troops. I talked to it, offered me the surrender or die/leave alone dialogue. I left the party alone and it wasn't on the map anymore and the game crashed. :razz:
 
Hello everybody!
I'm started an assassin mod, and I would need some scripts, if somebody can help me.
I would need a stealth ability. A script that if you press down key "t" or any other then you run faster and jump higher.
I would need these.
A credit will be natural.

Thanks!
 
Alexandru_cel_Mare said:
FrisianDude, you need to go to party templates or so and add troops to the party, otherwise indeed the game will crash.
Derp, yeah. Sometimes, sometimes, I feel so stupid. :lol: Those'd need to be rather generic troops then, though? It'd be odd to see a Khergit patrol with Nord troops.
 
Can someone help me with some coding?

If you have played the Rus XIII mod, you can go into first person with the inside of the helmet visible.

I dont really know where to start and I am fairly noobish with the whole coding part.
I want to do this for Warband.
 
Rath0s said:
Can someone help me with some coding?

If you have played the Rus XIII mod, you can go into first person with the inside of the helmet visible.

I dont really know where to start and I am fairly noobish with the whole coding part.
I want to do this for Warband.

http://forums.taleworlds.com/index.php/topic,70031.msg1818835.html#msg1818835
 
Would it be possible to script something that would let you buy bots in a multiplayer match? So basically you could buy bots for yourself, not the whole team.And after the round has ended, they would be wiped out.
 
Rongar said:
Culture-specific shop inventories

Prerequisites
1. Following scripts assume that factions are set correct for all troops (normally in native for regular troops nords are outlaws, vaerigs and swadian are neutral, khergits are khergits (should be kingdom_3)).

2. Merchants factions are set to original factions of their towns.

Code injection

Anywhere in module_constants.py, better to add around other slot_item_
slot_item_faction = 5 # additional item slot for culture-specific shop inventories

At the header of module_scripts.py
from ID_factions import *
from module_troops import *

In module_scripts.py just before scripts = [
def set_item_faction():
  command_list = []
  for i_troop in xrange(len(troops)):
    for i_item in troops[i_troop][7]:   
      command_list.append((item_get_slot, ":val",i_item, slot_item_faction))   
      command_list.append((val_or, ":val",1 << troops[i_troop][6]))   
      command_list.append((item_set_slot, i_item, slot_item_faction,":val"))   
  return command_list [:]
(Respect spaces!)

In module_scripts.py in game_start
(call_script,"script_set_item_faction"),

Anywhere in module_scripts.py inside  scripts
  # script_set_item_faction
  # Input: none
  # Output: none
  ("set_item_faction",  set_item_faction()), 
 
  # script_get_faction_mask
  # Input: faction
  # Output: reg0 -- mask
  ("get_faction_mask",  [
  (assign,reg0,1),
(store_script_param_1, ":faction"),
(try_for_range,":unused",0,":faction"),
(val_mul,reg0,2),
(try_end),
 
  ]),   

In armor, weapon and horse merchant refresh triggers in module_triggers.py between (try_for_range,reg(2),...), and (troop_add_merchandise,reg(2),...),
(reset_item_probabilities,100),     
(store_troop_faction,":faction",reg(2)),
(call_script,"script_get_faction_mask",":faction"),      
(store_add,":last_item_plus_one","itm_rabati",1),
(try_for_range,":i_item","itm_no_item",":last_item_plus_one"),
    (item_get_slot,":item_faction_mask",":i_item",slot_item_faction),
    (val_and,":item_faction_mask",reg0),
    (eq,":item_faction_mask",0),
    (set_item_probability_in_merchandise,":i_item",0),
(try_end),

# Refresh Armor sellers
(0.0, 0, 24.0, [], [
(set_merchandise_modifier_quality,150),      
(try_for_range,reg2,armor_merchants_begin,armor_merchants_end),

#code injection start
    (reset_item_probabilities,100),     
    (store_troop_faction,":faction",reg2),
    (call_script,"script_get_faction_mask",":faction"),      
    (store_add,":last_item_plus_one","itm_rabati",1),
    (try_for_range,":i_item","itm_no_item",":last_item_plus_one"),
        (item_get_slot,":item_faction_mask",":i_item",slot_item_faction),
        (val_and,":item_faction_mask",reg0),
        (eq,":item_faction_mask",0),
        (set_item_probability_in_merchandise,":i_item",0),
    (try_end),
#code injection end

    (troop_add_merchandise,reg2,itp_type_body_armor,16),
    (troop_add_merchandise,reg2,itp_type_head_armor,16),
    (troop_add_merchandise,reg2,itp_type_foot_armor,:cool:,
    (troop_add_merchandise,reg2,itp_type_hand_armor,4),
    (troop_ensure_inventory_space,reg2,merchant_inventory_space),
    (troop_sort_inventory, reg2),
    (store_troop_gold, reg6,reg2),
    (lt,reg6,900),
    (store_random_in_range,":new_gold",200,400),
    (call_script, "script_troop_add_gold",reg2,":new_gold"),
(try_end),
]),

Remarks

1. Current code take into account all troops (regulars, lords, merchants).  To set custom range you should change
  for i_troop in xrange(len(troops)):
on
for i_troop in range(trp_troop1, trp_troop2+1):
also you need to import ID_troops. More sophisticated ranges requires more sophisticated code.

2. Non-factional items will never appear in shops.  There are multiple bypasses. Shortest by description  - add one troop per faction and fill its inventory with non-factional items that you need in shops.

3. Debug code
      (try_begin),
      (eq, ":extra_text_id", 4),
(item_get_slot,reg1,":item_no",slot_item_faction),
(set_result_string, "@Mask={reg1}"),
      (else_try),
        (eq, ":extra_text_id", 5),
(item_get_slot,reg1,":item_no",slot_item_faction),
(str_clear,s1),
(try_begin),
(call_script,"script_get_faction_mask","fac_kingdom_1"),
(val_and,reg0,reg1),
(neq,reg0,0),
(str_store_string,s1,"@{s1}(S)"),
(try_end),
(try_begin),
(call_script,"script_get_faction_mask","fac_kingdom_2"),
(val_and,reg0,reg1),
(neq,reg0,0),
(str_store_string,s1,"@{s1}(V)"),
(try_end),
(try_begin),
(call_script,"script_get_faction_mask","fac_kingdom_3"),
(val_and,reg0,reg1),
(neq,reg0,0),
(str_store_string,s1,"@{s1}(K)"),
(try_end),
(try_begin),
(call_script,"script_get_faction_mask","fac_kingdom_4"),
(val_and,reg0,reg1),
(neq,reg0,0),
(str_store_string,s1,"@{s1}(N)"),
(try_end),
(try_begin),
(call_script,"script_get_faction_mask","fac_kingdom_5"),
(val_and,reg0,reg1),
(neq,reg0,0),
(str_store_string,s1,"@{s1}(R)"),
(try_end),
(set_result_string, s1),

      (try_end),

4. It is possible to avoid setting faction for merchants (there are couple reasons for that). Instead you can calculate offset for reg2 from town_1_<merchant type> and get original faction of town_1 + offset.

5. Lords in native have sometimes not that evident equipment,  kettle hat will be very popular.

6. No changes are needed for def set_item_faction() if you have more or less factions or have e.g. outlaw items seller. You should check only troop factions, refresh triggers and debug code (if you are going to use the last).

I implemented this and now where to define which faction will have which item. By implementing this, by default, some armors doesn't belong to some shops, and yet they should and some items are in some factions shops and they shouldn't be- for example, khergits got plate armour and great helm, but there is no lamellar there, swadians got tribal warrior outfit, vaeghirs mail haubergeon and so on. Same with weapons and horses.
 
I implemented this and now where to define which faction will have which item.
Is that a question?
For this script you don't define  which faction will have which item directly. The script distributes items between shops base on how they are used by units.

So, iggorbb. 
Have you checked units factions?
Have you added debug code? It should show factions (first letters) when you point on an item. It's really helpful to find out what is wrong.
 
Back
Top Bottom