Page 1 of 1

Enhanced Teleport Troubles (Solved)

Posted: Mon Apr 13, 2009 12:44 pm
by theITfactor
I set up a basic teleport, but now I want to enhance it by playing a "teleport effect" before the player gets teleported.

The basic idea is on enter region, the player is frozen in place, an invisible object is created on the player's location, the object is then destroyed, with its destruction effect being the "teleport effect" around the player, then once the effect is over the player is teleported away.

This is the code I have so far, however after the object is created, nothing further happens. In addition to getting this current bit of code to work I need to add in the freeze effect.

EDIT: Tried to fix timer:
Hidden/Spoiler:
-----------------------
--Main Teleport A--
-----------------------

TeleTimer = CreateTimer("Tele")
SetTimerValue(TeleTimer, 5)

main_a = OnEnterRegion(

function(regIn,character)
local unit = GetCharacterUnit( character )
if not unit then return end

--get the unit's location
local point = GetEntityMatrix( unit )

--drop an invisible character prop directly on the unit

CreateEntity("teledummy", point, "teledummy")
-- SetProperty("teledummy", "CurHealth", 10)
-- SetProperty("teledummy", "CurHealth", 0)
KillObject("teledummy")
StartTimer(TeleTimer)

end,
"main_a"
)

OnTimerElapse(
function(timer)
MoveEntityToNode(character,"main_a")
DestroyTimer(TeleTimer)
end,
"Tele"
)

ActivateRegion("main_a")

Re: Enhanced Teleport Troubles

Posted: Mon Apr 13, 2009 4:44 pm
by [RDH]Zerted
Your OnTimerElapse isn't written correctly. Reread the scripting doc to learn how to do timers.

Re: Enhanced Teleport Troubles

Posted: Mon Apr 13, 2009 6:00 pm
by theITfactor
[RDH]Zerted wrote:Your OnTimerElapse isn't written correctly. Reread the scripting doc to learn how to do timers.
Attempted to fix it, but still have same problem:
Hidden/Spoiler:
-----------------------
--Main Teleport A--
-----------------------

TeleTimer = CreateTimer("Tele")
SetTimerValue(TeleTimer, 5)

main_a = OnEnterRegion(

function(regIn,character)
local unit = GetCharacterUnit( character )
if not unit then return end

--get the unit's location
local point = GetEntityMatrix( unit )

--drop an invisible character prop directly on the unit

CreateEntity("teledummy", point, "teledummy")
-- SetProperty("teledummy", "CurHealth", 10)
-- SetProperty("teledummy", "CurHealth", 0)
KillObject("teledummy")
StartTimer(TeleTimer)

end,
"main_a"
)

OnTimerElapse(
function(timer)
MoveEntityToNode(character,"main_a")
DestroyTimer(TeleTimer)
end,
"Tele"
)

ActivateRegion("main_a")

Re: Enhanced Teleport Troubles

Posted: Mon Apr 13, 2009 6:04 pm
by Maveritchell
Your reference in the OnTimerElapse should be TeleTimer, not "Tele".

Re: Enhanced Teleport Troubles

Posted: Mon Apr 13, 2009 6:11 pm
by theITfactor
Maveritchell wrote:Your reference in the OnTimerElapse should be TeleTimer, not "Tele".
I had that but it gave this error:
Hidden/Spoiler:
Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #2 to `OnTimerElapse' (string expected, got nil)
stack traceback:
[C]: in function `OnTimerElapse'
(none): in function `ScriptPostLoad'
so Rep said to change it to "Tele"

Re: Enhanced Teleport Troubles

Posted: Mon Apr 13, 2009 6:16 pm
by Maveritchell
Was it also in quotations? It should not have been. Also, assign your OnTimerElapse function to a variable (TeleportTimer = OnTimerEla...)

Re: Enhanced Teleport Troubles

Posted: Mon Apr 13, 2009 6:24 pm
by ryukaji
OnTimerElapse(
function(timer)
MoveEntityToNode(character,"main_a")
DestroyTimer(TeleTimer)
end,
"Tele"
its supposed to be function(timer,TeleTimer) isnt it?

Re: Enhanced Teleport Troubles

Posted: Mon Apr 13, 2009 6:31 pm
by RepSharpshooter
Maveritchell wrote:Was it also in quotations? It should not have been. Also, assign your OnTimerElapse function to a variable (TeleportTimer = OnTimerEla...)
I have always used the timer's name in quotes as the actor argument to the filter. It works as well as the direct instance of the timer.

In either case, the timer is only an issue if it causes the lua to crash.

I suggested placing a static object in ZE, killing it at the top of the lua, then respawning and killing later to produce the effect.

Re: Enhanced Teleport Troubles

Posted: Mon Apr 13, 2009 6:36 pm
by Maveritchell
RepSharpshooter wrote:
Maveritchell wrote:Was it also in quotations? It should not have been. Also, assign your OnTimerElapse function to a variable (TeleportTimer = OnTimerEla...)
I have always used the timer's name in quotes as the actor argument to the filter. It works as well as the direct instance of the timer.

In either case, the timer is only an issue if it causes the lua to crash.

I suggested placing a static object in ZE, killing it at the top of the lua, then respawning and killing later to produce the effect.
That is how I usually do it; but he seems to want to create an effect directly on top of the unit, no matter where he is. Unless it is a very small region or a very large effect, the object would have to be created by capturing the player's location.

Re: Enhanced Teleport Troubles

Posted: Mon Apr 13, 2009 6:46 pm
by theITfactor
I think I figured out part of it - I had placed "teledummy" in ZE in an obscure location in order to get it to load that .odf

When I created entity "teledummy" it already existed in ZE so it probably was destroying the one I placed in ZE and not the one I just created.

I'm just going to make the tele region smaller and try the static method.

Re: Enhanced Teleport Troubles

Posted: Mon Apr 13, 2009 6:49 pm
by Maveritchell
theITfactor wrote:I'm just going to make the tele region smaller and try the static method.
As a point of reference, regions "act" larger then they actually are. You usually won't notice it except with small regions - in reality a "single-person" sized region is about .23 (X) * .23 (Z). It's best to have some sort of visible indicator for regions this size, though.

Re: Enhanced Teleport Troubles

Posted: Mon Apr 13, 2009 6:53 pm
by theITfactor
Maveritchell wrote:
theITfactor wrote:I'm just going to make the tele region smaller and try the static method.
As a point of reference, regions "act" larger then they actually are. You usually won't notice it except with small regions - in reality a "single-person" sized region is about .23 (X) * .23 (Z). It's best to have some sort of visible indicator for regions this size, though.
I'll put a teleport-pad in ZE for it :wink:

Edit: It all works now, here is the final code I used for reference:
Hidden/Spoiler:
TeleTimer = CreateTimer("Tele")
SetTimerValue(TeleTimer, 2)

--Creating the variable in the global scope so all functions can use it
tobeteleported = nil

main_a = OnEnterRegion(
function(regIn,character)
StartTimer(TeleTimer)
KillObject("teledummy")
--character only exists in this function, so set it to the global var
tobeteleported = character
end,
"main_a"
)
ActivateRegion("main_a")

TeleportTimer = OnTimerElapse(
function(timer)
MoveEntityToNode(tobeteleported,"tele_a")
end,
"Tele"
)

Re: Enhanced Teleport Troubles

Posted: Mon Apr 13, 2009 8:43 pm
by [RDH]Zerted
Might I suggest a change? I'm not sure how well your code will work if two people run into the region at the same time. If that won't happen, then just ignore me. The following code should handle this case a bit better. It creates a new timer for each player entering the region and deletes the timer when it is no longer needed.
Hidden/Spoiler:
[code]
--holds teleport timer callbacks for multiple players
teleTable = {}

main_a = OnEnterRegion(
function(regIn,character)

--generates a new timer name representing this character entering the region
timerName = "tele_"..character

teleTable[timerName] = OnTimerElapse(
function(timer)
--teleport the player
MoveEntityToNode(character,"tele_a")

--clear this timer
ReleaseTimerElapse(teleTable[timerName])
DestroyTimer(timerName)
teleTable[timerName] = nil
end,
timerName
)

--create and start the timer
CreateTimer(timerName)
SetTimerValue(timerName, 2)
StartTimer(timerName)

KillObject("teledummy")
end,
"main_a"
)
ActivateRegion("main_a")[/code]

Re: Enhanced Teleport Troubles

Posted: Mon Apr 13, 2009 9:20 pm
by theITfactor
[RDH]Zerted wrote:Might I suggest a change? I'm not sure how well your code will work if two people run into the region at the same time. If that won't happen, then just ignore me. The following code should handle this case a bit better. It creates a new timer for each player entering the region and deletes the timer when it is no longer needed.
Hidden/Spoiler:
[code]
--holds teleport timer callbacks for multiple players
teleTable = {}

main_a = OnEnterRegion(
function(regIn,character)

--generates a new timer name representing this character entering the region
timerName = "tele_"..character

teleTable[timerName] = OnTimerElapse(
function(timer)
--teleport the player
MoveEntityToNode(character,"tele_a")

--clear this timer
ReleaseTimerElapse(teleTable[timerName])
DestroyTimer(timerName)
teleTable[timerName] = nil
end,
timerName
)

--create and start the timer
CreateTimer(timerName)
SetTimerValue(timerName, 2)
StartTimer(timerName)

KillObject("teledummy")
end,
"main_a"
)
ActivateRegion("main_a")[/code]
Thanks zerted, I'll use that :)


EDIT
Hmm, the first time you enter the region, the object is destroyed, but no teleport occurs. Leaving and reentering the region teleports you, but no object is destroyed.

Edit2: Ended up using this, thanks Mav and Zerted:
Hidden/Spoiler:
teleregionon = 0
TeleTimer = CreateTimer("Tele")
ArriveTimer = CreateTimer("Arrival")

--Creating the variable in the global scope so all functions can use it
tobeteleported = nil

main_a = OnEnterRegion(
function(regIn,character)
if teleregionon == 0 then
SetTimerValue(TeleTimer, 1)
StartTimer(TeleTimer)
SetProperty(GetCharacterUnit(character), "PhysicsActive", 0)
SetProperty("teledummy", "CurHealth", 0)
--KillObject("teledummy")
--RespawnObject("teledummy")
--character only exists in this function, so set it to the global var
tobeteleported = character
teleregionon = 1
end
end,
"main_a"
)
ActivateRegion("main_a")

TeleportTimer = OnTimerElapse(
function(timer)
MoveEntityToNode(tobeteleported,"tele_a")
SetProperty("teledummy_arrive", "CurHealth", 0)
SetProperty("teledummy", "CurHealth", 1)
SetTimerValue(ArriveTimer, 1)
StartTimer(ArriveTimer)
end,
"Tele"
)

ArrivalTimer = OnTimerElapse(
function(timer)
SetProperty(GetCharacterUnit(tobeteleported), "PhysicsActive", 1)
SetProperty("teledummy_arrive", "CurHealth", 1)
teleregionon = 0
end,
"Arrival"
)
http://www.xfire.com/video/a3c06/