FurryEskimo Posted April 19, 2022 Share Posted April 19, 2022 Hello. I'm working on an improvement to some of my own code, but need a way to detect when a player has right clicked on their own follower. I think this code is very similar to what I need, but I don't really understand it.. Could anyone offer some advice so I can make my own version? This code appears to be a 'sit' command (which is cool), but I needed something simpler, a simple way to check if the follower's leader right clicked on them. local SITCOMMAND = GLOBAL.Action(4, true, true, 10, false, false, nil) local SITCOMMAND_CANCEL = GLOBAL.Action(4, true, true, 10, false, false, nil) AddComponentPostInit("talker", function(self) local old_Say = self.Say function self:Say(script, ...) if self.inst.prefab == "saberlion" then if script and type(script) == "string" then script = script:match("^%$%$(.*)$") or "GAO GAO GAO!" end end return old_Say(self, script, ...) end end) AddReplicableComponent("followersitcommand") SITCOMMAND.id = "SITCOMMAND" SITCOMMAND.str = "Order to Stay" SITCOMMAND.fn = function(act) local targ = act.target if targ and targ.components.followersitcommand then act.doer.components.locomotor:Stop() act.doer.components.talker:Say("Sit!") targ.components.followersitcommand:SetStaying(true) targ.components.followersitcommand:RememberSitPos("currentstaylocation", GLOBAL.Point(targ.Transform:GetWorldPosition())) return true end end AddAction(SITCOMMAND) SITCOMMAND_CANCEL.id = "SITCOMMAND_CANCEL" SITCOMMAND_CANCEL.str = "Order to Follow" SITCOMMAND_CANCEL.fn = function(act) local targ = act.target if targ and targ.components.followersitcommand then act.doer.components.locomotor:Stop() act.doer.components.talker:Say("Come!") targ.components.followersitcommand:SetStaying(false) return true end end AddAction(SITCOMMAND_CANCEL) AddComponentAction("SCENE", "followersitcommand", function(inst, doer, actions, rightclick) if rightclick and inst.replica.followersitcommand then if not inst.replica.followersitcommand:IsCurrentlyStaying() then table.insert(actions, GLOBAL.ACTIONS.SITCOMMAND) else table.insert(actions, GLOBAL.ACTIONS.SITCOMMAND_CANCEL) end end end) Link to comment https://forums.kleientertainment.com/forums/topic/139378-detect-right-click-on-prefab/ 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