Jump to content

Please help me edit the status of my custom character.


Recommended Posts

I'm trying to make a modification that changes status in a day/night cycle.

local function WorldPhaseChangeSpeed(inst, phase) 
    local spmultplier = 1
	local dmultplier = 1
	--local healthtest = 1
	if not inst:HasTag("playerghost") then
		if not TheWorld:HasTag("cave") then
			if phase == "day" then
			local percent = inst.components.health:GetPercent() 
				spmultplier = 0.8
				dmultplier = 0.5
				--healthtest = 50
				inst.components.health:SetMaxHealth(50)
				inst.components.health:DoDelta(0)
				inst.components.health:SetPercent(percent)
			elseif phase == "dusk" then
			local percent = inst.components.health:GetPercent() 
				spmultplier = 1.0
				dmultplier = 0.8
				--healthtest = 100
				inst.components.health:SetMaxHealth(100)
				inst.components.health:DoDelta(0)
				inst.components.health:SetPercent(percent)
			elseif phase == "night" then
			local percent = inst.components.health:GetPercent() 
				spmultplier = 1.4
				dmultplier = 1.5
				--healthtest = 200
				inst.components.health:SetMaxHealth(200)
				inst.components.health:DoDelta(0)
				inst.components.health:SetPercent(percent)
			end
			inst.components.locomotor:SetExternalSpeedMultiplier(inst, "phase_speed", spmultplier)
			inst.components.combat.externaldamagemultipliers:SetModifier("phase_power", dmultplier)
			--TUNING.UNNAMED_HEALTH = healthtest
			--inst.components.health:DoDelta(0)
		else
			if phase == "caveday" then
				local percent = inst.components.health:GetPercent() 
				spmultplier = 1.2
				dmultplier = 1.2
				inst.components.health:SetMaxHealth(80)
				inst.components.health:DoDelta(0)
				inst.components.health:SetPercent(percent)
			elseif phase == "cavedusk" then
				local percent = inst.components.health:GetPercent() 
				spmultplier = 1.2
				dmultplier = 1.2
				inst.components.health:SetMaxHealth(130)
				inst.components.health:DoDelta(0)
				inst.components.health:SetPercent(percent)
			elseif phase == "cavenight" then
				local percent = inst.components.health:GetPercent() 
				spmultplier = 1.2
				dmultplier = 1.2
				inst.components.health:SetMaxHealth(160)
				inst.components.health:DoDelta(0)
				inst.components.health:SetPercent(percent)
			end
			inst.components.locomotor:SetExternalSpeedMultiplier(inst, "phase_speed", spmultplier)
			inst.components.combat.externaldamagemultipliers:SetModifier("phase_power", dmultplier)
		end
	end
end

--master_postinit
	inst:WatchWorldState("phase", WorldPhaseChangeSpeed)
	WorldPhaseChangeSpeed(inst, TheWorld.state.phase)

 

The code worked on the surface world, but not on the cave world.
What part am I doing wrong?

 

My English is not good, sorry if I'm rude.

Link to comment
Share on other sites

In the cave, phase is always considered night, that's why there is no change.

You need to add another WatchWorldState that is watching for "cavephase", and there you can enter your section of your function that sets the speed for caves.

  • Like 2
Link to comment
Share on other sites

40 minutes ago, Monti18 said:

In the cave, phase is always considered night, that's why there is no change.

You need to add another WatchWorldState that is watching for "cavephase", and there you can enter your section of your function that sets the speed for caves.

Thanks for the reply!

 

I'm still learning to modify it, so I don't know if this is right or not, but it worked!

I have separated the functions in the process of trying many times, is it possible to merge them?

 

local function WorldPhaseChangeSpeed(inst, phase) 
    local spmultplier = 1
	local dmultplier = 1

	if not inst:HasTag("playerghost") then
		if not TheWorld:HasTag("cave") then
			if phase == "day" then
			local percent = inst.components.health:GetPercent() 
				spmultplier = 0.8
				dmultplier = 0.5
				inst.components.health:SetMaxHealth(50)
				inst.components.health:DoDelta(0)
				inst.components.health:SetPercent(percent)
			elseif phase == "dusk" then
			local percent = inst.components.health:GetPercent() 
				spmultplier = 1.0
				dmultplier = 0.8
				inst.components.health:SetMaxHealth(100)
				inst.components.health:DoDelta(0)
				inst.components.health:SetPercent(percent)
			elseif phase == "night" then
			local percent = inst.components.health:GetPercent() 
				spmultplier = 1.4
				dmultplier = 1.5
				inst.components.health:SetMaxHealth(200)
				inst.components.health:DoDelta(0)
				inst.components.health:SetPercent(percent)
			end
			inst.components.locomotor:SetExternalSpeedMultiplier(inst, "phase_speed", spmultplier)
			inst.components.combat.externaldamagemultipliers:SetModifier("phase_power", dmultplier)


		end
	end
end

---------------------------------------------------------------------

local function WorldPhaseChangeSpeed2(inst, cavephase)
	local spmultplier = 1
	local dmultplier = 1
		if not inst:HasTag("playerghost") then
			if TheWorld:HasTag("cave") then
				if cavephase == "day" then
					local percent = inst.components.health:GetPercent() 
					spmultplier = 1.2
					dmultplier = 1.2
					inst.components.health:SetMaxHealth(80)
					inst.components.health:DoDelta(0)
					inst.components.health:SetPercent(percent)
				elseif cavephase == "dusk" then
					local percent = inst.components.health:GetPercent() 
					spmultplier = 1.2
					dmultplier = 1.2
					inst.components.health:SetMaxHealth(130)
					inst.components.health:DoDelta(0)
					inst.components.health:SetPercent(percent)
				elseif cavephase == "night" then
					local percent = inst.components.health:GetPercent() 
					spmultplier = 1.2
        			dmultplier = 1.2
					inst.components.health:SetMaxHealth(160)
					inst.components.health:DoDelta(0)
					inst.components.health:SetPercent(percent)
				end	
				inst.components.locomotor:SetExternalSpeedMultiplier(inst, "phase_speed", spmultplier)
				inst.components.combat.externaldamagemultipliers:SetModifier("phase_power", dmultplier)
			end
		end
end

--master_postinit
	inst:WatchWorldState("phase", WorldPhaseChangeSpeed)
	WorldPhaseChangeSpeed(inst, TheWorld.state.phase)
	inst:WatchWorldState("cavephase", WorldPhaseChangeSpeed2)
	WorldPhaseChangeSpeed2(inst, TheWorld.state.phase)

 

Link to comment
Share on other sites

During the test play, I noticed that when entering the cave from the ground, it would branch off into the cavephase == "night".

If the time is updated in the cave, max health will change.
Is there any way to branch to the correct time when I enter the cave?

Link to comment
Share on other sites

I think you need to change 

WorldPhaseChangeSpeed2(inst, TheWorld.state.phase)

to

WorldPhaseChangeSpeed2(inst, TheWorld.state.cavephase)

because otherwise, it will still look for the normal phase which is always night in the cave.

I think you can just use the function like you had at the beginning, change the phase names to the same ones as on the surface and in your masterpostinit you just change WorldPhaseChangeSpeed2 to WorldPhaseChangeSpeed.

Edited by Monti18
  • Like 2
Link to comment
Share on other sites

2 hours ago, Monti18 said:

I think you need to change 


WorldPhaseChangeSpeed2(inst, TheWorld.state.phase)

to


WorldPhaseChangeSpeed2(inst, TheWorld.state.cavephase)

because otherwise, it will still look for the normal phase which is always night in the cave.

I think you can just use the function like you had at the beginning, change the phase names to the same ones as on the surface and in your masterpostinit you just change WorldPhaseChangeSpeed2 to WorldPhaseChangeSpeed.

I tried everything I could think of, but it either banished me from the cave or crashed me back to character selection.

What am I doing wrong?

Spoiler

local function WorldPhaseChangeSpeed(inst, phase)
    local spmultplier = 1
    local dmultplier = 1
    if not inst:HasTag("playerghost") then
        if not TheWorld:HasTag("cave") then
            if phase == "day" then
            local percent = inst.components.health:GetPercent() 
                spmultplier = 0.8
                dmultplier = 0.5
                inst.components.health:SetMaxHealth(50)
                inst.components.health:DoDelta(0)
                inst.components.health:SetPercent(percent)
            elseif phase == "dusk" then
            local percent = inst.components.health:GetPercent() 
                spmultplier = 1.0
                dmultplier = 0.8
                inst.components.health:SetMaxHealth(100)
                inst.components.health:DoDelta(0)
                inst.components.health:SetPercent(percent)
            elseif phase == "night" then
            local percent = inst.components.health:GetPercent() 
                spmultplier = 1.4
                dmultplier = 1.5
                inst.components.health:SetMaxHealth(200)
                inst.components.health:DoDelta(0)
                inst.components.health:SetPercent(percent)
            end
            inst.components.locomotor:SetExternalSpeedMultiplier(inst, "phase_speed", spmultplier)
            inst.components.combat.externaldamagemultipliers:SetModifier("phase_power", dmultplier)
        else
            if phase == "day" then
                local percent = inst.components.health:GetPercent() 
                spmultplier = 1.2
                dmultplier = 1.2
                inst.components.health:SetMaxHealth(80)
                inst.components.health:DoDelta(0)
                inst.components.health:SetPercent(percent)
            elseif phase == "dusk" then
                local percent = inst.components.health:GetPercent() 
                spmultplier = 1.2
                dmultplier = 1.2
                inst.components.health:SetMaxHealth(130)
                inst.components.health:DoDelta(0)
                inst.components.health:SetPercent(percent)
            elseif phase == "night" then
                local percent = inst.components.health:GetPercent() 
                spmultplier = 1.2
                dmultplier = 1.2
                inst.components.health:SetMaxHealth(160)
                inst.components.hdsealth:DoDelta(0)
                inst.components.health:SetPercent(percent)
            end
                inst.components.locomotor:SetExternalSpeedMultiplier(inst, "phase_speed", spmultplier)
                inst.components.combat.externaldamagemultipliers:SetModifier("phase_power", dmultplier)
        end
    end
end

--master_postinit

    inst:WatchWorldState("phase", WorldPhaseChangeSpeed)
    WorldPhaseChangeSpeed(inst, TheWorld.state.phase)
    WorldPhaseChangeSpeed(inst, TheWorld.state.cavephase)

 

Link to comment
Share on other sites

	elseif phase == "night" then
                local percent = inst.components.health:GetPercent() 
                spmultplier = 1.2
                dmultplier = 1.2
                inst.components.health:SetMaxHealth(160)
                inst.components.hdsealth:DoDelta(0)
                inst.components.health:SetPercent(percent)
            end

You wrote hdsealth instead of health, that's why it was crashing. If you are having crashes when entering caves, you won't always find the error in the server log of the master, you need to also have a look into the server log of the caves.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

6 hours ago, Monti18 said:

	elseif phase == "night" then
                local percent = inst.components.health:GetPercent() 
                spmultplier = 1.2
                dmultplier = 1.2
                inst.components.health:SetMaxHealth(160)
                inst.components.hdsealth:DoDelta(0)
                inst.components.health:SetPercent(percent)
            end

You wrote hdsealth instead of health, that's why it was crashing. If you are having crashes when entering caves, you won't always find the error in the server log of the master, you need to also have a look into the server log of the caves.

I completely overlooked that part.

I fixed the code and the error is gone, but the maximum health is no longer updated when the time is updated in the cave.

split the function into surface and cave again to test it, and they worked correctly.

If I merge, will I no longer get the cave update trigger?

 

By the way, I thought all game errors were output to cliant.log. It really helps me to know that server.log exists. Thank you so much!

Link to comment
Share on other sites

It's strange that it's working if you split the function... I did a little testing and the watchworldstate doesn't set the phase to a new value, that's why I thought phase is probably not the right keyword for watching the state in the caves.

This should work if you add it to the master postinit:

	if TheWorld:HasTag("cave") then
		inst:WatchWorldState("cavephase", WorldPhaseChangeSpeed)
		WorldPhaseChangeSpeed(inst, TheWorld.state.cavephase)
	else
		inst:WatchWorldState("phase", WorldPhaseChangeSpeed)
    	WorldPhaseChangeSpeed(inst, TheWorld.state.phase)
    end

If you have a server without caves, the errors will be in the client log, but if you have a server with caves, most of them will be in the server log, except for those that happen on the client. Best is to always check both :)

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

7 hours ago, Monti18 said:

It's strange that it's working if you split the function... I did a little testing and the watchworldstate doesn't set the phase to a new value, that's why I thought phase is probably not the right keyword for watching the state in the caves.

This should work if you add it to the master postinit:


	if TheWorld:HasTag("cave") then
		inst:WatchWorldState("cavephase", WorldPhaseChangeSpeed)
		WorldPhaseChangeSpeed(inst, TheWorld.state.cavephase)
	else
		inst:WatchWorldState("phase", WorldPhaseChangeSpeed)
    	WorldPhaseChangeSpeed(inst, TheWorld.state.phase)
    end

If you have a server without caves, the errors will be in the client log, but if you have a server with caves, most of them will be in the server log, except for those that happen on the client. Best is to always check both :)

I thought that "inst:WatchWorldState("phase", WorldPhaseChangeSpeed)" was assigning WorldState information to "phase".
I'm confused by the fact that it works without changing "if phase" to "if cavephase".

 

Anyway, it's working as I wanted now!

I sincerely appreciate your kindness.

I'm starting to understand some parts of the DST mod rules.

  • Thanks 1
Link to comment
Share on other sites

If I understand your question correctly, you are wondering why in the function WorldChangeSpeed you don't need to change phase to cavephase for the part of the function that is running in the caves.

When using inst:WatchWorldState, you listen to the change of a variable, in this case phase or cavephase. When it's changed, your function, here WorldChangeSpeed, is called with the arguments inst and TheWorld.state.phase or TheWorld.state.cavephase, depending on if you listen to phase or cavephase. When your function is running, you have inst = inst as your first argument and phase = TheWorld.state.phase or phase = TheWorld.state.cavephase. Your second argument can be named whatever you want, as the value will always be given from WatchWorldState.

The second part of the master postinit, WorldPhaseChangeSpeed(inst, TheWorld.state.phase), is just your function running once at the beginning, so that the values for your character are correct, as there isn't an event that WatchWorldState could listen to, as the server has just been started.

So you run your function once so that all values are correct and when the state changes, WatchWorldState will run the function again with the right arguments.

I hope that answers your question, if not, don't hesitate to ask me!

That's good to hear, it's always nice when something is finally working.

You're welcome, if you have other problems, you can always shoot me a message :)

  • Like 1
  • Thanks 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...