Jump to content

[SOLVED] How to say when character's inside cave for event?


Recommended Posts

Hello, I need help :(...

So, my character has some command that makes birds spawn faster for a while which's this

        if inst.whistle_cooldown == nil then
        inst.whistle_cooldown = true
        local birdspawner = TheWorld.components.birdspawner
        birdspawner:SetMaxBirds(TUNING.BIRD_SPAWN_MAX_FEATHERHAT)
        birdspawner:SetSpawnTimes(TUNING.BIRD_SPAWN_DELAY_FEATHERHAT)
        inst:DoTaskInTime(90, function() inst.whistle_cooldown = nil end)
        inst:DoTaskInTime(30, function(inst)
        local birdspawner = TheWorld.components.birdspawner
        birdspawner:SetSpawnTimes(TUNING.BIRD_SPAWN_DELAY)
        birdspawner:SetMaxBirds(TUNING.BIRD_SPAWN_MAX)
        end)
        end
        end

now the problem is that if you do this command inside caves obviously birds can't spawn in caves so it crashes the game :(... So, is there a way I can say like for example 

if inst.iscave then
return
end

is there some code like "inst.iscave" or something because I don't know what to do, please help me because i'm so dumb :(......

I appreciate help so much, thank you so, so much for reading my dumb problem & have a gorgeous day/night :D!!!!!!!!!!!

Edited by SuperDavid
Link to comment
Share on other sites

I just used

if inst.whistle_cooldown == nil and not inst.iscave then

and got this crash

[00:02:48]: [string "../mods/Adam DST Mod/scripts/stategraphs/SG..."]:3348: attempt to index local 'birdspawner' (a nil value)

dangit :(... :) welp

 

PS. I tried this to & still same crash

if TheWorld.state.iscave then
		return
		end

*cries*

Edited by SuperDavid
Link to comment
Share on other sites

the "world" has the tag "cave".
But you can also check
GLOBAL.GetWorld():IsCave()

 

edit:
I'm not 100% sure, if this also works for client, so you should check if this works with caves enabled.
I'm not sure, because for items there is a Tag "INLIMBO" and a function IsInLimbo(). The function can only be called from the host, not from clients. The Tag can be checked from both.
 

Edited by Serpens
Link to comment
Share on other sites

@Serpens

I did this

if inst.whistle_cooldown == nil then
		if GLOBAL.GetWorld():IsCave() then
		return
		end
        inst.whistle_cooldown = true
        local birdspawner = TheWorld.components.birdspawner
        birdspawner:SetMaxBirds(TUNING.BIRD_SPAWN_MAX_FEATHERHAT)
        birdspawner:SetSpawnTimes(TUNING.BIRD_SPAWN_DELAY_FEATHERHAT)
        inst:DoTaskInTime(90, function() inst.whistle_cooldown = nil end) -- Cooldown = 1.30.0.
        inst:DoTaskInTime(30, function(inst)
        local birdspawner = TheWorld.components.birdspawner
        birdspawner:SetSpawnTimes(TUNING.BIRD_SPAWN_DELAY)
        birdspawner:SetMaxBirds(TUNING.BIRD_SPAWN_MAX)
        end)
        end
        end,

and got crash " [00:00:26]: [string "../mods/Adam DST Mod/scripts/stategraphs/SG..."]:3346: variable 'GLOBAL' is not declared "

What did I do wrong :shock:?

Edited by SuperDavid
Link to comment
Share on other sites

I assumed that your code is in modmain ;)
If in modmain, you need to add GLOBAL to most commands. But if your are not, just delete the "GLOBAL."

I'm sure you can also make
TheWorld:IsCave()   --(-> probably only for host)
TheWorld:HasTag("cave")  --(should always work)

Edited by Serpens
Link to comment
Share on other sites

My code's in SGwilson so I just change it to?

Thank you @Serpens  

TheWorld:HasTag("cave")

worked perfectly for me she odn't crash the game anymore, thank you so much man 

:D!!!!!!!

GetWorld():IsCave()
Edited by SuperDavid
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...