Jump to content

Triggering Periodic Spawner with Hunger Threshold


Recommended Posts

Hey guys, just started modding DST again. I'm working on a character that gets diarrhea on full stomach, pooping rapidly and draining sanity when her hunger is above 150.

I copied the relevant parts of the periodic poop spawner from the beefalo.lua, and figured use the hunger threshold trigger from Wolfgang's code to trigger a switch in hunger rate and trigger the period spawner of poop. This is what I ended up doing:

local function onhungerchange(inst, data)

    if inst.components.hunger.current > 150  then 
	inst.components.hunger.hungerrate = 20 * TUNING.WILSON_HUNGER_RATE
    inst.components.periodicspawner:Start()
	else 
    end
	
	end

On the bright side, it doesn't crash the game, but it doesn't seem to change either the hunger rate or trigger the poop spawner. (Also I'm not sure how I would code the sanity drain when above the threshold, but I can probably figure it out later)

 

local MakePlayerCharacter = require "prefabs/player_common"


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

-- Custom starting items
local start_inv = {
"boomerang",
}
	
	

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

local function onbecameghost(inst)
	-- Remove speed modifier when becoming a ghost
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "winnie_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( "winnie.tex" )
	inst:AddTag( "winnie" )
	
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 = "winnie"
	
	-- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
    --inst.talker_path_override = "dontstarve_DLC001/characters/"
	inst.components.combat:SetAttackPeriod(0.5)
	-- Stats	
	inst.components.health:SetMaxHealth(150)
	inst.components.hunger:SetMax(200)
	inst.components.sanity:SetMax(200)
	
	inst:AddComponent("periodicspawner")
    inst.components.periodicspawner:SetPrefab("poopy")
    inst.components.periodicspawner:SetRandomTimes(60, 90)
    inst.components.periodicspawner:Start()
	
	
	-- Damage multiplier (optional)
    inst.components.combat.damagemultiplier = 1
	
	inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED* 1)
    inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED* 1)
	inst.Transform:SetScale( 1,  1, 1)

	-- Hunger rate (optional)
	inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE
	
	inst:AddComponent("periodicspawner")
    inst.components.periodicspawner:SetPrefab("poop")
    inst.components.periodicspawner:SetRandomTimes(1,1)
	
	local Combat = Class(function(self, inst)
	--attack range is how far away the enemy is where the player will try to take a jab at it
	inst.components.combat.attackrange = 1
	--hitrange how far the player can actually hit
	inst.components.combat.hitrange = 1
	--attack_period is how long it takes to attack
	inst.components.combat.min_attack_period = 1
    end)
	 
	
	inst.OnLoad = onload
    inst.OnNewSpawn = onload
	
	
	end
	
	local function onhungerchange(inst, data)

    if inst.components.hunger.current > 150  then 
	inst.components.hunger.hungerrate = 20 * TUNING.WILSON_HUNGER_RATE
    inst.components.periodicspawner:Start()
	else 
    end
	
	end
	

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

 

Link to comment
Share on other sites

I don't see inst:ListenForEvent("hungerdelta", onhungerchange), so that function is probably never getting called.  Also why is there an else statement in your onhungerchange function?  To change sanity drain could probably use sanity.dapperness.

Link to comment
Share on other sites

16 hours ago, Wolf_EX said:

I don't see inst:ListenForEvent("hungerdelta", onhungerchange), so that function is probably never getting called.  Also why is there an else statement in your onhungerchange function?  To change sanity drain could probably use sanity.dapperness.

Cool this worked for me!

Link to comment
Share on other sites

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
 Share

×
  • Create New...