Posts: 25
Threads: 6
Joined: Oct 2015
Thanks: 5
Given 12 thank(s) in 6 post(s)
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.)
Posts: 513
Threads: 10
Joined: May 2014
Thanks: 138
Given 89 thank(s) in 75 post(s)
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
Posts: 25
Threads: 6
Joined: Oct 2015
Thanks: 5
Given 12 thank(s) in 6 post(s)
(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
Posts: 513
Threads: 10
Joined: May 2014
Thanks: 138
Given 89 thank(s) in 75 post(s)
10-10-2015, 06:08 PM
(This post was last modified: 10-10-2015, 06:08 PM by Seadragon91.)
Strange, only thought I have now is that you forgot to register the hook, but I think you have registered it.
Posts: 25
Threads: 6
Joined: Oct 2015
Thanks: 5
Given 12 thank(s) in 6 post(s)
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
Posts: 513
Threads: 10
Joined: May 2014
Thanks: 138
Given 89 thank(s) in 75 post(s)
HasTeleported will be set from a command, or? For what is it needed?
Posts: 4,629
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
Perhaps a different plugin stops the hook. Try loading the plugin as the first plugin.
Posts: 25
Threads: 6
Joined: Oct 2015
Thanks: 5
Given 12 thank(s) in 6 post(s)
(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 command
(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
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.
|