Jump to content

Need help understanding how to load code on client/server specifically (Solved)


Recommended Posts

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

@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 by penguin0616
  • Like 1
Link to comment
Share on other sites

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 by poolcool2
Link to comment
Share on other sites

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 by penguin0616
  • Like 1
Link to comment
Share on other sites

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

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

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 by penguin0616
  • Like 1
Link to comment
Share on other sites

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

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 by penguin0616
  • Like 2
Link to comment
Share on other sites

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

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 by TheSkylarr
Didn't finish typing
Link to comment
Share on other sites

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

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

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

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...