Jump to content

(HELP) I want that when I give you something specific to lightning goat you give me something in return. my custom character.


Recommended Posts

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 by Makaoshi
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 :D

So change the line to 

if food.components.edible.foodtype == FOODTYPE.VEGGIE and food: HasTag ("friendbulb") then

 

  • Like 1

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 by Makaoshi
  • Like 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...