Nergall89 Posted December 6, 2020 Share Posted December 6, 2020 I am making a mod where when you eat meat, cooked or in a recipe there is a change to spawn hounds to attack you like they are attracted from the smell of meat. Gave them a buff as well to be faster and stronger, basically to add a challenge. Now I am trying to make them have a chance to become Horror Hounds on death but can't figure it out. Any ideas? I appreciate it. Link to comment https://forums.kleientertainment.com/forums/topic/124514-need-help-with-spawning-mutated-horror-hounds/ Share on other sites More sharing options...
Yakuzashi Posted December 7, 2020 Share Posted December 7, 2020 (edited) I would add the code below to the stategraph - death section if math.random() < 0.5 local x, y, z = inst.Transform:GetWorldPosition() SpawnPrefab("mutatedhound").Transform:SetPosition(x, y, z) return true end I am not sure if this will work, but you can try at least Edited December 7, 2020 by Yakuzashi Link to comment https://forums.kleientertainment.com/forums/topic/124514-need-help-with-spawning-mutated-horror-hounds/#findComment-1402302 Share on other sites More sharing options...
Nergall89 Posted December 8, 2020 Author Share Posted December 8, 2020 Thank you for the reply, for some reason I can't generate a world with it, no errors occurs, it is just not finishing the world Link to comment https://forums.kleientertainment.com/forums/topic/124514-need-help-with-spawning-mutated-horror-hounds/#findComment-1402635 Share on other sites More sharing options...
Yakuzashi Posted December 8, 2020 Share Posted December 8, 2020 I'll test it later on my vanilla version Link to comment https://forums.kleientertainment.com/forums/topic/124514-need-help-with-spawning-mutated-horror-hounds/#findComment-1402636 Share on other sites More sharing options...
Yakuzashi Posted December 8, 2020 Share Posted December 8, 2020 (edited) Okay. You will need to paste this little boy inside modmain.lua local function deadlydoggo(sg) local _onenter = sg.states["death"].onenter sg.states["death"].onenter = function(inst) _onenter(inst) if math.random() < 0.5 then ---- percent chance of very bad doggo reborn local x, y, z = inst.Transform:GetWorldPosition() SpawnPrefab("shadow_despawn").Transform:SetPosition(x, y, z) --this is only visual effect to smooth up the transition between death of hound and its transformation into spooky one SpawnPrefab("mutatedhound").Transform:SetPosition(x, y, z) return true end end end AddStategraphPostInit("hound", deadlydoggo) Remember to add this somewhere above: local require = GLOBAL.require local STRINGS = GLOBAL.STRINGS local SpawnPrefab = GLOBAL.SpawnPrefab If you have any questions do not hesitate, I am always willing to help! Cheers! Edited December 8, 2020 by Yakuzashi visual effect Link to comment https://forums.kleientertainment.com/forums/topic/124514-need-help-with-spawning-mutated-horror-hounds/#findComment-1402654 Share on other sites More sharing options...
Nergall89 Posted December 8, 2020 Author Share Posted December 8, 2020 It works, however now it apply the chance when the horror hound is killed as well which makes it to spawn a Horror one out of a horror one. Maybe there is a problem with the code I have here. local function spawnoffscreen(pt, radius)    local theta = math.random() * 2 * GLOBAL.PI    radius = radius or 40    local offset = GLOBAL.FindWalkableOffset(pt, theta, radius, 12, true)    if offset then       return pt+offset    end end function spawnattacker(prefab, teleporttoinst, guy)    teleporttoinst=teleporttoinst or false    local pt = Vector3(guy.Transform:GetWorldPosition())    local spawn_pt = spawnoffscreen(pt)    if spawn_pt and prefab then       local attacker = SpawnPrefab(prefab)       if attacker and teleporttoinst==true then          spawn_pt = Vector3(guy.Transform:GetWorldPosition())          attacker.Physics:Teleport(spawn_pt:Get())       end       if attacker and attacker.Physics and attacker.components.combat then          attacker:FacePoint(pt)          attacker.Physics:Teleport(spawn_pt:Get())          attacker:DoTaskInTime(1, function(attacker)             if attacker.components.knownlocations then                attacker.components.knownlocations.locations["home"]=Vector3(guy.Transform:GetWorldPosition())             end          end)          if attacker.components.sleeper and attacker.components.sleeper.isasleep then             attacker.components.sleeper:WakeUp()          end          attacker.components.combat:SetTarget(guy)       end    end end AddPlayerPostInit(function(inst)    inst:ListenForEvent("oneat", function(inst, data)       if data.food.prefab == "meat" or data.food.prefab == "cookedmeat" or data.food.prefab == "meat_dried" or data.food.prefab == "smallmeat_dried" or data.food.prefab == "baconeggs" or data.food.prefab == "fishsticks" or data.food.prefab == "honeyham" or data.food.prefab == "honeynuggets" or data.food.prefab == "kabobs" or data.food.prefab == "meatballs" or data.food.prefab == "bonestew" or data.food.prefab == "perogies" or data.food.prefab == "turkeydinner" or data.food.prefab == "surfnturf" then          if math.random() < 0.5 then             if inst.components.talker then                inst.components.talker:Say("Oh no! Hounds!")             end             spawnattacker("hound", false, inst)          end       end    end)    inst:ListenForEvent("killed", function(inst, data)       if data.victim.prefab == "hound" then          if math.random() < 0.3 then             spawnattacker("hound", false, inst)          end       end    end) end) local function deadlydoggo(sg)  local _onenter = sg.states["death"].onenter    sg.states["death"].onenter = function(inst)       _onenter(inst)          if math.random() < 0.5 then  ---- percent chance of very bad doggo reborn          local x, y, z = inst.Transform:GetWorldPosition()              SpawnPrefab("shadow_despawn").Transform:SetPosition(x, y, z) --this is only visual effect to smooth up the transition between death of hound and its transformation into spooky one             SpawnPrefab("mutatedhound").Transform:SetPosition(x, y, z)                return true       end    end end AddStategraphPostInit("hound", deadlydoggo) And is there a way to make the horror hound spawn where the dead one is with little delay? Like 3 seconds or something? And Thanks again for all the help! Link to comment https://forums.kleientertainment.com/forums/topic/124514-need-help-with-spawning-mutated-horror-hounds/#findComment-1402807 Share on other sites More sharing options...
Yakuzashi Posted December 8, 2020 Share Posted December 8, 2020 (edited) Horror Hound and regular one must use the same stategraph. local function deadlydoggo(sg) local _onenter = sg.states["death"].onenter sg.states["death"].onenter = function(inst) _onenter(inst) if inst.prefab == "hound" then if math.random() < 0.5 then local x, y, z = inst.Transform:GetWorldPosition() SpawnPrefab("shadow_despawn").Transform:SetPosition(x, y, z) SpawnPrefab("mutatedhound").Transform:SetPosition(x, y, z) return true end end end end Edit: Yep, it works just fine Edited December 8, 2020 by Yakuzashi edit Link to comment https://forums.kleientertainment.com/forums/topic/124514-need-help-with-spawning-mutated-horror-hounds/#findComment-1402897 Share on other sites More sharing options...
Nergall89 Posted December 8, 2020 Author Share Posted December 8, 2020 This time is a charm! Works great, thanks! Link to comment https://forums.kleientertainment.com/forums/topic/124514-need-help-with-spawning-mutated-horror-hounds/#findComment-1402926 Share on other sites More sharing options...
Nergall89 Posted December 8, 2020 Author Share Posted December 8, 2020 1 hour ago, Yakuzashi said: Horror Hound and regular one must use the same stategraph. local function deadlydoggo(sg) local _onenter = sg.states["death"].onenter sg.states["death"].onenter = function(inst) _onenter(inst) if inst.prefab == "hound" then if math.random() < 0.5 then local x, y, z = inst.Transform:GetWorldPosition() SpawnPrefab("shadow_despawn").Transform:SetPosition(x, y, z) SpawnPrefab("mutatedhound").Transform:SetPosition(x, y, z) return true end end end end Edit: Yep, it works just fine Only 1 thing - any chance to make them spawn after lets say 2 or 3 seconds ? Link to comment https://forums.kleientertainment.com/forums/topic/124514-need-help-with-spawning-mutated-horror-hounds/#findComment-1403000 Share on other sites More sharing options...
Yakuzashi Posted December 8, 2020 Share Posted December 8, 2020 Quote any chance to make them spawn after lets say 2 or 3 seconds ? I'll check this out tomorrow. I have tested sth and still don't know how to do this 1 Link to comment https://forums.kleientertainment.com/forums/topic/124514-need-help-with-spawning-mutated-horror-hounds/#findComment-1403067 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