Jump to content

Recommended Posts

I want character to gain or lose it when it has item made out of gold like tools goldnugget walking cane etc. i can't get it i am not good in lua programing i started with losing sanity when not having gold nugget and thats all i have doesn't crash but doesn't wokr either

local function sanityfn(inst, data)
    if inst.components.inventory:NumItems("goldnugget") == 0 then inst.components.sanity.dapperness = -20 else end
 end
 
inst:ListenForEvent("equip", sanityfn)

Well for starters this would only be happening when you equip something, which I don't recommend. Better to use the custom_rate_fn instead, which would be replacing "inst:ListenForEvent" with "inst.components.sanity.custom_rate_fn = sanityfn

custom_rate_fn should return a number value that will be added onto the positive/negative sanity drain automatically.

The NumItems function takes no paramaters, so "goldnugget" is doing nothing here, instead its finding the amount of total items in your inventory. I suggest using either "Has", "HasItemWithTag" or "GetItemsWithTag". "Has" will look for a specific item in your inv, "HasItemWithTag" will look for any item with a tag, and "GetItemsWithTag" will return a list of every item in your inventory with a tag. You can do AddPrefabPostInit in your modmain to add a tag to all the items you want to count for this. With GetItemsWithTag you can check if the list is empty and then return a positive or negative amount of sanity loss/gain depending on the result.

Sorry to reply so late i was working on it and thanks that advice helped abit because it made me go and see how to add prefabs but thats all i did i added prefab "gold" so i got this now
if you have any idea how to help me here
 

local function sanityfn(inst, data) 
inst.components.inventory:HasItemWithTag("gold") == 0 and
inst.components.inventory:GetItemsWithTag("gold") == 0 then
inst.components.sanity.dapperness = -20 else end

inst.components.sanity.custom_rate_fn = sanityfna

that is my problem called being a comeplete buffon and working on something i know very little about

 

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...