Memeyun Posted March 28, 2023 Share Posted March 28, 2023 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) Link to comment https://forums.kleientertainment.com/forums/topic/146788-sanity-gaindrain-if-inst-it-havedont-have-item-help/ Share on other sites More sharing options...
Merkyrrie Posted March 28, 2023 Share Posted March 28, 2023 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. Link to comment https://forums.kleientertainment.com/forums/topic/146788-sanity-gaindrain-if-inst-it-havedont-have-item-help/#findComment-1627427 Share on other sites More sharing options...
Memeyun Posted April 3, 2023 Author Share Posted April 3, 2023 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 Link to comment https://forums.kleientertainment.com/forums/topic/146788-sanity-gaindrain-if-inst-it-havedont-have-item-help/#findComment-1628017 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