Setting a MP Team Leader

Users who are viewing this thread

Fat Cat

Recruit
Hello there, I want to make a non/hosting player the team leader of their team ideally by keypress, only for LAN (example, start a LAN battle with bots, NOT tick / checkbox select any to control, Press a key = all bots on your team come under control, same for 2nd player on other team).

My following codes do not work tried a few variations (looked at mbcommands Operations Page), was getting opcode errors in game, invalid player / agent / group to each code block below

Only done very basic codes for game before, do I need to use multiplayer_send_int_to_server, is my code complete garbage, can anyone please help?


Code:
multiplayer_make_agent_team_leader = (### this code gives invalid agent id.
  0, 0, 0, [],
  [
  (this_or_next|multiplayer_is_server),
  (neg|game_in_multiplayer_mode),
  (key_is_down, key_minus),

##### find the player ID and their agent ID ?
    # (try_for_players, ":player_no", 0),#                   (try_for_players, <destination>, [skip_server]), 1 skip server player entry
    (try_begin),
      (assign, ":player_no", reg0),#                   (try_for_players, <destination>, [skip_server]), 1 skip server player entry
      (player_get_team_no, ":playerteam", ":player_no"),#  (player_get_team_no,  <destination>, <player_id>),
      (player_get_agent_id, ":agent_id", ":player_no"),#   (player_get_agent_id, <destination>, <player_id>),
      (agent_get_team, ":playerteam", ":agent_id"),#       (agent_get_team, <destination>, <agent_id>),
    # (try_end),

##### now try for the bot agents...
        (try_for_agents, ":bots_id"),#                 (try_for_players, <destination>, [skip_server]), 1 skip server player entry
          (agent_is_human, ":bots_id"),
          (agent_is_alive, ":bots_id"),
          (agent_get_team, ":botteam", ":bots_id"),#     (agent_get_team, <destination>, <agent_id>),
          # (agent_get_group, ":botgroups", ":bots_id"),# (agent_get_group, <destination>, <agent_id>),### Retrieves reference to player who is currently the leader of specified bot agent.
          (eq, ":botteam", ":playerteam"),# Does Value 1 = Value 2?
            (try_begin),
              (team_set_leader, ":playerteam", ":player_no"),#     (team_set_leader, <team_no>, <new_leader_agent_id>),### tried agent_id,
              # (agent_set_group, ":botgroups", ":player_no"),#     (agent_set_group, <agent_id>, <player_leader_id>),### puts bot under player control MP
              (str_store_string, s1, "@agent is leader ???"),
              (display_message, "@{s1}"),
            (try_end),
        (try_end),
    (try_end),
  ])


multiplayer_make_agent_admin = (### this code gives invalid player id.
  0, 0, 0, [],
  [
  (this_or_next|multiplayer_is_server),
  (neg|game_in_multiplayer_mode),
  (key_is_down, key_equals),
##### find the player ID and their agent ID ?
    # (try_for_players, ":player_no", 0),#                   (try_for_players, <destination>, [skip_server]), 1 skip server player entry
    (try_begin),
      (assign, ":agent_id", reg0),#                   (try_for_players, <destination>, [skip_server]), 1 skip server player entry
      # (player_get_team_no, ":playerteam", ":player_no"),#  (player_get_team_no,  <destination>, <player_id>),
      # (player_get_agent_id, ":agent_id", ":player_no"),#   (player_get_agent_id, <destination>, <player_id>),
      (agent_is_alive, ":agent_id"),
      (agent_is_human, ":agent_id"),
      (agent_get_team, ":playerteam", ":agent_id"),#       (agent_get_team, <destination>, <agent_id>),
    # (try_end),

##### now try for the bot agents...
        (try_for_agents, ":bots_id"),#                 (try_for_players, <destination>, [skip_server]), 1 skip server player entry
          (agent_is_human, ":bots_id"),
          (agent_is_alive, ":bots_id"),
          (agent_get_team, ":botteam", ":bots_id"),#     (agent_get_team, <destination>, <agent_id>),
          # (agent_get_group, ":botgroups", ":bots_id"),# (agent_get_group, <destination>, <agent_id>),### Retrieves reference to player who is currently the leader of specified bot agent.
          (eq, ":botteam", ":playerteam"),# Does Value 1 = Value 2?   
            (try_begin),
              (team_set_leader, ":playerteam", ":agent_id"),#     (team_set_leader, <team_no>, <new_leader_agent_id>),### tried agent_id,
              # (agent_set_group, ":botgroups", ":player_no"),#     (agent_set_group, <agent_id>, <player_leader_id>),### puts bot under player
              ###(agent_set_group, ":botgroups", ":agent_id"),#     # (agent_set_group, <agent_id>, <value>),### puts bot under player
              (str_store_string, s1, "@any notes ???"),
              (display_message, "@{s1}"),
            (try_end),
        (try_end),
    (try_end),
  ])

multiplayer_make_agent_team_leader_v2 = (### this code gives invalid group id.
  0, 0, 0, [],
  [
  (this_or_next|multiplayer_is_server),
  (neg|game_in_multiplayer_mode),
  (key_is_down, key_0),
    (try_begin),
      (assign,":agent_id"),
      (get_player_agent_no,":agent_id"),
      (agent_get_team, ":playerteam", ":agent_id"),#       (agent_get_team, <destination>, <agent_id>),
      (team_set_leader, ":playerteam", ":agent_id"),#     (team_set_leader, <team_no>, <new_leader_agent_id>),### tried agent_id,
      (multiplayer_send_int_to_server, multiplayer_event_agent_team_and_group_leader, slot_player_bot_type_1_wanted),
      (str_store_string, s1, "@any notes ???"),
      (display_message, "@{s1}"),
    (try_end),
  ])

Thank you.
 
LAN is not supported anymore, TW silently updated Warband and made LAN not working in the game.

Also, the following does not make any sense.
Python:
(this_or_next|multiplayer_is_server),
(neg|game_in_multiplayer_mode),
 
Upvote 0
Hello again, I remember when LAN closing down was a problem over 2 year back, it has been working again / re-active since late 2020, tested it out few days ago - no problems hosting or joining LAN what so ever - that is why after setting leader by key press. Only problem here is my code chief.
As for them lines;
(this_or_next|multiplayer_is_server),
(neg|game_in_multiplayer_mode),

I copy pasted straight out off the native MP source codes, they seam to be pretty frequent, to my noob eyes its looks like neg|game_in_MP means "no, not in multiplayer mode you won't do this" but it is in a lot of the MP source code.
 
Upvote 0
Python:
(this_or_next|multiplayer_is_server),
(neg|game_in_multiplayer_mode),
Iirc this is a line combo which indicates the scripts run on the server. So this only works on dedicated servers and fail at the clients (afaik you are both clients at a LAN). Which means, this is exactly the opposite of what you want to have. I also don't understand why you want to make everyone an admin, the host is automatically the admin.

What you basically want is that the bots follow the player even without having to tick any of the boxes at the equipment selection, yes? Take a look at the lines which assign the checked bots to the player and comment out the lines which are doing the checks so that the bot-follow-player-automatically is always getting done.
 
Upvote 0
So this only works on dedicated servers and fail at the clients
Thanks for clearing that I had no idea.

What you basically want is that the bots follow the player even without having to tick any of the boxes at the equipment selection, yes?
Yes exactly like you just said. Reason is other player (non hosting) cannot key spawn troops into scene (got the "Highlight Selection" problem sorted will post to OSP once got other problems worked out)

Take a look at the lines which assign the checked bots to the player
sorry Eärendil do you mean look at my own code or look at original source code? Thanks for your time there.
 
Last edited by a moderator:
Upvote 0
Some people on Steam complained about the lack of support for LAN some time ago; I did not know that LAN support had been restored.

Also, that is right about the code snippet I mentioned. It turns out it is just fine, I just confused one operation.
 
Upvote 0
Back
Top Bottom