Jump to content

"leftclickoverride" not working on client-side


Recommended Posts

Hey! I'm having some trouble with my "leftclickoverride", "rightclickoverride", and "actionbuttonoverride" functions. I'm trying to disallow all actions save for attacking, moving around, and generally anything to do with your inventory (like eating). My code actually works perfectly fine when I'm the host of the world, but as soon as I run a server with caves turned on (which makes it so that I'm just a client), I'm able to see the prompt for picking flowers, jumping in wormholes, examining things, etc when I mouse over something. The code activates after you've equipped a custom piece of armor that I made in the body equip slot and then right click to use it. Hopefully someone can spot some sort of error in my code.
 

local function ActionOverride(owner, enable)
	if enable then
		print("AO enabled")
		--Disable Examination
		owner.CanExamine = function(owner)
			print("examine override")
			return false
		end
		--Disable Button Actions and Map
		if owner.components.playercontroller ~= nil then
			owner.components.playercontroller.actionbuttonoverride = function()
				print("ab override")
			end
			owner.components.playercontroller:SetCanUseMap(false)
		end
		--Disable Click Actions
		if owner.components.playeractionpicker ~= nil then
			owner.components.playeractionpicker.leftclickoverride = function(owner, target)
				print("lc override")
				if target ~= nil and target ~= owner then
					if owner.replica.combat:CanTarget(target) then
						return (not target:HasTag("player") or owner.components.playercontroller:IsControlPressed(CONTROL_FORCE_ATTACK))
							and owner.components.playeractionpicker:SortActionList({ ACTIONS.ATTACK }, target, nil)
							or nil
					end
				end
			end
			owner.components.playeractionpicker.rightclickoverride = function()
				print("rc override")
			end
		end
	else
		print("AO disabled")
		--Enable Examination
		owner.CanExamine = nil
		--Enable Buton Actions and Map
		if owner.components.playercontroller ~= nil then
			owner.components.playercontroller.actionbuttonoverride = nil
			owner.components.playercontroller:SetCanUseMap(true)
		end
		--Enable Click Actions
		if owner.components.playeractionpicker ~= nil then
			owner.components.playeractionpicker.leftclickoverride = nil
			owner.components.playeractionpicker.rightclickoverride = nil
		end
	end
end


Additionally, the "owner.CanExamine" function doesn't seem to do anything at all. I don't need it for my code to work properly with caves turned off, and obviously it hasn't fixed my problem. However, I saw a comment about "CanExamine" needing to be done client-side in the player_common.lua file, so I have a suspicion that maybe I'm doing something wrong with that, but it's just a hunch.

As another quick note (in case it helps), when I'm the host, the log ends up filled to the brim with "lc override", and "rc override", so it's printing those messages out almost constantly. It seems like "ab override" will print out for as long as I'm holding down the space bar for. However, when I run caves, it seems to only print those messages out once per click or button press. So for instance, it will only print "lc override" once for every time that I click on something.

I've been using Woodie's werebeaver form as a general example of how to override actions, but I can't figure out what I'm doing differently for the life of me. I've been pulling my hair out over this for a couple days now, so I'd really appreciate an assist on this. Thanks so much for reading through all of this, and please let me know if you need to see more of the code to try to help with this.

Link to comment
Share on other sites

Hi, I'm Dark Matter's mod partner. We really need some insight on this; we have been working on this mod together for over a year and we were scheduled to release a beta a week ago, until this came up. We are SO close to getting this mod up and running for everyone to enjoy. He's about to pull his hair out over this. Please help (;-;).

Link to comment
Share on other sites

Hey! Bit of an update here. After a couple long nights of looking into this issue extensively, I've concluded that I need to run some sort of code that will allow my ActionOverride function to be run properly client-side. (Huge shock, right?)

So in the prefab file for Woodie, there's this line of code:

inst.isbeavermode = net_bool(inst.GUID, "woodie.isbeavermode", "isbeavermodedirty")

I haven't really worked with netvars and whatnot yet, so the way it all works is a little bit beyond me. I've looked at multiple forum posts that talk about net variables and data types, but I just can't quite wrap my mind around it. If somebody could walk me through the process of overriding actions on client-side, I'd really appreciate it.

Thanks so much for your time.

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