Page 1 of 2

Teleporting (FAQ)

Posted: Mon Sep 03, 2007 1:21 pm
by Caleb1117
First off, I folowed Penguin's tut, or whoever originaly made it.

Second, I tryed doing a search, but the seach is kinda weird... anyway, I couldn't find any topics on this.

Ok
I made my region, its a cylinder, and I named it telre1 [aka (teleport - Region - #1)].
Then I made a new path that I named telpa1 [aka (teleport - path - #1)] and placed one node, and moved it underground. (which was hard to get in the right spot underground.)

Then comes the Lua.
Note: Parts of the lua have been renamed (mostly side unit names) for secrecy.
Hidden/Spoiler:
[quote]--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

ScriptCB_DoFile("setup_teams")
ScriptCB_DoFile("ObjectiveConquest")

-- Empire Attacking (attacker is always #1)
local ALL = 2
local IMP = 1
-- These variables do not change
local ATT = 1
local DEF = 2

function ScriptPostLoad()


--This defines the CPs. These need to happen first
cp1 = CommandPost:New{name = "cp1"}
cp2 = CommandPost:New{name = "cp2"}
cp3 = CommandPost:New{name = "cp3"}
cp4 = CommandPost:New{name = "cp4"}
cp5 = CommandPost:New{name = "cp5"}
cp6 = CommandPost:New{name = "cp6"}



--This sets up the actual objective. This needs to happen after cp's are defined
conquest = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF,
textATT = "game.modes.con",
textDEF = "game.modes.con2",
multiplayerRules = true}

--This adds the CPs to the objective. This needs to happen after the objective is set up
conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
conquest:AddCommandPost(cp4)
conquest:AddCommandPost(cp5)
conquest:AddCommandPost(cp6)

conquest:Start()

EnableSPHeroRules()

OnEnterRegion(
function(regIn,character)
MoveEntityToNode(character,"telpa1")
end,
"telre1"
)
ActivateRegion("telre1")

AddDeathRegion("DR1")

end

---------------------------------------------------------------------------
-- FUNCTION: ScriptInit
-- PURPOSE: This function is only run once
-- INPUT:
-- OUTPUT:
-- NOTES: The name, 'ScriptInit' is a chosen convention, and each
-- mission script must contain a version of this function, as
-- it is called from C to start the mission.
---------------------------------------------------------------------------

function ScriptInit()

ReadDataFile("ingame.lvl")
ReadDataFile("dc:Load\\common.lvl")


SetMaxFlyHeight(40)
SetMaxPlayerFlyHeight(40)


SetMemoryPoolSize ("ClothData",20)
SetMemoryPoolSize ("Combo",50) -- should be ~ 2x number of jedi classes
SetMemoryPoolSize ("Combo::State",650) -- should be ~12x #Combo
SetMemoryPoolSize ("Combo::Transition",650) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Condition",650) -- should be a bit bigger than #Combo::State
SetMemoryPoolSize ("Combo::Attack",550) -- should be ~8-12x #Combo
SetMemoryPoolSize ("Combo::DamageSample",6000) -- should be ~8-12x #Combo::Attack
SetMemoryPoolSize ("Combo::Deflect",100) -- should be ~1x #combo


ReadDataFile("sound\\tat.lvl;tat2gcw")
ReadDataFile("dc:SIDE\\orep.lvl",
[Side Info edited out]

ReadDataFile("dc:SIDE\\[side name edited out].lvl",
[Side Info edited out]

ReadDataFile("dc:SIDE\\sith.lvl",
[Side Info edited out]

ReadDataFile("SIDE\\tur.lvl",
"tur_bldg_tat_barge",
"tur_bldg_laser")

SetupTeams{
all = {
team = ALL,
units = 20,
reinforcements = 150,
soldier = { "orep_whos_it",9, 25},
assault = { "orep_whos_it",1,4},
engineer = { "orep_whos_it",1,4},
sniper = { "orep_whos_it",1,4},
officer = { "orep_whos_it",1,4},
special = { "orep_whos_it",1,4},

},
imp = {
team = IMP,
units = 20,
reinforcements = 150,
soldier = { "sith_Something",9, 25},
assault = { "sith_Something",1,4},
engineer = { "sith_Something",1,4},
sniper = { "sith_Something",1,4},
officer = { "sith_Something",1,4},
special = { "sith_Something",1,4},
},
}

SetTeamName (3, "Secret Local group")
AddUnitClass (3, "secret_local_stuff", 1,2)
AddUnitClass (3, "secret_local_stuff", 1,2)
AddUnitClass (3, "secret_local_stuff", 1,2)
AddUnitClass (3, "secret_local_stuff", 1,2)
SetUnitCount (3, 9)
AddAIGoal(3, "Deathmatch", 100)
SetTeamAsEnemy(ATT,3)
SetTeamAsEnemy(3,ATT)
SetTeamAsEnemy(DEF,3)
SetTeamAsEnemy(3,DEF)


SetHeroClass(ALL, "other_hero_here")
SetHeroClass(IMP, "hero_here")

-- Level Stats
ClearWalkers()
AddWalkerType(0, 0) -- special -> droidekas
AddWalkerType(1, 0) -- 1x2 (1 pair of legs)
AddWalkerType(2, 0) -- 2x2 (2 pairs of legs)
AddWalkerType(3, 0) -- 3x2 (3 pairs of legs)

local weaponCnt = 1024
SetMemoryPoolSize("Aimer", 75)
SetMemoryPoolSize("AmmoCounter", weaponCnt)
SetMemoryPoolSize("BaseHint", 1024)
SetMemoryPoolSize("EnergyBar", weaponCnt)
SetMemoryPoolSize("EntityCloth", 32)
SetMemoryPoolSize("EntityFlyer", 32)
SetMemoryPoolSize("EntityHover", 32)
SetMemoryPoolSize("EntityLight", 200)
SetMemoryPoolSize("EntitySoundStream", 4)
SetMemoryPoolSize("EntitySoundStatic", 32)
SetMemoryPoolSize("MountedTurret", 32)
SetMemoryPoolSize("EntityPortableTurret", 10)
SetMemoryPoolSize("Navigator", 128)
SetMemoryPoolSize("Obstacle", 1024)
SetMemoryPoolSize("PathNode", 1024)
SetMemoryPoolSize("SoundSpaceRegion", 64)
SetMemoryPoolSize("TreeGridStack", 1024)
SetMemoryPoolSize("UnitAgent", 128)
SetMemoryPoolSize("UnitController", 128)
SetMemoryPoolSize("Weapon", weaponCnt)

SetSpawnDelay(10.0, 0.25)
ReadDataFile("dc:IPF\\IPF.lvl", "IPF_conquest")
SetDenseEnvironment("false")

-- Birdies
SetNumBirdTypes(2)
SetBirdType(0,1.0,"bird")
SetBirdType(1,1.5,"bird2")

-- Sound Stats

voiceSlow = OpenAudioStream("sound\\global.lvl", "all_unit_vo_slow")
AudioStreamAppendSegments("sound\\global.lvl", "imp_unit_vo_slow", voiceSlow)
AudioStreamAppendSegments("sound\\global.lvl", "des_unit_vo_slow", voiceSlow)
AudioStreamAppendSegments("sound\\global.lvl", "global_vo_slow", voiceSlow)

voiceQuick = OpenAudioStream("sound\\global.lvl", "all_unit_vo_quick")
AudioStreamAppendSegments("sound\\global.lvl", "imp_unit_vo_quick", voiceQuick)

OpenAudioStream("sound\\global.lvl", "gcw_music")
OpenAudioStream("sound\\tat.lvl", "tat2")
OpenAudioStream("sound\\tat.lvl", "tat2")
-- OpenAudioStream("sound\\global.lvl", "global_vo_quick")
-- OpenAudioStream("sound\\global.lvl", "global_vo_slow")

SetBleedingVoiceOver(ALL, ALL, "all_off_com_report_us_overwhelmed", 1)
SetBleedingVoiceOver(ALL, IMP, "all_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(IMP, ALL, "imp_off_com_report_enemy_losing", 1)
SetBleedingVoiceOver(IMP, IMP, "imp_off_com_report_us_overwhelmed", 1)

SetLowReinforcementsVoiceOver(ALL, ALL, "all_off_defeat_im", .1, 1)
SetLowReinforcementsVoiceOver(ALL, IMP, "all_off_victory_im", .1, 1)
SetLowReinforcementsVoiceOver(IMP, IMP, "imp_off_defeat_im", .1, 1)
SetLowReinforcementsVoiceOver(IMP, ALL, "imp_off_victory_im", .1, 1)

SetOutOfBoundsVoiceOver(2, "Allleaving")
SetOutOfBoundsVoiceOver(1, "Impleaving")

SetAmbientMusic(ALL, 1.0, "all_tat_amb_start", 0,1)
SetAmbientMusic(ALL, 0.8, "all_tat_amb_middle", 1,1)
SetAmbientMusic(ALL, 0.2, "all_tat_amb_end", 2,1)
SetAmbientMusic(IMP, 1.0, "imp_tat_amb_start", 0,1)
SetAmbientMusic(IMP, 0.8, "imp_tat_amb_middle", 1,1)
SetAmbientMusic(IMP, 0.2, "imp_tat_amb_end", 2,1)

SetVictoryMusic(ALL, "all_tat_amb_victory")
SetDefeatMusic (ALL, "all_tat_amb_defeat")
SetVictoryMusic(IMP, "imp_tat_amb_victory")
SetDefeatMusic (IMP, "imp_tat_amb_defeat")

SetSoundEffect("ScopeDisplayZoomIn", "binocularzoomin")
SetSoundEffect("ScopeDisplayZoomOut", "binocularzoomout")
--SetSoundEffect("WeaponUnableSelect", "com_weap_inf_weaponchange_null")
--SetSoundEffect("WeaponModeUnableSelect", "com_weap_inf_modechange_null")
SetSoundEffect("SpawnDisplayUnitChange", "shell_select_unit")
SetSoundEffect("SpawnDisplayUnitAccept", "shell_menu_enter")
SetSoundEffect("SpawnDisplaySpawnPointChange", "shell_select_change")
SetSoundEffect("SpawnDisplaySpawnPointAccept", "shell_menu_enter")
SetSoundEffect("SpawnDisplayBack", "shell_menu_exit")

-- Camera Stats
--Tat2 Mos Eisley
AddCameraShot(0.974338, -0.222180, 0.035172, 0.008020, -82.664650, 23.668301, 43.955681);
AddCameraShot(0.390197, -0.089729, -0.893040, -0.205362, 23.563562, 12.914885, -101.465561);
AddCameraShot(0.169759, 0.002225, -0.985398, 0.012916, 126.972809, 4.039628, -22.020613);
AddCameraShot(0.677453, -0.041535, 0.733016, 0.044942, 97.517807, 4.039628, 36.853477);
AddCameraShot(0.866029, -0.156506, 0.467299, 0.084449, 7.685640, 7.130688, -10.895234);

function MoveEntityToNode(entIn,pathIn,nodeIn)
if not entIn then
print("Warning!: Entity not specified for move")
return false
elseif not pathIn then
print("Warning!: Path not specified for Entity " .. entIn .. " move")
return false
end

local node
if nodeIn then
node = nodeIn
else
node = 0
end

local locDest = GetPathPoint(pathIn,node)
local charUnit = GetCharacterUnit(entIn)
if charUnit then
SetEntityMatrix(charUnit,locDest)
return true
end
return false
end

end
[/quote]
While I'm at it,
AddDeathRegion("dr1")
Isn't working eather.

Re: Teleporting

Posted: Mon Sep 03, 2007 2:10 pm
by [RDH]Zerted
MoveEntityToNode(character,"telpa1")
MoveEntityToNode(entIn,pathIn,nodeIn)
You should say which node you what the character to spawn at.

Also, put print("<add your own defferent, random text here>") statements (don't forget to change the text inside the qoutes for each print() ) before and after your event callback and a few other places. Then run the map and check the error log. This will let you figure out what exactly segements of you code are being run and what it is skippping.

A bunch of people have been asking me about teleporting problems, so I decided to write and easier to use teleporting script. I'll be done it by the end of this week.

Here are two of the three main teleporting topics:
http://www.gametoast.com/forums/viewtop ... 27&t=10954
http://www.gametoast.com/forums/viewtop ... =27&t=6916

Re: Teleporting

Posted: Mon Sep 03, 2007 3:02 pm
by Caleb1117
not sure I got all that...

Your saying instead of refrencing the path, (telpa1) I need to use the node name itself, (node 0)

Re: Teleporting

Posted: Mon Sep 03, 2007 8:31 pm
by Taivyx
OFFTOPIC: Yeah, what's up with the search? I searched "region" and only came up with 4 results. I know that can't be right.

Re: Teleporting

Posted: Mon Sep 03, 2007 9:46 pm
by Penguin
Don't use deathregions, use damageregions, More control on how much damage on what type of unit/vehicle and no need for LUA editing.

And to fix your tele, at the end the end script needs to be put AFTER 'end' for the camerashots not before.

should look like this
AddCameraShot(0.169759, 0.002225, -0.985398, 0.012916, 126.972809, 4.039628, -22.020613);
AddCameraShot(0.677453, -0.041535, 0.733016, 0.044942, 97.517807, 4.039628, 36.853477);
AddCameraShot(0.866029, -0.156506, 0.467299, 0.084449, 7.685640, 7.130688, -10.895234);

end

function MoveEntityToNode(entIn,pathIn,nodeIn)
if not entIn then
print("Warning!: Entity not specified for move")
return false
elseif not pathIn then
print("Warning!: Path not specified for Entity " .. entIn .. " move")
return false
end

local node
if nodeIn then
node = nodeIn
else
node = 0
end

local locDest = GetPathPoint(pathIn,node)
local charUnit = GetCharacterUnit(entIn)
if charUnit then
SetEntityMatrix(charUnit,locDest)
return true
end
return false
end

Re: Teleporting

Posted: Tue Sep 04, 2007 9:05 pm
by Ace_Azzameen_5
Something of note with teleporting, is that, from my Observation, its not actually a vanish and reappear thing.

The teleported object actually moves very fast to the specified path, so fast that collisions are ignored...mostly...

If you have too many objects too close (or not close enough) and the destination isn't far away enough, the destination might be offset. For my race map with its billion anti-cheat / cliff fall down teleporters, I think i'll have to rig them to move the Entity to a distant node before the destination node.

Re: Teleporting

Posted: Tue Sep 04, 2007 9:16 pm
by Caleb1117
... Yep still not working.

So your saying sometimes if there are alot of objects near by, or in your path, you may not teleport?
Even so, I'm not moving really fast or anything like that.

Re: Teleporting

Posted: Fri Sep 07, 2007 8:21 am
by MetalcoreRancor
Hey Zerted, any luck with that code so far? My map is basically hinging on it to be completed.

Re: Teleporting

Posted: Fri Sep 07, 2007 7:40 pm
by [RDH]Zerted
MetalcoreRancor wrote:Hey Zerted, any luck with that code so far? My map is basically hinging on it to be completed.
Oh sorry. My dorm doesn't have air conditioning and the rooms are around 100, so I've been trying to spend most of the time away from my computer. Its going to cool down again tonight. I have most of it written, just need to test it. Want any special features?

Right now you would use it like:

Code: Select all

ScriptCB_DoFile("teleport")

--A single teleport
local from = GetCharacterLocation( player )
local to = GetRegionDestination( region )
DoSingleTeleport( from, to )

--Teleport anything in the region
SetupEnterRegionTeleport( region, destination, "AIandHuman"', "UnitsOnly" )
ActivateRegion( region )

Re: Teleporting

Posted: Fri Sep 07, 2007 7:48 pm
by MetalcoreRancor
Honestly, I'll be uber uber super happy to just finally have it, and get it working, so I can finish my map on the weekend. I'm content with the basic idea, no features needed for me.

Re: Teleporting

Posted: Sat Sep 08, 2007 11:04 am
by Caleb1117
So...
local from = GetCharacterLocation( player )
local to = GetRegionDestination(telre1)
DoSingleTeleport(telre1, telpa1 )
?


EDIT
Pardon dual post, but its not working.
ScriptCB_DoFile("teleport")

--A single teleport
local from = GetCharacterLocation( player )
local to = GetRegionDestination( telre1 )
DoSingleTeleport( telre1, telpa1 )

end

Re: Teleporting

Posted: Sat Sep 08, 2007 5:51 pm
by [RDH]Zerted
Caleb1117 wrote:So...
local from = GetCharacterLocation( player )
local to = GetRegionDestination(telre1)
DoSingleTeleport(telre1, telpa1 )
?
It would be

Code: Select all

local from = GetRegionLocation( telre1 )
local to = GetPathDestination(telre1,0)
SetupEnterRegionTeleport(from, to )
but you don't have teleport.lua yet. I'm still making that file.

Off-Topic: when I hit preview, the forum said there were new posts in the topic and displayed them. Nice new feature.

Re: Teleporting

Posted: Sat Sep 08, 2007 5:54 pm
by Caleb1117
Oh ok, there is a teleport lua that will go along with it.
In data_abc/common/scripts I assume?

Re: Teleporting

Posted: Sat Sep 08, 2007 5:56 pm
by [RDH]Zerted
Caleb1117 wrote:Oh ok, there is a teleport lua that will go along with it.
In data_abc/common/scripts I assume?
Yes. I'll do my best to have to done for tomorrow.

Re: Teleporting

Posted: Sat Sep 08, 2007 5:57 pm
by Caleb1117
Hey, no big rush.
Take your time, school is important.
Or so they tell me. :lol:

Re: Teleporting

Posted: Sat Sep 08, 2007 9:13 pm
by MetalcoreRancor
Thank you so much for doing this. I can't tell you how much it means to me. My map wont be possible without teleportation... But yea, I will look forward to it =)

Re: Teleporting

Posted: Sun Sep 09, 2007 12:01 am
by [RDH]Zerted
If anyone wants to test it out, you can download the 97% finished code here: https://www.se.rit.edu/~dpk3062/swbf2/r ... leport.lua

Edit:
The code works fine. You can also download it from here: http://zerted.getmyip.com/random/teleport.lua

Re: Teleporting

Posted: Sun Sep 09, 2007 9:24 am
by Ace_Azzameen_5
Wow...thats really complicated as opposed to the custom "Moveentitytomatrix" function that Penguin released in the other teleport thread. (+ the GetCharacterVehicle stuff I added)

Excuse the criticism, but that just looks like a lot of extra custom functions and possibly redundant nil checks. The debugs are nice, but, I like simplicity.

Code: Select all

--
-- MoveEntitytoNode for Star Wars Battlefront II Copyright (c) Sometime, distributed by Penguin, made by IDK inc.l, All rights reserved.
-- Star Wars Battlefront II and Zero Engine Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--
function MoveEntityToNode(entIn,pathIn,nodeIn)
if not entIn then
print("Warning!: Entity not specified for move")
return false
elseif not pathIn then
print("Warning!: Path not specified for Entity " .. entIn .. " move")
return false
end

local node
if nodeIn then
node = nodeIn
else
node = 0
end
 
locDest = GetPathPoint(pathIn,node)
local charUnit = GetCharacterUnit(entIn)
local charVeh = GetCharacterVehicle(entIn)
if charVeh then
SetEntityMatrix(charVeh,"locDest")
elseif charUnit then
SetEntityMatrix(charUnit,locDest)
return true
end
return false
end
Main Lua stuff

Code: Select all

OnEnterRegion(
function(regIn,character)
MoveEntityToNode(character,"waterFallTeleport")
end,
"TeleportRegion"
)
ActivateRegion("TeleportRegion")
I'm pretty sure you developed most of this, Zerted. It seems to work and I thought that 'if Variable then' checked to see if the variable was nil. I have had some mis-teleports though, it might be a mis-saved path move in the editor, or a missing path or something, but I think missing path ctds. So, if you're code will assist majorly with debugging and run more smoothly, please finish it!

Off-Topic: Zerted, do you know how or what entity matrixes are? I could never get them to print into bf2log. I wanted to be able to "dissect" them and alter say, the X value of the coordinates. I'm working on a race mode which has ~30 teleporter region-path setups, mostly for route/direction control, but a few belong to a system that will restore dead racers to a checkpoint. If there is a way to alter that to restore them to just behind where they died by grabbing and altering their orientation and location...
*Edit* Thats impossible without a taxing recursive timer store that the last location of all racers, because OnCharacterDeath...well, is flawed in one way or another. Still, editing matrix values would be extremely useful in some situation I'm sure.

Re: Teleporting

Posted: Sun Sep 09, 2007 11:51 am
by MetalcoreRancor
I really just want to have the code finished so I can get my map done soon =|

Btw I tried that posted lua code and it still didnt work Zerted.

Re: Teleporting

Posted: Sun Sep 09, 2007 12:01 pm
by Caleb1117
If I could have gotten the original code that penguin posted to work, this topic would not exist, if I knew, metal wouldn't have a problem eather.

Simple is good, but simple to use is better IMO.