Jump to content

[Mod Request] Make gobblers run away from Gnomes

Recommended Posts

Hey there,
I'm not a fan of huge berry bushes farms, and while I usually keep a few of them in a straight line with tooth traps in between I started thinking of some other way to keep the gobblers away from berry bushes clustered in a medium sized garden space. 

And what I was thinking is this: I know that people keep Gnomes statues in their garden for looks (irl), but what if the Gnomes (both male and female versions) would scare gobblers away? One could put the gnomes between their berry bushes and not have to worry about them bloody gobblers eating away the fruits.
Considering how Gnomes, and trinkets in general, aren't something you stumble upon on a daily basis, it would make digging the graves or scavenging tumbleweeds for gnomes quite a hefty mission for the players wanting a tight security on their berry bushes farms.
I've had a look myself at the perd.lua and perdbrain.lua files, and while I have a slight idea of how gobblers get scared and why they start running away when the player approaches, I wouldn't know what to modify in the code structure not to mention about making a mod with the feature I'm requesting. :-)
For anyone wanting to have a quick look at the 2 files mentioned above, I'll include each in a spoiler bellow:


require "behaviours/wander"require "behaviours/runaway"require "behaviours/doaction"require "behaviours/panic"local STOP_RUN_DIST = 10local SEE_PLAYER_DIST = 5local SEE_GNOME_DIST = 2local SEE_FOOD_DIST = 20local SEE_BUSH_DIST = 40local MAX_WANDER_DIST = 80local PerdBrain = Class(Brain, function(self, inst)    Brain._ctor(self, inst)end)local function FindNearestBush(inst)    local bush = FindEntity(inst, SEE_BUSH_DIST, function(bush) return bush.components.pickable and bush.components.pickable:CanBePicked() end, {"bush"})    return bush or (inst.components.homeseeker and inst.components.homeseeker.home)endlocal function HomePos(inst)    local bush = FindNearestBush(inst)    if bush then        return Vector3(bush.Transform:GetWorldPosition() )    endendlocal function GoHomeAction(inst)    local bush = FindNearestBush(inst)    if bush then        return BufferedAction(inst, bush, ACTIONS.GOHOME, nil, Vector3(bush.Transform:GetWorldPosition() ) )    endendlocal function EatFoodAction(inst)    local target = nil    if inst.components.inventory and inst.components.eater then        target = inst.components.inventory:FindItem(function(item) return inst.components.eater:CanEat(item) end)    end    if not target then        target = FindEntity(inst, SEE_FOOD_DIST, function(item) return inst.components.eater:CanEat(item) end)        if target then            --check for scary things near the food            local predator = GetClosestInstWithTag("scarytoprey", target, SEE_PLAYER_DIST)			local predator = GetClosestInstWithTag("scarytoprey", target, SEE_GNOME_DIST)            if predator then target = nil end        end    end    if target then        local act = BufferedAction(inst, target, ACTIONS.EAT)        act.validfn = function() return not (target.components.inventoryitem and target.components.inventoryitem.owner and target.components.inventoryitem.owner ~= inst) end        return act    endendlocal function PickBerriesAction(inst)    local target = FindEntity(inst, SEE_FOOD_DIST, function(item)        return item.components.pickable               and item.components.pickable:CanBePicked()               and item.components.pickable.product == "berries"    end)    if target then        --check for scary things near the bush        local predator = GetClosestInstWithTag("scarytoprey", target, SEE_PLAYER_DIST)		local predator = GetClosestInstWithTag("scarytoprey", target, SEE_GNOME_DIST)        if predator then target = nil end    end    if target then        return BufferedAction(inst, target, ACTIONS.PICK)    endendfunction PerdBrain:OnStart()    local root = PriorityNode(    {        WhileNode( function() return self.inst.components.hauntable and self.inst.components.hauntable.panic end, "PanicHaunted", Panic(self.inst)),        WhileNode( function() return self.inst.components.health.takingfiredamage end, "OnFire", Panic(self.inst)),        WhileNode(function() return not TheWorld.state.isday end, "IsNight",            DoAction(self.inst, GoHomeAction, "Go Home", true )),        DoAction(self.inst, EatFoodAction, "Eat Food"),        RunAway(self.inst, "scarytoprey", SEE_PLAYER_DIST, STOP_RUN_DIST),		RunAway(self.inst, "scarytoprey", SEE_PLAYER_DIST, STOP_RUN_DIST),        DoAction(self.inst, PickBerriesAction, "Pick Berries", true),        Wander(self.inst, HomePos, MAX_WANDER_DIST),    }, .25)        self.bt = BT(self.inst, root)endreturn PerdBrain 


local assets ={    Asset("ANIM", "anim/perd_basic.zip"),    Asset("ANIM", "anim/perd.zip"),    Asset("SOUND", "sound/perd.fsb"),}local prefabs ={    "drumstick",}local brain = require "brains/perdbrain"local loot ={    "drumstick",    "drumstick",}local function ShouldWake()    --always wake up if we're asleep    return trueendlocal function fn()    local inst = CreateEntity()    inst.entity:AddTransform()    inst.entity:AddAnimState()    inst.entity:AddSoundEmitter()    inst.entity:AddDynamicShadow()    inst.entity:AddNetwork()    MakeCharacterPhysics(inst, 50, .5)    inst.DynamicShadow:SetSize(1.5, .75)    inst.Transform:SetFourFaced()    inst.AnimState:SetBank("perd")    inst.AnimState:SetBuild("perd")    inst.AnimState:Hide("hat")    inst:AddTag("character")    inst:AddTag("berrythief")    inst.entity:SetPristine()    if not TheWorld.ismastersim then        return inst    end    inst:AddComponent("locomotor")    inst.components.locomotor.runspeed = TUNING.PERD_RUN_SPEED    inst.components.locomotor.walkspeed = TUNING.PERD_WALK_SPEED    inst:SetStateGraph("SGperd")    inst:AddComponent("homeseeker")    inst:SetBrain(brain)    inst:AddComponent("eater")    inst.components.eater:SetDiet({ FOODTYPE.VEGGIE }, { FOODTYPE.VEGGIE })    inst.components.eater:SetCanEatRaw()    inst:AddComponent("sleeper")    inst.components.sleeper:SetWakeTest(ShouldWake)    inst:AddComponent("health")    inst:AddComponent("combat")    inst.components.combat.hiteffectsymbol = "pig_torso"    inst.components.health:SetMaxHealth(TUNING.PERD_HEALTH)    inst.components.combat:SetDefaultDamage(TUNING.PERD_DAMAGE)    inst.components.combat:SetAttackPeriod(TUNING.PERD_ATTACK_PERIOD)    inst:AddComponent("lootdropper")    inst.components.lootdropper:SetLoot(loot)    inst:AddComponent("inventory")    inst:AddComponent("inspectable")    MakeHauntablePanic(inst)    MakeMediumBurnableCharacter(inst, "pig_torso")    MakeMediumFreezableCharacter(inst, "pig_torso")    return instendreturn Prefab("forest/animals/perd", fn, assets, prefabs) 

Edited by ailailou
Link to comment
Share on other sites

It's fairly easy to implement if you use tags.
local garden_gnomes = {"trinket_4","trinket_13"}
for i, gnome in ipairs(garden_gnomes) do
    AddPrefabPostInit(gnome, function(inst)
But the side effect is that all small animals will run away from gnomes.

Edited by Isosurface
Link to comment
Share on other sites

@Isosurface, I can't say I mind the downside of your solution. :grin: Any chance you could turn it into a mod, maybe on the steam workshop for dst? If you're up to it I'll gladly help out by providing a picture for the mod or a description!

Edited by ailailou
Link to comment
Share on other sites




"Just plant the gnomes in the garden and laugh your ass off at the panicked gobblers." - applebottom



Hehe, feel free to use the image above, as far the description goes I'd put that quote in it with Applebottom's permission, but that'd be just me. :grin:


Let us know when the mod is up on the workshop! :-)


-edit- Oh, I just realized you're the creator of "Ownership and PvP Traps". Sweet mod, I've been using it for quite some time now. I like the way you put your mod icons in a square box so I think it would be better to use the style of your previews. ^^

Edited by ailailou
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

  • Create New...