Skip to content

Commit

Permalink
Add hide support
Browse files Browse the repository at this point in the history
Player now automatically hides if he has a Bush Hat or Snurtle Armor equipped while following
  • Loading branch information
ViktorYu234 committed Oct 25, 2021
1 parent 0f08f63 commit 4a0faee
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions scripts/components/keepfollowing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ local function WalkToPoint(self, pt)
end
end

local function IsHiding(inst)
return inst and (inst.sg and inst.sg:HasStateTag("hiding") or inst.HasTag and inst:HasTag("hiding"))
end

local function HidePlayer(inst)
inst = inst or ThePlayer
local body = SDK.Player.Inventory.GetEquippedBodyItem(inst)
if body and body:HasTag("shell") then
SendRPCToServer(RPC.UseItemFromInvTile,ACTIONS.USEITEM.code,body)
else
local head = SDK.Player.Inventory.GetEquippedHeadItem(inst)
if head and head:HasTag("hide") then
SendRPCToServer(RPC.UseItemFromInvTile,ACTIONS.USEITEM.code,head)
else
return
end
end
end

--- General
-- @section general

Expand Down Expand Up @@ -326,6 +345,8 @@ function KeepFollowing:StartFollowingThread()
then
table.remove(self.leader_positions, 1)
end
elseif SDK.Player.IsIdle(self.inst) and not IsHiding(self.inst) then
HidePlayer(self.inst)
end
elseif self.config.follow_method == "closest" then
-- closest: player goes to the closest target point from a leader
Expand All @@ -335,6 +356,8 @@ function KeepFollowing:StartFollowingThread()
pos_prev = pos
WalkToPoint(self, pos)
end
elseif SDK.Player.IsIdle(self.inst) and not IsHiding(self.inst) then
HidePlayer(self.inst)
end
end

Expand Down

0 comments on commit 4a0faee

Please sign in to comment.