FurryEskimo Posted January 21, 2021 Share Posted January 21, 2021 Does anyone know how to tell when you're on a boat? I know I could check if the nearest tile is ocean, and my Y value, but I have a character that can swim and I'm hoping there's some easy way to tell if you're standing on land vs a boat. Link to comment Share on other sites More sharing options...
penguin0616 Posted January 21, 2021 Share Posted January 21, 2021 inst:GetCurrentPlatform() iirc 1 Link to comment Share on other sites More sharing options...
FurryEskimo Posted January 21, 2021 Author Share Posted January 21, 2021 @penguin0616 Thanks! I wrote: print("Current Platform: ", inst:GetCurrentPlatform() ) --Test code and was able to test the code. Most of the time it says "nil" but when I got onto a boat it said "118442 - boat". Any idea if it will always say that, or how to test exclusively for "boat"? I'm worried that every boat will have it's own code, which may may this a little tougher. Then again, if I check the water level of the tile under the player, and you're not on "nil", you're almost Certainly going to be on a boat! This could work! Thanks! ^-^ Link to comment Share on other sites More sharing options...
penguin0616 Posted January 21, 2021 Share Posted January 21, 2021 1 minute ago, FurryEskimo said: I'm worried that every boat will have it's own code I don't know what you mean by this. 1 minute ago, FurryEskimo said: Any idea if it will always say that, or how to test exclusively for "boat"? if inst:GetCurrentPlatform() and inst:GetCurrentPlatform().prefab == "boat" then -- ok end Not really recommended to only care about prefabs named "boat" though, since other mods have their own ocean/boating prefabs. 1 Link to comment Share on other sites More sharing options...
FurryEskimo Posted January 21, 2021 Author Share Posted January 21, 2021 @penguin0616 I know other people have likely added their own platforms, so I integrated it like this: if tileinfo.ocean_depth ~= nil and inst:GetCurrentPlatform() == nil then I've already gathered info about the tile under the player, so if there's water and no platform, I'm going to assume the player is swimming and assign a speed penalty. If it conflicts with another mod, I'll look for a way to fix it, but I thinkkkk this will be ok. Link to comment Share on other sites More sharing options...
CarlZalph Posted January 21, 2021 Share Posted January 21, 2021 1 hour ago, FurryEskimo said: @penguin0616 I know other people have likely added their own platforms, so I integrated it like this: if tileinfo.ocean_depth ~= nil and inst:GetCurrentPlatform() == nil then I've already gathered info about the tile under the player, so if there's water and no platform, I'm going to assume the player is swimming and assign a speed penalty. If it conflicts with another mod, I'll look for a way to fix it, but I thinkkkk this will be ok. Aye, this is the better way to do it- a platform of not nil means that the player is on a platform and that it is walkable. The code for GetCurrentPlatform as specified in entityscript.lua: function EntityScript:GetCurrentPlatform() local x, y, z = self.Transform:GetWorldPosition() local platform = TheWorld.Map:GetPlatformAtPoint(x, z) if platform ~= nil and platform.components.walkableplatform:CanBeWalkedOn() then return platform end return nil end Link to comment Share on other sites More sharing options...
FurryEskimo Posted January 21, 2021 Author Share Posted January 21, 2021 @CarlZalph Haha, well aren't you just the regular miracle worker? Currently my code is written in such a way that a check for being in the water and not on a boat is performed first, which your input shows is accurate. If I were to re-arrange it, I'd be checking for being on land or on a walkable platform, but I'm not sure I see the benefit of reversing these conditions. I'm checking a rare condition first which I expect to immediately fail, and the regular speed calculation takes places. Checking to make sure I'm on land or on a boat seems, sort of the same as what I have now, right? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now