Jump to content

How to check how many of a certain prefab is in the world.


Recommended Posts

I know there is

c_countprefabs("prefab")

  for server commands. But how would I in the middle of a function check how many of a prefab is in the world.
I want to make sure only 1 of a custom mob exists in the world at a time. Or at least 1 per spawn statue that summons them.
I don't want the players to walk up to a pile of clock queens chilling out.

Link to comment
Share on other sites

local SPAWN_COUNTER = 0
AddPrefabPostInit("mobprefab",function(inst)
	SPAWN_COUNTER = SPAWN_COUNTER + 1
	inst:ListenForEvent("onremove", function(inst)
		SPAWN_COUNTER = SPAWN_COUNTER - 1
	end)
end)

 

Link to comment
Share on other sites

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
 Share

×
  • Create New...