Jump to content

How to send an event to both client and server?

Recommended Posts

Hi, there. For one of the custom characters I'm making, they're able to craft an item when they're near puddles. This all works just fine, so long as the server isn't dedicated.

However, if the server is dedicated, then it doesn't properly send the "refreshcrafting" event to the server and thus doesn't show the update properly.

If I'm already standing on a puddle when I spawn in, and I have the PushEvent in the common_postinit, it does refresh properly- but only that once when first spawning in. I've tried all sorts of ways to use the common_postinit to send the event, but they either still don't work or cause the game to run out of memory and crash.

This is my function:

local function puddlefun(inst)
	local a,b,c = inst.Transform:GetWorldPosition()
	local fnts = TheSim:FindEntities(a,b,c, 3, {"frozen"})
	for k,v in pairs(fnts) do
		if v.entity:IsValid() and v.name == "Melted Mini Glacier" then

 Like I said, it works fine when first loading with the same PushEvent in common_postinit and on non-dedicated servers in general, but it seems I'm stuck here.

So, how can I tell the server I'm trying to push an event?

Thank you

Link to comment
Share on other sites

For server client communication you use "RPC" and netvars.
RPC is from Server to client.
netvars are from client to server.

I would advise to search the game code or code from other mods to see how exactly it works. Also searching the forum for "RPC" or "AddModRPCHandler" should help.

But are you really sure that is your best option?
Why not just making the puddle a craftstation and only allow your character to use it? This should be much simpler, although I don't have code for this at the moment.

Edited by Serpens
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

  • Create New...