RaymondFoxford Posted September 1, 2016 Share Posted September 1, 2016 Hey guys, is there any way to give a custom character the ability of "hunting" a rabbit without having to use the normal trap? for example if you press action key, the character will chase and pick up the rabbit like it does with flint, flowers, or any other item on the ground (in this case, a "quick pick"). The character is already fast enough to outrun the rabbit speed, but I still can't figure it out how to make it able to pick up the rabbit I tried with the pickable component from this other post, but I failed to make it work. Link to comment Share on other sites More sharing options...
Serpens Posted September 1, 2016 Share Posted September 1, 2016 (edited) I would try to set the following to true (inst is the rabbit): inst.components.inventoryitem.canbepickedup But I'm not sure if this will do the trick.. Edited September 1, 2016 by Serpens Link to comment Share on other sites More sharing options...
DarkXero Posted September 1, 2016 Share Posted September 1, 2016 modmain.lua: AddPrefabPostInit("rabbit", function(inst) if GLOBAL.TheWorld.ismastersim then inst:AddComponent("rabbitcatchable") end end) AddComponentAction("SCENE", "rabbitcatchable", function(inst, doer, actions, right) if right and doer:HasTag("rabbithunter") then table.insert(actions, GLOBAL.ACTIONS.PICKUP) end end) local _fn1 = GLOBAL.ACTIONS.PICKUP.fn GLOBAL.ACTIONS.PICKUP.fn = function(act) if act.doer and act.doer:HasTag("rabbithunter") and act.target and act.target.components.rabbitcatchable then local _canbepickedup = act.target.components.inventoryitem.canbepickedup act.target.components.inventoryitem.canbepickedup = true local ret = _fn1(act) act.target.components.inventoryitem.canbepickedup = _canbepickedup return ret end return _fn1(act) end scripts/components/rabbitcatchable.lua local RabbitCatchable = Class(function(self, inst) self.inst = inst end) return RabbitCatchable scripts/prefabs/character.lua local function common_postinit(inst) inst:AddTag("rabbithunter") end Link to comment Share on other sites More sharing options...
RaymondFoxford Posted September 2, 2016 Author Share Posted September 2, 2016 On 01/09/2016 at 1:10 AM, DarkXero said: modmain.lua: AddPrefabPostInit("rabbit", function(inst) if GLOBAL.TheWorld.ismastersim then inst:AddComponent("rabbitcatchable") end end) AddComponentAction("SCENE", "rabbitcatchable", function(inst, doer, actions, right) if right and doer:HasTag("rabbithunter") then table.insert(actions, GLOBAL.ACTIONS.PICKUP) end end) local _fn1 = GLOBAL.ACTIONS.PICKUP.fn GLOBAL.ACTIONS.PICKUP.fn = function(act) if act.doer and act.doer:HasTag("rabbithunter") and act.target and act.target.components.rabbitcatchable then local _canbepickedup = act.target.components.inventoryitem.canbepickedup act.target.components.inventoryitem.canbepickedup = true local ret = _fn1(act) act.target.components.inventoryitem.canbepickedup = _canbepickedup return ret end return _fn1(act) end scripts/components/rabbitcatchable.lua local RabbitCatchable = Class(function(self, inst) self.inst = inst end) return RabbitCatchable scripts/prefabs/character.lua local function common_postinit(inst) inst:AddTag("rabbithunter") end Works way better than what I expected, thank you! 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