Adding cheats to the cheatmenu

正在查看此主题的用户

kipponium

Sergeant
Ive been trying to add a cheat that spawns an enemy party around the player and the code i have compiles fine but crashes the game whenever i try to use it; i cant find the fault in it so i thought i would ask some of the more experienced modders their opinion. Its loosely modelled on the find item cheat by the way.

插入代码块:
("cheat_spawn_party",0,
   "{!}Current troop range: {reg5} to {reg6}",
   "none",
   [
     (assign, reg5, "$cheat_find_troop_range_begin"),
     (store_add, reg6, "$cheat_find_troop_range_begin", 10),
	 (val_min, reg6, "trp_kidnapped_girl"),
	 (val_sub, reg6, 1),


     ],
    [
    ("cheat_find_troop_next_range",[], "{!}Move to next troop range.",
       [
	    (val_add, "$cheat_find_troop_range_begin", 10),
	    (try_begin),
	      (ge, "$cheat_find_troop_range_begin", "trp_kidnapped_girl"),
		  (assign, "$cheat_find_troop_range_begin", 0),
	    (try_end),
	    (jump_to_menu, "mnu_cheat_spawn_party"),
	   ]
       ),	   

	   ("cheat_find_troop_choose_this",[], "{!}Choose from this range.",
       [
(set_spawn_radius,5),
(spawn_around_party,"p_main_party","pt_spawned_party"),
(assign,":p_spawned_party",reg0),
(party_stack_get_troop_id,":id1","p_main_party",2),
(party_stack_get_size,":num1","p_main_party",2),
(party_stack_get_troop_id,":id2","p_main_party",3),
(party_stack_get_size,":num2","p_main_party",3),
(party_stack_get_troop_id,":id3","p_main_party",4),
(party_stack_get_size,":num3","p_main_party",4),
(party_stack_get_troop_id,":id4","p_main_party",5),
(party_stack_get_size,":num4","p_main_party",5),
(party_stack_get_troop_id,":id5","p_main_party",6),
(party_stack_get_size,":num5","p_main_party",6),
(party_stack_get_troop_id,":id6","p_main_party",7),
(party_stack_get_size,":num6","p_main_party",7),
(party_stack_get_troop_id,":id7","p_main_party",8),
(party_stack_get_size,":num7","p_main_party",8),
(party_stack_get_troop_id,":id8","p_main_party",9),
(party_stack_get_size,":num8","p_main_party",9),
(party_stack_get_troop_id,":id9","p_main_party",10),
(party_stack_get_size,":num9","p_main_party",10),
(party_stack_get_troop_id,":id10","p_main_party",11),
(party_stack_get_size,":num10","p_main_party",11),
(party_remove_members,"p_main_party",":id1",":num1"),
(party_remove_members,"p_main_party",":id2",":num2"),
(party_remove_members,"p_main_party",":id3",":num3"),
(party_remove_members,"p_main_party",":id4",":num4"),
(party_remove_members,"p_main_party",":id5",":num5"),
(party_remove_members,"p_main_party",":id6",":num6"),
(party_remove_members,"p_main_party",":id7",":num7"),
(party_remove_members,"p_main_party",":id8",":num8"),
(party_remove_members,"p_main_party",":id9",":num9"),
(party_remove_members,"p_main_party",":id10",":num10"),
        (store_add, ":max_troop", "$cheat_find_troop_range_begin", 10),
	    (val_min, ":max_troop", "trp_kidnapped_girl"),
		(store_sub, ":num_troops_to_add", ":max_troop", "$cheat_find_troop_range_begin"),
         	(try_for_range, ":id_slot", 0, ":num_troops_to_add"),
		  (store_add, ":troop_id", "$cheat_find_troop_range_begin", ":id_slot"),
                (party_force_add_members, "p_main_party",":troop_id",10),
                (try_end),
(change_screen_exchange_with_party, ":p_spawned_party"),
         	(try_for_range, ":id_slot", 0, ":num_troops_to_add"),
		  (store_add, ":troop_id", "$cheat_find_troop_range_begin", ":id_slot"),
                (party_remove_members,"p_main_party",":troop_id",10),
                (try_end),
(party_force_add_members, "p_main_party",":id1",":num1"),
(party_force_add_members, "p_main_party",":id2",":num2"),
(party_force_add_members, "p_main_party",":id3",":num3"),
(party_force_add_members, "p_main_party",":id4",":num4"),
(party_force_add_members, "p_main_party",":id5",":num5"),
(party_force_add_members, "p_main_party",":id6",":num6"),
(party_force_add_members, "p_main_party",":id7",":num7"),
(party_force_add_members, "p_main_party",":id8",":num8"),
(party_force_add_members, "p_main_party",":id9",":num9"),
(party_force_add_members, "p_main_party",":id10",":num10"),
	   ]
       ),	   
	   
      ("camp_action_4",[],"{!}Back to camp menu.",
       [(jump_to_menu, "mnu_camp"),
        ]
       ),
      ]
  ),

 
I suspect that you're using
插入代码块:
(change_screen_exchange_with_party,   ":p_spawned_party"),
incorrectly. In its only use in game_menu.py, it is at the end of a conditional block followed by an (else_try), whereas in your case you have code after it. The party exchange menu is a hard-coded interface, so having code interferring with it will cause problems.
In addition, your party may not have 11 slots, so you may encounter an error. Instead of hard-coding 10 ids, use party_get_num_companion_stacks (don't worry, it gets more than just companions) to get how many slots your party actually uses, and store its members inside a loop into another temporary party instead.
 
Ok i took your advice and rearranged the code to this

插入代码块:
  ("cheat_spawn_party",0,
   "{!}Current troop range: {reg5} to {reg6}^{!}Current stacks in main party: {reg7}",
   "none",
   [
     (party_get_num_companions,":stacks","p_main_party"),
     (assign, reg7, ":stacks"),
     (assign, reg5, "$cheat_find_troop_range_begin"),
     (store_add, reg6, "$cheat_find_troop_range_begin", 10),
	 (val_min, reg6, "trp_kidnapped_girl"),
	 (val_sub, reg6, 1),


     ],
    [

    ("cheat_reset_main_party",[], "{!}Reset main party.",
       [
            (store_add, ":max_troop", "$cheat_find_troop_range_begin", 10),
	    (val_min, ":max_troop", "trp_kidnapped_girl"),
		(store_sub, ":num_troops_to_add", ":max_troop", "$cheat_find_troop_range_begin"),
         	(try_for_range, ":id_slot", 0, ":num_troops_to_add"),
		  (store_add, ":troop_id", "$cheat_find_troop_range_begin", ":id_slot"),
                (party_remove_members, "p_main_party",":troop_id",10),
                (try_end),
            (party_get_num_companions,":refill_stacks","p_add_troops"),
            (try_begin),
                (neq, ":refill_stacks", 0),
                (store_add, ":stacks_new",":refill_stacks", 1),
                (try_for_range, ":stack_number",2,":stacks_new"),
                    (party_stack_get_troop_id,":id","p_add_troops",":stack_number"),
                    (party_stack_get_size,":num","p_add_troops",":stack_number"),
                    (party_remove_members,"p_add_troops",":id",":num"),
                    (party_force_add_members,"p_main_party",":id",":num"),
                (try_end),
            (try_end),
            (jump_to_menu, "mnu_cheat_spawn_party"),
            ]
     ),
        
    ("cheat_find_troop_next_range",[], "{!}Move to next troop range.",
       [
	    (val_add, "$cheat_find_troop_range_begin", 10),
	    (try_begin),
	      (ge, "$cheat_find_troop_range_begin", "trp_kidnapped_girl"),
		  (assign, "$cheat_find_troop_range_begin", 0),
	    (try_end),
	    (jump_to_menu, "mnu_cheat_spawn_party"),
	   ]
       ),	   

	   ("cheat_find_troop_choose_this",[], "{!}Choose from this range.",
       [
(set_spawn_radius,5),
(spawn_around_party,"p_main_party","pt_spawned_party"),
(assign,":p_spawned_party",reg0),
(party_get_num_companions,":main_stacks","p_main_party"),
(try_begin),
(neq, ":main_stacks", 0),
(store_add, ":stacks_new",":main_stacks", 1),
(try_for_range, ":stack_number",2,":stacks_new"),
  (party_stack_get_troop_id,":id","p_main_party",":stack_number"),
  (party_stack_get_size,":num","p_main_party",":stack_number"),
  (party_remove_members,"p_main_party",":id",":num"),
  (party_force_add_members,"p_add_troops",":id",":num"),
(try_end),
(try_end),

        (store_add, ":max_troop", "$cheat_find_troop_range_begin", 10),
	    (val_min, ":max_troop", "trp_kidnapped_girl"),
		(store_sub, ":num_troops_to_add", ":max_troop", "$cheat_find_troop_range_begin"),
         	(try_for_range, ":id_slot", 0, ":num_troops_to_add"),
		  (store_add, ":troop_id", "$cheat_find_troop_range_begin", ":id_slot"),
                (party_force_add_members, "p_main_party",":troop_id",10),
                (try_end),
(change_screen_exchange_members, ":p_spawned_party"),

	   ]
       ),	   
	   
      ("camp_action_4",[],"{!}Back to camp menu.",
       [(jump_to_menu, "mnu_camp"),
        ]
       ),
      ]
  ),

It now works and can swap members between the two parties but in the exchange members screen it seems to be swapping members with a bandit camp; which causes the newly spawned party to be empty, not move, and crash when interacted with; at least i assume thats what causes that as the party template is a straight clone of the sea raiders one minus the sea raiders.

I guess the problems originate from (assign,":p_spawned_party",reg0), and its subsequent use, but i was pretty sure that the id of spawned parties is stored in reg0.

Any help on this matter would be much appreciated.
 
It's used in stuff that you aren't supposed to see. For example, in earlier versions, you could see bandits patrolling {!}the coast. There are also some dialogues, such as with a guy (fight promoter) who would pay you to stage a fight in taverns, which had {!} in front of every line to indicate that they're not supposed to be in-game yet.
 
后退
顶部 底部