Jump to content

Recommended Posts

Alright, I'm bringing this back up as I still haven't found a suitable solution.

 

I am trying to edit the beefalos periodic spawner component to make it poop more often and in closer groups, however the only way to do this is to add it with a postinit and then add inst.components.periodicspawner:Start()

 

However, if you do that then there is two Periodic Spawners running, one from the mod, and one from the base game. The only solution I have found is to edit beefalo.lua in data\scripts\prefabs which is not ideal, as it is editing it through base game files. is there a way to make it so that there isn't two periodicspawners running?    

 

If you don't add the periodic spawner start in the postinit it will not apply those changes. Any ideas?

 

This is what beefalo.lua looks like

    inst:AddComponent("periodicspawner")    inst.components.periodicspawner:SetPrefab("poop")    inst.components.periodicspawner:SetRandomTimes(40, 60)    inst.components.periodicspawner:SetDensityInRange(20, 2)    inst.components.periodicspawner:SetMinimumSpacing(8)    inst.components.periodicspawner:Start()

 and this is what the post init looks like 

local function MorePoop(inst)    inst.components.periodicspawner:SetPrefab("poop")    inst.components.periodicspawner:SetRandomTimes(1, 2)    inst.components.periodicspawner:SetDensityInRange(20, 90)    inst.components.periodicspawner:SetMinimumSpacing(0)    inst.components.periodicspawner:Start()endAddPrefabPostInit("beefalo",MorePoop)

I think I figured it out, does this fix it?

local function MorePoop(inst)	inst.components.periodicspawner:Stop()		    inst.components.periodicspawner:SetPrefab("poop")    inst.components.periodicspawner:SetRandomTimes(1, 2)    inst.components.periodicspawner:SetDensityInRange(20, 90)    inst.components.periodicspawner:SetMinimumSpacing(0)	inst.components.periodicspawner:Start()endAddPrefabPostInit("beefalo",MorePoop)

Since it stops the current periodic spawner, then starts a new one?

Edited by bigpak

@bigpak Change the variables with SetRandomTimes, SetDensityInRange, etc, but don't call Stop or Start. The new variables will be used when the task resets.

 

Edit: Regarding your edit, yes it probably would fix it, but you don't need to do that. The variables being set through SetRandomTimes etc are the ones used by the old task.

See the TrySpawn function in the PeriodicSpawner component. (lines 57 - 99)

Edited by Blueberrys

@bigpak Change the variables with SetRandomTimes, SetDensityInRange, etc, but don't call Stop or Start. The new variables will be used when the task resets.

 

 

Oh, I see what you are saying, however that is not the case. I have tried that, to no avail however. It still uses the normal beefalos periodicspawner.

 

When does the task reset?

Edited by bigpak

Yes, the code with the stop and start works perfectly, however I don't know if that is the correct way.

 

I'm going to try what you suggested again, however It didn't work before.

 

I would really appreciate if you test it, as I cannot get it to work without doing what I did.

 

 

I lied, it does work after it resets, I just wasn't waiting long enough. Why does it take so long for it to reset? you mean after 40-60 seconds?

 

Will it hurt to do the stop and start thing? Just to be sure/get it to start instantly?'

 

Edited by bigpak

@bigpak, In RoG, the periodicspawner component was changed to that when the SetRandomTimes() method is called, it will automatically call Stop() and Start().  I think that's what he's referring to.

function PeriodicSpawner:SetRandomTimes(basetime, variance, no_reset)    self.basetime = basetime    self.randtime = variance    if self.task and not no_reset then        self:Stop()        self:Start()    endend

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