Giving gold to all of your team via actions - multiplayer question

Users who are viewing this thread

Grendal-777

Veteran
Giving gold or setting player gold is fairly straight forward, has anyone found the mechanic for giving gold to other team members via actions?

Example: Each time team 1 member kills team 2 member instead of player getting x gold, everyone on their team gets x gold.

It would have to be sent to server and out to each client.
Just curious if this has been used before and can't find reference in search.
 
This is easy; just search in module_scripts.py for "money_management_after_agent_death", and modify to your taste. You don't have to add any new network messages or anything; gold is one of the things that is updated on the clients automatically.
 
In FPW there is a chest which when activated will give gold to everyone in the area. I am sure that can be altered in some way
I haven't found where any of the scripts from FPW have been released publicly.

This is easy; just search in module_scripts.py for "money_management_after_agent_death", and modify to your taste. You don't have to add any new network messages or anything; gold is one of the things that is updated on the clients automatically.

Glad to know gold is handled server side (course now that I think about it, would be easy to hack otherwise).
I read through the money_management_after_agent_death, I am looking to create gold that is then added to all members of only your faction and it looks to be more about distributing percentages. I have some python coding skills but not much M&B modified coding skills and could really use an example if anyone has tried this in the past.
 
Ok, made some progress thanks to help from Wookie Warlord, but code not working as intended.

When I access the prop it maxes out my player gold instead of adding the amount in the :profit variable.
Maybe someone who hasn't stared it it as long as I can point out where I have erred.

check_objectxused = (ti_on_scene_prop_use,
    [
      (store_trigger_param_1, ":agent_id"),
      (multiplayer_is_server),
      (assign, ":profit", 50),
      (agent_get_player_id,":player_no",":agent_id"),
      (player_get_team_no,  ":myteam", ":player_no"),
      (get_max_players, ":num_players"),

          (try_for_range,":player",1,":num_players"), #was 0 but t_f_r comments says use 1 for players
          (player_get_team_no, ":team", ":player"),
  (eq, ":team", ":myteam"),
      (try_begin),
              (player_is_active, ":player_no"),
      (player_get_gold, ":player_gold", ":player_no"),
      (val_add, ":player_gold", ":profit"),
              (player_set_gold, ":player_no", ":player_gold", multi_max_gold_that_can_be_stored),
              (try_end),
          (try_end),
 
])

edit: put code in spoiler, spell checking
 
Your loop variable is player, yet you're using player_no (the one that activated the prop) to test for activity and to fetch (and subsequently add) gold. So the player that activated the scene prop will get profit*number of players on his/her team.
 
Thank you!
Fixing my variable problem pointed out by Somebody, along with changing my "(try_for_range,":player_no",1,":num_players")" to "(try_for_range,":player_no",0,":num_players")" (it was skipping the accessing player then running thru team)
It seems to be functioning as intended. I won't be 100% sure till I can get in with an actual team member later today, but I am pretty confident it will work.

Finished code:
check_objectxused = (ti_on_scene_prop_use,
    [
      (store_trigger_param_1, ":agent_id"),

      (multiplayer_is_server),

      (assign, ":profit", 50),
      (agent_get_player_id,":player_no",":agent_id"),
      (player_is_active, ":player_no"),
      (player_get_team_no,  ":myteam", ":player_no"),
      (get_max_players, ":num_players"),
          (try_for_range,":player_no",0,":num_players"),
              (player_get_team_no, ":team", ":player_no"),
      (eq, ":team", ":myteam"),
        (try_begin),
                    (player_get_gold, ":player_gold", ":player_no"),
            (val_add, ":player_gold", ":profit"),
                    (player_set_gold, ":player_no", ":player_gold", multi_max_gold_that_can_be_stored),
                (try_end),
          (try_end),
])
 
The fact that skipping player 0 (the server) makes a difference means you are testing with a client hosted server; I reccomend you do all script related testing with a dedicated server, as client hosted servers are a special case that won't show a lot of possible problems with the code. You can copy the dedicated server executable with a startup script and bat file to your client install directory, and run it from there - so you don't need to copy across your module all the time - and then start it on the same computer as you are using for the client.

Though this might not be workable if you have a large scene and not much computer memory, as it will load things twice when the server is not client hosted.
 
Back
Top Bottom