Jump to content

Need help (player_common_extensions.lua)


Recommended Posts

Hello!
I want edit "player_common_extensions.lua", need changes this code:

    -- Resurrector is involved
    if source ~= nil then
        inst.DynamicShadow:Enable(true)
        inst.AnimState:SetBank("wilson")
        inst.components.skinner:SetSkinMode("normal_skin") -- restore skin
        inst.components.bloomer:PopBloom("playerghostbloom")
        inst.AnimState:SetLightOverride(0)

        source:PushEvent("activateresurrection", inst)

        if source.prefab == "amulet" then
            inst.components.inventory:Equip(source)
            inst.sg:GoToState("amulet_rebirth")
        elseif source.prefab == "resurrectionstone" then
            inst.components.inventory:Hide()
            inst:PushEvent("ms_closepopups")
            inst.sg:GoToState("wakeup")
        elseif source.prefab == "resurrectionstatue" then
            inst.sg:GoToState("rebirth")
        elseif source:HasTag("multiplayer_portal") then
            inst.components.health:DeltaPenalty(TUNING.PORTAL_HEALTH_PENALTY)

            source:PushEvent("rez_player")
            inst.sg:GoToState("portal_rez")
        end
    else -- Telltale Heart
        inst.sg:GoToState("reviver_rebirth", item)
    end

How I can do this?
I can change this code using only "modmain.lua"?

Edited by Tezumoto
Link to comment
Share on other sites

What exactly do you want to change? Just because the code is right there, it doesn't mean it's the only place to "get at it". You kind of HAVE to do all your changes from modmain.lua. Any other file you make, will need to be "activated" in the modmain anyway.

Link to comment
Share on other sites

2 minutes ago, Ultroman said:

What exactly do you want to change? Just because the code is right there, it doesn't mean it's the only place to "get at it". You kind of HAVE to do all your changes from modmain.lua. Any other file you make, will need to be "activated" in the modmain anyway.

I want add this:

            inst.components.health:DeltaPenalty(TUNING.PORTAL_HEALTH_PENALTY)

For "resurrectionstone".

Link to comment
Share on other sites

So, you want the player to receive a max-HP penalty when using the resurrection stone. Got it.

You can see that the "source" pushes the event "activateresurrection" just before the if-statement.

source:PushEvent("activateresurrection", inst)

Looking at the resurrectionstone.lua you can see that it listens to this event already, and calls a function which does some things when it's called. You want to edit this function, and add the functionality you want.

Simply do this

AddPrefabPostInit("resurrectionstone", function(inst)
	local oldFn = inst.OnActivateResurrection
	inst.OnActivateResurrection = function(inst, guy)
		oldFn(inst, guy)
		if guy.components.health then
			guy.components.health:DeltaPenalty(TUNING.PORTAL_HEALTH_PENALTY)
		end
	end
end)

 

Alternatively, you can just add another listener, and call your own function. That's probably even better.

AddPrefabPostInit("resurrectionstone", function(inst)
	inst:ListenForEvent("activateresurrection", function(source, guy)
		if guy.components.health then
			guy.components.health:DeltaPenalty(TUNING.PORTAL_HEALTH_PENALTY)
		end
	end
end)

 

Edited by Ultroman
Link to comment
Share on other sites

Don't need add "GLOBAL.TheWorld.ismastersim"?

AddPrefabPostInit("resurrectionstone", function(inst)
	inst:ListenForEvent("activateresurrection", function(source, guy)
		if guy.components.health and GLOBAL.TheWorld.ismastersim then
			guy.components.health:DeltaPenalty(TUNING.PORTAL_HEALTH_PENALTY)
		end
	end
end)

 

Edited by Tezumoto
Link to comment
Share on other sites

Not sure, actually. I don't do it for any of my mods anymore, because it makes them not work on servers with caves. Put it in there, and if it works on servers with and without caves, then keep it. If it doesn't work on servers with caves, remove it, and test again.

Link to comment
Share on other sites

1 minute ago, Ultroman said:

Not sure, actually. I don't do it for any of my mods anymore, because it makes them not work on servers with caves. Put it in there, and if it works on servers with and without caves, then keep it. If it doesn't work on servers with caves, remove it, and test again.

Need more ")"?

AddPrefabPostInit("resurrectionstone", function(inst)
	inst:ListenForEvent("activateresurrection", function(source, guy)
		if guy.components.health then
			guy.components.health:DeltaPenalty(TUNING.PORTAL_HEALTH_PENALTY)
		end
	end)
end)

At line 6.

Link to comment
Share on other sites

Just now, Ultroman said:

It doesn't look like it. They match up as far as I can see.

My Notepad++ just shows me that one "(" not closed.

AddPrefabPostInit("resurrectionstone", function(inst)
	inst:ListenForEvent("activateresurrection", function(source, guy)
		if guy.components.health then
			guy.components.health:DeltaPenalty(TUNING.PORTAL_HEALTH_PENALTY)
		end
	end)
end)

This code work on my server with cave.
I hope for other players on my server this will also work without errors.

Link to comment
Share on other sites

6 minutes ago, Ultroman said:

It should. If you test on a server without caves, you're essentially testing whether it works on a server-player, and when you test on a server with caves, you're essentially testing whether it works on client-players.

Why do need "TheWorld.ismastersim"?
Me was told that this parameter is responsible for what is being processed on the server side, and not just for the player.

Edited by Tezumoto
Link to comment
Share on other sites

The clients don't need all the components and stuff, since they're essentially looking at "replicants" of the actual entities. The server does most of the work, and then tells clients what is happening. The clients mostly just know how things are supposed to be shown, and not how they work. For example, clients don't know how much health a thing has. They just know if they can click on it and interact with it. I'm not completely versed in this aspect of the code structure, but I probably should get familiar with it, since I have quite a lot of mods on the workshop ^^

Link to comment
Share on other sites

9 minutes ago, Ultroman said:

The clients don't need all the components and stuff, since they're essentially looking at "replicants" of the actual entities. The server does most of the work, and then tells clients what is happening. The clients mostly just know how things are supposed to be shown, and not how they work. For example, clients don't know how much health a thing has. They just know if they can click on it and interact with it. I'm not completely versed in this aspect of the code structure, but I probably should get familiar with it, since I have quite a lot of mods on the workshop ^^

Hmm...
This too work on my server with cave.
(with "GLOBAL.TheWorld.ismastersim")
I didn't really understand all this, but it works :D

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