Oregon Posted August 18, 2020 Share Posted August 18, 2020 Greetings! I have recently started creating a custom character but i have no experience with modding at all so i was hoping i could get some help over here. I started the creation using tutorials, however, none of the tutorials i found so far have been getting into detail on how to code new features and stuff. I put the plans i have for my char below and hope i could get some help on how to implement those features here. Spoiler HP: 200 Hunger: 200 Sanity: 100 Planned features: (Currently only visuals available) *Regains sanity from foraging (picking berries, carrots, twigs, mushrooms etc. like Flowers) *can pick evil flowers without penalty *More resistant to cold, less resistant to heat *Pigs, Merman, Cave rabbits etc are not hostile towards him *gets bonus sanity from eating uncooked food *loses sanity in caves and on boats *loses sanity from killing non-hostile mobs *cannot eat any kind of monster meat *starts with backpack and Stormfang *can craft sturdier traps (Rabbit traps, bird cages etc) Item: Stormfang *Can be charged with moonstones (Charge is shown by percentage) *Cannot break *Base-damage: 30 Chargeddamage: 61 Link to comment Share on other sites More sharing options...
DecDuck Posted August 18, 2020 Share Posted August 18, 2020 So I have a few questions: 1. "*loses sanity in caves..." Do you want to lose more sanity in the caves, because it already has a constant sanity drain. 2. "*cannot eat any kind of monster meat" Do you want it so it doesn't show the eat option? Or do you want it to have very bad effect (e.g. dying) 3. For Stormfang, do you want the damage based on the charge, or do you want it to always do 61 damage if it's charged? 1 Link to comment Share on other sites More sharing options...
Oregon Posted August 20, 2020 Author Share Posted August 20, 2020 On 8/18/2020 at 11:51 PM, decduck3 said: So I have a few questions: 1. "*loses sanity in caves..." Do you want to lose more sanity in the caves, because it already has a constant sanity drain. 2. "*cannot eat any kind of monster meat" Do you want it so it doesn't show the eat option? Or do you want it to have very bad effect (e.g. dying) 3. For Stormfang, do you want the damage based on the charge, or do you want it to always do 61 damage if it's charged? 1. Increased sanity yes. 2. He refuses to eat monster meat just like Wigfried wouldn't eat vegetables. 3. Damage would be 61 as long as there is any charge Link to comment Share on other sites More sharing options...
DecDuck Posted August 20, 2020 Share Posted August 20, 2020 1. You could do a couple things: a. Make your character more scared (like Wolfgang) so they take more sanity loss. b. Check if the character is in the caves, and then apply a small sanity drain. 2. In wathgrithr.lua (wigrid's character), there is: inst.components.eater:SetDiet({ FOODGROUP.OMNI }, { FOODTYPE.MEAT, FOODTYPE.GOODIES }) This prevents her from eating veggies. The problem is that monster foods are meat and monster, so I have no idea how you can exclude monster. 3. Have you go a equip-able item working first? 1 Link to comment Share on other sites More sharing options...
Oregon Posted August 22, 2020 Author Share Posted August 22, 2020 How would make them more scared? I've not done any items yet since i couldn't find any tutorials on how to create custom items Link to comment Share on other sites More sharing options...
DecDuck Posted August 23, 2020 Share Posted August 23, 2020 (edited) This is in Wolfgang's code: inst.components.sanity.night_drain_mult = 1.1 inst.components.sanity.neg_aura_mult = 1.1 This makes him more scared. Most of the time, you don't need a tutorial. What you do is find something that is similar to what you want to do, and then adapt it to what you want to do. Also you can look through the game's code, and see what certain values and functions do. Edited August 23, 2020 by decduck3 2 Link to comment Share on other sites More sharing options...
Oregon Posted August 25, 2020 Author Share Posted August 25, 2020 Thanks for you help so far! I am currently trying to figure out how to add sanity from picking berries, carrots and other vegetables. I tried to use the code that gives sanity when picking flowers and apply it to the other plants, but that's in the flower.lua rather than the character codes, so i'm not sure how to add this to my char. Also i set the backpack as a starting item, but it won't appear since, i assume, backpacks cannot be put into the inventory. Is there a way to make him start with a backpack equipped? Link to comment Share on other sites More sharing options...
DecDuck Posted August 25, 2020 Share Posted August 25, 2020 (edited) I’m not currently at my computer, but if you look through player_common.lua, there should be a onpickup function. Override that, check prefab name, add sanity. You should be able to either set the body slot to a backpack, or spawn one in when the first join the game. Edit: Disregard my first comment. There is no pickup function. What you will have to do is go to every item that you want the sanity for, and add it in the onpickupfn, just like the flower. Edited August 26, 2020 by decduck3 1 Link to comment Share on other sites More sharing options...
Oregon Posted August 26, 2020 Author Share Posted August 26, 2020 But if i change the item scripts, how would that update for others since the items aren't in the mod's folder? Link to comment Share on other sites More sharing options...
DecDuck Posted August 27, 2020 Share Posted August 27, 2020 Umm.. What? local changeOnPickup = function(inst) local function onpickedfn(inst, picker) if picker ~= nil then if picker.components.sanity ~= nil and not picker:HasTag("plantkin") then picker.components.sanity:DoDelta(TUNING.SANITY_TINY) end end end AddPrefabPostInit("examplepickup",changeOnPickup) --do for all items I'm going to assume you are worried about compatibility with other mods: 1 Link to comment Share on other sites More sharing options...
Oregon Posted August 28, 2020 Author Share Posted August 28, 2020 I assume "examplepickup" has to be replaced with the name of the item? I tried putting in "carrot" but that causes the server to crash when i try to start it with the mod enabled Link to comment Share on other sites More sharing options...
DecDuck Posted August 28, 2020 Share Posted August 28, 2020 Couple of things: 1. You need to check if it’s your character 2. Carrot has a onpicked function, not onpickedfn, so you just need to change that Link to comment Share on other sites More sharing options...
Oregon Posted August 29, 2020 Author Share Posted August 29, 2020 So i get to the character selection now, but if i select my char the game gets stuck on a loading screen Link to comment Share on other sites More sharing options...
AkaiNight Posted August 30, 2020 Share Posted August 30, 2020 On 8/29/2020 at 5:39 PM, Oregon said: So i get to the character selection now, but if i select my char the game gets stuck on a loading screen can you send log files im not pro but i can take a look if there is anything i can do Link to comment Share on other sites More sharing options...
Oregon Posted August 30, 2020 Author Share Posted August 30, 2020 (edited) 1 hour ago, AkaiNight said: can you send log files im not pro but i can take a look if there is anything i can do Where can i find those? edit: found it client_log.txt Edited August 30, 2020 by Oregon Link to comment Share on other sites More sharing options...
AkaiNight Posted August 30, 2020 Share Posted August 30, 2020 54 minutes ago, Oregon said: Where can i find those? edit: found it client_log.txt 39.81 kB · 0 downloads can you post 120th line in trash.lua? Link to comment Share on other sites More sharing options...
DecDuck Posted August 30, 2020 Share Posted August 30, 2020 *tash.lua Also the AddPrefabPostInit has to be in modmain.lua. It doesn't work anywhere else. Link to comment Share on other sites More sharing options...
Oregon Posted August 31, 2020 Author Share Posted August 31, 2020 3 hours ago, decduck3 said: *tash.lua Also the AddPrefabPostInit has to be in modmain.lua. It doesn't work anywhere else. ah, that was the problem xD However, i don't gain any sanity from picking carrots for some reason Link to comment Share on other sites More sharing options...
DecDuck Posted August 31, 2020 Share Posted August 31, 2020 Can you post your code here? Link to comment Share on other sites More sharing options...
Oregon Posted September 2, 2020 Author Share Posted September 2, 2020 On 8/31/2020 at 11:05 PM, decduck3 said: Can you post your code here? i attached the modmain and tash.lua below. Also i wasn't sure if only the AddPrefabPostInit line was supposed to go into modmain or the whole local changeOnPickup = function(inst) function part. I tried both and neither seems to work tash.lua modmain.lua Link to comment Share on other sites More sharing options...
DecDuck Posted September 2, 2020 Share Posted September 2, 2020 (edited) Sorry I should of been more specific when I said you have to redefine the onpickup function: local function onpicked(inst, picker) if picker ~= nil then if picker.components.sanity ~= nil and not picker:HasTag("plantkin") then picker.components.sanity:DoDelta(TUNING.SANITY_TINY) end end TheWorld:PushEvent("beginregrowth", inst) inst:Remove() end local changeOnPickup = function(inst) inst.components.pickable.onpickedfn = onpicked end AddPrefabPostInit("carrot",changeOnPickup) (In your modmain.lua) The onpicked function has to be outside of the function. Edited September 2, 2020 by decduck3 Link to comment Share on other sites More sharing options...
Oregon Posted September 4, 2020 Author Share Posted September 4, 2020 I copied the code and now i get this error when picking up a carrot: Link to comment Share on other sites More sharing options...
DecDuck Posted September 4, 2020 Share Posted September 4, 2020 local function onpicked(inst, picker) if picker ~= nil then if picker.components.sanity ~= nil and not picker:HasTag("plantkin") then picker.components.sanity:DoDelta(TUNING.SANITY_TINY) end end TheWorld:PushEvent("beginregrowth", inst) inst:Remove() end local changeOnPickup = function(inst) if inst.components.pickable ~= nil then inst.components.pickable.onpickedfn = onpicked end end AddPrefabPostInit("carrot",changeOnPickup) If that doesn't work, I have no idea how to do it, apart from overriding carrot.lua. Link to comment Share on other sites More sharing options...
Oregon Posted September 5, 2020 Author Share Posted September 5, 2020 12 hours ago, decduck3 said: local function onpicked(inst, picker) if picker ~= nil then if picker.components.sanity ~= nil and not picker:HasTag("plantkin") then picker.components.sanity:DoDelta(TUNING.SANITY_TINY) end end TheWorld:PushEvent("beginregrowth", inst) inst:Remove() end local changeOnPickup = function(inst) if inst.components.pickable ~= nil then inst.components.pickable.onpickedfn = onpicked end end AddPrefabPostInit("carrot",changeOnPickup) If that doesn't work, I have no idea how to do it, apart from overriding carrot.lua. unfortunately, it does not work. It doesn't crash anymore but there is no sanity gain... Link to comment 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