Jump to content

Recommended Posts

I want a particular item of mine to spawn another item at a specific time range but something is off?

 

I thought this would work:

    inst:AddComponent("periodicspawner")    inst.components.periodicspawner:SetPrefab("balloon")    inst.components.periodicspawner:SetRandomTimes(2, 4)    inst.components.periodicspawner:SetDensityInRange(20, 2)    inst.components.periodicspawner:SetMinimumSpacing(8)    inst.components.periodicspawner:Start()

But it isn't working as I thought it would.

 

When I make this particular item it does spawn the balloon but only once. The only way it can spawn another balloon is by attacking the balloon.

 

But then I decided to make the same particular item and that same item doesn't spawn the balloon, but after attacking the balloon of the first particular item the second same item spawns the balloon instead not the first. And this goes on for each copy of the doll I've made.

 

How do I bypass this?

@rons0n, It looks from this block that your minimum spacing specification may be messing things up:

    if canspawn and (self.range or self.spacing) then        local pos = Vector3(self.inst.Transform:GetWorldPosition())        local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, self.range or self.spacing)        local count = 0        for k,v in pairs(ents) do            if v.prefab == prefab then                if self.spacing and v:GetDistanceSqToInst(self.inst) < self.spacing*self.spacing then                    canspawn = false                    break                end                count = count + 1            end        end        if self.density and count >= self.density then            canspawn = false        end    end

Does it work if you remove SetMinimumSpacing? According to that block, it won't spawn a new entity if there's already one within the minimum spacing.

@rezecib,  Thanks, you are most definitely correct. Removing the SetMinimumSpacing has had me spawn balloons galore. Well by galore I mean only 2 balloons.

 

Turns out there was a second culprit, inst.components.periodicspawner:SetDensityInRange(20, 2)

 

But I dont understand still, why does it spawn 2 but not 20 as its shown in that line?

Same goes for SetRandomTimes where it'll spawn a new one every 4 seconds but not 2. Am I missing something here?

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