Adipup Posted October 28, 2020 Share Posted October 28, 2020 (edited) Hi everyone! I'm new to modding this game, so forgive me if I don't understand a lot yet. Would it be possible to make a character passively gain or lose hunger depending on light levels? So, for example, on a sunny day they would gain hunger the fastest, on a cloudy/rainy/snowy day there would be less of a gain, at dusk there would be a slight hunger loss, and at night in complete darkness they would be at risk of starving. I'd also like food to be much less filling as a result, and for light sources to help restore hunger. Thanks in advance for any help! Edited October 28, 2020 by Adipup Link to comment https://forums.kleientertainment.com/forums/topic/122913-looking-for-help-with-coding-a-custom-character/ Share on other sites More sharing options...
Yakuzashi Posted October 28, 2020 Share Posted October 28, 2020 (edited) For Quote passively gain or lose hunger depending on light levels? So, for example, on a sunny day they would gain hunger the fastest, on a cloudy/rainy/snowy day there would be less of a gain, at dusk there would be a slight hunger loss, and at night in complete darkness they would be at risk of starving add this: ((inside master_postinit) (in your [charactername].lua (mod->scripts->prefabs->...)) local function gluttony(inst) --NIGHT if TheWorld.state.isnight then inst.components.hunger.hungerrate = 7.5 * TUNING.WILSON_HUNGER_RATE end --DUSK if TheWorld.state.isdusk then inst.components.hunger.hungerrate = 3 * TUNING.WILSON_HUNGER_RATE end --DAY if TheWorld.state.isday then inst.components.hunger.hungerrate = -2 * TUNING.WILSON_HUNGER_RATE end --SUNNY DAY if TheWorld.state.issummer and TheWorld.state.isday then inst.components.hunger.hungerrate = -3 * TUNING.WILSON_HUNGER_RATE end ---SNOWY DAY if TheWorld.state.issnowing and TheWorld.state.isday then inst.components.hunger.hungerrate = -1.5 * TUNING.WILSON_HUNGER_RATE end --RAINY DAY if TheWorld.state.israining and TheWorld.state.isday then inst.components.hunger.hungerrate = -1.5 * TUNING.WILSON_HUNGER_RATE end end and for: Quote light sources to help restore hunger. this: local function sootinglight(inst) local x,y,z = inst.Transform:GetWorldPosition() local range = 4 -- HUNGER RESTORATION RANGE local tags = { "lighter", "campfire", "lamp" } local lightsources = TheSim:FindEntities(x,y,z, range, nil, nil, tags) for k,v in pairs(lightsources) do inst.components.hunger:DoDelta(1,1) -- +1 HUNGER end end You will also need inst:DoPeriodicTask(15, gluttony, nil, inst) inst:DoPeriodicTask(1.5, sootinglight, nil, inst) -- TIME INTERVALS BETWEEN +1 HUNGER EVENTS under those functions above. Second function works with: campfires, torch, willow's lighter, mushlight, glowcap. I suck at lua and logical thinking , but it should work... at least until someone competent will show up. Cheers! Edited October 28, 2020 by Yakuzashi 2 Link to comment https://forums.kleientertainment.com/forums/topic/122913-looking-for-help-with-coding-a-custom-character/#findComment-1385464 Share on other sites More sharing options...
Adipup Posted October 28, 2020 Author Share Posted October 28, 2020 Thank you so much! I had to tweak the multipliers a bit to get it right where I wanted it, but this works like a charm. Do you perhaps also know how to make it so that all hunger gained from food is (for example) halved, but the character still gains all the health from it? 1 Link to comment https://forums.kleientertainment.com/forums/topic/122913-looking-for-help-with-coding-a-custom-character/#findComment-1385511 Share on other sites More sharing options...
Thomas_klei Posted October 28, 2020 Share Posted October 28, 2020 (edited) if inst.components.eater ~= nil then --inst.components.eater:SetAbsorptionModifiers(Health, Hunger, Sanity) inst.components.eater:SetAbsorptionModifiers(1, 0.5, 1) end your boi wortox got this figured outthey use them in a decimal percentage e.g 0.5 equals 50% Edited October 28, 2020 by thomas4846 2 Link to comment https://forums.kleientertainment.com/forums/topic/122913-looking-for-help-with-coding-a-custom-character/#findComment-1385519 Share on other sites More sharing options...
Adipup Posted October 29, 2020 Author Share Posted October 29, 2020 Thank you! Didn't realize it was going to be that simple. There's one more thing I want to do with this character, but I feel like it would take a lot more than a few lines of code. I want them to spawn with a custom weapon that behaves like a whip, but with custom sprites (drawn by me) and infinite durability. I found a tutorial on how to make a custom weapon, but that only seems to cover ones that behave like swords. Link to comment https://forums.kleientertainment.com/forums/topic/122913-looking-for-help-with-coding-a-custom-character/#findComment-1385739 Share on other sites More sharing options...
Yakuzashi Posted October 29, 2020 Share Posted October 29, 2020 I have made template for custom weapons: https://forums.kleientertainment.com/forums/topic/115694-templatetutorial-custom-crafting-tab-and-items/ You need to compare weapon.lua from template with whip.lua from DST and decide what to change. You can take whip.zip and decompile it with ktools (I have done that it's in .rar format in attachments, just in case you don't know how to do it) and modify acquired sprites. whip.rar 2 Link to comment https://forums.kleientertainment.com/forums/topic/122913-looking-for-help-with-coding-a-custom-character/#findComment-1385901 Share on other sites More sharing options...
Adipup Posted October 29, 2020 Author Share Posted October 29, 2020 (edited) I'm trying to follow your template, but I can't really figure it out. The whip item seems a lot different to a normal weapon (it only has one .scml file instead of two as an example found the other zip and converted it with krane, but I'm still having issues). Would you mind if I send you my mod so you can take a look at it and maybe tell me where I went wrong? Edited October 29, 2020 by Adipup Link to comment https://forums.kleientertainment.com/forums/topic/122913-looking-for-help-with-coding-a-custom-character/#findComment-1386017 Share on other sites More sharing options...
Yakuzashi Posted October 30, 2020 Share Posted October 30, 2020 11 hours ago, Adipup said: I'm trying to follow your template, but I can't really figure it out. The whip item seems a lot different to a normal weapon (it only has one .scml file instead of two as an example found the other zip and converted it with krane, but I'm still having issues). Would you mind if I send you my mod so you can take a look at it and maybe tell me where I went wrong? Ok, send it. Link to comment https://forums.kleientertainment.com/forums/topic/122913-looking-for-help-with-coding-a-custom-character/#findComment-1386241 Share on other sites More sharing options...
Adipup Posted October 30, 2020 Author Share Posted October 30, 2020 6 minutes ago, Yakuzashi said: Ok, send it. I think it's working now, actually! I just forgot to include this bit in the weapon's lua file: inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "weapon" inst.components.inventoryitem.atlasname = "images/inventoryimages/weapon.xml" Thanks for all your help! Link to comment https://forums.kleientertainment.com/forums/topic/122913-looking-for-help-with-coding-a-custom-character/#findComment-1386244 Share on other sites More sharing options...
Yakuzashi Posted October 30, 2020 Share Posted October 30, 2020 No problem Link to comment https://forums.kleientertainment.com/forums/topic/122913-looking-for-help-with-coding-a-custom-character/#findComment-1386245 Share on other sites More sharing options...
Adipup Posted October 30, 2020 Author Share Posted October 30, 2020 @Yakuzashi @thomas4846 My character is up on the Steam workshop now if you want to see: https://steamcommunity.com/sharedfiles/filedetails/?id=2272337557 Couldn't have done much of this without you, so thanks again! 3 Link to comment https://forums.kleientertainment.com/forums/topic/122913-looking-for-help-with-coding-a-custom-character/#findComment-1386546 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