Jump to content

SpawnPrefab in amounts greater than one


Recommended Posts

7 hours ago, Yakuzashi said:

Yep. I am surprised

That line Ivo posted will only make the first entity spawned set its position, all other entities will go to 0, 0

 

Something like this would be better

for i  = 1, count do --replace count with number of entities you want
       SpawnPrefab("").Transform:SetPosition(...)
end

 

  • Health 1
  • Hunger 1
  • Sanity 1
Link to comment
Share on other sites

I am trying to replace logs with living logs upon spell cast, but my Frankenstein function turns every log in area into just 1 living log.
 

local function detransformer(inst)
local owner = inst.components.inventoryitem.owner
local livinglog = SpawnPrefab("livinglog")	
local pt = inst:GetPosition()
local range = 10

		local ents = TheSim:FindEntities(pt.x,pt.y,pt.z,range)
		for _,ent in ipairs(ents) do
			if ent.prefab == "log" and ent.components.stackable and ent.components.stackable.stacksize == 20 and not owner.components.inventory:Has("log", 1) then 		
						local x,y,z = ent.Transform:GetWorldPosition()			
					for i  = 1, 20 do 					
						livinglog.Transform:SetPosition(x, y, z)
					end
				ent:Remove()
			end
		end
end

The:

Quote

for i  = 1, count do --replace count with number of entities you want
       SpawnPrefab("").Transform:SetPosition(...)
end

part doesn't work and I don't know what I did wrong. Sorry for my lack of knowledge

Edit: c_spawn() works good, but it spawns prefabs at the mouse pointer location

 

Edit2: I am an idiot I shouldn't use local livinglog = SpawnPrefab("livinglog") 

Edited by Yakuzashi
edit
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...