Jump to content

Get resurrector ?


Recommended Posts

I would like to help improving the fire resurrection mod. steamcommunity.com/sharedfiles/filedetails/?id=676297854

This mod makes it possible to resurrect at firepits and so on. It also listens for the resurrector Event (something with "ghost" in name), with the aim, to set hunger/sanity/hp values after resurrecting.

But the problem is now, that these value changes also happen, when in endless mode resurrected at the portal. But they should only apply if resurrected at a fire.
I did not find out, how to get the resurrector, so we can change the values only for fires...

Also I would like to add optinally the max health penalty, you get when resurrectiong at portal. How can this be done?
 

Link to comment
Share on other sites

the code that handels this does look like this:

--Punish player for rezzing at fire if the admin has configured to do so.
function apply_negative_effects(inst)
        if GetModConfigData('fire_rez_hunger_level') ~= 'default' then
            inst.components.hunger.current = inst.components.hunger.max * GetModConfigData('fire_rez_hunger_level')
        end

        if GetModConfigData('fire_rez_sanity_level') ~= 'default' then
            inst.components.sanity.current = inst.components.sanity.max * GetModConfigData('fire_rez_sanity_level')
        end

        if GetModConfigData('fire_rez_health_level') ~= 'default' then
            inst.components.health:SetCurrentHealth( inst.components.health.maxhealth * GetModConfigData('fire_rez_health_level') )
        end
end

--Add listener on new player spawns so we can punish them, if so configured.
AddPlayerPostInit( 
    function(inst) 
        inst:ListenForEvent('ms_respawnedfromghost', apply_negative_effects)    
    end
)

I also tried adding "data", so the function was
apply_negative_effects(inst,data)
but data is nil.

So where is the cause?

Edited by Serpens
Link to comment
Share on other sites

You are right. The event ms_respawnedfromghost does not have a data table. However, a similar event, called respawnfromghost, does have a data table with one entry called source, which is a reference to the entity that caused the resurrection, e.g., a touchstone.

Link to comment
Share on other sites

okay.. I looked in the scripts, and it seems respawnfromghost is called before the resurrection and ms_respawnedfromghost is called after it.

So I assume when I try to change hunger in the respawnfromghost event, it won't work, since the respawn did not happend yet..

My first idea to solve this would be, to listen for both events, and in the respawnfromghost event I only save the LastSource in local variable of the mod to use it in the ms_respawnedfromghost event?
Or is there a simpler solution?

edit:
since it has to work for every player, I would save the source in inst.
so maybe:
inst.LastResSource = data.source

I also gave all the fire things the Tag "fire_rez_mod", to identify them.

--Punish player for rezzing at fire if the admin has configured to do so.
function apply_negative_effects(inst)

    if inst.LastResSource and inst.LastResSource:HasTag("fire_rez_mod") then -- only if resseructed through this mod, make the following changes
        if GetModConfigData('fire_rez_hunger_level') ~= 'default' then
            inst.components.hunger.current = inst.components.hunger.max * GetModConfigData('fire_rez_hunger_level')
        end

        if GetModConfigData('fire_rez_sanity_level') ~= 'default' then
            inst.components.sanity.current = inst.components.sanity.max * GetModConfigData('fire_rez_sanity_level')
        end

        if GetModConfigData('fire_rez_health_level') ~= 'default' then
            inst.components.health:SetCurrentHealth( inst.components.health.maxhealth * GetModConfigData('fire_rez_health_level') )
        end
    end

end


function save_last_respawn_source(inst,data)
    if datan then inst.LastResSource = data.source end -- is the thing were we resurrected
end

--Add listener on new player spawns so we can punish them, if we're so configured.
AddPlayerPostInit( 
    function(inst) 
        inst:ListenForEvent('respawnfromghost', save_last_respawn_source)  -- before resurrection, but we have the resurrector
        inst:ListenForEvent('ms_respawnedfromghost', apply_negative_effects)  -- after resurrection, but we get no resurreector
    end
)

 

Edited by Serpens
Link to comment
Share on other sites

I think you are correct on the method required to achieve this. You need to locally save the last source during the pre-resurrect event and then look for it in the post-resurrect event.

Edited by Joachim
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...