. . . Posted July 10, 2017 Share Posted July 10, 2017 (edited) Hello, if someone can help me with this that'd be great ! So, I wanna try to make some swimming thing for my character, but for that I need to be able to check if my character's standing on the ocean. Does anyone know a code then I can check if my character's standing on the ocean ? If you know that code, maybe you'd also know a way I can check how far my character's from land? Since I want my character to die if they go too far from land then he can't get to the black screen of nothingness! Solved 1st problem thanks to IronHunter ! So, does anyone know a code that my character doesn't get slowed down by honey trails, & terrain? I saw "PushTempGroundSpeedMultiplier" in honey_trail.lua, but I have no idea how to use it or would it be as simple as setting it to 0? I have no idea! Any help would be appreciated! Thanks for your time & have a good day/night ! Edited July 12, 2017 by SuperDavid Link to comment Share on other sites More sharing options...
IronHunter Posted July 12, 2017 Share Posted July 12, 2017 I remember the :IsOnValidGround() function checks if there is any ground beneath you, not valid ground is the ocean and the black void of the caves. Take note that by default items are deleted when they fall on said invalid ground, as for calculating distance I would check out how the rescue command is used its in the entityscript.lua Spoiler Excerpt from the file --Excerpt from entityscript.lua function EntityScript:IsOnValidGround() local tile = self:GetCurrentTileType() return tile ~= nil and tile ~= GROUND.IMPASSABLE end function EntityScript:PutBackOnGround() if not self:IsOnValidGround() then local dest = FindNearbyLand(self:GetPosition(), 8) if dest ~= nil then if self.Physics ~= nil then self.Physics:Teleport(dest:Get()) elseif self.Transform ~= nil then self.Transform:SetPosition(dest:Get()) end end end end Apparently FindNearbyLand in simutil.lua could be of use? Spoiler Excerpt from simutil.lua function FindNearbyLand(position, range) local finaloffset = FindValidPositionByFan(math.random() * 2 * PI, range or 8, 8, function(offset) local x, z = position.x + offset.x, position.z + offset.z return TheWorld.Map:IsAboveGroundAtPoint(x, 0, z) and not TheWorld.Map:IsPointNearHole(Vector3(x, 0, z)) end) if finaloffset ~= nil then finaloffset.x = finaloffset.x + position.x finaloffset.z = finaloffset.z + position.z return finaloffset end end Using the function EntityScript:GetDistanceSqToPoint(x, y, z) to figure out your distance from x,y,z that is returned from FindNearbyLand() Spoiler Also Excerpt from entityscript.lua function EntityScript:GetDistanceSqToPoint(x, y, z) if y == nil and z == nil and x ~= nil then x, y, z = x:Get() end local x1, y1, z1 = self.Transform:GetWorldPosition() return distsq(x, z, x1, z1) end Have a look at these files, and you can probably work something out, but this should get you started on the concept. Link to comment Share on other sites More sharing options...
. . . Posted July 12, 2017 Author Share Posted July 12, 2017 Thanks IronHunter, now I can work on my swim thingy ! And have one less thing I need help with ! Link to comment Share on other sites More sharing options...
Gubbey Posted July 12, 2017 Share Posted July 12, 2017 In honey_trail.lua, near the top is the function OnUpdate: Spoiler local function OnUpdate(inst, x, y, z, rad) for i, v in ipairs(TheSim:FindEntities(x, y, z, rad, { "locomotor" }, { "flying", "playerghost", "INLIMBO" })) do if v.components.locomotor ~= nil then v.components.locomotor:PushTempGroundSpeedMultiplier(TUNING.BEEQUEEN_HONEYTRAIL_SPEED_PENALTY, GROUND.MUD) end end end "for i, v in ipairs(TheSim:FindEntities(x, y, z, rad, { "locomotor" }, { "flying", "playerghost", "INLIMBO" })) do" is a loop that only executes if it "finds entities" WITH the tag specified on the left (locomotor) and WITHOUT the tags specified on the right (flying, playerghost, INLIMBO). This means in the prefab file for your character, you can use inst:AddTag to create a new tag for them. Let's call it "honeywalker." Then, copy honey_trail.lua into your own mod prefab folder, and alter the above code like so: Spoiler local function OnUpdate(inst, x, y, z, rad) for i, v in ipairs(TheSim:FindEntities(x, y, z, rad, { "locomotor" }, { "flying", "playerghost", "INLIMBO", "honeywalker" })) do if v.components.locomotor ~= nil then v.components.locomotor:PushTempGroundSpeedMultiplier(TUNING.BEEQUEEN_HONEYTRAIL_SPEED_PENALTY, GROUND.MUD) end end end Simply add "honeywalker" on the right. This lets the OnUpdate function know not to apply the speed multiplier to your prefab, since they have the honeywalker tag. Link to comment Share on other sites More sharing options...
Gubbey Posted July 12, 2017 Share Posted July 12, 2017 Actually, a way simpler way to do it (while also preventing slowing from spider creep) would be to add the following line of code under your character prefab's master_postinit function: inst.components.locomotor:SetSlowMultiplier( 1 ) This sets the speed of the prefab when it is slowed by any source. Setting it to "1" is basically saying that if your character is slowed, they'll move at 1x their original speed. Link to comment Share on other sites More sharing options...
ZupaleX Posted July 13, 2017 Share Posted July 13, 2017 On 7/12/2017 at 1:13 AM, Gubbey said: In honey_trail.lua, near the top is the function OnUpdate: Reveal hidden contents local function OnUpdate(inst, x, y, z, rad) for i, v in ipairs(TheSim:FindEntities(x, y, z, rad, { "locomotor" }, { "flying", "playerghost", "INLIMBO" })) do if v.components.locomotor ~= nil then v.components.locomotor:PushTempGroundSpeedMultiplier(TUNING.BEEQUEEN_HONEYTRAIL_SPEED_PENALTY, GROUND.MUD) end end end "for i, v in ipairs(TheSim:FindEntities(x, y, z, rad, { "locomotor" }, { "flying", "playerghost", "INLIMBO" })) do" is a loop that only executes if it "finds entities" WITH the tag specified on the left (locomotor) and WITHOUT the tags specified on the right (flying, playerghost, INLIMBO). This means in the prefab file for your character, you can use inst:AddTag to create a new tag for them. Let's call it "honeywalker." Then, copy honey_trail.lua into your own mod prefab folder, and alter the above code like so: Hide contents local function OnUpdate(inst, x, y, z, rad) for i, v in ipairs(TheSim:FindEntities(x, y, z, rad, { "locomotor" }, { "flying", "playerghost", "INLIMBO", "honeywalker" })) do if v.components.locomotor ~= nil then v.components.locomotor:PushTempGroundSpeedMultiplier(TUNING.BEEQUEEN_HONEYTRAIL_SPEED_PENALTY, GROUND.MUD) end end end Simply add "honeywalker" on the right. This lets the OnUpdate function know not to apply the speed multiplier to your prefab, since they have the honeywalker tag. I would advice against this kind of practice as it could create incompatibility with other mods working on the same prefab. 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