Sign in to follow this  
FurryEskimo

Enable Swimming (It IS Possible, but how?)

Recommended Posts

FurryEskimo    43

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

Share this post


Link to post
Share on other sites
CarlZalph    4913

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.

Share this post


Link to post
Share on other sites
FurryEskimo    43

@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

Share this post


Link to post
Share on other sites
FurryEskimo    43

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

Share this post


Link to post
Share on other sites
Eusong    156
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

Share this post


Link to post
Share on other sites
FurryEskimo    43

@Pitchblack58
Sure!  I sent you a DM.
The mod is still in progress but it works Much better than it used to!  Stability has been massively improved.
Currently playtesters are helping to provide feedback and ensure the character is fun to play as.  Character art/animations will come next, then a public release.

Share this post


Link to post
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
Sign in to follow this