Makaoshi Posted September 7, 2021 Share Posted September 7, 2021 (edited) I'm working on a character who is a friend to goats and I want him to be able to change them. vegetables per poop. meats for poop. but I want him to give me milk only when I give him a special object. The problem is that the special object that I have to give you is classified as vegetable. So when I give him vegetables he also gives me milk and I don't want that to happen. I would need help to make sure that only when I gave him a particular object would he give me milk. I am new to mods and I would like help to know what to do or a code (with an explanation if possible) this is where I left off. local function OnEat (inst, food) if food.components.edible then if food.components.edible.foodtype == FOODTYPE.VEGGIE and not food: HasTag ("friendbulb") then SpawnPrefab ("goatmilk"). Transform: SetPosition (inst.Transform: GetWorldPosition ()) end if food.components.edible.foodtype == FOODTYPE.VEGGIE then SpawnPrefab ("poop"). Transform: SetPosition (inst.Transform: GetWorldPosition ()) end if food.components.edible.foodtype == FOODTYPE.MEAT then SpawnPrefab ("poop"). Transform: SetPosition (inst.Transform: GetWorldPosition ()) end end end I welcome your help. Makaoshi. If it is not well understood it is because (excuse me first) I do not speak any English and I use a translator. Edited September 7, 2021 by Makaoshi Link to comment https://forums.kleientertainment.com/forums/topic/133357-help-i-want-that-when-i-give-you-something-specific-to-lightning-goat-you-give-me-something-in-return-my-custom-character/ Share on other sites More sharing options...
Monti18 Posted September 7, 2021 Share Posted September 7, 2021 if food.components.edible.foodtype == FOODTYPE.VEGGIE and not food: HasTag ("friendbulb") then In this line, you wrote "not food:HasTag("friendbulb")", but it should be only "food:HasTag("friendbulb")", as otherwise you are checking if it doesn't have the tag and I don't think any vegetable has that tag So change the line to if food.components.edible.foodtype == FOODTYPE.VEGGIE and food: HasTag ("friendbulb") then 1 Link to comment https://forums.kleientertainment.com/forums/topic/133357-help-i-want-that-when-i-give-you-something-specific-to-lightning-goat-you-give-me-something-in-return-my-custom-character/#findComment-1491838 Share on other sites More sharing options...
Makaoshi Posted September 11, 2021 Author Share Posted September 11, 2021 (edited) aquí está el código de las cabras todo esto está probado y todo gracias a (Monti18) que me ayudó a hacerlo. todo esto va en el modmain de su carácter. local FOODGROUP = GLOBAL.FOODGROUP local FOODTYPE = GLOBAL.FOODTYPE local function OnEat (inst, food) if food.components.edible then if food.components.edible.foodtype == FOODTYPE.VEGGIE and food: HasTag ("friendbulb") then GLOBAL.SpawnPrefab ("goatmilk"). Transform: SetPosition (inst.Transform: GetWorldPosition ()) elseif food.components.edible.foodtype == FOODTYPE.VEGGIE then GLOBAL.SpawnPrefab ("poop"). Transform: SetPosition (inst.Transform: GetWorldPosition ()) elseif food.components.edible.foodtype == FOODTYPE.MEAT then GLOBAL.SpawnPrefab ("poop"). Transform: SetPosition (inst.Transform: GetWorldPosition ()) end end end local function ShouldAcceptItem (inst, item) local last_eat_time = inst.components.eater: TimeSinceLastEating () return (last_eat_time == nil or last_eat_time >= 280) end local function OnGetItemFromPlayer (inst, giver, item) if inst.components.eater:CanEat(item) then inst.components.eater:Eat(item) end end local function OnRefuseItem(inst, item) if inst.components.sleeper:IsAsleep() then inst.components.sleeper:WakeUp() end end AddPrefabPostInit ("lightninggoat", function (inst) inst: AddTag ("trader") if not GLOBAL.TheWorld.ismastersim then return inst end inst: AddComponent ("trader") if inst.components and inst.components.trader then inst.components.trader: SetAcceptTest (ShouldAcceptItem) inst.components.trader.onaccept = OnGetItemFromPlayer inst.components.trader.onrefuse = OnRefuseItem inst.components.trader.deleteitemonaccept = true end inst: AddComponent ("timer") inst: AddComponent ("saltlicker") inst.components.saltlicker:SetUp (TUNING.SALTLICK_LIGHTNINGGOAT_USES) ------------------------------------------ inst: AddComponent ("eater") inst.components.eater:SetDiet ({FOODGROUP.OMNI}, {FOODGROUP.OMNI}) inst.components.eater:SetOnEatFn (OnEat) end) Edited September 11, 2021 by Makaoshi 1 Link to comment https://forums.kleientertainment.com/forums/topic/133357-help-i-want-that-when-i-give-you-something-specific-to-lightning-goat-you-give-me-something-in-return-my-custom-character/#findComment-1493783 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