Jump to content

Recommended Posts

In my mod, I'm attempting to create a custom action that Woodie can use to climb trees and increase his field of vision (zoom out the camera). Editing the camera can only be done client-side (as far as I'm aware) so I had to learn how to use networked variables. For the most part it works; Woodie can right-click on a tree to climb it, the server changes a networked variable which causes the client to zoom out the camera. The problem is, however, that it doesn't just zoom out Woodie's camera, it affects the camera of all players. Relevant code:

AddPrefabPostInit("woodie", function(inst)
    
	inst.change_view = false
	
	inst.net_change_view = GLOBAL.net_bool(inst.GUID, "change_view", "change_viewdirty" )
	
	local function OnChangeViewDirty(inst)    
		inst.change_view = inst.net_change_view:value()
		ChangeVertView(inst.change_view)
	end
	
	if not GLOBAL.TheWorld.ismastersim then
		inst:ListenForEvent("change_viewdirty", OnChangeViewDirty)
		return
	end
end
inst.change_view = true
inst.net_change_view:set(true)

The second bit of code is in the function called when the action is performed for the server to update the networked variable. It isn't in a custom component or anything, just a function in the modmain, if that matters.

As you can see, I'm only adding the network variable to Woodie's prefab, and when the action is performed it only passes the specific Woodie prefab to the function that updates said variable, so why is it being updated for every other client as well (where it shouldn't even exist)? Clearly there something about net_vars that I'm not getting.

I'm not 100% sure, but I think:
netvars are created for every client. So every client saves the netvar in the woodie object. That's why it is called for everyone.

So I think the simplest solution is the camera code. There you should check who is "ThePlayer" and if it is the player playing woodie and climbed a tree. And do you use "TheCamera" ? I think there is also a player specific camera object. Search all lua file with help of notepas++ for "camera" and see what options you have.

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