Jump to content

ListenForEvent: (Enter Cave)


Codelyy

Recommended Posts

I've been trying to call a function when the player enters a cave but i can't find anyway to call the function when they do enter the cave. I've looked for a ListenForEvent thing for a cave but i can't find one and i'm just guessing there isn't one unless I'm not looking hard enough.

 

Can anyone help? I just need something that i can use to call my function when the player enters a cave 

Link to comment
Share on other sites

Well, you can either...

  1. use AddPrefabPostInit to modify the sinkhole so it fires your code when activated. This will fire the code on the surface.
  2. always run an AddSimPostInit and check whether the world has a cave tag. This makes the code fire when already in the cave, and also when loading the saved game.
Link to comment
Share on other sites

Well, I know "if GetWorld():HasTag("cave") then" is a thing. But it's something that would have to run like every few ticks or something, because it doesn't just happen when a player enters a cave.

there probably is a way to listen for entering a cave, I just don't know what it is

Link to comment
Share on other sites

Keep in mind that the game reloads when you change worlds, so any non-persistent functionality won't be carried over. What exactly are you trying to do?

 

For Mobbstar's first suggestion, you would need to modify the "activatable" component, like this:

--This code goes in modmain.luaAddComponentPostInit("activatable", function(self)    local fn = self.DoActivate    self.DoActivate = function(inst, doer)        if inst.inst.prefab == "cave_entrance" then            --Call whatever code you want to        end        fn(inst, doer)    endend)

As he said though, this would be called before the player enters the cave, and the game would end a moment later.

 

For the other option, there are quite a few ways to check. The simplest I can think of would be this:

--This would also go in modmain.luaAddPrefabPostInit("cave_exit", function(self)    if SaveGameIndex:GetCurrentCaveLevel() == 1 then        --Do your thing. If you want it to run each time you go down a cave level, leave out the if statement.    endend

Which is probably what you were looking for.

Link to comment
Share on other sites

Keep in mind that the game reloads when you change worlds, so any non-persistent functionality won't be carried over. What exactly are you trying to do?

 

For Mobbstar's first suggestion, you would need to modify the "activatable" component, like this:

 

Why, no. I meant the following. It's no less dirty than your suggestion.

 

EDIT: This doesn't work well due to what Arkathorn pointed out. This method is actually dirtier than their suggestion.

 

AddPrefabPostInit("cave_entrance",function(inst)

  old = inst.components.activatable.OnActivate

  inst.components.activatable.OnActivate = function(inst)

    --your code here

    old(inst)

  end

end)

 

Though lyoko should probably do the latter method anyways.

Link to comment
Share on other sites

Keep in mind that the game reloads when you change worlds, so any non-persistent functionality won't be carried over. What exactly are you trying to do?

 

For Mobbstar's first suggestion, you would need to modify the "activatable" component, like this:

--This code goes in modmain.luaAddComponentPostInit("activatable", function(self)    local fn = self.DoActivate    self.DoActivate = function(inst, doer)        if inst.inst.prefab == "cave_entrance" then            --Call whatever code you want to        end        fn(inst, doer)    endend)

As he said though, this would be called before the player enters the cave, and the game would end a moment later.

 

For the other option, there are quite a few ways to check. The simplest I can think of would be this:

--This would also go in modmain.luaAddPrefabPostInit("cave_exit", function(self)    if SaveGameIndex:GetCurrentCaveLevel() == 1 then        --Do your thing. If you want it to run each time you go down a cave level, leave out the if statement.    endend

Which is probably what you were looking for.

I've figured it out now so don't worry but I'm basically trying to fix a problem where the players follower will spawn again when they enter a cave so they will have two of the same follower

Link to comment
Share on other sites

Why, no. I meant the following. It's no less dirty than your suggestion.

 

AddPrefabPostInit("cave_entrance",function(inst)

  old = inst.components.activatable.OnActivate

  inst.components.activatable.OnActivate = function(inst)

    --your code here

    old(inst)

  end

end)

 

Though lyoko should probably do the latter method anyways.

The "cave_entrance" prefab doesn't have the "activatable" component by default, it's added in 'Open', when it's worked.

Link to comment
Share on other sites

re: don't you want to tell us how you fixed that part so that people with this same issue later on can look to this forum for answers?

 

anyways, perhaps you could attach something directly to the follower that, on load, checks the area for nearby copies of itself and deletes them.

Here's a quick example that I didn't test so idk if it works but it might.

local entities = TheSim:FindEntities(x,y,z, 20, {}) --20=SEARCH RADIUSfor k,v in pairs(entities) do	if k >=1 then		if v:HasTag("your_follower_tag") then  --PUT A SPECIAL TAG ON YOUR FOLLOWER IN IT'S PREFAB SO THAT THE GAME CAN CHECK FOR IT HERE			v:Remove()  --HOPE THIS DOESN'T REMOVE BOTH OF THEM		end	endend

oh, but you'd have to put that all in a function that starts up when your follower prefab loads

Link to comment
Share on other sites

re: don't you want to tell us how you fixed that part so that people with this same issue later on can look to this forum for answers?

Do you mean me? If so, it's shown in my post above.

 

Also, I think he may mean that when you enter the caves with a follower, he spawns next to you down there, but a version is also still in the overworld. Is that correct, or am I misinterpreting you entirely?

Link to comment
Share on other sites

Do you mean me? If so, it's shown in my post above.

 

Also, I think he may mean that when you enter the caves with a follower, he spawns next to you down there, but a version is also still in the overworld. Is that correct, or am I misinterpreting you entirely?

 

oh, no I meant him, not you.

 

 

ah, I just assumed that's what he meant because I know theres a popular mod in the workshop with that same issue. I forget what it's called, the one that looks like a ghost cat (basically esctemplate fill-bucketed black) with a terrorbeak follower.

Link to comment
Share on other sites

oh, no I meant him, not you.

 

 

ah, I just assumed that's what he meant because I know theres a popular mod in the workshop with that same issue. I forget what it's called, the one that looks like a ghost cat (basically esctemplate fill-bucketed black) with a terrorbeak follower.

That's my mod. "The Nightmare"

 

Only just getting around to fixing issues when i should of started ages ago sadly

Link to comment
Share on other sites

oh

 

Um, well, I guess you can kill two birds with one stone if you fix this bug then. Assuming it's the same problem?

Well it seems my mod has a lot more problems then I expected and due to my lack of programming skill...sadly. I may not be able to fix my mod.

 

Apparently i screwed up the leader component somehow so it doesn't even take note of how many followers i have and always says 0 so i'm unable to do something like check if i got another terrorbeak follower.

 

There is also the issues that i ported it wrongly to DST missing a couple stuff out from what i see which has lead to the main issue everyone complains about with the night vision that only the host can use the night vision. I made a post about it earlier but no one has replied.

Link to comment
Share on other sites

Well it seems my mod has a lot more problems then I expected and due to my lack of programming skill...sadly. I may not be able to fix my mod.

 

Apparently i screwed up the leader component somehow so it doesn't even take note of how many followers i have and always says 0 so i'm unable to do something like check if i got another terrorbeak follower.

 

There is also the issues that i ported it wrongly to DST missing a couple stuff out from what i see which has lead to the main issue everyone complains about with the night vision that only the host can use the night vision. I made a post about it earlier but no one has replied.

 

 

Well I can't help with the DST part, I'm aweful at that stuff.

 

 

But how is the follower declared? Can you show us how you got the follower to follow the player in the first place?

 

If you haven't already done this, maybe you can fix it by adding this to whatever code adds the follower.

 

local player = GetPlayer()

player.components.leader:AddFollower(inst)    --where inst = whatever your follower reference is

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...