Jump to content

Recommended Posts

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.

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 by Yakuzashi

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 by Yakuzashi
visual effect

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!

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 by Yakuzashi
edit
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 ?

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...