BloxingGames Posted November 7, 2017 Share Posted November 7, 2017 Hello, I have been making a character mod for DST and I ran into an error as I'm trying to make my character heal in the rain but I can't get it to work. The full code is below but here is the main bit and how I call on the function (NOTE: he also glows in the dark if the light part of the code was confusing.) ---------MAIN BIT--------- local rainheal = function(inst) if c_moisture => 1 then c_setmoisture(c_moisture - 1) c_sethealth(c_health + 1) end end -- Hunger rate (optional) inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE inst:DoPeriodicTask(2/1, function() rainheal(inst) end) -------FULL CODE-------- local MakePlayerCharacter = require "prefabs/player_common" local assets = { Asset("SCRIPT", "scripts/prefabs/player_common.lua"), } local prefabs = {} -- Custom starting items local start_inv = { } -- When the character is revived from human local function onbecamehuman(inst) -- Set speed when reviving from ghost (optional) inst.components.locomotor:SetExternalSpeedMultiplier(inst, "pete_speed_mod", 1) local Light = inst.entity:AddLight() inst.Light:Enable(true) inst.Light:SetRadius(0.45) inst.Light:SetIntensity(0.55) inst.Light:SetFalloff(0.5) inst.Light:SetColour(255/255, 255/255, 150/255) end local function onbecameghost(inst) -- Remove speed modifier when becoming a ghost inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "pete_speed_mod") local Light = inst.entity:AddLight() inst.Light:Enable(true) inst.Light:SetRadius(0.45) inst.Light:SetIntensity(0.55) inst.Light:SetFalloff(0.5) inst.Light:SetColour(255/255, 255/255, 150/255) end -- When loading or spawning the character local function onload(inst) inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman) inst:ListenForEvent("ms_becameghost", onbecameghost) local Light = inst.entity:AddLight() inst.Light:Enable(true) inst.Light:SetRadius(0.45) inst.Light:SetIntensity(0.55) inst.Light:SetFalloff(0.5) inst.Light:SetColour(255/255, 255/255, 150/255) 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( "pete.tex" ) end local rainheal = function(inst) if c_moisture => 1 then c_setmoisture(c_moisture - 1) c_sethealth(c_health + 1) 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.soundsname = "webber" -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used inst.talker_path_override = "dontstarve_DLC001/characters/" -- Stats inst.components.health:SetMaxHealth(100) inst.components.hunger:SetMax(250) inst.components.sanity:SetMax(80) -- Damage multiplier (optional) inst.components.combat.damagemultiplier = 1.05 -- Hunger rate (optional) inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE inst:DoPeriodicTask(2/1, function() rainheal(inst) end) inst.OnLoad = onload inst.OnNewSpawn = onload local Light = inst.entity:AddLight() inst.Light:Enable(true) inst.Light:SetRadius(0.45) inst.Light:SetIntensity(0.55) inst.Light:SetFalloff(0.5) inst.Light:SetColour(255/255, 255/255, 150/255) end return MakePlayerCharacter("pete", prefabs, assets, common_postinit, master_postinit, start_inv) Link to comment Share on other sites More sharing options...
Cunning fox Posted November 9, 2017 Share Posted November 9, 2017 local function OnRainHeal(inst) if inst.components.moisture ~= nil and inst.components.moisture:GetMoisturePercent() == 1 then inst.components.health:DoDelta(1) inst:DoTaskInTime(math.random()*10 + 5, OnRainHeal) end end 1 Link to comment Share on other sites More sharing options...
BloxingGames Posted November 9, 2017 Author Share Posted November 9, 2017 Thank you very much. I will test this out! Link to comment Share on other sites More sharing options...
BloxingGames Posted November 11, 2017 Author Share Posted November 11, 2017 I couldn't get this to work: (I did some messing around to try and get it to work) local function OnRainHeal(inst) if inst.components.moisture ~= nil and inst.components.moisture:GetMoisturePercent() == 1 then inst.components.health:DoDelta(1) inst:DoTaskInTime(math.random(1,10), OnRainHeal) end end inst:DoPeriodicTask(1/10, function() OnRainHeal(inst) end) Link to comment 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