Jump to content

Player teleportation timer


Cunning fox
  • Pending

When the player leaves the game on a boat and then rejoins the game they're teleported to the portal if they're suppose to drown. It's done through DoTaskInTime, reference to which is not saved anywhere. I want to change this behavior, but right now there's no way to change it (at least not ugly one). I suggest changing:
prefabs/player_common.lua:809

inst:DoTaskInTime(0, function()
	--V2C: HACK! enabled false instead of nil means it was overriden by weregoose on load.
	--     Please refactor drownable and this block to use POST LOAD timing instead.
	if inst.components.drownable ~= nil and inst.components.drownable.enabled ~= false then
		local my_x, my_y, my_z = inst.Transform:GetWorldPosition()

		if not TheWorld.Map:IsPassableAtPoint(my_x, my_y, my_z) then
		for k,v in pairs(Ents) do
				if v:IsValid() and v:HasTag("multiplayer_portal") then
					inst.Transform:SetPosition(v.Transform:GetWorldPosition())
					inst:SnapCamera()
				end
			end
		end
	end
end)

To:

inst.portal_teleport_task = inst:DoTaskInTime(0, function()
        --V2C: HACK! enabled false instead of nil means it was overriden by weregoose on load.
        --     Please refactor drownable and this block to use POST LOAD timing instead.
        if inst.components.drownable ~= nil and inst.components.drownable.enabled ~= false then
            local my_x, my_y, my_z = inst.Transform:GetWorldPosition()

            if not TheWorld.Map:IsPassableAtPoint(my_x, my_y, my_z) then
            for k,v in pairs(Ents) do
                    if v:IsValid() and v:HasTag("multiplayer_portal") then
                        inst.Transform:SetPosition(v.Transform:GetWorldPosition())
                        inst:SnapCamera()
                    end
                end
			inst.portal_teleport_task = nil
            end
        end
    end)

 


Steps to Reproduce

None

  • Like 3
  • Thanks 3



User Feedback


Could you tune '_OnLoad' (line 806) instead ? DoTaskInTime will only act if your method fails.

Share this comment


Link to comment
Share on other sites

14 hours ago, Cuikui said:

Could you tune '_OnLoad' (line 806) instead ? DoTaskInTime will only act if your method fails.

There's no return anywhere near _OnLoad
image.thumb.png.e2705833220c747fbf4a54d7840e95c4.png

Share this comment


Link to comment
Share on other sites

If your custom function _Onload places the player on a platform, then the IsPassableAtPoint test will be false and DoTaskInTime will activate but do nothing.

  • Thanks 1

Share this comment


Link to comment
Share on other sites

this will be done for the next hotfix
One day, the hack comments my be addressed. When that day comes, this variable will be removed, so please test for nil before calling Cancel

  • Thanks 1

Share this comment


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

×
  • Create New...