Author Topic: Ask Winter  (Read 52553 times)

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Ask Winter
« on: May 03, 2007, 12:31:17 AM »
If there was ever anything you wanted to know about the module system but were afraid to ask, some obscure or complicated piece of scripting knowledge or advice that you thought would require a long trek to the dragon's lair, then look no further. This is the thread where you can ask Winter about what happens or what is needed in the dark recesses of the module system.

The only things I ask are:

1) That your questions relate to using the official module system, not to any other part of modding or modelling.

2) That you not throw me really basic stuff which is better left for the FAQ or other parts of this forum.

3) Please be specific. If you're asking about a bug in your code, try to include all related code. If you want to do something complicated, write up a full description. I can't help you if I can't make out what you want to do.

If you obey these simple rules, I'll do what I can to answer you.

Offline fujiwara

  • Master
  • *****
  • Posts: 858
    • View Profile
Re: Ask Winter
« Reply #1 on: May 03, 2007, 06:27:47 PM »
Could you give as much of a description of the troop_loot_troop operation as you can? I see a lot of potential there, but I'm somewhat unsure of what goes on behind the scenes.

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

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: Ask Winter
« Reply #2 on: May 04, 2007, 01:12:31 AM »
Could you give as much of a description of the troop_loot_troop operation as you can? I see a lot of potential there, but I'm somewhat unsure of what goes on behind the scenes.

No problem. Just remember I only know what I can see from the module system, I don't have a back road into Armagan's mind. :P

The operation (troop_loot_troop,<target_troop>,<source_troop>,<probability>) is essentially a random item selection and transferring script. It reads all items present in the source troop, and then calculates a random chance that each item will be added to the target troop according to the Probability input. If an item is added to the target troop, it's given a random modifier from the item's imod list.


In the wider sense of how it's used in Native, it's coupled with two scripts that 1) calculate the Probability argument required for troop_loot_troop, based on the size of "p_main_party" and the amount of loot shares given to each member (party_calculate_shares, module_scripts.py), then 2) iterate over all party stacks of the enemy party, using troop_loot_troop on each stack's troop ID. The target troop here is always trp_temp_troop, whose inventory is pre-cleared. After troop_loot_troop is finished looping over the party stacks, the script calculates the number of items looted by iterating over the inventory slots of trp_temp_troop and counting the number of full slots (party_calculate_loot, module_scripts.py)

Lastly, the player is shown to the loot screen by a (change_screen_loot,"trp_temp_troop"). This arrangement allows a whole party to be looted in only one loot screen.

I hope that's all you were looking for. If you need anything more, ask away!
« Last Edit: May 04, 2007, 02:13:36 AM by Winter »

Neophyte

  • Guest
Re: Ask Winter
« Reply #3 on: May 04, 2007, 05:55:37 AM »
It's worth noting that although the script party_calculate_loot does calculate shares using the loot_calculate_loot_shares script it doesn't actually use that value...
Code: [Select]
      (call_script, "script_calculate_party_shares", ":allied_party"),
      (assign, ":num_player_party_shares", reg0),
      (assign, ":num_ally_shares", reg1),
      (store_add, ":num_shares",  ":num_player_party_shares", ":num_ally_shares"),

      (assign, ":num_shares",10),

I have absolutely no idea why it does this.

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: Ask Winter
« Reply #4 on: May 04, 2007, 07:16:19 AM »
It's worth noting that although the script party_calculate_loot does calculate shares using the loot_calculate_loot_shares script it doesn't actually use that value...
Code: [Select]
      (call_script, "script_calculate_party_shares", ":allied_party"),
      (assign, ":num_player_party_shares", reg0),
      (assign, ":num_ally_shares", reg1),
      (store_add, ":num_shares",  ":num_player_party_shares", ":num_ally_shares"),

      (assign, ":num_shares",10),

I have absolutely no idea why it does this.

Your guess is as good as mine, man.

Offline fujiwara

  • Master
  • *****
  • Posts: 858
    • View Profile
Re: Ask Winter
« Reply #5 on: May 04, 2007, 03:19:21 PM »
I noticed this too, though I'm with ya'll, unless the script is buggy for some reason.

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

Apollon-04

  • Guest
Re: Ask Winter
« Reply #6 on: May 04, 2007, 03:46:30 PM »
This is a fairly basic question, and I'm sorry to have to post it here, but it wasn't in the FAQ.

In what file can I modify the original player classes and their items, stats, etc.

Highlander

  • Guest
Re: Ask Winter
« Reply #7 on: May 04, 2007, 04:03:07 PM »
it's in the very top of module_game_menus

Offline Nethros

  • Journeyman
  • ***
  • Posts: 253
    • View Profile
Re: Ask Winter
« Reply #8 on: May 04, 2007, 11:35:17 PM »
Ask, Winter:lol:

I'll bring up the same question as I brought up once in the FAQ, but didn't really get what was the problem. (My brain is that limited.)


Code: [Select]
Exporting item data...
Traceback <most recent call last>:
  File  "process_items.py", line 59 in ?
    write_items<variables>
  File "process_items.py", line 27, in write items
    ofile.write(" %d %d %d %d %f %d %d %d %d %d %d %d %d %d %d %d %d\n"%(item[3], item[4], item[5], item[7],
IndexError: list index out of range

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: Ask Winter
« Reply #9 on: May 05, 2007, 03:48:57 AM »
Ask, Winter:lol:

I'll bring up the same question as I brought up once in the FAQ, but didn't really get what was the problem. (My brain is that limited.)


Code: [Select]
Exporting item data...
Traceback <most recent call last>:
  File  "process_items.py", line 59 in ?
    write_items<variables>
  File "process_items.py", line 27, in write items
    ofile.write(" %d %d %d %d %f %d %d %d %d %d %d %d %d %d %d %d %d\n"%(item[3], item[4], item[5], item[7],
IndexError: list index out of range

Very simple, syntax error in your module_items.py. Too many fields, or a similar screwup. Look at all the items you've added since before this error appeared, and check them against a known good tuple.

DarkAnd

  • Guest
Re: Ask Winter
« Reply #10 on: May 25, 2007, 11:09:17 AM »
i typed the formation code copying and pasting it

Code: [Select]
# script_check_enemies_nearby
# Input: none
# Output: none, fails when enemies are nearby
  ("check_enemies_nearby",
   [
       (get_player_agent_no, ":player_agent"),
       (agent_is_alive, ":player_agent"),
       (try_begin),
         (agent_is_defender, ":player_agent"),
         (assign, ":player_defender", 1),
       (else_try),
         (assign, ":player_defender", 0),
       (try_end),
       (agent_get_position, 1, ":player_agent"),
       (assign, ":result", 0),
       (try_for_agents,":cur_agent"),
         (neq, ":cur_agent", ":player_agent"),
         (agent_is_alive, ":cur_agent"),
         (agent_is_human, ":cur_agent"),
         (try_begin),
           (agent_is_defender, ":cur_agent"),
           (assign, ":agent_defender", 1),
         (else_try),
           (assign, ":agent_defender", 0),
         (try_end),
         (neq, ":player_defender", ":agent_defender"),
         (agent_get_position, 2, ":cur_agent"),
         (get_distance_between_positions, ":cur_distance", 1, 2),
         (le, ":cur_distance", 1500),
         (assign, ":result", 1),
       (try_end),
       (eq, ":result", 0),
    ]),
]
("formation_start",
[(get_player_agent_no,reg(10)),
(agent_get_position,1,reg(10)),
  (try_for_range,reg(20),1,100), #reset of the player dummy-slots
  (agent_set_slot,reg(10),reg(20),0),
  (try_end),
          (try_for_agents,reg(5)),
             (assign,reg(0),0),
             #Not the player
             (neq, reg(5), reg(10)),
             #Not Dead
             (agent_is_alive, reg(5)),
             #Not a Horse?
             (agent_is_human, reg(5)),
             #If the Selected Troop is an Ally
             (agent_is_ally,reg(5)),
           (assign,reg(1),1),
          (try_begin),
             (assign,reg(20),1), #reg(20) is the agent number to use every position only once
             (agent_get_slot,reg(21),reg(10),reg(20)), #player agent used as a dummy not to make several agent use one position
             (eq,reg(21),0), #number isn't used, yet
             (assign,reg(1),reg(20)),
            (assign,reg(3),reg(1)),
            (val_mul,reg(3),100),
            (copy_position,reg(1),1),
            (position_move_x,reg(1),reg(3)), #number 1 = 100 metres right to the player agent 2= 200 etc...
            (agent_set_scripted_destination,reg(5),reg(1)), #tells the agent to run there
             (agent_set_slot,reg(5),1,reg(1)), #tells the agent which position he has - only important if you want to do somethink else with the script, it would work without it right now.
            (agent_set_slot,reg(10),reg(20),1), #tells the game that the number is used, by using the player slots.
          (else_try),
#very odd, sorry (the more call_scripts are there \/, the more agents will build a formation
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),(else_try),
(call_script,"script_formation_repeat"),(else_try),(call_script,"script_formation_repeat"),
           (try_end),           
          (try_end),
   ]),
("formation_repeat",
 [             (val_add,reg(20),1), # adds 1 to the agent number
             (agent_get_slot,reg(21),reg(10),reg(20)),
             (eq,reg(21),0), # again, is the number already used?
             (assign,reg(1),reg(20)), #just copying the number to use it somewhere else...
            (assign,reg(3),reg(1)), #again copying
            (assign,reg(4),0), #assigns the row of this agent to 0
#-#-#-#-#-#-#-#-#-#
            (try_for_range,reg(15),1,100), #this try-code assigns the right row.
            (assign,reg(17),reg(15)),
            (assign,reg(16),reg(15)),
            (val_mul,reg(15),5), #number of troops in one line
            (val_mul,reg(16),5), #has to be the same as above
            (val_add,reg(16),5), #has to be the same as above
            (gt,reg(3),reg(15)),
            (le,reg(3),reg(16)),
            (assign,reg(15),reg(17)),
            (val_mul,reg(15),6), #number of troops in one line + 1
            (val_sub,reg(3),reg(15)),
            (assign,reg(4),reg(17)),
            (try_end),
#delete these lines to get a 1 line formation
#-#-#-#-#-#-#-#-#-#
            (val_mul,reg(3),100),
            (val_mul,reg(4),200),
            (copy_position,reg(1),1),
            (position_move_x,reg(1),reg(3)),
            (position_move_y,reg(1),reg(4)),
            (agent_set_scripted_destination,reg(5),reg(1)),
             (agent_set_slot,reg(5),1,reg(1)),
            (agent_set_slot,reg(10),reg(20),1),
 ]),

and it says

ERROR: illegal identifier script_formation_start
error: unable to find object script_formation_start


wen i added it at any thing

mission templates

Code: [Select]
  (
    "charge",mtf_battle_mode,charge,
    "You lead your men to the charge",
    [
     (8,mtef_defenders,0,group(1)|aif_start_alarmed,8,[]),
     (9,mtef_defenders,0,group(1)|aif_start_alarmed,0,[]),
     (10,mtef_attackers,0,aif_start_alarmed,8,[]),
     (11,mtef_attackers,0,aif_start_alarmed,0,[]),
     (12,mtef_attackers,0,aif_start_alarmed,0,[]),
     (13,mtef_attackers,0,aif_start_alarmed,0,[]),
     ],
    [
      (ti_tab_pressed, 0, 0, [],
       [
           (try_begin),
             (eq, "$battle_won", 1),
             (finish_mission,0),
           (else_try),
             (call_script, "script_check_enemies_nearby"),
             (question_box,"str_do_you_want_to_retreat"),
           (else_try),
             (display_message,"str_can_not_retreat"),
           (try_end),
        ]),
      (ti_question_answered, 0, 0, [],
       [(store_trigger_param_1,":answer"),(eq,":answer",0),(finish_mission,0),]),

      (0, 0, ti_once, [], [(assign,"$battle_won",0),(assign,"$defender_reinforcement_stage",0),(assign,"$attacker_reinforcement_stage",0)]),
      (1, 0, 5, [(lt,"$defender_reinforcement_stage",2),(store_mission_timer_a,reg(1)),(ge,reg(1),10),(store_defender_count,reg(2)),(lt,reg(2),3)],
           [(add_reinforcements_to_entry,0,4),(val_add,"$defender_reinforcement_stage",1)]),
      (1, 0, 5, [(lt,"$attacker_reinforcement_stage",2),(store_mission_timer_a,reg(1)),(ge,reg(1),10),(store_attacker_count,reg(2)),(lt,reg(2),3)],
           [(add_reinforcements_to_entry,3,4),(val_add,"$attacker_reinforcement_stage",1)]),
      (1, 60, ti_once, [(store_mission_timer_a,reg(1)),
                        (ge,reg(1),10),(all_enemies_defeated,2),
                        (neg|main_hero_fallen,0),
                        (set_mission_result,1),
                        (assign, "$g_battle_result", 1),
                        (display_message,"str_msg_battle_won"),
                        (assign,"$battle_won",1)],
           [(finish_mission,1)]),
      (10, 0, 0, [], [(eq,"$battle_won",1),(display_message,"str_msg_battle_won")]),
      (1, 4, ti_once, [(main_hero_fallen)],
          [
              (assign, "$g_battle_result", -1),
              (set_mission_result,-1),(finish_mission,1)]),
      (ti_inventory_key_pressed, 0, 0, [], [[color=red](call_script, "script_formation_start")[/color],(display_message,"str_formation")]),
    ],
 ),
module items

Code: [Select]
["javelin",         "Javelin", [("javelin",0),("javelins_quiver", ixmesh_carry)], itp_type_thrown |itp_merchandise|itp_primary|itp_bonus_against_shield ,itcf_throw_javelin|itcf_carry_quiver_back|itcf_show_holster_when_drawn, 75 , weight(5)|difficulty(0)|spd_rtng(91) | shoot_speed(28) | thrust_damage(27 ,  pierce)|max_ammo(7)|weapon_length(75),imodbits_missile ],
["formation",         "Long Spear", [("pike",0)], itp_type_thrown |itp_merchandise|itp_primary|itp_bonus_against_shield ,itcf_throw_javelin|itcf_show_holster_when_drawn, 75 , weight(5)|difficulty(0)|spd_rtng(91) | shoot_speed(28) | thrust_damage(27 ,  pierce)|max_ammo(17)|weapon_length(75),imodbits_missile ,[(ti_on_weapon_attack,[(call_script,"[color=red]script_formation_start[/color]")])]],
["stones",         "Stones", [("throwing_stone",0)], itp_type_thrown |itp_merchandise|itp_primary ,itcf_throw_stone, 1 , weight(4)|difficulty(0)|spd_rtng(97) | shoot_speed(30) | thrust_damage(10 ,  blunt)|max_ammo(18)|weapon_length(8),imodbit_large_bag ],

Offline Winter

  • I am Tek Jansen!
  • Administrator
  • *****
  • Posts: 476
  • MBX Forum owner
    • View Profile
    • Street of Eyes: The Writing of Ryan A. Span
Re: Ask Winter
« Reply #11 on: May 25, 2007, 12:02:50 PM »
# script_check_enemies_nearby
# Input: none
# Output: none, fails when enemies are nearby
  ("check_enemies_nearby",
   [
       (get_player_agent_no, ":player_agent"),
       (agent_is_alive, ":player_agent"),
       (try_begin),
         (agent_is_defender, ":player_agent"),
         (assign, ":player_defender", 1),
       (else_try),
         (assign, ":player_defender", 0),
       (try_end),
       (agent_get_position, 1, ":player_agent"),
       (assign, ":result", 0),
       (try_for_agents,":cur_agent"),
         (neq, ":cur_agent", ":player_agent"),
         (agent_is_alive, ":cur_agent"),
         (agent_is_human, ":cur_agent"),
         (try_begin),
           (agent_is_defender, ":cur_agent"),
           (assign, ":agent_defender", 1),
         (else_try),
           (assign, ":agent_defender", 0),
         (try_end),
         (neq, ":player_defender", ":agent_defender"),
         (agent_get_position, 2, ":cur_agent"),
         (get_distance_between_positions, ":cur_distance", 1, 2),
         (le, ":cur_distance", 1500),
         (assign, ":result", 1),
       (try_end),
       (eq, ":result", 0),
    ]),
]

There's your problem in bold. That bracket should be at the bottom of your file, not in between scripts, because it closes the list of scripts.

This is the sort of thing that I've stressed heavily in my official documentation. Remember to read it and refer to it often.

morgoth2005

  • Guest
Re: Ask Winter
« Reply #12 on: June 01, 2007, 07:12:51 AM »
Can I edit the trp_player?

Highlander

  • Guest
Re: Ask Winter
« Reply #13 on: June 01, 2007, 07:17:04 AM »
you should be able to edit stats, items, face (and I guess faction too). I'm not sure if you are allowed to remove tf_hero, but you should be allowed to add flags.

karl1s

  • Guest
Re: Ask Winter
« Reply #14 on: June 08, 2007, 10:49:33 AM »
How can I install the star wars patch? :-[ :-[