Jump to content

New guy needing help.


Recommended Posts

Trying to write what would seem to be a simple mod, and I am having difficulty understanding how to do something.

 

Basically I am making a beacon to teleport ghosts to.

 

But when I say use,

 

inst ListenForEvent("death", deathfunction)

 

It seems as if my function never see's the player die, i've tested it with

 

local deathfunction(inst)

    print("Am I getting called?")

end

 

With no avail.

 

I have also tested...

 
if inst.components.player.ghostenabled then
  print("What the hell?")
end

 

Also with no luck.

 

What am I missing to be able to tell when the player is dead, or in ghost form?

Should I be making these calls in modmain.lua or in my beacon.lua?

(i've tried both, not sure which would work or not work)

 

Any advice would be helpful, it seems like i've tried 100 things and my program can never tell when a player dies.

Link to comment
Share on other sites

Still need help resolving the issue.  I'm obviously new to lua, but i have programmed in several other languages.  So if i'm missing something simple, please let me know.  If its complex, let me know that too.

 

I just need pointed in the right direction, and i see a ton of views, no reply.  

 

Can anyone help me?

Link to comment
Share on other sites

@thisisashan, I think you want something like this in your modmain:

local function PlayerPostInit(inst)	inst:ListenForEvent("makeplayerghost", function() inst:DoTaskInTime(1, deathfunction) end)endfor k,v in pairs(GLOBAL.DST_CHARACTERLIST) do AddPrefabPostInit(v, PlayerPostInit) endfor k,v in pairs(GLOBAL.MODCHARACTERLIST) do AddPrefabPostInit(v, PlayerPostInit) end

Then I would set the mod's priority in the modinfo to something low (-1?) to make sure it loads after mod characters. There's probably another way to divorce it from individual player prefabs, and thus not require this, though.

 

Edit: Maybe this: (I think AddPlayerPostInit was broken earlier, not sure if it's been fixed now)

AddPlayerPostInit(function(inst)	inst:ListenForEvent("makeplayerghost", function() inst:DoTaskInTime(1, deathfunction) end)end)
Edited by rezecib
Link to comment
Share on other sites

 

@thisisashan, I think you want something like this in your modmain:

local function PlayerPostInit(inst)	inst:ListenForEvent("makeplayerghost", function() inst:DoTaskInTime(1, deathfunction) end)endfor k,v in pairs(GLOBAL.DST_CHARACTERLIST) do AddPrefabPostInit(v, PlayerPostInit) endfor k,v in pairs(GLOBAL.MODCHARACTERLIST) do AddPrefabPostInit(v, PlayerPostInit) end

Then I would set the mod's priority in the modinfo to something low (-1?) to make sure it loads after mod characters. There's probably another way to divorce it from individual player prefabs, and thus not require this, though.

 

Edit: Maybe this: (I think AddPlayerPostInit was broken earlier, not sure if it's been fixed now)

AddPlayerPostInit(function(inst)	inst:ListenForEvent("makeplayerghost", function() inst:DoTaskInTime(1, deathfunction) end)end)

You sir, are awesome. 

 

Addplayerpostinit seemed to work without a warning, but i'll keep an eye on it if crazy stuff happens. 

 

Going to let my brain try to figure out the other stuff going on, then i'll probably be back with more questions.

 

Thank you again!

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