Jump to content

Need help making bees neutral


Recommended Posts

I'm struggling with a few perks for my character mod. Namely, the ability to approach killer bee hives and harvest bee boxes without the resident bees attacking the character.

Spoiler


local MakePlayerCharacter = require "prefabs/player_common"


local assets = {
    Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
    Asset( "ANIM", "anim/player_basic.zip" ),
    Asset( "ANIM", "anim/player_idles_shiver.zip" ),
    Asset( "ANIM", "anim/player_actions.zip" ),
    Asset( "ANIM", "anim/player_actions_axe.zip" ),
    Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),
    Asset( "ANIM", "anim/player_actions_shovel.zip" ),
    Asset( "ANIM", "anim/player_actions_blowdart.zip" ),
    Asset( "ANIM", "anim/player_actions_eat.zip" ),
    Asset( "ANIM", "anim/player_actions_item.zip" ),
    Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),
    Asset( "ANIM", "anim/player_actions_bugnet.zip" ),
    Asset( "ANIM", "anim/player_actions_fishing.zip" ),
    Asset( "ANIM", "anim/player_actions_boomerang.zip" ),
    Asset( "ANIM", "anim/player_bush_hat.zip" ),
    Asset( "ANIM", "anim/player_attacks.zip" ),
    Asset( "ANIM", "anim/player_idles.zip" ),
    Asset( "ANIM", "anim/player_rebirth.zip" ),
    Asset( "ANIM", "anim/player_jump.zip" ),
    Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),
    Asset( "ANIM", "anim/player_teleport.zip" ),
    Asset( "ANIM", "anim/wilson_fx.zip" ),
    Asset( "ANIM", "anim/player_one_man_band.zip" ),
    Asset( "ANIM", "anim/shadow_hands.zip" ),
    Asset( "SOUND", "sound/sfx.fsb" ),
    Asset( "SOUND", "sound/wilson.fsb" ),
    Asset( "ANIM", "anim/beard.zip" ),
}
local prefabs = {
"bee", "killerbee",}

-- Custom starting items
local start_inv = {
"bee",
"bee",
"bee",
"bee",
"bee",
"bee",
"bee",
"bee",
"butterfly",
"butterfly",
"butterfly",
"butterfly",
"butterfly",
"butterfly",
"butterfly",
"butterfly",
"butterfly",
"butterfly",
"honeycomb",
"honeycomb",
"boards",
"boards",
"boards",
"boards",
"beebox_blueprint",
}

-- When the character is revived from human
local function onbecamehuman(inst)
    -- Set speed when reviving from ghost (optional)
end

local function onbecameghost(inst)
    -- Remove speed modifier when becoming a ghost
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "apidae_speed_mod", 1)
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( "apidae.tex" )
    
    inst:AddTag("bee")
    inst:AddTag("insect")
    inst:AddTag("smallcreature")
    inst:AddTag("flying")
    inst:AddTag ("worker")
    inst:AddTag ("pollinator")
    inst:AddTag ("flower")
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 = "wx78"
    
    -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
    --inst.talker_path_override = "dontstarve_DLC001/characters/"
    
    -- Damage multiplier (optional)
    inst.components.combat.damagemultiplier = 1
    
    -- Hunger rate (optional)
    inst.components.hunger.hungerrate = 0.5 * TUNING.WILSON_HUNGER_RATE
    
    -- Stats

local function OnHit(inst, attacker, damage)
    if inst.components.childspawner ~= nil then
        inst.components.childspawner:ReleaseAllChildren(attacker, "killerbee")
        inst.components.childspawner.childname = "killerbee"
        inst.components.childspawner:SetMaxChildren(10)
        inst.components.childspawner.emergencychildname = "killerbee"
        inst.components.childspawner.emergencychildrenperplayer = 1
        inst.components.childspawner:SetMaxEmergencyChildren(10)
        inst.components.childspawner:SetEmergencyRadius(TUNING.WASPHIVE_EMERGENCY_RADIUS)
    end
end

local function SeasonalSpawnChanges(inst, season)
    if inst.components.childspawner ~= nil then
        if season == SEASONS.SPRING then
            inst.components.health:SetMaxHealth(150)
            inst.components.hunger:SetMax(100)
            inst.components.sanity:SetMax(150)
            inst.components.combat.damagemultiplier = 1.5
            inst.components.locomotor.walkspeed = 9
            inst.components.locomotor.runspeed = 10
        elseif season == SEASONS.SUMMER then
            inst.components.health:SetMaxHealth(125)
            inst.components.hunger:SetMax(90)
            inst.components.sanity:SetMax(125)
            inst.components.combat.damagemultiplier = 1
            inst.components.locomotor.walkspeed = 8
            inst.components.locomotor.runspeed = 9
        elseif season == SEASONS.AUTUMN then
            inst.components.health:SetMaxHealth(100)
            inst.components.hunger:SetMax(80)
            inst.components.sanity:SetMax(100)
            inst.components.combat.damagemultiplier = 0.5
            inst.components.locomotor.walkspeed = 7
            inst.components.locomotor.runspeed = 8
        elseif season == SEASONS.WINTER then
            inst.components.health:SetMaxHealth(75)
            inst.components.hunger:SetMax(70)
            inst.components.sanity:SetMax(75)
            inst.components.combat.damagemultiplier = 0        
            inst.components.locomotor.walkspeed = 6
            inst.components.locomotor.runspeed = 7
        end
    end
end

    inst:AddComponent("childspawner")
    inst.components.childspawner.childname = "killerbee"
    SeasonalSpawnChanges(inst, TheWorld.state.season)
    inst:WatchWorldState("season", SeasonalSpawnChanges)
    inst.components.childspawner.emergencychildname = "killerbee"
    inst.components.childspawner.emergencychildrenperplayer = 1
    inst.components.childspawner:SetMaxEmergencyChildren(10)
    inst.components.childspawner:SetEmergencyRadius(TUNING.BEEHIVE_EMERGENCY_RADIUS)
    
    inst.components.combat:SetOnHit(OnHit)
    
    MakeLargePropagator(inst)
        
    inst.OnLoad = onload
    inst.OnNewSpawn = onload
end

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

 

 

Edited by FeatherFallen
solved the last problem, updated thread with a new one
Link to comment
Share on other sites

19 hours ago, FeatherFallen said:

I'm struggling with a few perks for my character mod. Namely, the ability to approach killer bee hives and harvest bee boxes without the resident bees attacking the character.

  Hide contents

 

-- Custom starting items
local start_inv = {
"bee",
"bee",
"bee",
"bee",
"bee",
"bee",
"bee",
"bee",
"butterfly",
"butterfly",
"butterfly",
"butterfly",
"butterfly",
"butterfly",
"butterfly",
"butterfly",
"butterfly",
"butterfly",
"honeycomb",
"honeycomb",
"boards",
"boards",
"boards",
"boards",
"beebox_blueprint",}

 

Wait that's alot of stuff for starting in a new game and it could hurt the players playstyle in the beginning BEEcause of them having to much invintory space, it would help a little to remove bees and butterflies and instead replace them with a bee kepper hat and a butterfly net and let them use it more efficiently. Plus the idea of having a characters stats change throughout seson, have a nomadic playstyle, and rely on more renewable sources would be great to the don't starve team!

 

Link to comment
Share on other sites

58 minutes ago, Justme111 said:

 

The starting inventory is just what's needed for two bee boxes. The insects stack, so only take up two inventory slots. Regardless, that's not what I'm posting about. Everything already in my code works and is as I want it for my character.

I just need help disabling the initial hostility of bee boxes and killer bee hives.

Link to comment
Share on other sites

Maybe you can take a loot at the bee nice mod ? In this mod, when you interact with the beebox, bee will not come outside if you have a bee hat. Sure, you'll need to adapt to your specific case (character instead of hat, and adding killer bee hives), but i think it's close to what you want ?

Link to comment
Share on other sites

local function FriendlyWaspInit(prefab)
	local function OnNearBy(prefab, target)
	if prefab.components.childspawner ~= nil and not target:HasTag("bee") then
        prefab.components.childspawner:ReleaseAllChildren(target, "killerbee")
    end

	end
	
	if prefab.components.playerprox then
	prefab.components.playerprox:SetOnPlayerNear(OnNearBy)
	end
end

AddPrefabPostInit("wasphive", FriendlyWaspInit

 

Slap this into your modmain and edit the 3rd line to your liking. With this the killer bee hive won't send out bees if you have the bee tag.

For beeboxes you'll have to make a PrefabPostInit similar to this one. 

Edited by DarkKingBoo
Link to comment
Share on other sites

2 hours ago, DarkKingBoo said:

local function FriendlyWaspInit(prefab)
	local function OnNearBy(prefab, target)
	if prefab.components.childspawner ~= nil and not target:HasTag("bee") then
        prefab.components.childspawner:ReleaseAllChildren(target, "killerbee")
    end

	end
	
	if prefab.components.playerprox then
	prefab.components.playerprox:SetOnPlayerNear(OnNearBy)
	end
end

AddPrefabPostInit("wasphive", FriendlyWaspInit

 

Slap this into your modmain and edit the 3rd line to your liking. With this the killer bee hive won't send out bees if you have the bee tag.

For beeboxes you'll have to make a PrefabPostInit similar to this one. 

It worked! omg You're a life save, thank you so much! :D

Link to comment
Share on other sites

This thread has been perfect for what I needed, though I have to ask specifically how to make bees not target you when you harvest honey from a beebox.

The 'Bee Nice' mod works nicely on its own but after trying to dissect the code I couldn't figure out exactly how to apply it to my character without having to wear the Beehat. being able to harvest honey without an extra accessory would be nice. 

Link to comment
Share on other sites

52 minutes ago, RubixaSeraph said:

This thread has been perfect for what I needed, though I have to ask specifically how to make bees not target you when you harvest honey from a beebox.

The 'Bee Nice' mod works nicely on its own but after trying to dissect the code I couldn't figure out exactly how to apply it to my character without having to wear the Beehat. being able to harvest honey without an extra accessory would be nice. 

You'd have to do the same thing, except you'll be using beebox's function for the postinit. So find beebox's function where it spawns bees when looted and edit that function for your postinit.

 

Edit:Also maybe next time you should make a new topic instead of necromancing old threads.

Edited by DarkKingBoo
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...