Jump to content

Recommended Posts

Currently working on a character mod -

I need help with coding a "perk" (not so much) of the character. I want her to lose more sanity with higher precipitation, not just when it's raining.

 

-If that's hard to do with the recent RoG update, maybe something where an item with a waterproof component can stop the increased sanity drain...

 

I've tried sourcing codes from other mods but I haven't found anything regarding precipitation yet. Any help is appreciated (:

 

--Also I'm getting a crash related to my textures I believe.. I thought it was my inventory images at first but even after fixing it, nothing changed.

 

Crash Log :

1671844676
LUA ERROR stack traceback:
        scripts/widgets/image.lua(30,1) in function 'SetTexture'
        scripts/widgets/image.lua(11,1) in function '_ctor'
        scripts/class.lua(181,1) in function 'Image'
        scripts/widgets/itemtile.lua(45,1) in function '_ctor'
        scripts/class.lua(181,1) in function 'ItemTile'
        scripts/widgets/inventorybar.lua(178,1) in function 'Rebuild'
        scripts/widgets/inventorybar.lua(281,1) in function 'OnUpdate'
        scripts/frontend.lua(599,1) in function 'Update'
        scripts/update.lua(93,1)
 
stack traceback:
scripts/widgets/widget.lua:261 in (method) SetPosition (Lua) <256-265>
scripts/widgets/inventorybar.lua:237 in (method) Rebuild (Lua) <121-261>
scripts/widgets/inventorybar.lua:281 in (method) OnUpdate (Lua) <263-344>
scripts/frontend.lua:599 in (method) Update (Lua) <465-614>
scripts/update.lua:93 in () ? (Lua) <39-123>
 
The first part of it repeated twice, the second repeated four times... It doesn't say what exactly is causing the crash so I'm absolutely lost... );

Again, any help is appreciated.

Edited by Lileean
Link to comment
https://forums.kleientertainment.com/forums/topic/54248-modding-help/
Share on other sites

inst.components.sanity.custom_rate_fn = function(inst)	local waterproofness = 0	if inst.components.inventory then		waterproofness = inst.components.inventory:GetWaterproofness() or 0	end	if waterproofness >= 1 then		return 0	end	return (1 - waterproofness) * TheWorld.state.precipitationrate * (-0.075)end

in your master_postinit.

 

Regarding your inventory, it seems you are missing an

inst.components.inventoryitem.atlasname = "myitem.xml"

inside any possible custom item's prefab you may have.

 

Else, post what your mod is about.

DarkXero, I'm not sure that's the case as I do have the file + the line of code within the .lua file.

Here's the coding for the custom item involved:

local assets ={Asset("ANIM", "anim/umbrella.zip"),Asset("ANIM", "anim/swap_umbrella.zip"), Asset("ATLAS", "images/inventoryimages/umbrella.xml"),Asset("IMAGE", "images/inventoryimages/umbrella.tex")}  local prefabs = {}    local function fn() local function UpdateSound(inst)local soundShouldPlay = GetSeasonManager():IsRaining() and inst.components.equippable:IsEquipped()if soundShouldPlay ~= inst.SoundEmitter:PlayingSound("umbrellarainsound") thenif soundShouldPlay theninst.SoundEmitter:PlaySound("dontstarve/rain/rain_on_umbrella", "umbrellarainsound") elseinst.SoundEmitter:KillSound("umbrellarainsound")endendend      local function OnEquip(inst, owner) owner.AnimState:OverrideSymbol("swap_object", "swap_umbrella", "swap_umbrella")owner.AnimState:Show("ARM_carry")owner.AnimState:Hide("ARM_normal")UpdateSound(inst)    owner.DynamicShadow:SetSize(2.2, 1.4) end local function OnUnequip(inst, owner) owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal") UpdateSound(inst) owner.DynamicShadow:SetSize(1.3, 0.6)end  local inst = CreateEntity()local trans = inst.entity:AddTransform()local anim = inst.entity:AddAnimState()    local sound = inst.entity:AddSoundEmitter()        MakeInventoryPhysics(inst)inst.entity:AddNetwork() inst.AnimState:SetBank("umbrella")    inst.AnimState:SetBuild("umbrella")    inst.AnimState:PlayAnimation("idle")     inst:AddTag("nopunch")    inst:AddTag("umbrella") if not TheWorld.ismastersim thenreturn instend     inst:AddComponent("waterproofer")inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_HIGH)     inst:AddComponent("inspectable")     inst:AddComponent("inventoryitem")inst.components.inventoryitem.keepondeath = trueinst.components.inventoryitem.imagename = "wynnesumbrella"inst.components.inventoryitem.atlasname = "images/inventoryimages/umbrella.xml"    inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip( OnEquip )    inst.components.equippable:SetOnUnequip( OnUnequip )     inst:AddComponent("insulator")    inst.components.insulator:SetSummer()    inst.components.insulator:SetInsulation(TUNING.INSULATION_HIGH) if not inst.components.characterspecific theninst:AddComponent("characterspecific")end inst.components.characterspecific:SetOwner("wynne")inst.components.characterspecific:SetStorable(true)     inst:ListenForEvent("rainstop", function() UpdateSound(inst) end, GetWorld()) inst:ListenForEvent("rainstart", function() UpdateSound(inst) end, GetWorld())             return instend return Prefab( "common/inventory/wynnesumbrella", fn, assets, prefabs)

-Also, thank you for the coding (: Would you mind letting me know which values to edit (if possible) to adjust the sanity drain to my liking? (Figured it out) Again, thanks a bunch!

Edited by Lileean

In 1 dt, you apply the custom_rate_fn to your sanity, because you add it to the sanity rate.

 

For reference, the top hat gives +3.3/min. That is +3.3 in 60 dt. How do we know this?

 

Top hat has DAPPERNESS_MED = 100/(day_time*6), which is 100/(seg_time*day_segs*6), which equals 100/(30*10*6).

Those are all values in the TUNING.lua file.

100/1800 in 1 dt (roughly 0.056). Multiplied by 60, is 6000/1800, which is 3.333333...

 

-0.075 translates into -4.5/min, which is almost like the dusk/night sanity debuff.

 

However, I decided to make it depend on the precipitation rate, which varies from 0 to 1.

So on a terrible damp, you would be like in the night near your campfire, but during the day.

On clear skies, 0 makes the custom rate 0.

 

I also decided to make the waterproofness weigh in. For example, with a football helmet, you have 0.2 waterproofness, so you get 0.8 of the rate you would be getting. Totally waterproofed, you turn that rate into 0.

 

I suggest you edit the 0.075 number. But you can add or remove as many factors as you want.

 

 

And use

inst.components.inventoryitem.imagename = "umbrella.tex"

DarkXero, thanks for the info/help. (: Sadly I'm still getting a crash... It looks a bit different now, though.

stack traceback:        scripts/widgets/image.lua(30,1) in function 'SetTexture'        scripts/widgets/image.lua(11,1) in function '_ctor'        scripts/class.lua(181,1) in function 'Image'        scripts/widgets/itemtile.lua(45,1) in function 'constructor'        scripts/modutil.lua(72,1) in function '_ctor'        scripts/modutil.lua(80,1) in function 'ItemTile'        scripts/widgets/inventorybar.lua(971,1) in function 'OnItemGet'        scripts/widgets/inventorybar.lua(74,1) in function 'fn'        scripts/entityscript.lua(935,1) in function 'PushEvent'        scripts/components/inventory.lua(686,1) in function 'GiveItem'

I seem to be really bad at this. /: I kind of want to take advantage of your help cause I feel very stuck.. lol. I still have my animations to fix... Basically my character looks overall tiny but the sizes of the images are not tiny. + a lot of parts are either invisible or weird squares... I don't want to put my very first mod project to waste.

  :spidercowers:

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