Teleport doesn't work when changing world
#1
When teleporting to a new world, it won't teleport you to its destination. (even if you call it under the hook changing and/or changed)

The X, Y, Z cordinates are correct, since they work when i run the test command.

For example, these cordinates:
Code:
x: 1034.1873541002
y: 69
z: 660.55511181803

Here is the code:
function OnEntityChangedWorld(Entity, World)
	if Entity:IsPlayer() then
		if HasTeleported then
			local _name = Entity:GetName()
			local _zone = PlayersData[_name].zones
			
			Entity:TeleportToCoords(PortalsData.warps["".._zone].point.x, PortalsData.warps["".._zone].point.y, PortalsData.warps["".._zone].point.z)
			print("x: " .. PortalsData.warps["".._zone].point.x)
			print("y: " .. PortalsData.warps["".._zone].point.y)
			print("z: " .. PortalsData.warps["".._zone].point.z)
			Entity:SendMessage("You have been teleported!")
			IsWorld = false
			HasTeleported = false
		end
	end
	return false
end

I'm using the code from Portal v1 by Taugeshtu, but i improved it and fixed alot of issues (saving and stuff now works properly w/o giving out errors etc, but im going to re-create the storing to INI file to make it easier and user friendly, plus make it so you can modify it easier trough the web panel.)
Reply
Thanks given by:
#2
I tested the entity changed world hook. It works on my side. After I changed the world, I get teleported to the coordinates.

Reduced code:
function OnEntityChangedWorld(Entity, World)
	LOG("Entity changed world")
	if Entity:IsPlayer() then
		LOG("Entity is a player.")
		Entity:TeleportToCoords(1034, 69, 660)
	end
end
Reply
Thanks given by:
#3
(10-10-2015, 04:19 PM)Seadragon91 Wrote: I tested the entity changed world hook. It works on my side. After I changed the world, I get teleported to the coordinates.

Reduced code:
function OnEntityChangedWorld(Entity, World)
	LOG("Entity changed world")
	if Entity:IsPlayer() then
		LOG("Entity is a player.")
		Entity:TeleportToCoords(1034, 69, 660)
	end
end

Thats weird, for me it doesn't work at all. Might be the version I'm using maybe? I'm using the GIT version i believe (used the DigitalOcean installation). Probably the devs can help out with this, since It refuses to teleport after world change :p
Reply
Thanks given by:
#4
Strange, only thought I have now is that you forgot to register the hook, but I think you have registered it.
Reply
Thanks given by:
#5
Yeah, its pretty strange. I created a test command again called /pteleport, and it has the same values as the OnEntityChangedWorld, and it works when executing it, but not here. lol

Here is the code from the portal_main.lua (well, i only included the needed information here)
function Initialize(Plugin)
	PLUGIN = Plugin
	PLUGIN:SetName("Portal")
	PLUGIN:SetVersion(1)
	
	PluginManager = cRoot:Get():GetPluginManager()
	cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_MOVING, OnPlayerMoving)
	cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK, OnPlayerBreakingBlock)
	cPluginManager:AddHook(cPluginManager.HOOK_ENTITY_CHANGED_WORLD, OnEntityChangedWorld)
	
	PluginManager:BindCommand("/ptoggle",	"portal.create",	HandleToggleCommand,   		" - switches volume selection mode")
	PluginManager:BindCommand("/pwarp",	"portal.create",	HandleMakeWarpCommand,		" (name) - creates warp point with given name")
	PluginManager:BindCommand("/penter",	"portal.create",	HandleMakeEnterCommand,		" (name) - creates portal volume out of selection and associates it with given warp")
	PluginManager:BindCommand("/pteleport",	"",	HandlePortalCommand,		"")
	
	Plugin:AddWebTab("Portals", HandleRequest_Portals)
	
	LoadPortalsData()
	LoadPlayersData()
	LOG("Initialized " .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion())
	return true
end

function OnEntityChangedWorld(Entity, World)
	if Entity:IsPlayer() then
		if HasTeleported then
			local _name = Entity:GetName()
			local _zone = PlayersData[_name].zones

			-- doesn\'t even teleport.
			-- Even if i type in 1254, 255, 31 manually for example, it refuses
			Entity:TeleportToCoords(PortalsData.warps["".._zone].point.x, PortalsData.warps["".._zone].point.y, PortalsData.warps["".._zone].point.z)
			-- Shows the correct values of the location
			print("x: " .. PortalsData.warps["".._zone].point.x)
			print("y: " .. PortalsData.warps["".._zone].point.y)
			print("z: " .. PortalsData.warps["".._zone].point.z)
			-- Gets executed
			Entity:SendMessage("You have been teleported!")
			IsWorld = false
			HasTeleported = false
		end
	end
	return false
end

function HandlePortalCommand(Split, Player)
	local _name = Player:GetName()
	local _zone = PlayersData[_name].zones
	
	-- Ditto, does the same thing, execpt it works
	Player:TeleportToCoords(PortalsData.warps["".._zone].point.x, PortalsData.warps["".._zone].point.y, PortalsData.warps["".._zone].point.z)
	print("x: " .. PortalsData.warps["".._zone].point.x)
	print("y: " .. PortalsData.warps["".._zone].point.y)
	print("z: " .. PortalsData.warps["".._zone].point.z)
	Player:SendMessage("You have been teleported!")
	return true
end
Reply
Thanks given by:
#6
HasTeleported will be set from a command, or? For what is it needed?
Reply
Thanks given by:
#7
Perhaps a different plugin stops the hook. Try loading the plugin as the first plugin.
Reply
Thanks given by:
#8
(10-11-2015, 01:08 AM)Seadragon91 Wrote: HasTeleported will be set from a command, or? For what is it needed?

I created that to make sure it only teleports you to a certain destination if you walked trough a portal, so it won't teleport you randomly if you write /portal commandTongue

(10-11-2015, 01:09 AM)NiLSPACE Wrote: Perhaps a different plugin stops the hook. Try loading the plugin as the first plugin.

I just found the culprit. It was the hook HOOK_PLAYER_MOVING that was causing it to freak out. Re-wrote the stuff, and now it works, thats pretty weird. But at least it works now, so thats good Smile

Now I just need to re-write the teleport stuff again, so it will save everything as a INI file and not a weird string.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)