Jump to content

Recommended Posts

Phew, got it!  Big thanks to Vyuri who's hard work found a solution!  I made a few small edits, but this worked perfectly!

	local playercontroller = ThePlayer.components.playercontroller
	local v1, v2 = playercontroller:IsEnabled()  --"Gives two values, the 2nd value being False means you're using the crafting search bar."
	if playercontroller and v2 == false then  --Don't allow toggle if player is using crafting menu.
		return
	end

 

  • Thanks 1

So it appears there’s an issue..  When the player is on the character select screen and pressed the key, ThePlayer is called but it crashes the server..  I’ve tried a few ways to fix this but nothing’s worked yet.  Does anyone have a suggestion?

We got it working.  Turns out I made a typo and it wasn't working even though the code was right.

AddModRPCHandler(modname,"ToogleSwimming",ToogleSwimming)

GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.key_to_swim, function()  --Recoded with IronHunter's help.
	if not GLOBAL.ThePlayer or GLOBAL.ThePlayer.prefab ~= "wildchild" or GLOBAL.TheFrontEnd:GetActiveScreen() ~= GLOBAL.ThePlayer.HUD then  --Prevents toggle being used by other players and on character select screen.
		return
	end
	--Now that we can confirm that ThePlayer isn't nil we can attempt to run the player controller code
	local playercontroller = ThePlayer.components.playercontroller
	if playercontroller then
		local v1, v2 = playercontroller:IsEnabled()  --"Gives two values, the 2nd value being False means you're using the crafting search bar."

		if v2 == false then  --Don't allow toggle if player is using crafting search menu.
			return
		end
	end
--[[
	if ThePlayer.HUD ~= nil and ThePlayer.HUD:IsCraftingOpen() then  --Do not toggle ability if crafting menu is open.
		return
	end
--]]

	if GLOBAL.ThePlayer then
		SendModRPCToServer(MOD_RPC[modname]["ToogleSwimming"])
	end
end)

 

Edited by FurryEskimo
  • Ninja 1

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