Enhanced Teleport Troubles (Solved)

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
theITfactor
Chief Warrant Officer
Chief Warrant Officer
Posts: 327
Joined: Wed Jun 28, 2006 12:56 pm
Projects :: The Pwnfest and Games Complex
Games I'm Playing :: SWTOR
xbox live or psn: You and I Know
Location: The Old Republic
Contact:

Enhanced Teleport Troubles (Solved)

Post 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")
Last edited by theITfactor on Mon Apr 13, 2009 6:01 pm, edited 2 times in total.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Enhanced Teleport Troubles

Post by [RDH]Zerted »

Your OnTimerElapse isn't written correctly. Reread the scripting doc to learn how to do timers.
theITfactor
Chief Warrant Officer
Chief Warrant Officer
Posts: 327
Joined: Wed Jun 28, 2006 12:56 pm
Projects :: The Pwnfest and Games Complex
Games I'm Playing :: SWTOR
xbox live or psn: You and I Know
Location: The Old Republic
Contact:

Re: Enhanced Teleport Troubles

Post 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")
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Enhanced Teleport Troubles

Post by Maveritchell »

Your reference in the OnTimerElapse should be TeleTimer, not "Tele".
theITfactor
Chief Warrant Officer
Chief Warrant Officer
Posts: 327
Joined: Wed Jun 28, 2006 12:56 pm
Projects :: The Pwnfest and Games Complex
Games I'm Playing :: SWTOR
xbox live or psn: You and I Know
Location: The Old Republic
Contact:

Re: Enhanced Teleport Troubles

Post 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"
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Enhanced Teleport Troubles

Post by Maveritchell »

Was it also in quotations? It should not have been. Also, assign your OnTimerElapse function to a variable (TeleportTimer = OnTimerEla...)
ryukaji
Major
Major
Posts: 513
Joined: Mon Sep 17, 2007 7:46 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Contact:

Re: Enhanced Teleport Troubles

Post by ryukaji »

OnTimerElapse(
function(timer)
MoveEntityToNode(character,"main_a")
DestroyTimer(TeleTimer)
end,
"Tele"
its supposed to be function(timer,TeleTimer) isnt it?
RepSharpshooter
Gametoast Staff
Gametoast Staff
Posts: 1351
Joined: Tue Jul 10, 2007 4:10 pm

Re: Enhanced Teleport Troubles

Post 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.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Enhanced Teleport Troubles

Post 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.
theITfactor
Chief Warrant Officer
Chief Warrant Officer
Posts: 327
Joined: Wed Jun 28, 2006 12:56 pm
Projects :: The Pwnfest and Games Complex
Games I'm Playing :: SWTOR
xbox live or psn: You and I Know
Location: The Old Republic
Contact:

Re: Enhanced Teleport Troubles

Post 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.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Enhanced Teleport Troubles

Post 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.
theITfactor
Chief Warrant Officer
Chief Warrant Officer
Posts: 327
Joined: Wed Jun 28, 2006 12:56 pm
Projects :: The Pwnfest and Games Complex
Games I'm Playing :: SWTOR
xbox live or psn: You and I Know
Location: The Old Republic
Contact:

Re: Enhanced Teleport Troubles

Post 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"
)
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Enhanced Teleport Troubles

Post 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]
theITfactor
Chief Warrant Officer
Chief Warrant Officer
Posts: 327
Joined: Wed Jun 28, 2006 12:56 pm
Projects :: The Pwnfest and Games Complex
Games I'm Playing :: SWTOR
xbox live or psn: You and I Know
Location: The Old Republic
Contact:

Re: Enhanced Teleport Troubles

Post 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/
Post Reply