Skip to content

How to make bots place Nest #145

@Nikolay0525

Description

@Nikolay0525

I saw another issue with same theme but in my case i`m too dumb to understand how to make bots to place nests, but i have some kind of alghorithm:

  1. After random bot die with random reason he will look for prop on map called "prop_creepernest", if there is none bot switch to "Flash Creeper" class
  2. He will go to target like player and checks every second units to player.
  3. If player is near and not too near, just in right spot, he will kill himself and like that, place a nest where bots should spawn

That's all based on this block of code that SeekerTheTruth posted year ago:
flesh_creeper.lua
//////////////////////////////////////////////////////////////////////////////
if SERVER then
function CLASS:OnKilled(pl, attacker, inflictor, suicide, headshot, dmginfo)

	local CheckDist = false
	for _, pl in pairs(team.GetPlayers(TEAM_UNDEAD)) do -- check all z
		local b = pl:GetPos()	
			b1 = math.Round(b[1], 1) --x coordinat
			b2 = math.Round(b[2], 1) --y coordinat
			b3 = math.Round(b[3], 1) --z coordinat

		if pl:Team() == TEAM_UNDEAD and pl:GetZombieClassTable().Name == "Flesh Creeper" then --check for special class
			for _, sigs in pairs(ents.FindByClass("prop_obj_sigil")) do -- check for avaible sigils
				local c = sigs:GetPos()	
				c1 = math.Round(c[1], 1) --x coordinat
				c2 = math.Round(c[2], 1) --y coordinat
				c3 = math.Round(c[3], 1) --z coordinat
				local h1 = c1-b1 
				local h2 = c2-b2
				local h3 = c3-b3
				local dist2 = math.sqrt(h1*h1 + h2*h2 + h3*h3)	--final distance calculation
				
				if dist2 > 900 then --range condition
					CheckDist = true
				else
					CheckDist = false
				end					
			end
		end
	end

	local ent = pl:FakeDeath(pl:LookupSequence("Flip1"), self.ModelScale, math.Rand(0.45, 0.5))
	if ent:IsValid() then
		ent:SetMaterial("models/flesh")
	end

	if CheckDist == true then --section of code responsible for the appearance of the socket
		local CpNs = ent:GetPos(ent)
		local ent2 = ents.Create("prop_creepernest")
		if ent2:IsValid() then
			ent2:SetPos(CpNs)
			ent2:Spawn()
			ent2.OwnerUID = uid
			ent2:SetNestHealth(800 * math.random(0.6, 1)) --450
			ent2:SetNestBuilt(true)
		end
	end

	return true
end

end
//////////////////////////////////////////////////////////////////////
If somebody has any solve or has any hints please let me know, thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions