BoxyPop Posted July 6, 2020 Share Posted July 6, 2020 So... I making a character who can eat cutgrass. I have made different attempts but I have not come to anything yet, any help would be very helpful. I am quite a novice using the code. Thank you very much! Thanks 1 Link to comment Share on other sites More sharing options...
rawii22 Posted July 8, 2020 Share Posted July 8, 2020 You might run a prefab post init on cutgrass that adds a special tag to it like "ediblegrass" or something like that. Actually, you can just check for the prefab name itself. The hard part will be editing the eat action. You can alter this action like you would any other function. It seems like one of the checks the EAT action makes is whether the object in question has the edible component. You can add an additional check for the "ediblegrass" tag or prefab name, whichever you prefer. Might look like this: local EATFN = GLOBAL.ACTIONS.EAT.fn --copy the original function to be run later GLOBAL.ACTIONS.EAT.fn = function(act) local obj = act.target or act.invobject if obj ~= nil then if obj:HasTag("ediblegrass") and act.doer:HasTag("grasseater") then --alternative if obj.prefab == "cutgrass" and act.doer:HasTag("grasseater") then EATFN(act) else EATFN(act) --you want to run the function like you normally would if the first two conditions are false end end end HOWEVER this is not all. You'll end up actually having to add the edible component to cutgrass, and you'll have to add a special property to it. The EAT action eventually calls the Eat function located in the eater component. This means that eventually the game will look for properties that cutgrass will not have, such as it's hunger value and other food properties. So do this first: AddPrefabPostInit("cutgrass", addProperties) local function addProperties(prefab) prefab:AddComponent("edible") prefab.components.edible.foodtype = FOODTYPE.GRASS --this is the important part prefab.components.edible.healthvalue = myNumber prefab.components.edible.hungervalue = myNumber prefab.components.edible.sanityvalue = myNumber prefab:AddTag("ediblegrass") --this won't be necessary anymore since we will be checking another way end NOW we can do the check properly. Now that the game should have all that it needs. Btw, you should look at the edible component to see what other properties you might want to change. Here's the ACCURATE CHECK: local EATFN = GLOBAL.ACTIONS.EAT.fn --copy the original function to be run later GLOBAL.ACTIONS.EAT.fn = function(act) local obj = act.target or act.invobject if obj ~= nil then if obj.components.edible ~= nil and obj.components.edible.foodtype == FOODTYPE.GRASS and act.doer:HasTag("grasseater") then --this second check is to make sure the right character is eating the grass EATFN(act) else EATFN(act) --you want to run the function like you normally would if the first conditions are false end end end Notes: These two sections go in modmain of course. Also the grasseater tag belongs to the proper character. Also I'm not sure whether or not there should a GLOBAL before the FOODTYPE references, my belief is no. I hope this helps at least a little; please tell me everything about what goes wrong if something breaks... 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