Jump to content

Recommended Posts

Hello,

I am not that great at coding and it has never liked me either but I am trying to make a character where I lose sanity regardless of day and night and gain only upon killing things. I used ESCT and had to take snippets of code from characters I have come across. I have been trying all day to search for a way to get these two critical character aspects to work together but the don't seem to want to work together. Right now the whole killing to gain sanity is not working. Below is my entire code. Any help would greatly be appreciated, thank you!


local MakePlayerCharacter = require "prefabs/player_common"


local assets = {
    Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
}
local prefabs = {}

-- Custom starting items
local start_inv = {
}


--Things to restore upon respawning
function restorestatdoom_marine(inst)
        inst.Light:SetRadius(8)
        inst.Light:SetFalloff(4)
        inst.Light:SetIntensity(0.3)
        inst.Light:SetColour(245/255,100/255,100/255)
        inst.Light:Enable(true)
        inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 2)
        inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 2)
    end

local common_postinit = function(inst)
inst.soundsname = "s115"
        inst.entity:AddLight()
        inst.Light:SetRadius(8)
        inst.Light:SetFalloff(4)
        inst.Light:SetIntensity(0.3)
        inst.Light:SetColour(245/255,100/255,100/255)
        inst.Light:Enable(true)
end

 

 

local function onkill(inst, data)
    local delta = 5
    inst.components.sanity:DoDelta(delta)
end
-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)
    -- choose which sounds this character will play
    inst.soundsname = "willow"
    
    -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
    --inst.talker_path_override = "dontstarve_DLC001/characters/"
    
    -- Stats    
    inst.components.health:SetMaxHealth(250)
    inst.components.hunger:SetMax(100)
    inst.components.sanity:SetMax(100)
    inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 2)
    inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 2)

inst.components.sanity.dapperness = TUNING.DAPPERNESS_SMALL * (-8) --Sanity lost during the day.
    inst.components.hunger.hungerrate = 0.19
    inst.components.sanity.neg_aura_mult = 0
    inst.components.sanity.night_drain_mult = .6
    inst.components.catcher.catchdistance = 0
    inst.components.temperature.overheattemp = 1000
    
    -- Damage multiplier (optional)
    inst.components.combat.damagemultiplier = 3
    
--Prevent Overheating and Freezing
    inst.components.temperature.mintemp = 20.    
    inst.components.temperature.maxtemp = 60.
    
    --Listen for respawn, and after restore stats
    inst:ListenForEvent("entity_death", function(wrld, data) onkill(inst, data) end, GetWorld())
        
        
        
        --Listen for respawn, and after restore stats
    inst:ListenForEvent("respawnfromghost", function()
    inst:DoTaskInTime(7, restorestats115)
    
end)
end

 


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

 

1 hour ago, SuperDavid said:

I can give you code to make it that he restores sanity when he hits something but I don't know for killing sorry.


inst:ListenForEvent("onattackother", function(inst, data)
inst.components.sanity:DoDelta(1)
end)

 

If I cant figure it out I will definitely use this or maybe use this in tandem with the kill code. Thank you so much for this, I didn't even think of it! The character I am making is based of the Doom Marine and this would fit nicely.

10 hours ago, SuperDavid said:

I can give you code to make it that he restores sanity when he hits something but I don't know for killing sorry.


inst:ListenForEvent("onattackother", function(inst, data)
inst.components.sanity:DoDelta(1)
end)

 

probably better to use the event "killed" as it only triggers when you kill something, while onattackother triggers on every attack

inst:ListenForEvent("killed", function(inst, data)
	if not data.victim:HasTag("structure") and not data.victim:HasTag("wall") then
		inst.components.sanity:DoDelta(5)
	end
end)

 

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