Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hide support #8

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
victorpopkov marked this conversation as resolved.
Show resolved Hide resolved
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