Jump to content

How do I make a character with a timer?


Recommended Posts

I'm making a character that will die every 22 Minutes - no stopping it, but they have their own way to revive themselves.

However, I'm not sure how I would do that. I've been looking at Wanda and I saw a few various strings that could help, but I honestly need some help.

Is there anyone I could talk to who can help with this?

 

Additional information: I want a specific song to begin quietly playing once they've got about 2 minutes left, and I want them to be able to revive without losing any max HP.

Link to comment
Share on other sites

Your description reminds me of Outer Wilds where the world dies every serveral minutes.

Wanda's mechanism is that she loses health constantly. While a general way to trigger immediate death is using timer component and wait to push a death event, with no penalty. If you want an age-like countdown, it is possible that you add Wanda's clock to the UI, or something like Nightmare Phase Indicator mod.

You may want to save health when death and set it when resurrection.

Link to comment
Share on other sites

On 10/4/2022 at 6:33 PM, Rickzzs said:

Your description reminds me of Outer Wilds where the world dies every serveral minutes.

Wanda's mechanism is that she loses health constantly. While a general way to trigger immediate death is using timer component and wait to push a death event, with no penalty. If you want an age-like countdown, it is possible that you add Wanda's clock to the UI, or something like Nightmare Phase Indicator mod.

You may want to save health when death and set it when resurrection.

You know, that's actually what the mod is for! I'm making the Hatchling as a character!

Do you know of some guide that I could use to get a more detailed, step-by-step explanation?

Link to comment
Share on other sites

On 10/4/2022 at 3:27 PM, ScrewdriverLad said:

I'm making a character that will die every 22 Minutes - no stopping it, but they have their own way to revive themselves.

However, I'm not sure how I would do that. I've been looking at Wanda and I saw a few various strings that could help, but I honestly need some help.

Is there anyone I could talk to who can help with this?

 

Additional information: I want a specific song to begin quietly playing once they've got about 2 minutes left, and I want them to be able to revive without losing any max HP.

The death part I can do

function whatever(inst) -- you can name the function whatever

if inst.components.health and not inst.components.health:IsDead() or inst:HasTag("playerghost") then inst:PushEvent("death")

end

inst:DoPeriodicTask(1620, whatever, 1620) 

or

function whatever(inst) -- you can name the function whatever

if inst.components.health and not inst.components.health:IsDead() or inst:HasTag("playerghost") then

inst.components.health:Kill()

end

inst:DoPeriodicTask(1620, whatever, 1620) 

I'm pretty bad at doing modding I'm better at using the console but that should work.

Link to comment
Share on other sites

I'll explain it further.

First, you want to wait for 22 minutes. So you write in prefabpostinit function that

if not inst.components.timer then
  inst:AddComponent("timer")
end
inst.components.timer:StartTimer("when the sun explodes",22*60)
function YouGetKilled(data)
  -- check if it is our timer
  if not data or data.name~="when the sun explodes" then
    return
  end
  -- kill yourself here
end
inst:ListenForEvent("timerdone", YouGetKilled)

Second, kill your self

if inst.components.health then
  if not inst.components.health:IsDead() then
    inst.components.health:Kill()
  end
end
-- revive yourself here

Third, revive your self

-- assume you have a home
if inst.components.homeseeker then
  inst.Transform:SetPosition(inst.components.homeseeker:GetHomePos())
end
-- revive
inst:PushEvent("ms_respawnedfromghost")

Last, don't forget to start another timer

inst:ListenForEvent("ms_respawnedfromghost", function()
    if inst.components.timer:TimerExist("when the sun explodes") then
      inst.components.timer:StopTimer("when the sun explodes")
    end
    inst.components.timer:StartTimer("when the sun explodes",60*22)
end)

 

Edited by Rickzzs
Link to comment
Share on other sites

4 hours ago, ScrewdriverLad said:

Woah, thank you both for the help!

Rickzzs, what do you mean with the "--assume you have a home"? Would that be, say, a meat effigy or something similar?

  Hide contents

I plan on giving them a Nomai Mask that revives them, so it would likely work the same.

 

Hatchling does have a home, so a direct way to code such thing is by adding homeseeker component. And you can define where Hatchling's home is, like a spaceship. Still it is up to you to decide.

Link to comment
Share on other sites

11 hours ago, Rickzzs said:

Hatchling does have a home, so a direct way to code such thing is by adding homeseeker component. And you can define where Hatchling's home is, like a spaceship. Still it is up to you to decide.

Alright! How do I set components?

 

sorry for all these questions, I'm still pretty unfamiliar with lua...

Link to comment
Share on other sites

5 hours ago, ScrewdriverLad said:

Alright! How do I set components?

 

sorry for all these questions, I'm still pretty unfamiliar with lua...

Sorry for not providing examples, but as for grammar things, you can either learn from documents and tutorials, or learn from official codes and mods. There are tutorials in this forum to tell you what a component is, and there are official codes and mods out there, where you can copy&paste.

Link to comment
Share on other sites

15 hours ago, Rickzzs said:

Sorry for not providing examples, but as for grammar things, you can either learn from documents and tutorials, or learn from official codes and mods. There are tutorials in this forum to tell you what a component is, and there are official codes and mods out there, where you can copy&paste.

That's totally fine! Thank you so much!

On 10/8/2022 at 7:14 AM, Rickzzs said:

I'll explain it further.

First, you want to wait for 22 minutes. So you write in prefabpostinit function that

if not inst.components.timer then
  inst:AddComponent("timer")
end
inst.components.timer:StartTimer("when the sun explodes",22*60)
function YouGetKilled()
  -- kill yourself here
end
inst:ListenForEvent("timerdone", YouGetKilled)

Second, kill your self

if inst.components.health then
  if not inst.components.health:IsDead() then
    inst.components.health:Kill()
  end
end
-- revive yourself here

Third, revive your self

-- assume you have a home
if inst.components.homeseeker then
  inst.Transform:SetPosition(inst.components.homeseeker:GetHomePos())
end
-- revive
inst:PushEvent("ms_respawnedfromghost")

Last, don't forget to start another timer

inst:ListenForEvent("ms_respawnedfromghost", function()
    if inst.components.timer:TimerExist("when the sun explodes") then
      inst.components.timer:StopTimer("when the sun explodes")
    end
    inst.components.timer:StartTimer("when the sun explodes",60*22)
end)

 

Oh, and one last thing! I would be putting these into the character's lua file, right? (In this case, warthian.lua?)

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