poolcool2 Posted December 11, 2020 Share Posted December 11, 2020 So I am still fairly new to DST modding but one thing that keeps alluding me is a understanding of how the game decides to load code on the client, server, or both. I recently started a new project where this has finally become a roadblock. I am making a character with the ability to slow down time, in the prefab file I have the code near the top which slows down the simulation speed (Using "TheSim:SetTimeScale(x)") which works fine without caves, but when caves are enabled I have noticed it seems to only slow down the server speed while leaving the client expecting the usual speed which leads to some really bad desync issues. Could someone explain to me what parts in a mod files are loaded on the client and which are loaded on the server and why and/or how to tell the game to specifically run code on the client and server? Link to comment Share on other sites More sharing options...
Thomas Die Posted December 11, 2020 Share Posted December 11, 2020 Wait YOU CAN CHANGE TIME Link to comment Share on other sites More sharing options...
penguin0616 Posted December 12, 2020 Share Posted December 12, 2020 (edited) @thomas4846 Yes, but it can cause network issues and disconnections. @poolcool2 It depends on the settings you have for the mod. If its a client mod, it only runs on the client and cannot do anything on the server. If it's a server mod, it only runs on the server. If it is marked as all clients needing it, it runs on all clients and the server. From that point, it's up to you what you do. And worlds with caves have multiple servers (1 server runs the surface, other runs the caves), so your call to slow down the server would only happen on the server with the character. Edited December 12, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
poolcool2 Posted December 12, 2020 Author Share Posted December 12, 2020 (edited) 40 minutes ago, penguin0616 said: @poolcool2 It depends on the settings you have for the mod. If its a client mod, it only runs on the client and cannot do anything on the server. If it's a server mod, it only runs on the server. If it is marked as all clients needing it, it runs on all clients and the server. From that point, it's up to you what you do. And worlds with caves have multiple servers (1 server runs the surface, other runs the caves), so your call to slow down the server would only happen on the server with the character. Are you sure, because as I said I had a desync issue because the client was still expecting the usual speed whereas it did slow down the server correctly. for example I had the code activate slowing down time, which should slow down movement and animations, but I noticed that animations were definitely still normal speed and the movement seemed to get more and more desynced over time, presumably (I don't know much about how the movement is handled when it comes to lag and stuff so I am guessing here.) as the client went faster than the server, the client and the server both drifting further and further apart from their expected outcomes. And when I ran the code in the console when in "Remote" mode, which I assume runs on both the client and the server, it did indeed cause my client to be in slow motion and matching the server's speed again. Just to be clear I have this code as a function in the data of a equipable item positioned just under the assets and it is called to from the "OnEquip" function. Edited December 12, 2020 by poolcool2 Link to comment Share on other sites More sharing options...
penguin0616 Posted December 12, 2020 Share Posted December 12, 2020 (edited) @poolcool2 Yes, I am sure. Quote "Remote" mode, which I assume runs on both the client and the server And no, Remote only runs on the Remote, which is the server. Edited December 12, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
poolcool2 Posted December 12, 2020 Author Share Posted December 12, 2020 16 minutes ago, penguin0616 said: @poolcool2 Yes, I am sure. And no, Remote only runs on the Remote, which is the server. So what is the difference between running that code in the console and running from a prefab's lua file? what is causing the desync? Link to comment Share on other sites More sharing options...
penguin0616 Posted December 12, 2020 Share Posted December 12, 2020 (edited) The difference is that the code in the console only ran on the server, and ran on both sides in the prefab. That is, assuming the prefab replicates and you had it do so. Like I said, it generally depends on how you set up the mod info and your code. Edited December 12, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
poolcool2 Posted December 12, 2020 Author Share Posted December 12, 2020 5 minutes ago, penguin0616 said: The difference is that the code in the console only ran on the server, and ran on both sides in the prefab. That is, assuming the prefab replicates and you had it do so. Like I said, it generally depends on how you set up the mod info and your code. That sounds backwords to me, the console only runs it on the server but the prefab runs it on both? why does running it from the prefab cause a desync while the console runs it as intended, like I said, when it was done through the prefab animations still looked full speed while actions were slowed, however when doing it through the console it slows both animation and actions and has no desync problems. Link to comment Share on other sites More sharing options...
penguin0616 Posted December 12, 2020 Share Posted December 12, 2020 The console can run on both the client and the server, just depends on which you set it to. Quote why does running it from the prefab cause a desync while the console runs it as intended Probably something to do with how you set it up. 1 Link to comment Share on other sites More sharing options...
poolcool2 Posted December 12, 2020 Author Share Posted December 12, 2020 3 minutes ago, penguin0616 said: The console can run on both the client and the server, just depends on which you set it to. Probably something to do with how you set it up. Well how could I set it up to work? currently I just need it to slow down time for all players and all shards when the prefab is equipped and then resume to normal speed when unequipped and I could modify it to my needs as I figure out how it works. Link to comment Share on other sites More sharing options...
penguin0616 Posted December 12, 2020 Share Posted December 12, 2020 (edited) I would go about this by experimenting with setting time from just the console first. See what works, see what doesn't. Once that gets figured out, put it in the prefab and have it trigger on whatever side is needed/worked in the console. Edited December 12, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
poolcool2 Posted December 12, 2020 Author Share Posted December 12, 2020 2 minutes ago, penguin0616 said: I would go about this by experimenting with setting time from just the console first. See what works, see what doesn't. Once that gets figured out, put it in the prefab and have it trigger on whatever side is needed/worked in the console. I did but apparently it works when ran from the console, but not the prefab file if the mod is a server mod and all clients require it. That is why I decided to ask for help here because I am clueless as to why I can't get it to work in the prefab file. Link to comment Share on other sites More sharing options...
penguin0616 Posted December 12, 2020 Share Posted December 12, 2020 Mind providing the prefab file in question? Also, are you trying to set the time scale on the server, client, or both? 1 Link to comment Share on other sites More sharing options...
poolcool2 Posted December 12, 2020 Author Share Posted December 12, 2020 3 minutes ago, penguin0616 said: Mind providing the prefab file in question? Also, are you trying to set the time scale on the server, client, or both? I am trying to set the time scale on both because otherwise it causes a desync which makes it practically unplayable. timestophat.lua Link to comment Share on other sites More sharing options...
penguin0616 Posted December 12, 2020 Share Posted December 12, 2020 (edited) OnEquip only triggers on the server, not the client. This approach you have taken is also inherently unstable, since multiple hats of this can be worn by people to adverse effects. I suggest you move the time manipulation stuff to your modmain, and have the prefabs notify your modmain when they are equipped. To let the clients know that time is being manipulated and they need to change their scale as well, I suggest the use of netvars. If you don't know how to use those, I suggest this: https://forums.kleientertainment.com/forums/topic/48264-net_variable-types-and-sending-data-from-serverhost-to-clients/ (Alternately, you can use Client RPCs, explained here: https://forums.kleientertainment.com/forums/topic/122473-new-modding-rpcs-api/) Hope that helps. Edited December 12, 2020 by penguin0616 2 Link to comment Share on other sites More sharing options...
poolcool2 Posted December 12, 2020 Author Share Posted December 12, 2020 2 hours ago, penguin0616 said: OnEquip only triggers on the server, not the client. This approach you have taken is also inherently unstable, since multiple hats of this can be worn by people to adverse effects. I suggest you move the time manipulation stuff to your modmain, and have the prefabs notify your modmain when they are equipped. To let the clients know that time is being manipulated and they need to change their scale as well, I suggest the use of netvars. If you don't know how to use those, I suggest this: https://forums.kleientertainment.com/forums/topic/48264-net_variable-types-and-sending-data-from-serverhost-to-clients/ (Alternately, you can use Client RPCs, explained here: https://forums.kleientertainment.com/forums/topic/122473-new-modding-rpcs-api/) Hope that helps. It is super late for me so I will go to bed but this sounds like exactly what I needed, thank you so much ^-^ Ill have to test it tomorrow, Ill mention if I run into any more problems. Link to comment Share on other sites More sharing options...
Wonderlarr Posted December 12, 2020 Share Posted December 12, 2020 (edited) Hey, by any chance are you developing a mod for Hat Kid from A Hat in Time? I've been developing my own for quite some time, we may want to put our works together. The reason I ask is because that prefab file is almost identical to what a file with the same name in my mod looked like before I reworked it, and if you could get this idea to work that would be freaking sick, especially if we can somehow get the character to still work at full speed while everything else slows down. Edited December 12, 2020 by TheSkylarr Didn't finish typing Link to comment Share on other sites More sharing options...
poolcool2 Posted December 12, 2020 Author Share Posted December 12, 2020 10 hours ago, TheSkylarr said: Hey, by any chance are you developing a mod for Hat Kid from A Hat in Time? I've been developing my own for quite some time, we may want to put our works together. The reason I ask is because that prefab file is almost identical to what a file with the same name in my mod looked like before I reworked it, and if you could get this idea to work that would be freaking sick, especially if we can somehow get the character to still work at full speed while everything else slows down. You are spot on my friend, I was going to make my own take on the remake, I was going to call it "HatKid -Rewound" but I would love to collaborate with your rework. I actually had my eye on your rework for a while and liked some of it's changes and it gave me some ideas and was part of why I decided to start working on reworking that mod. If you want to talk on steam about our potential collaborating here is my profile. I don't have much progress on my version yet, but I would love to help out with your version. Link to comment Share on other sites More sharing options...
poolcool2 Posted December 13, 2020 Author Share Posted December 13, 2020 19 hours ago, penguin0616 said: OnEquip only triggers on the server, not the client. This approach you have taken is also inherently unstable, since multiple hats of this can be worn by people to adverse effects. I suggest you move the time manipulation stuff to your modmain, and have the prefabs notify your modmain when they are equipped. To let the clients know that time is being manipulated and they need to change their scale as well, I suggest the use of netvars. If you don't know how to use those, I suggest this: https://forums.kleientertainment.com/forums/topic/48264-net_variable-types-and-sending-data-from-serverhost-to-clients/ (Alternately, you can use Client RPCs, explained here: https://forums.kleientertainment.com/forums/topic/122473-new-modding-rpcs-api/) Hope that helps. I tried both of those methods and neither seems to fix the problem when I got them to work. with both methods the client still seemed to never realize that the timescale was changed. While I was learning about the RPCs it seems that they can be used to send data from the client to the server or from the server to another server, but not from the server to the client which is what I needed. If you have any other ideas on how I could fix the problem I would like to try them out. Link to comment Share on other sites More sharing options...
penguin0616 Posted December 13, 2020 Share Posted December 13, 2020 (edited) 56 minutes ago, poolcool2 said: but not from the server to the client which is what I needed Yes, you can send from the server to the client. It is in the link I provided. Edited December 13, 2020 by penguin0616 1 Link to comment Share on other sites More sharing options...
poolcool2 Posted December 13, 2020 Author Share Posted December 13, 2020 16 hours ago, penguin0616 said: Yes, you can send from the server to the client. It is in the link I provided. Oh, I think I see how I somehow messed up there, Ill try it again and tell you if I get it to work. Sorry for bothering you with my mistake. Link to comment Share on other sites More sharing options...
poolcool2 Posted December 14, 2020 Author Share Posted December 14, 2020 I got it to work now, thanks @penguin0616. Now I just need to figure out how I can double the character's attack speed, actually decreasing the attack delay itself does nothing even with lowering the minimum attack delay. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now