Jump to content

Recommended Posts

My mod is a lipstick that can add sanity buff when used. It worked well until the DST update this week. I saw some lines related to my mod "dior" in the client_log, and I couldn't find server_log.

I don't know if it's my prefabs have some vague statement or something that disagrees with the newest update or what. Please help me out,  I really like my sanityregenbuff, I got the idea from the existing healthregenbuff. Thanks a lot!

dior.zip

client_log.txt

 

modmain.lua

Spoiler

PrefabFiles = {
"dior",
"sanityregenbuff",
}

local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS
local Ingredient = GLOBAL.Ingredient
local RECIPETABS = GLOBAL.RECIPETABS
local Recipe = GLOBAL.Recipe
local TECH = GLOBAL.TECH


--lipsticks
AddRecipe("dior", { Ingredient("goldnugget", 1),Ingredient("honey", 1),Ingredient("petals", 1)}, GLOBAL.RECIPETABS.DRESS, GLOBAL.TECH.NONE, nil, nil, nil, nil, nil, "images/inventoryimages/dior.xml", "dior.tex" )
--Ingredient("mosquitosack", 1),Ingredient("stinger", 1),


    AddComponentPostInit("healer", function(self)
    function self:SetComponent(comp)
        self.component = comp
    end

    local oldHeal = self.Heal
    function self:Heal(target)
        if self.component == nil or self.component == "health" then
            return oldHeal(self, target)
        end
        if self.component == "sanity" then
            if target.components.sanity ~= nil then
                target.components.sanity:DoDelta(self.health, false)
                target.components.debuffable:AddDebuff("sanityregenbuff","sanityregenbuff")
                
                if self.inst.components.finiteuses then
                    self.inst.components.finiteuses:Use(1)
                elseif self.inst.components.stackable then
                     self.inst.components.stackable:Get(1):Remove()
                end
                
                return true
            end
        end
    end
end)
 

 

prefabs -> dior

Spoiler

local assets =
{
    Asset("ANIM", "anim/dior.zip"),
    Asset("ATLAS", "images/inventoryimages/dior.xml"),    
    Asset("IMAGE", "images/inventoryimages/dior.tex"),
}

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("dior")
    inst.AnimState:SetBuild("dior")
    inst.AnimState:PlayAnimation("idle")


    if not TheWorld.ismastersim then
        return inst
    end
    inst.entity:SetPristine()

    inst:AddComponent("inspectable")
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.atlasname = "images/inventoryimages/dior.xml"
    
    inst:AddComponent("tradable")
    inst.components.tradable.goldvalue = 60
    inst.data = {}
    
    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(100)
    inst.components.finiteuses:SetUses(100)
    inst.components.finiteuses:SetOnFinished(inst.Remove)
    
---------------------
    inst:AddComponent("healer")
    inst.components.healer:SetComponent("sanity")
    inst.components.healer:SetHealthAmount(20)--this is the amount of sanity gained
---------------------
--TUNING.DIOR_TICK_VALUE=3--TUNING.DIOR_TICK_RATE=30--TUNING.DIOR_DURATION=day_time*8

    return inst
end


STRINGS.NAMES.DIOR = "dior"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.DIOR = "make you look good"
STRINGS.RECIPE_DESC.DIOR = "top class lipstick"

return Prefab("common/inventory/dior", fn, assets)

 

prefabs -> sanityregenbuff

Spoiler

local function OnTick(inst, target)
    if target.components.sanity ~= nil and
        not target.components.health:IsDead() and
        not target:HasTag("playerghost") then
        target.components.sanity:DoDelta(TUNING.DIOR_TICK_VALUE, nil, "dior")
    else
        inst.components.debuff:Stop()
    end
end

local function OnAttached(inst, target)
    inst.entity:SetParent(target.entity)
    inst.Transform:SetPosition(0, 0, 0) --in case of loading
    inst.task = inst:DoPeriodicTask(TUNING.DIOR_TICK_RATE, OnTick, nil, target)
    inst:ListenForEvent("death", function()
        inst.components.debuff:Stop()
    end, target)
end

local function OnTimerDone(inst, data)
    if data.name == "regenover" then
        inst.components.debuff:Stop()
    end
end

local function OnExtended(inst, target)
    inst.components.timer:StopTimer("regenover")
    inst.components.timer:StartTimer("regenover", TUNING.DIOR_DURATION)
    inst.task:Cancel()
    inst.task = inst:DoPeriodicTask(TUNING.DIOR_TICK_RATE, OnTick, nil, target)
end

local function fn()
    local inst = CreateEntity()

    if not TheWorld.ismastersim then
        --Not meant for client!
        inst:DoTaskInTime(0, inst.Remove)

        return inst
    end

    inst.entity:AddTransform()

    --[[Non-networked entity]]
    --inst.entity:SetCanSleep(false)
    inst.entity:Hide()
    inst.persists = false

    inst:AddTag("CLASSIFIED")

    inst:AddComponent("debuff")
    inst.components.debuff:SetAttachedFn(OnAttached)
    inst.components.debuff:SetDetachedFn(inst.Remove)
    inst.components.debuff:SetExtendedFn(OnExtended)
    inst.components.debuff.keepondespawn = true

    inst:AddComponent("timer")
    inst.components.timer:StartTimer("regenover", TUNING.DIOR_DURATION)
    inst:ListenForEvent("timerdone", OnTimerDone)

    return inst
end

return Prefab("sanityregenbuff", fn)
 

 

 

Part of the client_log

Spoiler

[00:00:47]: [string "scripts/scheduler.lua"]:273: attempt to perform arithmetic on local 'dt' (a nil value)
LUA ERROR stack traceback:
    scripts/scheduler.lua:273 in (method) GetListForTimeFromNow (Lua) <271-284>
    scripts/scheduler.lua:287 in () ? (Lua) <286-292>
    =(tail call):-1 in ()  (tail) <-1--1>
    scripts/entityscript.lua:1190 in (method) DoTaskInTime (Lua) <1184-1194>
    scripts/components/timer.lua:44 in (method) StartTimer (Lua) <36-54>
    ../mods/dior/scripts/prefabs/sanityregenbuff.lua:59 in (field) fn (Lua) <33-63>
    scripts/mainfunctions.lua:207 in () ? (Lua) <196-238>
    =[C]:-1 in (method) SpawnPrefab (C) <-1--1>
    scripts/mainfunctions.lua:255 in (global) SpawnPrefab (Lua) <249-257>
    scripts/mainfunctions.lua:261 in (global) SpawnSaveRecord (Lua) <259-301>
    scripts/components/debuffable.lua:130 in (method) OnLoad (Lua) <126-137>
    scripts/entityscript.lua:1568 in (method) SetPersistData (Lua) <1559-1576>
    scripts/mainfunctions.lua:1389 in () ? (Lua) <1385-1397>
    =[C]:-1 in (method) SendResumeRequestToServer (C) <-1--1>
    scripts/prefabs/world_network.lua:30 in (field) fn (Lua) <19-34>
    scripts/scheduler.lua:177 in (method) OnTick (Lua) <155-207>
    scripts/scheduler.lua:371 in (global) RunScheduler (Lua) <369-377>
    scripts/update.lua:170 in () ? (Lua) <149-228>

 

Edited by nicknightyx
7 hours ago, Aquaterion said:

its probably due to the fact that you commented the tuning values in dior.lua:45 ?


--TUNING.DIOR_TICK_VALUE=3--TUNING.DIOR_TICK_RATE=30--TUNING.DIOR_DURATION=day_time*8

 

Oh I wrote that just for reference, showing what's in the tuning.lua file.

Edited by nicknightyx
Just now, Aquaterion said:

what do you mean in tuning.lua file? you didn't have anything like that in your mod.

I meant the tuning.lua in the DST scripts, and I used the value in tuning.lua in sanityregenbuff.lua

Spoiler

local function OnTick(inst, target)
    if target.components.sanity ~= nil and
        not target.components.health:IsDead() and
        not target:HasTag("playerghost") then
        target.components.sanity:DoDelta(TUNING.DIOR_TICK_VALUE, nil, "dior")
    else
        inst.components.debuff:Stop()
    end
end

local function OnAttached(inst, target)
    inst.entity:SetParent(target.entity)
    inst.Transform:SetPosition(0, 0, 0) --in case of loading
    inst.task = inst:DoPeriodicTask(TUNING.DIOR_TICK_RATE, OnTick, nil, target)
    inst:ListenForEvent("death", function()
        inst.components.debuff:Stop()
    end, target)
end

local function OnTimerDone(inst, data)
    if data.name == "regenover" then
        inst.components.debuff:Stop()
    end
end

local function OnExtended(inst, target)
    inst.components.timer:StopTimer("regenover")
    inst.components.timer:StartTimer("regenover", TUNING.DIOR_DURATION)
    inst.task:Cancel()
    inst.task = inst:DoPeriodicTask(TUNING.DIOR_TICK_RATE, OnTick, nil, target)
end

local function fn()
    local inst = CreateEntity()

    if not TheWorld.ismastersim then
        --Not meant for client!
        inst:DoTaskInTime(0, inst.Remove)

        return inst
    end

    inst.entity:AddTransform()

    --[[Non-networked entity]]
    --inst.entity:SetCanSleep(false)
    inst.entity:Hide()
    inst.persists = false

    inst:AddTag("CLASSIFIED")

    inst:AddComponent("debuff")
    inst.components.debuff:SetAttachedFn(OnAttached)
    inst.components.debuff:SetDetachedFn(inst.Remove)
    inst.components.debuff:SetExtendedFn(OnExtended)
    inst.components.debuff.keepondespawn = true

    inst:AddComponent("timer")
    inst.components.timer:StartTimer("regenover", TUNING.DIOR_DURATION)
    inst:ListenForEvent("timerdone", OnTimerDone)

    return inst
end

return Prefab("sanityregenbuff", fn)
 

 

Oh, okey, I will change it. Thanks for reminding, let's see if this works.

17 minutes ago, Aquaterion said:

declare them in the modmain.lua like so:

I think you are right! The DST update refreshed the tuning.lua and everything I did to the file had gone.

And I wrote this, would you please check my syntax and completeness because I got error starting the game LOL.

Spoiler

PrefabFiles = {
"dior",
"sanityregenbuff",
}

local require = GLOBAL.require
local STRINGS = GLOBAL.STRINGS
local Ingredient = GLOBAL.Ingredient
local RECIPETABS = GLOBAL.RECIPETABS
local Recipe = GLOBAL.Recipe
local TECH = GLOBAL.TECH


--lipsticks
AddRecipe("dior", { Ingredient("goldnugget", 1),Ingredient("honey", 1),Ingredient("petals", 1)}, GLOBAL.RECIPETABS.DRESS, GLOBAL.TECH.NONE, nil, nil, nil, nil, nil, "images/inventoryimages/dior.xml", "dior.tex" )
--Ingredient("mosquitosack", 1),Ingredient("stinger", 1),

GLOBAL.TUNING.DIOR_DURATION = day_time*8
GLOBAL.TUNING.DIOR_TICK_VALUE = 4
GLOBAL.TUNING.DIOR_TICK_RATE=30


    AddComponentPostInit("healer", function(self)
    function self:SetComponent(comp)
        self.component = comp
    end

    local oldHeal = self.Heal
    function self:Heal(target)
        if self.component == nil or self.component == "health" then
            return oldHeal(self, target)
        end
        if self.component == "sanity" then
            if target.components.sanity ~= nil then
                target.components.sanity:DoDelta(self.health, false)
                target.components.debuffable:AddDebuff("sanityregenbuff","sanityregenbuff")
                
                if self.inst.components.finiteuses then
                    self.inst.components.finiteuses:Use(1)
                elseif self.inst.components.stackable then
                     self.inst.components.stackable:Get(1):Remove()
                end
                
                return true
            end
        end
    end
end)
 

I get this client_log.

Spoiler

[00:00:23]: [string "../mods/dior/modmain.lua"]:18: attempt to perform arithmetic on global 'day_time' (a nil value)
LUA ERROR stack traceback:
        ../mods/dior/modmain.lua(18,1) in main chunk
        =[C] in function 'xpcall'
        scripts/util.lua(709,1) in function 'RunInEnvironment'
        scripts/mods.lua(511,1) in function 'InitializeModMain'
        scripts/mods.lua(485,1) in function 'LoadMods'
        scripts/main.lua(267,1) in function 'ModSafeStartup'
        scripts/main.lua(327,1)
        =[C] in function 'SetPersistentString'
        scripts/mainfunctions.lua(26,1) in function 'SavePersistentString'
        scripts/modindex.lua(77,1)
        =[C] in function 'GetPersistentString'
        scripts/modindex.lua(64,1) in function 'BeginStartupSequence'
        scripts/main.lua(326,1) in function 'callback'
        scripts/modindex.lua(542,1)
        =[C] in function 'GetPersistentString'
        scripts/modindex.lua(516,1) in function 'Load'
        scripts/main.lua(325,1) in main chunk
[00:00:23]: [string "scripts/mainfunctions.lua"]:1029: variable 'global_error_widget' is not declared
LUA ERROR stack traceback:
        =[C] in function 'error'
        scripts/strict.lua(23,1)
        scripts/mainfunctions.lua(1029,1)
        =[C] in function 'SetPersistentString'
        scripts/mainfunctions.lua(26,1) in function 'SavePersistentString'
        scripts/modindex.lua(77,1)
        =[C] in function 'GetPersistentString'
        scripts/modindex.lua(64,1) in function 'BeginStartupSequence'
        scripts/main.lua(326,1) in function 'callback'
        scripts/modindex.lua(542,1)
        =[C] in function 'GetPersistentString'
        scripts/modindex.lua(516,1) in function 'Load'
        scripts/main.lua(325,1) in main chunk

 

the problem is day_time variable is local to the tuning file, so it doesn't exist in your modmain.lua scope.

This is what tuning does to get that value;

local seg_time = 30
local day_segs = 10

local day_time = seg_time * day_segs--300

 

Edited by Aquaterion
2 minutes ago, Aquaterion said:

the problem is day_time variable is local to the tuning file, so it doesn't exist in your modmain.lua scope.

This is what tuning does to get that value;


local seg_time = 30
local day_segs = 10

local day_time = seg_time * day_segs--300

 

Oh, I see. Maybe I would just say GLOBAL.TUNING.DIOR_DURATION = 480*8  --just give it a value

And the mod works again! So happy, thank you!

1 hour ago, nicknightyx said:

I think you are right! The DST update refreshed the tuning.lua and everything I did to the file had gone.

Yes, it's one of the reason we don't modify base game file for modding. The other is that, as Aquaterion said, when we want to share a mod, these changes aren't shared with other players.

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