rawii22

  • Content Count

    117
  • Joined

  • Last visited

Community Reputation

33 Excellent

About rawii22

  • Rank
    Member
...

Recent Profile Visitors

952 profile views
  1. Hey! If you've ever needed to send information from one shard to another, we're pretty sure we figured out how. I partially wanted to write all this down since it doesn't look like anyone has had an in-depth discussion on handling inter-shard communication. @AlbertoRomanach (my brother) and I were recently working on a mod that needed this ability and we finally sat down and figured it out. There's a link at the bottom. As a little teaser, it is possible to send commands from one shard to another... This guide could help if you're making a mod that needs to deal with overworld and cave shards differently. First of all, Klei is very nice with their mod utils, and none of this would be possible without the AddShardModRPCHandler function. I'm pretty sure we also saw an example of this function used in GemCore under gemscripts/tools/shardrpc.lua in case anyone wants to take a look, so say thank you to @zarklord_klei! From A Mod Here is a very simple implementation of an RPC that allows you to execute a Lua string on any target shard: AddShardModRPCHandler(modname, "ShardInjection", function(shardId, namespace, code, injection) ------THIS BODY CAN BE CUSTOMIZED------ -- Only run if the current shard is different from the shard that called the RPC. The *calling* shard's ID is held in shardId. if GLOBAL.TheShard:GetShardId() ~= tostring(shardId) then GLOBAL.ExecuteConsoleCommand(injection) end ------END------ end) When you are using caves (or a dedicated server with caves), when one shard uses this RPC, the opposite shard will detect it and execute the contents of the RPC (which shown above is just a call to ExecuteConsoleCommand). If you remove the "GLOBAL.TheShard:GetShardId() ~= tostring(shardId)" check, then the RPC will run on ALL SHARDS. If you're somehow running a server with more than two shards, then you'll likely have to be a little more specific with the shardId check depending on what you're doing. The three parameters "shardId, namespace, and code" we found in GemCore's shardrpc.lua, but we never used them. But we added a custom parameter "injection" which is where the Lua string is passed in. You'll see its usage a little lower. Here is an example of its use in a mod file: function testFunction(string) --In mods, "modname" will automatically translate to the name of the directory the mod is in. SendModRPCToShard(GetShardModRPC(modname, "ShardInjection"), nil, nil, nil, "c_announce(\""..string.."\")") end For us normal cave users, the ShardInjection RPC will simply execute the string "c_announce(\""string"\")" from the opposite shard. If you're using more than two shards and you only want to target a single shard, I imagine you could theoretically change the first "nil" argument in the GetShardModRPC to be a more specific shardId, but I've never used more than two shards before, so you'll have to mess around with that. The Lua string can be literally anything you want, as long as the string can be executed from the console. Remember, this RPC can be customized to do something other than code execution. You can add parameters as you please. If you simply need to retrieve or send info from other shards or do anything else, you can do that. In fact, data retrieval was what we mainly used the AddShardModRPCHandler for in the first place. From the Terminal ~~~This next section talks about sending commands to another shard from the terminal, but a mod with this RPC must be enabled first.~~~ Now, for an even more interesting use of this, admins on a dedicated server can technically use this RPC from the console if they know what to do. They can execute a command on another shard. Clients without admin privileges, however, are not able to use the following command since they don't have access to the remote terminal. If they did, this would be a security issue since any random client would be able to hop onto a server with this RPC and execute Lua code injections. Fortunately, they can't! Unless you deliberately set that up, this should not be a problem. Using the same RPC as before, this command can be used from the console (remotely) by admins: SendModRPCToShard(GetShardModRPC("workshop-########", "ShardInjection"), nil, nil, nil, "Lua code here") "workshop-########" must be the mod that has the ShardInjection RPC defined in it. If you're testing locally, then you can just change "workshop-########" to be the mod's directory name like "folderNameHere" (it must be in quotes). Also, you could theoretically set up a new console command from inside a mod that simply accepts the Lua string and executes this line internally. It would look very similar to the RPC I showed earlier, but instead of "c_announce(\""string"\")" you could just put the variable "string". You'd also have to make the function GLOBAL to make it accessible from the console. Here's a console command that could go in a mod file: function GLOBAL.testFunctionTwo(string) SendModRPCToShard(GetShardModRPC(modname, "ShardInjection"), nil, nil, nil, string) end You should be able to call it from the console like this: testFunctionTwo("AllPlayers[2].components.health:SetPercent(1)"). If called from the overworld, this command would refill the health of player 2 from the perspective of the cave shard. This also works in the other direction. For example, if there are 4 players, 2 in the overworld, and 2 in the caves, the command will refill whoever is in the AllPlayers[2] spot in the caves. However, this command will not work if you try to target players who are in the same shard as you. Our mod shows a list of every player in the game (including caves) on the screen based on the server's version of AllPlayers. Using the same example, player 2 in caves would appear as player 4 on our list. We have a few console commands that are capable of detecting whether player 4 is in the caves. If the target player is in the caves, we have a function that both converts the number 4 into the proper player number and sends the command to the caves. But if player 4 is NOT in the caves, it can ALSO execute the console command on the same shard. You can see how my brother and I dealt with this toward the bottom of our modmain. You can also read more about it in the mod comments and in the readme for the mod. In Conclusion: Communication between shards doesn't have to be so much of a nightmare. Once you have it down, it's pretty easy to replicate and tailor to your needs. Like I said earlier, it's possible this could help with mods that need to deal with overworld and cave shards differently. Regardless, as I also mentioned earlier, Klei is very nice. I admire Don't Starve Together not only for its gameplay, but also for its amazing programming and team. I've learned a lot from its code, and I hope I can help people with what I've learned before I forget all of this ! Also, if anyone needs help setting up dedicated servers on Linux, I just recently figured that out (at least on ubuntu) so ask me about that if you need to. Leave a comment in case any of you need more info! If you think I should discuss anything else in here, please let me know and I can add it so people can see it. You can see the mod with which we used this method of communication right here. It was used in order to collect the list of players from both the overworld AND the caves and print them in order based on the server's version of AllPlayers: Sorry! I realized two seconds after I posted this that there was a tutorials and guides subforum
  2. I don't know if this is related, but I can't start a server with caves. Last night, it said it was unable to start the server. My brother (who lives somewhere else) tried the same thing and it didn't work for him either. I started the game up just a second ago and it looks like it was unable to get all the news and promotions from the klei servers either...
  3. Ok, I have a simple suggestion. I think everyone is used to the idea that one click equals crafting one item. Now you have to click at least twice to craft an item once. Maybe what you can do is add an option where you can right click an item once (from the full craft menu) to just craft it directly without activating the item description at the bottom of the UI. (Right now, the only way to click once to craft once is to bind the item to the tabs.) And, just throwing this out there either as a mod idea or as an idea for Klei, maybe you can add one more UI element right under the item description where you can choose how many items to craft. Maybe it can be as simple as a box with a left and right arrow next to it and it won't let you increment past what you can craft. Or maybe you can type the number, and if the amount is over what you can craft, it will just craft the maximum amount capable. Also, maybe you could restrict this counter to items with the "inventoryitem" tag or items without placers... Also little bug, when there are items in a chest that you can craft from, if you walk away from the chest, the items will still be lit up as craftable once the chest is already closed. Another little bug, if auto-pause is disabled and you open the craft menu, you can still move around but you can't click on anything in the world or use the space bar while it's open. I actually like the idea of still being able to play with the full craft UI open, so you don't have to make it auto-close if the world is clicked... (Also, the tooltips for the filters are a little low. It's difficult to see the filter you're currently on or the filters on the top row if you have your mouse on the bottom row...) (Lastly, you can't craft from the tabs if you have the whole craft UI open. You can only use the tabs if the full menu is closed.)
  4. When the auto-pause feature is disabled (for both the pause menu and console) and the server pause is toggled from the pause menu the game crashes. Sometimes you have to click the "Pause Server" button a few times for the game to crash. I've been able to replicate this many times. I had no server or client mods enabled. However, the game pauses normally when auto-pause is enabled. We spammed the escape key repeatedly and did not encounter any errors with auto-pause. The client log is attached.
  5. You should probably talk about this in the Mods and Tools sub forum. The bug tracker is for the game itself... [Don't Starve Together] Mods and Tools - Klei Entertainment Forums
  6. They're probably trying to think of a way to balance the system so that point rewards don't just automatically turn into spool rewards...
  7. Knowing that all games have their own way of saving save files, this should not be a steam problem. Here's the situation: the DST game itself is saved in a steam library on D drive, however the save files are still saved on C in Documents. If it is possible, how (without moving the Documents folder as a whole) would one go about moving the Klei folder to another drive or location? (ps. on my search, I saw one person on reddit say this was possible, but they did not explain how it could be done...)
  8. My brother and I tried using this for our in-game mod manager mod. Honestly, the best way to see how it works is to see how Klei used it. Try searching in these files from scripts: emailsignupscreen.lua mainscreen.lua multiplayermainscreen.lua lavaarena_communityprogression.lua -- I think file uses QueryServer to retrieve some sort of online scoreboard data for the forge (I never got to play the forge so I'm not sure...) motdmanager.lua I'm not sure how the function fully works myself since the website I needed to visit was literally just one small piece of text, but using these files I'm sure you can figure out what it requires and how it returns data. Sorry I couldn't be more specific, but that's just how modding goes sometimes...
  9. Here's a new one!! https://accounts.klei.com/link/forgottenspool It expires in one month from 10/22/2020
  10. Hey, I have a quick question about the networking behind DST. (It seems like @V2C or PeterA talk about networking more than most devs) My brother and I made a mod that allows people to change client mods in-game, and it reconnects people back to the server. We do this in our modmain: GLOBAL.JoinServer(GLOBAL.TheNet:GetServerListing()) Before this update, the world didn't pop up a screen saying "Duplicate Connection" when we used this line. My question is whether you guys may have changed a check in the backend that we can't see (like in TheNet), because now our mod is pretty difficult to adapt... (We have a way of retrieving the server's IP address and using TheNet:StartClient, but we're still figuring out how to make it work properly since it has worked in the past...)
  11. https://steamcommunity.com/sharedfiles/filedetails/?id=661253977
  12. Yeah, you can check the prefab of what's doing the cooking
  13. Check out the keep inventory mod. It lets you keep your inventory when you die.
  14. It's possible that the function is being run when nothing is in the hand slot, so when it checks for handitem.prefab for the first time it won't find anything. Maybe you should put "if handitem then" before you use handitem...