Jump to content

low sanity meteor spawner


Recommended Posts

Hey guys, I've been studying the "meteorshower.lua", "Meteorspawner.lua", "meteorwarning.lua", "shadowmeteor.lua" and "terrain_rocky.lua" files, and I was wondering if it is possible to make a character mod that spawns a meteor shower when his sanity gets low, a same meteor shower that happens randomly at the Rocky biomes, it would be something like this:

sanity reachs 30, it will spawn a level 1 meteor shower;

if sanity reachs 20 it will spawn a level 2 meteor shower;

and if sanity reachs 10 it will spawn a level 3 meteor shower;

if sanity reachs 0 another level 3 meteor shower will spawn.

is it possible to make something like that?

Link to comment
Share on other sites

@RaymondFoxford in the master_postinit:

inst:AddComponent("meteorshower")
if inst.components.meteorshower.task then --it automatically scheduled a shower
	inst.components.meteorshower:StopShower() --remove the automatically-scheduled shower
end
--override the StartCooldown on this particular component instance so it does not schedule more showers after completing one
inst.components.meteorshower.StartCooldown = inst.components.meteorshower.StopShower
--Watch sanity to know when to trigger the showers
inst:ListenForEvent("sanitydelta", function(inst, data)
	--data provides the oldpercent and newpercent for sanity, so it is easier to do thresholds in percents
	--... but you could convert like this
	local oldsanity = data.oldpercent * inst.components.sanity.max
	local newsanity = data.newpercent * inst.components.sanity.max
	local level = nil
	if newsanity <= 0 and oldsanity > 0 or newsanity <= 10 and oldsanity > 10 then
    	level = 3
    elseif newsanity <= 20 and oldsanity > 20 then
    	level = 2
    elseif newsanity <= 30 and oldsanity > 30 then
    	level = 1
    end
    if level then --we passed a threshold and need to spawn a shower
    	inst.components.meteorshower:StartShower(level)
    end
end)

 

Edited by rezecib
Link to comment
Share on other sites

17 hours ago, rezecib said:

@RaymondFoxford in the master_postinit:


inst:AddComponent("meteorshower")
if inst.components.meteorshower.task then --it automatically scheduled a shower
	inst.components.meteorshower:StopShower() --remove the automatically-scheduled shower
end
--override the StartCooldown on this particular component instance so it does not schedule more showers after completing one
inst.components.meteorshower.StartCooldown = inst.components.meteorshower.StopShower
--Watch sanity to know when to trigger the showers
inst:ListenForEvent("sanitydelta", function(inst, data)
	--data provides the oldpercent and newpercent for sanity, so it is easier to do thresholds in percents
	--... but you could convert like this
	local oldsanity = data.oldpercent * inst.components.sanity.max
	local newsanity = data.newpercent * inst.components.sanity.max
	local level = nil
	if newsanity <= 0 and oldsanity > 0 or newsanity <= 10 and oldsanity > 10 then
    	level = 3
    elseif newsanity <= 20 and oldsanity > 20 then
    	level = 2
    elseif newsanity <= 30 and oldsanity > 30 then
    	level = 1
    end
    if level then --we passed a threshold and need to spawn a shower
    	inst.components.meteorshower:StartShower(level)
    end
end)

 

It worked! Thank you so much! :D

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