Jump to content

Need help for script not eat "petals"


Recommended Posts

help me, I want to script to my character eating foodtype VEGGIE. But I don't want to eat "petals", please! tell me how to do?

EX.
if food and food.components.edible and food.components.edible.foodtype=="VEGGIE" then

Link to comment
Share on other sites

and not food.prefab == "petals"

This should work.

 

 

thank you , but is not all work.

EX

if food and food.components.edible and food.components.edible.foodtype=="VEGGIE" and not food.prefab == "petals" then

        --give an upgrade!

        inst.level = inst.level + 1

eat petals is not level up.

but i eat "carrot"  is not level up too.

i need eat all veggie type level up except petals.

help please.

Link to comment
Share on other sites

@Haru
 
Check your listener. remember that you receive data (an array) instead the inst. To access the actual food you use data.food.
 
This is working for me:

AddPlayerPostInit( function (inst)    inst:ListenForEvent("oneat", function (inst, data)        print("I'm eating!")        print("Eating something?", data.food ~= nil)        print("I'm eating a: ", data.food and data.food.name)        print("Edible?", data.food and data.food.components.edible ~= nil)        print("Eating veggie?", data.food and data.food.components.edible and data.food.components.edible.foodtype == "VEGGIE" or false)        print("Not petals?", data.food and data.food.prefab ~= "petals" or false)                if data.food and data.food.components.edible and data.food.components.edible.foodtype == "VEGGIE" and data.food.prefab ~= "petals" then            print("Level up!")        end    end)end)

It prints "Level up!" when I eat a carrot, and doesn't prints it when I eat some petals.

 

Edit: My bad x.x didn't realize you were changing the oneatfn.

Still, it's mostly the same.

inst.components.eater.oneatfn =  function (inst, food)        print("I'm eating!")        print("Eating something?", food ~= nil)        print("I'm eating a: ", food and food.name)        print("Edible?", food and food.components.edible ~= nil)        print("Eating veggie?", food and food.components.edible and food.components.edible.foodtype == "VEGGIE" or false)        print("Not petals?", food and food.prefab ~= "petals" or false)                if food and food.components.edible and food.components.edible.foodtype == "VEGGIE" and food.prefab ~= "petals" then            print("Level up!")        end    end
Edited by Ryuushu
Link to comment
Share on other sites

i know this is your thread i dont know how to contact ppl on this forum i wanted to ask if you can possably help me with making a character mod. i really like your work and it kinda made me wanna make one. if you can help it would be well appreciated 

Link to comment
Share on other sites

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
 Share

×
  • Create New...