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.
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...)
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
Edit: It all works now, here is the final code I used for reference:
--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")
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.
[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.
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:
--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")