Jump to content

Modding Game Modes - example The Hunt


Recommended Posts

  • Developer

Hey everyone,

 

In today's hot fix, we added code to support modding of game modes, as well as adding new game modes in a mod. To show off this new functionality I put together a small game mode mod called The Hunt. The premise of this game mode mod is to spawn extra creatures around the players, keep track of the number of kills, sync that data between the host and clients, and display the result when the game is over.
 

 

To add new game modes, add something similar to your modmain.lua

local the_hunt = AddGameMode( "the_hunt", "The Hunt" )the_hunt.ghost_sanity_drain = true

This will add the option to select this new game mode when creating a server. The first parameter is the game mode string, and the second is the text that will be displayed for this game mode. To see other details about the options on the game mode, take a look at gamemodes.lua.

 

Then I add my component to the world_network object if the server is using the new game_mode.

local TheNet = GLOBAL.TheNetfunction HuntSetup(inst)	if TheNet:GetServerGameMode() == "the_hunt" then		print("### HuntSetup ###")		inst.hunt_time = GetModConfigData("hunt_time")		inst:AddComponent("HuntGameLogic")	else		print("Not enabling The Hunt because the server game mode isn't matching.")	endendAddPrefabPostInit("world_network", HuntSetup)

My mod has UI that needs to run on the client, so I add the component on both the host and the client. During the game mode component's update (HuntGameLogic:OnUpdate) there are two sections, UI logic that happens on all machines, and game logic that only runs on the server.

function HuntGameLogic:OnUpdate(dt)        --UI logic        --Removed for simplicity	        --Server only logic	if TheWorld.ismastersim then		self:ServerOnUpdate(dt)	endend

Please take a look at the mod, and let me know if something isn't clear with regards to how game modes work.

 

You can subscribe to this mod here.

 

Have a happy holiday season, and watch out for Krampus! :-)

 

 

 

 

Edit: Known issue: Mod configuration data isn't getting sent to the clients.

Edit: Mod config data is now downloaded automatically to clients.

 

 

 

 

Link to comment
Share on other sites

I would like to thank you for putting this out, as a modder it really has helped for figuring the network side of don't starve together as I read through the code.

 

"Edit: Known issue: Mod configuration data isn't getting sent to the clients."

Is it actually possible for client to get mod configuration from host? I've been digging through the code and can't find any instance of host mod configuration getting passed to client. A function to retrieve mod configuration option from host would be very useful

Link to comment
Share on other sites

  • Developer
Is it actually possible for client to get mod configuration from host?
 

 

I was probably a little unclear here, I believe you are correct, this is a global issue, not specific to this mod. I'll be investigating a solution for this soon.

  • Wavey 1
Link to comment
Share on other sites

  • Developer
I would like to thank you for putting this out, as a modder it really has helped for figuring the network side of don't starve together as I read through the code.
 

 

You're welcome. I'll be posting some more information about the net_variables later today or tomorrow.

Link to comment
Share on other sites

On 1/2/2015 at 12:27 PM, PeterA said:

 

 

You're welcome. I'll be posting some more information about the net_variables later today or tomorrow.

I know this is insanely outdated and I'm necroposting, but where is this so-called "gamemodes.lua"? I'm trying to make a custom gamemode and I'd like to give it things like world presets with stuff like endless, and no trees, as an example. I've looked but was unable to find information on this.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...