Skip to content

Commit

Permalink
Add hide support
Browse files Browse the repository at this point in the history
The player now automatically hides if he/she has a "Bush Hat" or
"Snurtle Shell Armor" equipped while following someone.
  • Loading branch information
ViktorYu234 authored and victorpopkov committed Nov 11, 2021
1 parent 63729a7 commit 460a9ef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ files["**/*.lua"] = {
"RPC",
"SendRPCToServer",
"Sleep",
"ThePlayer",
"Vector3",
},
}
23 changes: 23 additions & 0 deletions scripts/components/keepfollowing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ end)
--- Helpers
-- @section helpers

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

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

local function WalkToPoint(self, pt)
if not SDK.Player.WalkToPoint(pt, self.inst) then
SDK.RPC.WalkToPoint(pt)
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 460a9ef

Please sign in to comment.