Don't Starve Together

Don't Starve Together

Better pet
Mooka 30 Nov, 2018 @ 12:26pm
Broodling change suggestion
Hi, I made some changes to your mod. I have added you on the steam to talk about it and know if you want to subbmit the changes to your mod but i'll just post it here.

Broodling:
Can cook food. (Plays fire animation)
Has 1.2 radius light when fed. (Decreases over time. 100% hungry = 100% light radius).

The change in cooker.lua was necessary to play the fire animation when cooking food with broodling.

cooker.lua
local Cooker = Class(function(self, inst) self.inst = inst self.oncookfn = nil; --V2C: Recommended to explicitly add tag to prefab pristine state inst:AddTag("cooker") end) function Cooker:OnRemoveFromEntity() self.inst:RemoveTag("cooker") end function Cooker:CanCook(item, chef) return item ~= nil and item.components.cookable ~= nil and not (self.inst.components.fueled ~= nil and self.inst.components.fueled:IsEmpty()) and not (item.components.burnable ~= nil and item.components.burnable:IsBurning()) and not (item.components.projectile ~= nil and item.components.projectile:IsThrown()) and (not self.inst:HasTag("dangerouscooker") or chef:HasTag("expertchef")) --V2C: don't do held or canbepickedup checks here, because it's really -- inconsistent; lots of code that shoves not canbepickedup things -- into your inventory! end function Cooker:CookItem(item, chef) if self:CanCook(item, chef) then local newitem = item.components.cookable:Cook(self.inst, chef) ProfileStatsAdd("cooked_"..item.prefab) if self.oncookitem ~= nil then self.oncookitem(item, newitem) end local sound_inst = self.inst.components.inventoryitem ~= nil and self.inst.components.inventoryitem:GetGrandOwner() or self.inst if sound_inst.SoundEmitter ~= nil then sound_inst.SoundEmitter:PlaySound("dontstarve/wilson/cook") end if self.oncookfn ~= nil then self.oncookfn(self.inst, newitem, chef) end item:Remove() if(oncookfn ~= nil) then self.oncookfn(self.inst, item) end return newitem end end return Cooker

critters.lua
local brain = require("brains/crittersbrain") local WAKE_TO_FOLLOW_DISTANCE = 6 local SLEEP_NEAR_LEADER_DISTANCE = 5 local HUNGRY_PERISH_PERCENT = 0.5 -- matches stale tag local STARVING_PERISH_PERCENT = 0.2 -- matches spoiked tag local BUFFTIME = 240 local BUFFMULT = 1.2 local function IsLeaderSleeping(inst) return inst.components.follower.leader and inst.components.follower.leader:HasTag("sleeping") end local function ShouldWakeUp(inst) return (DefaultWakeTest(inst) and not IsLeaderSleeping(inst)) or not inst.components.follower:IsNearLeader(WAKE_TO_FOLLOW_DISTANCE) end local function ShouldSleep(inst) return (DefaultSleepTest(inst) or IsLeaderSleeping(inst)) and inst.components.follower:IsNearLeader(SLEEP_NEAR_LEADER_DISTANCE) end local function oneat(inst, food) local owner = inst.components.follower.leader if inst.prefab == "critter_puppy" then --小狗 if not owner:HasTag("puppypower") then print("puppy power!") owner:AddTag("puppypower") if owner.components.combat.damagemultiplier then owner.components.combat.damagemultiplier = owner.components.combat.damagemultiplier*BUFFMULT else owner.components.combat.damagemultiplier = BUFFMULT end owner:DoTaskInTime(BUFFTIME, function() owner.components.combat.damagemultiplier = owner.components.combat.damagemultiplier/BUFFMULT owner:RemoveTag("puppypower") end) end end if inst.prefab == "critter_kitten" then --小猫 if not owner:HasTag("kittenspeed") then print("kitten speed!") owner:AddTag("kittenspeed") owner.components.locomotor.walkspeed = owner.components.locomotor.walkspeed*BUFFMULT owner.components.locomotor.runspeed = owner.components.locomotor.runspeed*BUFFMULT owner:DoTaskInTime(BUFFTIME, function() owner.components.locomotor.walkspeed = owner.components.locomotor.walkspeed/BUFFMULT owner.components.locomotor.runspeed = owner.components.locomotor.runspeed/BUFFMULT owner:RemoveTag("kittenspeed") end) end end if inst.prefab == "critter_perdling" then --小鸡 SpawnPrefab("redpouch").Transform:SetPosition(inst.Transform:GetWorldPosition()) end -- minigame around feeding, if fed at the right time, its max hunger goes up, if left too long, its max hunger goes down local perish = inst.components.perishable:GetPercent() local is_wellfed = inst.components.crittertraits:IsDominantTrait("wellfed") if perish <= STARVING_PERISH_PERCENT then inst.components.perishable.perishtime = math.max(inst.components.perishable.perishtime - TUNING.CRITTER_HUNGERTIME_DELTA, is_wellfed and TUNING.CRITTER_DOMINANTTRAIT_HUNGERTIME_MIN or TUNING.CRITTER_HUNGERTIME_MIN) elseif perish <= HUNGRY_PERISH_PERCENT then inst.components.perishable.perishtime = math.min(inst.components.perishable.perishtime + TUNING.CRITTER_HUNGERTIME_DELTA, is_wellfed and TUNING.CRITTER_DOMINANTTRAIT_HUNGERTIME_MAX or TUNING.CRITTER_HUNGERTIME_MAX) else if is_wellfed and inst.components.perishable.perishtime < TUNING.CRITTER_DOMINANTTRAIT_HUNGERTIME_MIN then inst.components.perishable.perishtime = TUNING.CRITTER_DOMINANTTRAIT_HUNGERTIME_MIN end end inst.components.perishable:SetPercent(1) inst.components.perishable:StartPerishing() if inst.prefab == "critter_dragonling" then inst.DragonlingLightUpdate(inst) end end ------------------------------------------------------------------------------- local function DragonlingLightUpdate(inst) local owner = inst.components.follower.leader local hungryPercent = inst.components.perishable:GetPercent() if hungryPercent == 0 then inst.Light:SetRadius(0) else inst.Light:SetRadius(1.2 * hungryPercent) owner:DoTaskInTime(30, function() inst.DragonlingLightUpdate(inst) end) end end ------------------------------------------------------------------------------- local function OnCook(inst, item) if inst.prefab == "critter_dragonling" then -- play fire animation inst.AnimState:PlayAnimation("emote_flame") end end ------------------------------------------------------------------------------- local function GetPeepChance(inst) local hunger_percent = inst.components.perishable:GetPercent() if hunger_percent <= 0 then return 0.8 elseif hunger_percent < STARVING_PERISH_PERCENT then -- matches spoiled tag return (0.2 - inst.components.perishable:GetPercent()) * 2 elseif hunger_percent < HUNGRY_PERISH_PERCENT then return 0.025 end return 0 end local function IsAffectionate(inst) return (inst.components.perishable == nil or inst.components.perishable:GetPercent() > STARVING_PERISH_PERCENT) or false end local function IsPlayful(inst) return IsAffectionate(inst) end local function IsSuperCute(inst) return true end ------------------------------------------------------------------------------- local function OnSave(inst, data) if inst.wormlight ~= nil then data.wormlight = inst.wormlight:GetSaveRecord() end end local function OnLoad(inst, data) if data ~= nil and data.wormlight ~= nil and inst.wormlight == nil then local wormlight = SpawnSaveRecord(data.wormlight) if wormlight ~= nil and wormlight.components.spell ~= nil then wormlight.components.spell:SetTarget(inst) if wormlight:IsValid() then if wormlight.components.spell.target == nil then wormlight:Remove() else wormlight.components.spell:ResumeSpell() end end end end end ------------------------------------------------------------------------------- local function MakeCritter(name, animname, face, diet, flying, data) local assets = { Asset("ANIM", "anim/"..animname.."_build.zip"), Asset("ANIM", "anim/"..animname.."_basic.zip"), Asset("ANIM", "anim/"..animname.."_emotes.zip"), Asset("ANIM", "anim/"..animname.."_traits.zip"), } local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddSoundEmitter() inst.entity:AddDynamicShadow() inst.entity:AddNetwork() inst.DynamicShadow:SetSize(2, .75) if face == 2 then inst.Transform:SetTwoFaced() elseif face == 4 then inst.Transform:SetFourFaced() elseif face == 6 then inst.Transform:SetSixFaced() elseif face == 8 then inst.Transform:SetEightFaced() end if name == "critter_dragonling" then --小蜻蜓 inst.entity:AddLight() inst.Light:SetRadius(1.5) inst.Light:SetFalloff(0.5) inst.Light:SetIntensity(0.75) inst.Light:SetColour(235/255, 121/255, 12/255) inst.Light:Enable(true) inst:AddTag("cooker") inst:AddComponent("cooker") inst.components.cooker.oncookfn = OnCook end inst.AnimState:SetBank(animname) inst.AnimState:SetBuild(animname.."_build") inst.AnimState:PlayAnimation("idle_loop") if flying then --We want to collide with players --MakeFlyingCharacterPhysics(inst, 1, .5) inst.entity:AddPhysics() inst.Physics:SetMass(1) inst.Physics:SetCapsule(.5, 1) inst.Physics:SetFriction(0) inst.Physics:SetDamping(5) inst.Physics:SetCollisionGroup(COLLISION.CHARACTERS) inst.Physics:ClearCollisionMask() inst.Physics:CollidesWith(COLLISION.WORLD) inst.Physics:CollidesWith(COLLISION.FLYERS) inst.Physics:CollidesWith(COLLISION.CHARACTERS) inst:AddTag("flying") else MakeCharacterPhysics(inst, 1, .5) end inst:AddTag("critter") inst:AddTag("companion") inst:AddTag("notraptrigger") inst:AddTag("noauradamage") inst:AddTag("small_livestock") inst:AddTag("NOBLOCK") if data ~= nil and data.flyingsoundloop ~= nil then inst.SoundEmitter:PlaySound(data.flyingsoundloop, "flying") end inst:AddComponent("spawnfader") inst.entity:SetPristine() if not TheWorld.ismastersim then if name == "critter_lamb" then inst:DoTaskInTime(0, function() inst.replica.container:WidgetSetup("chester") end) end return inst end if name == "critter_lamb" then --小绵羊 inst:AddComponent("container") inst.components.container:WidgetSetup("chester") end if name == "critter_glomling" then --小格格姆 inst:AddComponent("sanityaura") inst.components.sanityaura.aura = TUNING.SANITYAURA_TINY end inst.favoritefood = data.favoritefood inst.GetPeepChance = GetPeepChance inst.IsAffectionate = IsAffectionate inst.IsSuperCute = IsSuperCute inst.IsPlayful = IsPlayful inst.DragonlingLightUpdate = DragonlingLightUpdate inst.playmatetags = {"critter"} if data ~= nil and data.playmatetags ~= nil then inst.playmatetags = JoinArrays(inst.playmatetags, data.playmatetags) end inst:AddComponent("inspectable") inst:AddComponent("follower") inst.components.follower:KeepLeaderOnAttacked() inst.components.follower.keepdeadleader = true inst:AddComponent("knownlocations") inst:AddComponent("sleeper") inst.components.sleeper:SetResistance(3) inst.components.sleeper.testperiod = GetRandomWithVariance(6, 2) inst.components.sleeper:SetSleepTest(ShouldSleep) inst.components.sleeper:SetWakeTest(ShouldWakeUp) inst:AddComponent("eater") inst.components.eater:SetDiet(diet, diet) inst.components.eater:SetOnEatFn(oneat) inst:AddComponent("perishable") inst.components.perishable:SetPerishTime(TUNING.CRITTER_HUNGERTIME) inst.components.perishable:StartPerishing() inst:AddComponent("locomotor") inst.components.locomotor:EnableGroundSpeedMultiplier(not flying) inst.components.locomotor:SetTriggersCreep(false) inst.components.locomotor.softstop = true inst.components.locomotor.walkspeed = TUNING.CRITTER_WALK_SPEED inst:AddComponent("crittertraits") inst:AddComponent("timer") inst:SetBrain(brain) inst:SetStateGraph("SG"..name) --MakeMediumFreezableCharacter(inst, "critters_body") --MakeHauntablePanic(inst) inst.OnSave = OnSave inst.OnLoad = OnLoad if inst.prefab == "critter_dragonling" then inst.DragonlingLightUpdate(inst) end return inst end return Prefab(name, fn, assets) end ------------------------------------------------------------------------------- local function builder_onbuilt(inst, builder) local theta = math.random() * 2 * PI local pt = builder:GetPosition() local radius = 1 local offset = FindWalkableOffset(pt, theta, radius, 6, true) if offset ~= nil then pt.x = pt.x + offset.x pt.z = pt.z + offset.z end builder.components.petleash:SpawnPetAt(pt.x, 0, pt.z, inst.pettype, inst.skin_name) inst:Remove() end local function MakeBuilder(prefab) local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst:AddTag("CLASSIFIED") --[[Non-networked entity]] inst.persists = false --Auto-remove if not spawned by builder inst:DoTaskInTime(0, inst.Remove) if not TheWorld.ismastersim then return inst end inst.pettype = prefab inst.OnBuiltFn = builder_onbuilt return inst end return Prefab(prefab.."_builder", fn, nil, { prefab }) end ------------------------------------------------------------------------------- local standard_diet = { FOODGROUP.OMNI } return MakeCritter("critter_lamb", "sheepington", 6, standard_diet, false, {favoritefood="guacamole"}), MakeBuilder("critter_lamb"), MakeCritter("critter_puppy", "pupington", 4, standard_diet, false, {favoritefood="monsterlasagna"}), MakeBuilder("critter_puppy"), MakeCritter("critter_kitten", "kittington", 6, standard_diet, false, {favoritefood="fishsticks"}), MakeBuilder("critter_kitten"), MakeCritter("critter_perdling", "perdling", 4, standard_diet, false, {favoritefood="trailmix"}), MakeBuilder("critter_perdling"), MakeCritter("critter_dragonling", "dragonling", 6, standard_diet, true, {favoritefood="hotchili", flyingsoundloop="dontstarve_DLC001/creatures/together/dragonling/fly_LP"}), MakeBuilder("critter_dragonling"), MakeCritter("critter_glomling", "glomling", 6, standard_diet, true, {favoritefood="taffy", playmatetags={"glommer"}, flyingsoundloop="dontstarve_DLC001/creatures/together/glomling/flap_LP"}), MakeBuilder("critter_glomling")
Last edited by Mooka; 30 Nov, 2018 @ 12:29pm
< >
Showing 1-1 of 1 comments
john silent hill 17 Mar, 2022 @ 1:49pm 
how much time did you spend on this?
< >
Showing 1-1 of 1 comments
Per page: 1530 50