FurryEskimo Posted July 2, 2021 Share Posted July 2, 2021 (edited) I've been poking around the varg (warg) code, and I know this determined how many hounds a varg summons but what actually spawns them? I'm working to update the code I use now, which spawns a hound in a puff of smoke, but would like to figure out how hounds are spawned normally, slightly off screen. local function NumHoundsToSpawn(inst) local numHounds = TUNING.WARG_BASE_HOUND_AMOUNT local pt = Vector3(inst.Transform:GetWorldPosition()) local ents = TheSim:FindEntities(pt.x, pt.y, pt.z, TUNING.WARG_NEARBY_PLAYERS_DIST, TARGETS_MUST_TAGS, TARGETS_CANT_TAGS) for i,player in ipairs(ents) do local playerAge = player.components.age:GetAgeInDays() local addHounds = math.clamp(Lerp(1, 4, playerAge/100), 1, 4) numHounds = numHounds + addHounds end local numFollowers = inst.components.leader:CountFollowers() local num = math.min(numFollowers+numHounds/2, numHounds) -- only spawn half the hounds per howl num = (math.log(num)/0.4)+1 -- 0.4 is approx log(1.5) num = RoundToNearest(num, 1) return num - numFollowers end Edited July 2, 2021 by FurryEskimo Link to comment https://forums.kleientertainment.com/forums/topic/131491-spawning-hounds-like-a-varg/ Share on other sites More sharing options...
Thomas_klei Posted July 3, 2021 Share Posted July 3, 2021 (edited) From varg stategraph, activated in varg brain local function SpawnHound(inst) local hounded = TheWorld.components.hounded --> code/component where all the meat of it is if hounded ~= nil then --> if the code is present it does it thing local num = inst:NumHoundsToSpawn() --> code from varg caclulating the readonsable amont of hounds to spawn local pt = inst:GetPosition() --> saving location of the varg for i = 1, num do --> looping though each time a varg must be spawned in local hound = hounded:SummonSpawn(pt) --> spawining in the varg and saving it if hound ~= nil and hound.components.follower ~= nil then --> depending whenever you can make it a follower converting it over hound.components.follower:SetLeader(inst) end end end end From hounded code local function SummonSpawn(pt) local spawn_pt = GetSpawnPoint(pt) --> checks location of possible spawn if spawn_pt ~= nil then --> if exists it does the code local spawn = SpawnPrefab( (math.random() >= GetSpecialSpawnChance() and _spawndata.base_prefab) or --> if you're lucky you get epic hound ((TheWorld.state.iswinter or TheWorld.state.isspring) and _spawndata.winter_prefab) or -->depending on the season you can varied hounds for each season _spawndata.summer_prefab ) if spawn ~= nil then --> if atleast one of the hounds were chosen it spawns in one spawn.Physics:Teleport(spawn_pt:Get()) --> spawns the hound at position given spawn:FacePoint(pt) --faces the target if spawn.components.spawnfader ~= nil then --> literalyly no idea spawn.components.spawnfader:FadeIn() end return spawn --> this is just so it works dw about it, remove it in your code end end end From hounded codeI'm assuming this is what you want but if it works with normal hounds i'll leave the rest unless you made custom ones, just use this to get a location though unless spawnfader is the meat of it. --math local function GetSpawnPoint(pt) if TheWorld.has_ocean then local function OceanSpawnPoint(offset) local x = pt.x + offset.x local y = pt.y + offset.y local z = pt.z + offset.z return TheWorld.Map:IsAboveGroundAtPoint(x, y, z, true) and NoHoles(pt) end local offset = FindValidPositionByFan(math.random() * 2 * PI, SPAWN_DIST, 12, OceanSpawnPoint) if offset ~= nil then offset.x = offset.x + pt.x offset.z = offset.z + pt.z return offset end else if not TheWorld.Map:IsAboveGroundAtPoint(pt:Get()) then pt = FindNearbyLand(pt, 1) or pt end local offset = FindWalkableOffset(pt, math.random() * 2 * PI, SPAWN_DIST, 12, true, true, NoHoles) if offset ~= nil then offset.x = offset.x + pt.x offset.z = offset.z + pt.z return offset end end end Edited July 3, 2021 by Thomas Die 1 Link to comment https://forums.kleientertainment.com/forums/topic/131491-spawning-hounds-like-a-varg/#findComment-1475851 Share on other sites More sharing options...
FurryEskimo Posted July 5, 2021 Author Share Posted July 5, 2021 @Thomas Die Thanks a lot! I hadn't noticed the 'hounded' code. Sorry for the late reply, I've been pretty bus this weekend. I'll give this code a try as soon as possible. Link to comment https://forums.kleientertainment.com/forums/topic/131491-spawning-hounds-like-a-varg/#findComment-1476412 Share on other sites More sharing options...
FurryEskimo Posted July 5, 2021 Author Share Posted July 5, 2021 @Thomas Die I think I got it!! There were a few missing variables, and a whole function was missing, but I think I got it! This isn't the whole thing, but it's what I used to replace the "hound.Transform:SetPosition(x, 0, z) --Spawns the actual hound." part: local function NoHoles(pt) --Test code. return not TheWorld.Map:IsPointNearHole(pt) end local function GetSpawnPoint(pt) --Test code. local SPAWN_DIST = 30 --hounded.lua::SPAWN_DIST if TheWorld.has_ocean then local function OceanSpawnPoint(offset) local x = pt.x + offset.x local y = pt.y + offset.y local z = pt.z + offset.z return TheWorld.Map:IsAboveGroundAtPoint(x, y, z, true) and NoHoles(pt) end local offset = FindValidPositionByFan(math.random() * 2 * PI, SPAWN_DIST, 12, OceanSpawnPoint) if offset ~= nil then offset.x = offset.x + pt.x offset.z = offset.z + pt.z return offset end else if not TheWorld.Map:IsAboveGroundAtPoint(pt:Get()) then pt = FindNearbyLand(pt, 1) or pt end local offset = FindWalkableOffset(pt, math.random() * 2 * PI, SPAWN_DIST, 12, true, true, NoHoles) if offset ~= nil then offset.x = offset.x + pt.x offset.z = offset.z + pt.z return offset end end end ---------------------------------------- ---------------------------------------- ---------------------------------------- local pt = Vector3(inst.Transform:GetWorldPosition()) local spawn_pt = GetSpawnPoint(pt) --Checks location of possible spawn. if hound ~= nil then --The hound is ready for edits. hound.Physics:Teleport(spawn_pt:Get()) --Spawns the hound at position given. hound:FacePoint(pt) --Faces the target. if hound.components.spawnfader ~= nil then --Adds a fade effect when spawning. --Note: Makes poof of smoke unneeded. hound.components.spawnfader:FadeIn() end end I used to spawn the hounds at the player, with a big puff of smoke, but now they appear offscreen and run to the player! Also, the 'spawnfader' that you had no idea about, thank you for finding! That's the hole reason I was using a puff of smoke in the first place! See, when a Varg summons a hound, it just fades into existence. I had no idea how, but this should help a ton! 1 Link to comment https://forums.kleientertainment.com/forums/topic/131491-spawning-hounds-like-a-varg/#findComment-1476513 Share on other sites More sharing options...
Thomas_klei Posted July 5, 2021 Share Posted July 5, 2021 Nice to hear, happy modding! 1 Link to comment https://forums.kleientertainment.com/forums/topic/131491-spawning-hounds-like-a-varg/#findComment-1476515 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