Jump to content

Does anyone have old red amulet.lua?


Recommended Posts

I have backups of most script files since end 2018.
What was changed for amulet? which version do you need?

edit:
just compared my oldest with the newest amulet.lua and there is not much difference, only few things added, no complete overhaul. so why do you need an old version?

Edited by Serpens
Link to comment
Share on other sites

6 hours ago, Serpens said:

I have backups of most script files since end 2018.
What was changed for amulet? which version do you need?

edit:
just compared my oldest with the newest amulet.lua and there is not much difference, only few things added, no complete overhaul. so why do you need an old version?

i just need resurrection code

Link to comment
Share on other sites

yes, Sunset Skye might be right, the DST code does not have a ressurection of wearer. And the current DS code in amulet.lua also does not have it. So I guess you are looking for an old DS amulet.lua file? I don't have backups of this =/

But you can also code it yourself. If you explain a little bit more how EXACTLY it should work, I may be able to help you. beware, you really have to explain it exactly, otherwise I wont help.

Link to comment
Share on other sites

1 hour ago, Serpens said:

yes, Sunset Skye might be right, the DST code does not have a ressurection of wearer. And the current DS code in amulet.lua also does not have it. So I guess you are looking for an old DS amulet.lua file? I don't have backups of this =/

But you can also code it yourself. If you explain a little bit more how EXACTLY it should work, I may be able to help you. beware, you really have to explain it exactly, otherwise I wont help.

I am trying to code it myself but  its not going well. I want to make an amulet that resurrect the person who wear it per 7 in game days

10 hours ago, Sunset Skye said:

I don't think the life giving amulet has ever worked like that in DST, so you'll need to look at DS's life giving amulet for reference and then figure out how to make that kind of thing work in DST.

well i find ds amulet.lua and it does not work either both 

Link to comment
Share on other sites

5 minutes ago, AkaiNight said:

I am trying to code it myself but  its not going well. I want to make an amulet that resurrect the person who wear it per 7 in game days

that is not exactly, elaborate.
What do you mean with "per 7 ingame days" ? Should the person be a ghost for 7 days? Or is it a cooldown, so at max one ressurection per 7 days and the ressurrection itself is instant after dying? And should the amulet break/consumes itself? More details please

Link to comment
Share on other sites

Just now, Serpens said:

that is not exactly, elaborate.
What do you mean with "per 7 ingame days" ? Should the person be a ghost for 7 days? Or is it a cooldown, so at max one ressurection per 7 days and the ressurrection itself is instant after dying? And should the amulet break/consumes itself? More details please

It does not have durability so you must wait 7 days after resurrecrion like cooldown and it would be great if you just resurrect with 1/10 of your max health

Link to comment
Share on other sites

4 minutes ago, AkaiNight said:

It does not have durability so you must wait 7 days after resurrecrion like cooldown and it would be great if you just resurrect with 1/10 of your max health

ok, should the ressurection be instant, so directly after death? Should the amulet be consumed (looses part of its uses?)?
And why is the current mechanic of haunting the amulet not good enough?

Edited by Serpens
Link to comment
Share on other sites

Just now, Serpens said:

ok, should the ressurection be instant, so directly after death? Should the amulet be consumed (losses part of its uses?)?
And why is the current mechanic of haunting the amulet not good enough?

yes it should res you instand, no amulet has no durability or somethinglike that. because it does not have any in game image(except inv image) and if you lose it there is no way to craft or got it back thats why it must not be haunted

Link to comment
Share on other sites

1 minute ago, AkaiNight said:

yes it should res you instand, no amulet has no durability or somethinglike that. because it does not have any in game image(except inv image) and if you lose it there is no way to craft or got it back thats why it must not be haunted

So it is more like a special character ability, one free ressurect every 7 ingame days? Do you really want that amulet? Or could the code for it also be in the character itself? I mean, if it is currently an item without ingame image, you might loose it if you accidently drop it (and then it is invisible), so it might be better if it is no item.

And how important is the 7 days cooldown? I mean we have several ways to implement that. We could do a PeriodicTask that is activating the amulet after 7 days. But the problem is that when leave the server, that PeriodicTask is stopped and restarted when you join again. That means we would need to save the current state (eg. save that we already waited 4 of 7 days and next time the timer start when entering the server again, it should only wait 3 more days). This Save code is possible, but much more complex.
An alternative would be to check the current day every day and if the number of days already passed is dividable by 7 without rest, then activate the amulet again. This should work without the need to save anything.

Link to comment
Share on other sites

Just now, Serpens said:

So it is more like a special character ability, one free ressurect every 7 ingame days? Do you really want that amulet? Or could the code for it also be in the character itself? I mean, if it is currently an item without ingame image, you might loose it if you accidently drop it (and then it is invisible), so it might be better if it is no item.

And how important is the 7 days cooldown? I mean we have several ways to implement that. We could do a PeriodicTask that is activating the amulet after 7 days. But the problem is that when leave the server, that PeriodicTask is stopped and restarted when you join again. That means we would need to save the current state (eg. save that we already waited 4 of 7 days and next time the timer start when entering the server again, it should only wait 3 more days). This Save code is possible, but much more complex.
An alternative would be to check the current day every day and if the number of days already passed is dividable by 7 without rest, then activate the amulet again. This should work without the need to save anything.

well im ok with both ways tbh

Link to comment
Share on other sites

40 minutes ago, AkaiNight said:

well im ok with both ways tbh

ok, I will write you the code for that, with saving, because it is better.

But please answer the question if it still should be an amulet, or a character perk? If an amulet, should it only work when equipped? Or also if in inventory?

Link to comment
Share on other sites

ok, I did the code now to attach it to any character, not to an amulet. Because with an amulet it would be quite difficult, because when dying you drop everything, so after death there is no good way to find out if you had the amulet or not.

Put the following code into a new file called "freerevive.lua" and put that file in your mod into scripts/components folder.

local FreeRevive = Class(function(self, inst)
    self.inst = inst
    self.is_active = true
    self.cooldown_task = nil
    self.cooldown_taskinfo = nil
    self.player = nil
    
    self.revive_after_cooldown_if_ghost = true
    self.say_again_revive = nil
    self.revive_delay = 10 -- in seconds, revive with a short delay, so you do not will die again to the same cause -> flee as ghost
    self.cooldown_days = 7*TUNING.TOTAL_DAY_TIME -- in days. after a ressurection, it will only trigger again after that many days
    if self.inst:HasTag("player") then
        self.player = self.inst
        self.inst:ListenForEvent("death", function() self:OnDeath() end)
    end
end)


function FreeRevive:DoRevive()
    local revived = false
    if self.player:HasTag("playerghost") then
        self.player:PushEvent("respawnfromghost")
        revived = true
    elseif self.player:HasTag("corpse") then
        self.player:PushEvent("respawnfromcorpse")
        revived = true
    end
    if revived then
        self.is_active = false
        if self.cooldown_task==nil then -- ResumeTask is the same like DoTaskInTime, but it also returns taskinfo which can be used to get the remaining time when saving
            self.cooldown_task,self.cooldown_taskinfo = self.player:ResumeTask(self.cooldown_days, function() self:ActivateFreeRevive() end)
        end
    end
end


function FreeRevive:ActivateFreeRevive()
    self.is_active = true
    if self.cooldown_task~=nil then
        self.cooldown_task:Cancel()
        self.cooldown_task = nil
        self.cooldown_taskinfo = nil
    end
    if self.say_again_revive~=nil and self.player~=nil and self.player.components~=nil and self.player.components.talker~=nil then
        self.player.components.talker:Say(self.say_again_revive)
    end
    if self.revive_after_cooldown_if_ghost and self.player~=nil then
        self:DoRevive() -- try to revive, if player is a ghost
    end
end


function FreeRevive:OnDeath()
    if self.is_active and self.player~=nil then
        self.player:DoTaskInTime(self.revive_delay,function() self:DoRevive() end) -- revive with a delay, so we wont die again to the same cause
    end
end

function FreeRevive:OnSave()
	local rest_cooldown = nil
    if self.cooldown_task~=nil and self.player~=nil then -- ResumeTask is the same like DoTaskInTime, but it also returns taskinfo which can be used to get the remaining time when saving
        rest_cooldown = self.player:TimeRemainingInTask(self.cooldown_taskinfo)
    end
    return { is_active = self.is_active, rest_cooldown = rest_cooldown }
end

function FreeRevive:OnLoad(data)
	if data~=nil then
        self.is_active = data.is_active
        if data.rest_cooldown~=nil and self.player~=nil then -- ResumeTask is the same like DoTaskInTime, but it also returns taskinfo which can be used to get the remaining time when saving
            self.cooldown_task,self.cooldown_taskinfo = self.player:ResumeTask(data.rest_cooldown, function() self:ActivateFreeRevive() end)
        end
    end
end



return FreeRevive

After that you can add to your modmain for example this code:

AddPlayerPostInit(function(inst)
    if inst.prefab=="wilson" then
        inst:AddComponent("freerevive")
        inst.components.freerevive.revive_delay = 10 -- in seconds, revive with a short delay, so you do not will die again to the same cause -> flee as ghost
        inst.components.freerevive.cooldown_days = 7*TUNING.TOTAL_DAY_TIME -- in days. after a ressurection, it will only trigger again after that many days
        inst.components.freerevive.say_again_revive = "I have a free ressurect again" -- a string the character should say, when there is a new free revive again
        inst.components.freerevive.revive_after_cooldown_if_ghost = true -- if true and the cooldown ends while you are currently a ghost, you will be revived. 
    end
end)

then every wilson will have this ability (of course you can exchange the prefab name with your special character)

 

Edited by Serpens
edit, added some self.player~=nil checks to be sure.
  • Like 1
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...