Jump to content

Recommended Posts

Spoiler

 

Warhammer prefab file

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

local function onequip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "swap_warhammer", "swap_diviningrod")
    owner.SoundEmitter:PlaySound("dontstarve/wilson/equip_item_gold")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")
end

local function onunequip(inst, owner)
    owner.AnimState:Hide("ARM_carry")
    owner.AnimState:Show("ARM_normal")
end

--Config Settings
chance = (GetModConfigData("warhammer_chance_base", KnownModIndex:GetModActualName("Athor Ironhorn, the dwarven king"))=="yes")
dwarfchance = (GetModConfigData("warhammer_chance_dwarf", KnownModIndex:GetModActualName("Athor Ironhorn, the dwarven king"))=="yes")
TUNING_WARHAMMER_DAMAGE    = (GetModConfigData("warhammer_damage", KnownModIndex:GetModActualName("Athor Ironhorn, the dwarven king"))=="yes")
TUNING_WARHAMMER_DAMAGE_DWARF    = (GetModConfigData("warhammer_damage_dwarf", KnownModIndex:GetModActualName("Athor Ironhorn, the dwarven king"))=="yes")
TUNING_WARHAMMER_HUNGER_LOSS = (GetModConfigData("Warhammer_hunger_loss_base", KnownModIndex:GetModActualName("Athor Ironhorn, the dwarven king"))=="yes")
TUNING_WARHAMMER_HUNGER_LOSS_DWARF = (GetModConfigData("Warhammer_hunger_loss_dwarf", KnownModIndex:GetModActualName("Athor Ironhorn, the dwarven king"))=="yes")

local function onattack(inst, owner, target)
    if not owner:HasTag("dwarf") then
    if math.random() < chance then
        inst.components.weapon:SetDamage(0)
        owner.components.hunger:DoDelta(-TUNING_WARHAMMER_HUNGER_LOSS)
    else        
        inst.components.weapon:SetDamage(TUNING_WARHAMMER_DAMAGE)
        owner.components.hunger:DoDelta(-TUNING_WARHAMMER_HUNGER_LOSS)
    end
    end
    
    if owner:HasTag("dwarf") then
    if math.random() < dwarfchance then
        inst.components.weapon:SetDamage(0)
        owner.components.hunger:DoDelta(-TUNING_WARHAMMER_HUNGER_LOSS_DWARF)
    else        
        inst.components.weapon:SetDamage(TUNING_WARHAMMER_DAMAGE)
        owner.components.hunger:DoDelta(-TUNING_WARHAMMER_HUNGER_LOSS_DWARF)
    end
    end
end

local function fn()
    local inst = CreateEntity()

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

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("umbrella")
    inst.AnimState:SetBuild("warhammer")
    inst.AnimState:PlayAnimation("idle")

    --inst:AddTag("sharp")
    --inst:AddTag("pointy")

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("weapon")

    inst.components.weapon.onattack = onattack
    -------

    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(10*TUNING.HAMMER_USES)
    inst.components.finiteuses:SetUses(10*TUNING.HAMMER_USES)

    inst.components.finiteuses:SetOnFinished(inst.Remove)
    inst.components.finiteuses:SetConsumption(ACTIONS.HAMMER, 1)

    inst:AddComponent("inspectable")

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "warhammer"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/warhammer.xml"
    
    inst:AddComponent("tool")
    inst.components.tool:SetAction(ACTIONS.HAMMER)

    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(onequip)
    inst.components.equippable:SetOnUnequip(onunequip)

    MakeHauntableLaunch(inst)

    return inst
end

return Prefab("warhammer", fn, assets)

Hello I am trying to add modconfig to my dwarven mod, but it keeps crashing when I hit something with the weapon.

It says something like: attempt to call number for boulean or something in the crash.

Can someone help me?

 

Sincerely 

-Eremus007

Link to comment
https://forums.kleientertainment.com/forums/topic/68091-modconfig-crashes/
Share on other sites

I'd say get the values in modmain instead, and make them global, tuning variables are already global too

--in modmain.lua
TUNING.WARHAMMER_CHANCE_BASE = GetModConfigData("warhammer_chance_base")
TUNING.WARHAMMER_CHANCE_DWARF = GetModConfigData("warhammer_chance_dwarf")
TUNING.WARHAMMER_DAMAGE_BASE = GetModConfigData("warhammer_damage")
TUNING.WARHAMMER_DAMAGE_DWARF = GetModConfigData("warhammer_damage_dwarf")
TUNING.WARHAMMER_HUNGER_LOSS_BASE = GetModConfigData("Warhammer_hunger_loss_base")
TUNING.WARHAMMER_HUNGER_LOSS_DWARF = GetModConfigData("Warhammer_hunger_loss_dwarf")

in warhammer.lua remove the GetModConfigs since we moved them to modmain and change the onattack function to:

local function onattack(inst, owner, target)
    if owner:HasTag("dwarf") then--if dwarf
		if math.random() < TUNING.WARHAMMER_CHANCE_DWARF then
			inst.components.weapon:SetDamage(0)
			owner.components.hunger:DoDelta(-TUNING.WARHAMMER_HUNGER_LOSS_DWARF)
		else        
			inst.components.weapon:SetDamage(TUNING.WARHAMMER_DAMAGE_DWARF)
			owner.components.hunger:DoDelta(-TUNING.WARHAMMER_HUNGER_LOSS_DWARF)
		end
    else--if not dwarf
		if math.random() < TUNING.WARHAMMER_CHANCE_BASE then
			inst.components.weapon:SetDamage(0)
			owner.components.hunger:DoDelta(-TUNING.WARHAMMER_HUNGER_LOSS)
		else        
			inst.components.weapon:SetDamage(TUNING.WARHAMMER_DAMAGE_BASE)
			owner.components.hunger:DoDelta(-TUNING.WARHAMMER_HUNGER_LOSS_BASE)
		end
    end
end

question tho, why do you keep setting the weapon damage to 0?

Edited by Aquaterion
24 minutes ago, Aquaterion said:

I'd say get the values in modmain instead, and make them global, tuning variables are already global too


--in modmain.lua
TUNING.WARHAMMER_CHANCE_BASE = GetModConfigData("warhammer_chance_base")
TUNING.WARHAMMER_CHANCE_DWARF = GetModConfigData("warhammer_chance_dwarf")
TUNING.WARHAMMER_DAMAGE_BASE = GetModConfigData("warhammer_damage")
TUNING.WARHAMMER_DAMAGE_DWARF = GetModConfigData("warhammer_damage_dwarf")
TUNING.WARHAMMER_HUNGER_LOSS_BASE = GetModConfigData("Warhammer_hunger_loss_base")
TUNING.WARHAMMER_HUNGER_LOSS_DWARF = GetModConfigData("Warhammer_hunger_loss_dwarf")

in warhammer.lua remove the GetModConfigs since we moved them to modmain and change the onattack function to:


local function onattack(inst, owner, target)
    if owner:HasTag("dwarf") then--if dwarf
		if math.random() < TUNING.WARHAMMER_CHANCE_DWARF then
			inst.components.weapon:SetDamage(0)
			owner.components.hunger:DoDelta(-TUNING.WARHAMMER_HUNGER_LOSS_DWARF)
		else        
			inst.components.weapon:SetDamage(TUNING.WARHAMMER_DAMAGE_DWARF)
			owner.components.hunger:DoDelta(-TUNING.WARHAMMER_HUNGER_LOSS_DWARF)
		end
    else--if not dwarf
		if math.random() < TUNING.WARHAMMER_CHANCE_BASE then
			inst.components.weapon:SetDamage(0)
			owner.components.hunger:DoDelta(-TUNING.WARHAMMER_HUNGER_LOSS)
		else        
			inst.components.weapon:SetDamage(TUNING.WARHAMMER_DAMAGE_BASE)
			owner.components.hunger:DoDelta(-TUNING.WARHAMMER_HUNGER_LOSS_BASE)
		end
    end
end

question tho, why do you keep setting the weapon damage to 0?

Thanks I will try that, the damage is set to zero if the chance is less than Math.random.

So the warhammer has a chance (WARHAMMER_CHANCE) to miss the target.

8 minutes ago, Eremus007 said:

Thanks I will try that, the damage is set to zero if the chance is less than Math.random.

So the warhammer has a chance (WARHAMMER_CHANCE) to miss the target.

onattack happens after you attack, setting the damage will only make the next attack do that damage

use this instead

target.components.combat:GetAttacked(owner, TUNING.WARHAMMER_DAMAGE_DWARF, inst)

move this:

inst.components.weapon:SetDamage(0)

into the main fn under "inst:AddComponent("weapon")"

here's how the onattack should look like:

local function onattack(inst, owner, target)
    if owner:HasTag("dwarf") then--if dwarf
		if math.random() < TUNING.WARHAMMER_CHANCE_DWARF then
			target.components.combat:GetAttacked(owner, TUNING.WARHAMMER_DAMAGE_DWARF, inst)       
		end
		owner.components.hunger:DoDelta(-TUNING.WARHAMMER_HUNGER_LOSS_DWARF)
    else--if not dwarf
		if math.random() < TUNING.WARHAMMER_CHANCE_BASE then
			target.components.combat:GetAttacked(owner, TUNING.WARHAMMER_DAMAGE_BASE, inst)
		end       
		owner.components.hunger:DoDelta(-TUNING.WARHAMMER_HUNGER_LOSS_BASE)
    end
end

 

Edited by Aquaterion
Spoiler

Skyminer Character.LUA:

local function OnSave(inst, data)
    if inst.dwarventonicresttime then data.dwarventonicresttime = inst.dwarventonicresttime end --tonic
    if inst.dwarvenaleresttime then data.dwarvenaleresttime = inst.dwarvenaleresttime end --ale
end

local function OnLoad(inst, data)
    --tonic
    if data.dwarventonicresttime then 
        inst.dwarventonicresttime = data.dwarventonicresttime 
        if inst.dwarventonicresttime > 0 then
            inst.components.sanity.dapperness = inst.components.sanity.dapperness - TUNING.DAPPERNESS_SMALL
        end
    end
    --ale
    if data.dwarvenaleresttime then 
        inst.dwarvenaleresttime = data.dwarvenaleresttime 
        if inst.dwarvenaleresttime > 0 then
            inst.components.sanity.dapperness = eater.components.sanity.dapperness - TUNING.DAPPERNESS_MED
            inst.components.combat.damagemultiplier = inst.components.combat.damagemultiplier - TUNING.WILSON_DAMAGE_MULT
        end
    end
end

local MakePlayerCharacter = require "prefabs/player_common"


local assets = {
    Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
    Asset( "ANIM", "anim/skyminer_beard.zip" ),
}
local prefabs = {   "beardhair",}

-- Custom starting items
local start_inv = 
{
  "crown",
  "dwarvenale",
}

-- When the character is revived from human
local function onbecamehuman(inst)
    -- Set speed when reviving from ghost (optional)
    inst.components.locomotor:SetExternalSpeedMultiplier(inst, "skyminer_speed_mod", 1)
end

local function onbecameghost(inst)
    -- Remove speed modifier when becoming a ghost
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "skyminer_speed_mod")
end

-- When loading or spawning the character
local function onload(inst)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)

    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
end


-- This initializes for both the server and client. Tags can be added here.
local common_postinit = function(inst) 
    -- Minimap icon
    inst.MiniMapEntity:SetIcon( "skyminer.tex" )
    inst:AddTag("crown_builder")
    inst:AddTag("betty_builder")
    inst:AddTag("dwarvenpickaxe_builder")
    inst:AddTag("woodenmug_builder")
    inst:AddTag("dwarf")
    inst:AddTag("bearded")
end

local function OnResetBeard(inst)    
inst.AnimState:ClearOverrideSymbol("beard")
end 

--tune the beard economy...
local BEARD_DAYS = { 1, 2,  3 }
local BEARD_BITS = { 1, 2,  4 } 

local function OnGrowShortBeard(inst)    
inst.AnimState:OverrideSymbol("beard", "skyminer_beard", "beard_short")    
inst.components.beard.bits = BEARD_BITS[1]
end 

local function OnGrowMediumBeard(inst)    
inst.AnimState:OverrideSymbol("beard", "skyminer_beard", "beard_medium")    
inst.components.beard.bits = BEARD_BITS[2]
end 

local function OnGrowLongBeard(inst)    
inst.AnimState:OverrideSymbol("beard", "skyminer_beard", "beard_long")    
inst.components.beard.bits = BEARD_BITS[3]
end

--Gaining Sanity from mining boulders.
local function OnFinishedWork(inst, data)
    local target = data.target
    if target and target:HasTag("boulder") then
        inst.components.sanity:DoDelta(TUNING_MINING_SANITY)
    end
end

-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)
    -- choose which sounds this character will play
    inst.components.eater.strongstomach = true
    
    inst.soundsname = "woodie"
    inst:AddComponent("beard")
    inst.components.beard.insulation_factor = TUNING.WEBBER_BEARD_INSULATION_FACTOR * 1.7
    inst.components.beard.onreset = OnResetBeard
    inst.components.beard.prize = "dwarvenbeardhair"    
    inst.components.beard:AddCallback(BEARD_DAYS[1], OnGrowShortBeard)    
    inst.components.beard:AddCallback(BEARD_DAYS[2], OnGrowMediumBeard)    
    inst.components.beard:AddCallback(BEARD_DAYS[3], OnGrowLongBeard)
    
    -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
    --inst.talker_path_override = "dontstarve_DLC001/characters/"
    
    -- Stats    
    inst.components.health:SetMaxHealth(125)
    inst.components.hunger:SetMax(200)
    inst.components.sanity:SetMax(115)
    inst.components.sanity.night_drain_mult = 0.5
    inst.components.eater:SetDiet({FOODGROUP.OMNI}, {FOODTYPE.MEAT, FOODTYPE.CARROTS, FOODTYPE.GENERIC})
    
    -- Damage multiplier (optional)
    inst.components.combat.damagemultiplier = 1
    
    -- Hunger rate (optional)
    inst.components.hunger.hungerrate = 1.5 * TUNING.WILSON_HUNGER_RATE
    
    inst.OnLoad = onload
    inst.OnNewSpawn = onload
    inst.OnSave = OnSave
    
    inst.light = inst.entity:AddLight()
    inst.light:SetFalloff(0.75)
    inst.light:SetIntensity(.6)
    inst.light:SetRadius(10)
    inst.light:SetColour(169/255, 231/255, 245/255)
    inst.light:Enable(false)
    inst:ListenForEvent("death", function(inst)
        if (inst.dwarventonicresttime) then if (inst.dwarventonicresttime > 0) then     inst.dwarventonicresttime = 0 end end
        if (inst.dwarvenaleresttime) then if (inst.dwarvenaleresttime > 0) then     inst.dwarvenaleresttime = 0 end end
        inst.light:Enable(false)
    end)
    
    
    inst:ListenForEvent("finishedwork", OnFinishedWork)
    
    --Loses his mind -sanity- when using up gold in a crafting recipe.
    local self = inst.components.builder
    local old = self.RemoveIngredients
    function self:RemoveIngredients(ingredients)
        for item, ents in pairs(ingredients) do
            for k, v in pairs(ents) do
                for i = 1, v do
                    if k.prefab == "goldnugget" then
                        self.inst.components.sanity:DoDelta(-TUNING_GOLD_SANITY)
                        if inst.components.talker ~= nil then
                            inst.components.talker:Say(GetString(inst, "ANNOUNCE_LOSING_GOLD"))
                        end
                    end
                end
            end
         end
         old(self, ingredients)
    end
    
--Lose sanity when removing gold from your inventory
    inst:ListenForEvent("dropitem", function(inst, data)        
    if data.item.prefab == "goldnugget" then            
    inst.components.sanity:DoDelta(-TUNING_GOLD_SANITY)    
    if inst.components.talker ~= nil then
                    inst.components.talker:Say(GetString(inst, "ANNOUNCE_LOSING_GOLD_DROP"))
    end                
    end    
end)

    inst:DoPeriodicTask(1, function()
        --dwarventonic
        if inst.dwarventonicresttime then
            if inst.dwarventonicresttime > 0 then                
                inst.dwarventonicresttime = inst.dwarventonicresttime - 1
                if TheWorld.state.isnight then    
                    inst.light:SetFalloff(0.75)
                    inst.light:SetIntensity(.6)
                    inst.light:SetRadius(10)
                    inst.light:SetColour(169/255, 231/255, 245/255)
                    inst.light:Enable(true)
                    inst.AnimState:SetBloomEffectHandle( "shaders/anim.ksh" )
                else
                    inst.light:Enable(false)
                end
            elseif inst.dwarventonicresttime == 0 then
                inst.components.sanity.dapperness = inst.components.sanity.dapperness + TUNING.DAPPERNESS_MED_LARGE
                inst.light:Enable(false)
                inst.dwarventonicresttime= inst.dwarventonicresttime - 1
            end
        end
        --dwarvenale
        if inst.dwarvenaleresttime then    
            if inst.dwarvenaleresttime > 0 then            
                inst.dwarvenaleresttime = inst.dwarvenaleresttime - 1
            elseif inst.dwarvenaleresttime == 0 then
                inst.dwarvenaleresttime = inst.dwarvenaleresttime - 1
                inst.components.sanity.dapperness = inst.components.sanity.dapperness + TUNING.DAPPERNESS_MED_LARGE
                inst.components.combat.damagemultiplier = inst.components.combat.damagemultiplier / 2
            end
        end
    end)
end    

return MakePlayerCharacter("skyminer", prefabs, assets, common_postinit, master_postinit, start_inv)
 

Thanks, now the warhamer works as well as it should.

But now I have the problem that when I mine boulders or drop gold the game crashes the same way as before.

It says: TUNING_MINING_SANITY is not declared, even though I specified it in the modmain.

What is causing the crash? I can't tell...

 

21 minutes ago, Eremus007 said:
  Reveal hidden contents

Skyminer Character.LUA:

local function OnSave(inst, data)
    if inst.dwarventonicresttime then data.dwarventonicresttime = inst.dwarventonicresttime end --tonic
    if inst.dwarvenaleresttime then data.dwarvenaleresttime = inst.dwarvenaleresttime end --ale
end

local function OnLoad(inst, data)
    --tonic
    if data.dwarventonicresttime then 
        inst.dwarventonicresttime = data.dwarventonicresttime 
        if inst.dwarventonicresttime > 0 then
            inst.components.sanity.dapperness = inst.components.sanity.dapperness - TUNING.DAPPERNESS_SMALL
        end
    end
    --ale
    if data.dwarvenaleresttime then 
        inst.dwarvenaleresttime = data.dwarvenaleresttime 
        if inst.dwarvenaleresttime > 0 then
            inst.components.sanity.dapperness = eater.components.sanity.dapperness - TUNING.DAPPERNESS_MED
            inst.components.combat.damagemultiplier = inst.components.combat.damagemultiplier - TUNING.WILSON_DAMAGE_MULT
        end
    end
end

local MakePlayerCharacter = require "prefabs/player_common"


local assets = {
    Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
    Asset( "ANIM", "anim/skyminer_beard.zip" ),
}
local prefabs = {   "beardhair",}

-- Custom starting items
local start_inv = 
{
  "crown",
  "dwarvenale",
}

-- When the character is revived from human
local function onbecamehuman(inst)
    -- Set speed when reviving from ghost (optional)
    inst.components.locomotor:SetExternalSpeedMultiplier(inst, "skyminer_speed_mod", 1)
end

local function onbecameghost(inst)
    -- Remove speed modifier when becoming a ghost
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "skyminer_speed_mod")
end

-- When loading or spawning the character
local function onload(inst)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)

    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
end


-- This initializes for both the server and client. Tags can be added here.
local common_postinit = function(inst) 
    -- Minimap icon
    inst.MiniMapEntity:SetIcon( "skyminer.tex" )
    inst:AddTag("crown_builder")
    inst:AddTag("betty_builder")
    inst:AddTag("dwarvenpickaxe_builder")
    inst:AddTag("woodenmug_builder")
    inst:AddTag("dwarf")
    inst:AddTag("bearded")
end

local function OnResetBeard(inst)    
inst.AnimState:ClearOverrideSymbol("beard")
end 

--tune the beard economy...
local BEARD_DAYS = { 1, 2,  3 }
local BEARD_BITS = { 1, 2,  4 } 

local function OnGrowShortBeard(inst)    
inst.AnimState:OverrideSymbol("beard", "skyminer_beard", "beard_short")    
inst.components.beard.bits = BEARD_BITS[1]
end 

local function OnGrowMediumBeard(inst)    
inst.AnimState:OverrideSymbol("beard", "skyminer_beard", "beard_medium")    
inst.components.beard.bits = BEARD_BITS[2]
end 

local function OnGrowLongBeard(inst)    
inst.AnimState:OverrideSymbol("beard", "skyminer_beard", "beard_long")    
inst.components.beard.bits = BEARD_BITS[3]
end

--Gaining Sanity from mining boulders.
local function OnFinishedWork(inst, data)
    local target = data.target
    if target and target:HasTag("boulder") then
        inst.components.sanity:DoDelta(TUNING_MINING_SANITY)
    end
end

-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)
    -- choose which sounds this character will play
    inst.components.eater.strongstomach = true
    
    inst.soundsname = "woodie"
    inst:AddComponent("beard")
    inst.components.beard.insulation_factor = TUNING.WEBBER_BEARD_INSULATION_FACTOR * 1.7
    inst.components.beard.onreset = OnResetBeard
    inst.components.beard.prize = "dwarvenbeardhair"    
    inst.components.beard:AddCallback(BEARD_DAYS[1], OnGrowShortBeard)    
    inst.components.beard:AddCallback(BEARD_DAYS[2], OnGrowMediumBeard)    
    inst.components.beard:AddCallback(BEARD_DAYS[3], OnGrowLongBeard)
    
    -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
    --inst.talker_path_override = "dontstarve_DLC001/characters/"
    
    -- Stats    
    inst.components.health:SetMaxHealth(125)
    inst.components.hunger:SetMax(200)
    inst.components.sanity:SetMax(115)
    inst.components.sanity.night_drain_mult = 0.5
    inst.components.eater:SetDiet({FOODGROUP.OMNI}, {FOODTYPE.MEAT, FOODTYPE.CARROTS, FOODTYPE.GENERIC})
    
    -- Damage multiplier (optional)
    inst.components.combat.damagemultiplier = 1
    
    -- Hunger rate (optional)
    inst.components.hunger.hungerrate = 1.5 * TUNING.WILSON_HUNGER_RATE
    
    inst.OnLoad = onload
    inst.OnNewSpawn = onload
    inst.OnSave = OnSave
    
    inst.light = inst.entity:AddLight()
    inst.light:SetFalloff(0.75)
    inst.light:SetIntensity(.6)
    inst.light:SetRadius(10)
    inst.light:SetColour(169/255, 231/255, 245/255)
    inst.light:Enable(false)
    inst:ListenForEvent("death", function(inst)
        if (inst.dwarventonicresttime) then if (inst.dwarventonicresttime > 0) then     inst.dwarventonicresttime = 0 end end
        if (inst.dwarvenaleresttime) then if (inst.dwarvenaleresttime > 0) then     inst.dwarvenaleresttime = 0 end end
        inst.light:Enable(false)
    end)
    
    
    inst:ListenForEvent("finishedwork", OnFinishedWork)
    
    --Loses his mind -sanity- when using up gold in a crafting recipe.
    local self = inst.components.builder
    local old = self.RemoveIngredients
    function self:RemoveIngredients(ingredients)
        for item, ents in pairs(ingredients) do
            for k, v in pairs(ents) do
                for i = 1, v do
                    if k.prefab == "goldnugget" then
                        self.inst.components.sanity:DoDelta(-TUNING_GOLD_SANITY)
                        if inst.components.talker ~= nil then
                            inst.components.talker:Say(GetString(inst, "ANNOUNCE_LOSING_GOLD"))
                        end
                    end
                end
            end
         end
         old(self, ingredients)
    end
    
--Lose sanity when removing gold from your inventory
    inst:ListenForEvent("dropitem", function(inst, data)        
    if data.item.prefab == "goldnugget" then            
    inst.components.sanity:DoDelta(-TUNING_GOLD_SANITY)    
    if inst.components.talker ~= nil then
                    inst.components.talker:Say(GetString(inst, "ANNOUNCE_LOSING_GOLD_DROP"))
    end                
    end    
end)

    inst:DoPeriodicTask(1, function()
        --dwarventonic
        if inst.dwarventonicresttime then
            if inst.dwarventonicresttime > 0 then                
                inst.dwarventonicresttime = inst.dwarventonicresttime - 1
                if TheWorld.state.isnight then    
                    inst.light:SetFalloff(0.75)
                    inst.light:SetIntensity(.6)
                    inst.light:SetRadius(10)
                    inst.light:SetColour(169/255, 231/255, 245/255)
                    inst.light:Enable(true)
                    inst.AnimState:SetBloomEffectHandle( "shaders/anim.ksh" )
                else
                    inst.light:Enable(false)
                end
            elseif inst.dwarventonicresttime == 0 then
                inst.components.sanity.dapperness = inst.components.sanity.dapperness + TUNING.DAPPERNESS_MED_LARGE
                inst.light:Enable(false)
                inst.dwarventonicresttime= inst.dwarventonicresttime - 1
            end
        end
        --dwarvenale
        if inst.dwarvenaleresttime then    
            if inst.dwarvenaleresttime > 0 then            
                inst.dwarvenaleresttime = inst.dwarvenaleresttime - 1
            elseif inst.dwarvenaleresttime == 0 then
                inst.dwarvenaleresttime = inst.dwarvenaleresttime - 1
                inst.components.sanity.dapperness = inst.components.sanity.dapperness + TUNING.DAPPERNESS_MED_LARGE
                inst.components.combat.damagemultiplier = inst.components.combat.damagemultiplier / 2
            end
        end
    end)
end    

return MakePlayerCharacter("skyminer", prefabs, assets, common_postinit, master_postinit, start_inv)
 

Thanks, now the warhamer works as well as it should.

But now I have the problem that when I mine boulders or drop gold the game crashes the same way as before.

It says: TUNING_MINING_SANITY is not declared, even though I specified it in the modmain.

What is causing the crash? I can't tell...

 

it should be TUNING.MINING_SANITY not TUNING_MINING_SANITY . instead _ after tuning

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