Jump to content

Enable Swimming (It IS Possible, but how?)


Recommended Posts

I assumed players were hardwired to drown, but wow, apparently not.  This mod makes the player able to swim, and tried figuring out how, but I can't seem to figure out the embark code, aka jumping into the water.  https://steamcommunity.com/sharedfiles/filedetails/?id=2294644441

This is basically what I have now, but I feel like I'm missing something vital.
 

	--Can swim, like hounds.  --Test code.
	inst:AddComponent("waterproofer")
--	inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_ABSOLUTE)

	if inst.components.drownable then
		inst.components.drownable.enabled = false
	end

	inst:AddComponent("amphibiouscreature")
	inst.components.amphibiouscreature:SetBanks("lilina_shark", "lilina_shark_water")  --Unsure what these variables are refering to.
	inst.components.amphibiouscreature:SetEnterWaterFn(
		function()
			inst.DynamicShadow:Enable(false)
		end)
	inst.components.amphibiouscreature:SetExitWaterFn(
		function()
			inst.DynamicShadow:Enable(true)
		end)

Thoughts?

  • Like 1
Link to comment
Share on other sites

The SetBanks are the banks that the entity should use when on land and on ocean.

 

The Set<>WaterFns should be using a static function declared elsewhere, the first argument to it is the entity that Entered/Exited the water.  Otherwise for every new instance of the prefab (the character) it will create a new function in memory when there is no changes to it at all.

 

The hopping is done through some series of hotglues but it ultimately is triggered through a client-side RPC during a stategraph update that's only active when the player has a tag- the tag is added and removed on item equip and unequip.  I suspect there's an easier way to manage this without having to resort to an RPC call.

Look to the hound prefab for how Klei set some things up, but I'd still suggest making the Set<>WaterFns to static functions and not how Klei has it in their code.

Link to comment
Share on other sites

@CarlZalph
I've tried to do what you suggested, and poked around in the hound code for what allows them to swim.  I think I found what I need, but this 'bank' stuff is something I'm not familiar with and it caused my game to crash because it wasn't defined.

	inst:AddComponent("embarker")
	inst.components.embarker.embark_speed = 6  --inst.components.locomotor.runspeed
	inst.components.embarker.antic = true

	inst.components.locomotor:SetAllowPlatformHopping(true)

	inst:AddComponent("amphibiouscreature")
	inst.components.amphibiouscreature:SetBanks(bank, bank.."_water")  --Note:  This line crashes the mod.
	inst.components.amphibiouscreature:SetEnterWaterFn(
		function(inst)
			inst.landspeed = 6  --inst.components.locomotor.runspeed
			inst.components.locomotor.runspeed = 6  --TUNING.HOUND_SWIM_SPEED
			inst.hop_distance = inst.components.locomotor.hop_distance
			inst.components.locomotor.hop_distance = 4
		end)            
	inst.components.amphibiouscreature:SetExitWaterFn(
		function(inst)
			if inst.landspeed then
				inst.components.locomotor.runspeed = 6  --inst.landspeed 
			end
			if inst.hop_distance then
				inst.components.locomotor.hop_distance = inst.hop_distance
			end
		end)

		inst.components.locomotor.pathcaps = { allowocean = true }
[00:00:58]: [string "../mods/workshop-2238207705/scripts/prefabs..."]:348: variable 'bank' is not declared
LUA ERROR stack traceback:

@Well-met
I'll do my best to share what I discover, so you and others can do this yourselves.  There is an issue though..  Hounds can, technically follow you way out into the ocean, so characters that can swim basically have free rein of the entire ocean!  The 'Lilina' mod got around this by making an item grant the swimming ability to the character, and it would slowly use 'fuel' while being used, but the item used so little fuel it honestly didn't matter..

Edit:  I got on a boat and sunk it, so see if I'd swim, but got a similar error to before.  It seems like it Needs this 'bank' value but idk what I'm supposed to tell it.  I'm going to review the code again after Thanksgiving Dinner, but idk what it wants.

[00:03:28]: [string "scripts/components/amphibiouscreature.lua"]:56: calling 'SetBank' on bad self (string expected, got nil)

 

Edited by FurryEskimo
Link to comment
Share on other sites

The mod maker told me the embark code is handled in the modmain file, so that's a start.  I think I found part of it, but I can't see the big picture yet.  I'll attach a copy of the modmain file.

AddStategraphState("wilson",
    State{
        name = "lilina_shark_hop_pst",
        tags = { "busy", "jumping" },

        onenter = function(inst, data)
            inst.sg.statemem.collisionmask = data.collisionmask and data.collisionmask or nil
            if data.land_in_water then
                inst.components.amphibiouscreature:OnEnterOcean()
            else
                inst.components.amphibiouscreature:OnExitOcean()
            end
            inst.AnimState:PlayAnimation("jump_pst", false)
        end,

        timeline =
        {
            TimeEvent(4 * FRAMES, function(inst)
                if inst:HasTag("swimming") then
                    SpawnPrefab("splash_green").Transform:SetPosition(inst.Transform:GetWorldPosition())
                end
            end),
        },

        events =
        {
            EventHandler("animover", function(inst)
                if inst.AnimState:AnimDone() then
                    inst.sg:GoToState("hop_pst_complete")
                end
            end),
        },

        onexit = function(inst)
            inst.components.locomotor:SetExternalSpeedMultiplier(inst, "lilina_speed", inst:HasTag("swimming") and 1.5 or 0.7)
        end
    }
)

 

modmain.lua

Link to comment
Share on other sites

On 11/26/2020 at 1:02 PM, FurryEskimo said:

this 'bank' stuff is something I'm not familiar with and it caused my game to crash because it wasn't defined.

Banks are telling the game which sets of animations to use when the character is in that state, rather than using the normal animations the entity would have. They're used alongside builds, which are the images that the bank pulls from to give the animation visible features to move around. You may need your default build to include images that the swimming bank will use if there's nothing telling it to swap builds as well.

In another wording, banks are the animations, builds are the images the animations are made up of. Hopefully this helps.

Edited by Eusong
  • Like 1
Link to comment
Share on other sites

Update:  With the help of pxl_42 (Steam) I've managed to code a character that can swim.  The code is a little confusing, and the animation's a little wonky, but the character Can jump into the water and swim around.  This took around 3-5 weeks, and my code will be available once this is ready for the workshop.

Currently my character can swim whenever and wherever they want to, and I was planning to limit their swimming to shallow water, but idk how to do that..  I'll probably have to make an item that grants the ability of jumping in and out of the water, unless someone knows how to limit a player's movement in relationship to the shore?

  • Like 4
  • Thanks 1
  • Potato Cup 1
Link to comment
Share on other sites

On 6/15/2022 at 10:10 PM, FurryEskimo said:

@luciota777
Well I finished the character, haha.  Took me almost two years, but her name is Wirra.  You can find her on the Steam Workshop.  With the help of Soooooo many people, we made it a reality.  ^-^

I tried to use Wirra but it crashed any time the mod was installed.  Only other character mod I was using at the time was Widgette, but I did have a bunch of other mods.

Link to comment
Share on other sites

On 7/14/2022 at 9:19 PM, Greystar said:

I tried to use Wirra but it crashed any time the mod was installed.  Only other character mod I was using at the time was Widgette, but I did have a bunch of other mods.

If you’re encountering any problems, please tell me about them on the workshop’s discussion thread for bugs.  If you can provide information from the log file that will also be super helpful!  That will tell me why your game crashed.  Do you know how to find the log file?

Link to comment
Share on other sites

On 7/16/2022 at 10:17 AM, FurryEskimo said:

If you’re encountering any problems, please tell me about them on the workshop’s discussion thread for bugs.  If you can provide information from the log file that will also be super helpful!  That will tell me why your game crashed.  Do you know how to find the log file?

When I start next time I'll resubscribe to the mod and see if I can get you an error log.

  • Like 1
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...