Faerendipitous Posted January 22, 2017 Share Posted January 22, 2017 I'm trying to add an increase of crows, but keep hitting the same stumbling block I have the birdspawn code that I know I need to add to my character.lua in the MasterPostInIt local birdspawner = TheWorld.components.birdspawner if not TheWorld.ismastersim then return inst end if birdspawner ~= nil then birdspawner:SetSpawnTimes({min=2, max=5}) birdspawner:SetMaxBirds(15) end but I don't know how to make it SPECIFICALLY crows And that being said, if I add this to spawn specifically crows, will other birds still spawn? They should, right?? Addendum: I ran it just like this and I didn't... really see an increase of birds... Addendum to the Addendum: like five seconds later I upped the values and ran it again and am now DROWNING in birds WHOOPS Link to comment Share on other sites More sharing options...
Ryuushu Posted January 23, 2017 Share Posted January 23, 2017 @Faerendipitous I was messing around with the birdattractor and birdspawner for a while but I couldn't come up with a way to change the bird type rates for a specific character nicely, so I came up with the following: local min_radius = 3 local max_radius = 15 local min_time = 1 local max_time = 5 local function SpawnCrowNearby(inst) local pos = inst:GetPosition() pos.x = pos.x + GetRandomMinMax(min_radius, max_radius) * (math.random() > 0.5 and 1 or -1) pos.z = pos.z + GetRandomMinMax(min_radius, max_radius) * (math.random() > 0.5 and 1 or -1) local offset = FindWalkableOffset(pos, math.random() * 2 * GLOBAL.PI, 5, 3) if offset == nil then return end pos.x = pos.x + offset.x pos.z = pos.z + offset.z local bird = SpawnPrefab("crow") if math.random() > 0.5 then bird.Transform:SetRotation(180) end pos.y = 15 bird.Physics:Teleport(pos:Get()) end ... if TheWorld.components.birdspawner then inst.spawncrowtask = inst:DoPeriodicTask(0, function(inst) SpawnCrowNearby(inst) inst.spawncrowtask.period = GetRandomMinMax(min_time,max_time) end) end That spawns a crow near the player every 1-5 seconds. It's missing some checks for the day time and scarecrows, but they should be easy enough to implement. Maybe. Err, I'll help you with them if you want me to. By the way, your current code will spawn tons of birds for everyone, not just your character, since you're changing a world's component. Link to comment Share on other sites More sharing options...
CarlZalph Posted January 23, 2017 Share Posted January 23, 2017 @Faerendipitous And here's another way of doing it: AddComponentPostInit( "birdspawner", function(inst) if GLOBAL.TheWorld.ismastersim then if inst.SpawnBird and inst.GetSpawnPoint then local shouldSpawnCrow = false local GetSpawnPoint_old = inst.GetSpawnPoint inst.GetSpawnPoint = function(self, pt, ...) shouldSpawnCrow = false local spawnpoint_calculated = GetSpawnPoint_old(self, pt, ...) if spawnpoint_calculated then for _,v in pairs(GLOBAL.AllPlayers) do local pt_2 = v:GetPosition() if pt==pt_2 and v.prefab=="wilson" -- We have the owner being our mod character, in this case 'wilson' then shouldSpawnCrow = true break end end end if shouldSpawnCrow and (math.random() > .3) -- 30% chance to force a crow spawn, 70% of doing default behaviour. then shouldSpawnCrow = false end return spawnpoint_calculated end local SpawnBird_old = inst.SpawnBird inst.SpawnBird = function(self, spawnpoint, ignorebait, ...) if shouldSpawnCrow then shouldSpawnCrow = false local birdtype = "crow" local x, y, z = spawnpoint:Get() -- Crow to canary checks local canarylure = GLOBAL.TheSim:FindEntities(x, y, z, GLOBAL.TUNING.BIRD_CANARY_LURE_DISTANCE, { "scarecrow" }) if #canarylure ~= 0 then birdtype = "canary" end local bird = GLOBAL.SpawnPrefab(birdtype) if math.random() < .5 then bird.Transform:SetRotation(180) end if bird:HasTag("bird") then spawnpoint.y = 15 end -- Ignore traps and bait bird.Physics:Teleport(spawnpoint:Get()) return bird else return SpawnBird_old(self, spawnpoint, ignorebait, ...) end end end end end ) Link to comment Share on other sites More sharing options...
Arlesienne Posted January 23, 2017 Share Posted January 23, 2017 (edited) @ImDaMisterL, could you please move this? Should fit better and get even more help. http://forums.kleientertainment.com/forum/79-dont-starve-together-mods-and-tools/ EDIT: Literally beaten as I hit submit. You're a marvel! Edited January 23, 2017 by Arlesienne Link to comment Share on other sites More sharing options...
Developer ImDaMisterL Posted January 23, 2017 Developer Share Posted January 23, 2017 3 hours ago, Arlesienne said: EDIT: Literally beaten as I hit submit. You're a marvel! I was going to give credit where credit is due and say who actually moved it, because I didn't, but... the moderation history doesn't say anything about this having been moved 0-0 Link to comment Share on other sites More sharing options...
Arlesienne Posted January 23, 2017 Share Posted January 23, 2017 Just now, ImDaMisterL said: I was going to give credit where credit is due and say who actually moved it, because I didn't, but... the moderation history doesn't say anything about this having been moved 0-0 Either way... PRRRAISE BEEE!!! Literally. I saw this in the general area, went to get the nice scented candles to summon you, wrote the supplication and BAM. Link to comment Share on other sites More sharing options...
Faerendipitous Posted January 23, 2017 Author Share Posted January 23, 2017 5 hours ago, Arlesienne said: Either way... PRRRAISE BEEE!!! Literally. I saw this in the general area, went to get the nice scented candles to summon you, wrote the supplication and BAM. Hey, sorry about that?? I could have sworn I placed this in Mods and Tools. Either a misclick or just a straight glitch. Sorry again!! and @CarlZalph the bird code works like charm!! The way I was doing it before was just..... an overabundance of crows lmao This is much more balanced!! 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