MakeSureToKnock Posted January 10, 2024 Share Posted January 10, 2024 Greeting vetern posters! As a virgin to DST coding I seek your expertise. As the title suggest this post is about the differences between client and server requirements, or a game in which there aren't and are caves. As far as I'm aware differences mainly revolve around Components and Stagegraphs were: There is a secondary Stategraph that lacks "game calculations" and simply plays animations for the client Components are used mainly by the server, when one exists, and clients or worlds without caves skip them... somehow. Replica components exist, but as for the full purpose I am unaware. What I'm looking for is information and examples that will help me piece together what I already know. I know thats kind of vague so I'll start with a question. Within my character prefab I have a ListenForEvent("equip", fn) within the master_postinit function. This Listen runs a function that, just for testing purposes, changes the character current health to a random value between 1 and 50 using inst.components.health:SetCurrentHealth(math.random(50)) and well as prints a message for confirmation. This works fully on a world with caves, but fails to work on a world without them; server versus client. On the world without caves it prints the message, so I know ListenForEvent works on clients, but health change doesn't occur. Through that I can conclude that client doesn't interact with health through the health component, or if it does, then not using inst.components.health. My question: how would I, using the same listen, change the health of my character in a no cave, client world. I'm sure this has been answered somewhere, so a reference to a relevent page would work wonders if explaining here is to tedious. My wish is to someday get good enough at this to create updated documents and tutorials of my own, but we all have to start somewhere. Thanks in advance! Link to comment https://forums.kleientertainment.com/forums/topic/153772-doing-it-right-the-first-time-client-vs-server/ Share on other sites More sharing options...
ClumsyPenny Posted January 10, 2024 Share Posted January 10, 2024 7 hours ago, MakeSureToKnock said: is about the differences between client and server requirements, or a game in which there aren't and are caves. Hosting without Caves simply means you're both client and server, so you have easy access to server information. While other players who join your game or if you were to host with Caves would only have client information. Most mistakes in terms of modding here come from assuming that clients have access to server information. 7 hours ago, MakeSureToKnock said: There is a secondary Stategraph that lacks "game calculations" and simply plays animations for the client Yes, "wilson_client", but it's the only one, since it's for the character you control as a player. 7 hours ago, MakeSureToKnock said: Components are used mainly by the server, when one exists, and clients or worlds without caves skip them... somehow. There's a few components that exist on clients too, but yes, most of them are server-side only. Clients can "skip" them because... 7 hours ago, MakeSureToKnock said: Replica components exist, but as for the full purpose I am unaware. ...replicas exist. The purpose of replicas is to replicate a component on the client too, but heavily simplified to only really get information like values, like health or anything else. There's even simpler ways to replicate information without using replicas, like adding/removing tags server-side, because tags are automatically replicated on the client too. 7 hours ago, MakeSureToKnock said: Within my character prefab I have a ListenForEvent("equip", fn) within the master_postinit function. This Listen runs a function that, just for testing purposes, changes the character current health to a random value between 1 and 50 using inst.components.health:SetCurrentHealth(math.random(50)) and well as prints a message for confirmation. This works fully on a world with caves, but fails to work on a world without them; server versus client. On the world without caves it prints the message, so I know ListenForEvent works on clients, but health change doesn't occur. Through that I can conclude that client doesn't interact with health through the health component, or if it does, then not using inst.components.health. Weird that it's not working without Caves, usually it's the other way around if there's an issue. You don't really need to account for different behavior for being both client and server, since you simply have access to even more information. Could you upload your mod? 7 hours ago, MakeSureToKnock said: My wish is to someday get good enough at this to create updated documents and tutorials of my own, but we all have to start somewhere. That's a great idea, would love to help with this project in the future! 1 Link to comment https://forums.kleientertainment.com/forums/topic/153772-doing-it-right-the-first-time-client-vs-server/#findComment-1693478 Share on other sites More sharing options...
MakeSureToKnock Posted January 11, 2024 Author Share Posted January 11, 2024 Sorry for the days delay in reply, college comes first. Below you will find the my current teardown/reassemble project. Thanks to whoever orginally made the Woge the dog mod and the person who reuploaded it for allowing me to destory for science. As a summery of major modifications beside mass culling of the oringal code to see what the bare minimum required was. Modmain contains an addaction set that allows work to be done(chopping, digging, mining) without a tool. It works, but could use some cleaning later. The only prefab contains nothing exceptional save for the Listen event and subsquent function that I was having an issue with. Stategraph has two states, both contain the GetClosestInstWithTag follow by some statements that decide if the character can actually do work on that object. My intention is to have the character grow as the game progresses which limits them in the begning to not being able to chop large trees or mine rocks. GetClosestInstWithTag is obviously not my best choice here but it works for now. Finally the soze component is what I'll be using to track the characters growth as well as things they'll allowed to do and their current stats at certain growth stages. There are also "animations", technically, for idle left/right/down and walking left/right/down, but I am not a career animator or artist so... I do know why it's doing that, though. BetterNameNeeded.zip Link to comment https://forums.kleientertainment.com/forums/topic/153772-doing-it-right-the-first-time-client-vs-server/#findComment-1693742 Share on other sites More sharing options...
ClumsyPenny Posted January 12, 2024 Share Posted January 12, 2024 Okay, I looked into it, I kind of figured out what's happening. The health value is actually changing even on a world without Caves, but it's not changing on the UI visually. Normally the UI is updated automatically for stuff like this (whether you're hosting with or without Caves), but specifically when using SetCurrentHealth it doesn't. I don't really know why, I don't feel like looking into this that deep, but there's an easy solution that Klei employs as well whenever they call SetCurrentHealth for players, which is to add this line of code right after: inst.components.health:ForceUpdateHUD(true) (The first argument that I have set to "true" here is whether or not the health is an overtime effect. If it's overtime, then the health badge won't pulse green/red. This is used for stuff like health drain, it'd be annoying if every frame there was a pulse and a sound effect playing) Hope this helps! And if you need more help with your mod, feel free to ask. 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/153772-doing-it-right-the-first-time-client-vs-server/#findComment-1693829 Share on other sites More sharing options...
MakeSureToKnock Posted January 12, 2024 Author Share Posted January 12, 2024 (edited) Works like a charm. Guess I have something new to add to my documents. Thanks a bunch for taking time to figure this out. Next time I'll look at more places the function exists before asking in. I suppose I have one more question but it's not realated this what's in this tread. Before I ask, would it be more proper to start a new thread or just quick as here? I hope you succeed in whatever your current project is! Edited January 13, 2024 by MakeSureToKnock 1 Link to comment https://forums.kleientertainment.com/forums/topic/153772-doing-it-right-the-first-time-client-vs-server/#findComment-1693920 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