SP Tutorial Other export/import NPCs - source code released

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

rubik

Squire
Best answers
0
Incidentally I found that when a NPC do as the commander in battles, you can export/import him/her just like the player in my MOD Custom Commander.

There is some code below to implement it in a menu, no need to enter a scene any more.

I just insert the menu option in the menu "camp_action", in fact you can insert it in any menu you like.
........................
........................

      ("action_read_book",[],"Select a book to read.",
      [(jump_to_menu,
"mnu_camp_action_read_book"),
        ]
      ),
#### export/import NPCs begin ####
     
("action_export_import",[],"Export/import NPCs.",
        [
          (jump_to_menu,
"mnu_export_import_npcs"),
        ]
      ),
#### export/import NPCs end ####
     
("action_modify_banner",[(eq, "$cheat_mode", 1)],"Cheat: Modify your banner.",
      [
          (start_presentation, "prsnt_banner_selection"),
         
#(start_presentation, "prsnt_custom_banner"),
       
]
      ),

........................
........................



These two menus below can be added anywhere.
#### export/import NPCs begin ####
 
("export_import_npcs", mnf_enable_hot_keys,
 
"Please choose an NPC, then press key C to view and export/import this character.^^You choose {reg0?{s0}:none}.",
 
"none",
    [
      (assign, reg0,
"$g_player_troop"),
      (str_store_troop_name, s0,
"$g_player_troop"),
    ],
    [
      (
"export_import_back",[],"Go back",
        [
          (assign,
"$g_player_troop", "trp_player"),
          (set_player_troop,
"$g_player_troop"),
          (jump_to_menu,
"mnu_camp_action"),
        ]
      ),
    ]+[(
"export_import_npc"+str(x+1),
        [
          (store_add,
":dest_npc", "trp_npc1", x),
          (str_store_troop_name, s0,
":dest_npc"),
        ],
"{s0}",
        [
          (store_add,
":dest_npc", "trp_npc1", x),
          (assign,
"$g_player_troop", ":dest_npc"),
          (set_player_troop,
"$g_player_troop"),
        ])
for x in range(0, 8)]+[
      (
"export_import_next",[],"Next page", [(jump_to_menu, "mnu_export_import_npcs_2")]),
    ]
  ),
 
  (
"export_import_npcs_2", mnf_enable_hot_keys,
   
"Please choose an NPC, then press key C to view and export/import this character.^^You choose {reg0?{s0}:none}.",
   
"none",
    [
      (assign, reg0,
"$g_player_troop"),
      (str_store_troop_name, s0,
"$g_player_troop"),
    ],
    [
      (
"export_import_prev",[],"Previous page", [(jump_to_menu, "mnu_export_import_npcs")]),
    ]+[(
"export_import_npc"+str(x+1),
      [
        (store_add,
":dest_npc", "trp_npc1", x),
        (str_store_troop_name, s0,
":dest_npc"),
      ],
"{s0}",
      [
        (store_add,
":dest_npc", "trp_npc1", x),
        (assign,
"$g_player_troop", ":dest_npc"),
        (set_player_troop,
"$g_player_troop"),
      ])
for x in range(8, 16)]
  ),
#### export/import NPCs end ####
 

fisheye

Grandmaster Knight
Best answers
0
Awesome.... looks like you can import your whole party! Does this work in menu or do you have to be in a scene?
 

rubik

Squire
Best answers
0
No need in a scene, it can be also done in a menu with the following key function:
(set_player_troop,<troop_id>),
 

HokieBT

Grandmaster Knight
M&BWB
Best answers
0
well damn, that is cool.  here we were looking into hex editing saved game files so we could edit companions (and other stuff) and you figure out a way to just export/import them with a new menu system....  :smile:    this is very interesting, thx.
 

rubik

Squire
Best answers
0
add some simple instruction inside the menus instead the string "Export/import npcs". now you know how to operate it.
 

HokieBT

Grandmaster Knight
M&BWB
Best answers
0
I had previous added this (thanks!) so just updated the new line.  The "You choose" doesn't seem to be working correctly, it always displays the last name on each page when you click on it?

edit:  adding  (str_store_troop_name, s0, "trp_npc1") to each section looks like it would fix it when I did a quick test....  But when you go to the character screen and then click done, it will just display the work "none" and regardless of what you click on it won't display the npc name again.  Anyway, just though I'd let you know, this really is great tho, very handy.
 

rubik

Squire
Best answers
0
I have not the problem, it always works right. maybe it is needed to assign "trp_player" to "$g_player_troop" before entering the menu of export/import NPCs.

#### export/import NPCs begin ####
     
("action_export_import",[],"Export/import NPCs.",
        [
          (assign,
"$g_player_troop", "trp_player"),
          (jump_to_menu,
"mnu_export_import_npcs"),
        ]
      ),
#### export/import NPCs end ####
 

HokieBT

Grandmaster Knight
M&BWB
Best answers
0
I re-pasted your code and started a new game and it worked fine, sorry, i should have tried that before.

I think your latest code is a good idea as well since i am also using your custom commander, so i added that, thanks!
 

HokieBT

Grandmaster Knight
M&BWB
Best answers
0
bump and minor comment for the code.  I had a small issue because s0 wasn't cleared so the NPC name randomly appeared in a few spots.  I added the following to fix this, otherwise it seems to work fine and is included in the latest release of my star wars mod.  thx

      ("export_import_back",[],"Go back",
        [
          (assign, "$g_player_troop", "trp_player"),
          (set_player_troop, "$g_player_troop"),
  #SW - modified to clear the s0 string
  (str_clear, s0),

          (jump_to_menu, "mnu_camp_action"),
        ]
      ),
 

rubik

Squire
Best answers
0
I use some PYTHON code in it. The code is shorter now. Maybe there is a bit difficulty to understand the new code.
 

SPD_Phoenix

Master Knight
Best answers
0
Yes, if you add it properly.

Modification to existing menu is save compatible most of the time. Additional menu added to the end of the file should be save compatible.
 

Schemer

I typed out a long message, but then the forum maintenance killed it. Here's my attempt at writing it again. :sad:

I traveled to where the would-be king of the Khergit Khanate was, and agreed to take up his cause. He can be assigned abilities and equipment just like normal companions, but he unfortunately only has a single point in Power Strike and none at all in Ironflesh, Power Draw, and Horse Archery. This doesn't feel right for a king. Any chance the export/import function could be extended to rebel faction leaders? I don't know... it just feels strange to have a king in armour and weapons fit for a demigod, but no idea how to use half the things he has available in his arsenal. I could use the good old method of spamming Ctrl+X to train him up, but unfortunately, my fingers would have broken by the time I added a billion experience to him. I'd do the script myself and post the details here, but unfortunately, I'm not much of a scripter.

But regardless -- thanks for the amazing script! I can't imagine having to spam Ctrl+X again in a vain attempt to have my companions at an old savegame's level of skill. :smile: