Teleport Buff Tutorial

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
CalvaryCptMike
Captain
Captain
Posts: 476
Joined: Sat Feb 19, 2011 3:10 pm
Projects :: Nothing--absolutely nothing
Location: Freed by alien robots, now living on Mars
Contact:

Teleport Buff Tutorial

Post by CalvaryCptMike »

Teleport Buff Tutorial


This is a tutorial showing how to make a very simple weapon, that when fired, teleports your entire team to your position. For example, you're all alone and low on health trying to capture back your cp
Hidden/Spoiler:
Image
call for backup!
Hidden/Spoiler:
Image
I won't be laying out how this works like in my other tutorials, I'm just going to show you step by step how to do it.

First go into your mod folder-->sides-->common-->odf. Find the file "com_weap_inf_powerup_dispenser" Copy it and rename it to "com_weap_inf_rally". Now open it up and select all the code and delete it. Then copy the code from below and paste it in.
Hidden/Spoiler:
[quote][WeaponClass]
ClassLabel = "dispenser"

[Properties]
HUDTag = "hud_invun_buff"

//MuzzleFlash = "small_muzzle_flash"
//Discharge = "small_smoke_effect"

//GeometryName = "com_weap_inf_medkit"
PlayEffectOnOwner = "com_sfx_buff_defense"
Effect = "com_sfx_buff_defense"
RoundsPerClip = "1"
ReloadTime = "1.0"
LockOnRange = "80.0"
LockTime = "0.4"

AnimationBank = "rifle"
OffhandWeapon = 1

RefillFromItem = 0

TrackingSound = ""

WEAPONSECTION = 1

ModeTexture = "HUD_weap_health"
ReticuleTexture = "reticule_00"
OrdnanceName = "com_item_teleport"

ShotDelay = "0.0"
MaxItems = "4.0"

AutoAimSize = "1.0"

SalvoCount = "1"
SalvoDelay = "0.0"
InitialSalvoDelay = "0.5"

MinStrength = "0.3"
MaxStrength = "0.4"
MaxPressedTime = "0.0"

FireSound = "com_weap_throw"
FireEmptySound = "com_weap_inf_ammo_empty"
FireLoopSound = ""
ReloadSound = "com_weap_inf_equip_sm"
ChargeSound = ""
ChangeModeSound = "com_weap_inf_equip_sm"
WeaponChangeSound = "com_weap_inf_equip_sm"
JumpSound = "com_weap_inf_pistol_mvt_jump"
LandSound = "com_weap_inf_pistol_mvt_land"
RollSound = "com_weap_inf_pistol_mvt_roll"
//ProneSound = "com_weap_inf_pistol_mvt_lie"
SquatSound = "com_weap_inf_pistol_mvt_squat"
//StandSound = "com_weap_inf_pistol_mvt_getup"
[/quote]
Close and save that file. Now go into the folder your mod folder-->common-->odfs, and find the file "com_item_powerup_dual". Copy it, go to your mod folder-->sides-->common-->odf and paste it. Open it up, delete all the text in it, copy the text below and paste it into it:
Hidden/Spoiler:
[quote][GameObjectClass]
ClassLabel = "powerupitem"
GeometryName = "com_prop_ctfdrop.msh"

[Properties]
GeometryName = "com_prop_ctfdrop"
Lifespan = "1.0"
Velocity = "0.0"
Gravity = "1.0"
Rebound = "0.0"
Friction = "1.0"
[/quote]
This "item" being dropped is what will trigger the teleport, and is very important. Give one of your units the "com_weap_inf_rally" weapon as a secondary weapon, and move onto the next step. Now open your map's script file, any script that has the unit you gave the weapon to. In the function Scriptpostload(), right above the 'end' paste the following code.
Hidden/Spoiler:
--teleport code start -v
--teleport code start -v
--teleport code start -v

--declares what the powerup we're looking for is named
TeleportWeapon = "com_item_teleport"

OnCharacterDispensePowerup(
function(character,powerup)

--checks for our special powerup every time a powerup is dropped
if GetEntityClass(powerup) == GetEntityClassPtr(TeleportWeapon) then

--this sees which team the person who dropped the powerup was on, that way you won't rally the enemy team to your pos!
if GetCharacterTeam(character) == 1 then

--get the team's size
local size = GetTeamSize( 1 )

--for each team member,
local m = 0
for m = 0, size-1 do

--get a team member's unit
local member = GetTeamMember(1, m)

--make sure the character exists is alive
if member ~= nil then

--make sure the character is not dead
local unit = GetCharacterUnit( member )
if unit ~= nil then
--make sure the teleported unit is NOT human
if not IsCharacterHuman(member) then

--do the teleport
local to = GetEntityMatrix( GetCharacterUnit(character) )
SetEntityMatrix( unit, to )

end
end
end
end

--if it wasn't team 1 that dropped the powerup then it was team 2, so teleport team 2 to whoever's pos
elseif GetCharacterTeam(character) == 2 then
--get the team's size
local size = GetTeamSize( 2 )

--for each team member,
local m = 0
for m = 0, size-1 do

--get a team member's unit
local member = GetTeamMember(2, m)

--make sure the character exists is alive
if member ~= nil then

--make sure the character is not dead
local unit = GetCharacterUnit( member )
if unit ~= nil then
--make sure the teleported unit is NOT human
if not IsCharacterHuman(member) then

--do the teleport
local to = GetEntityMatrix( GetCharacterUnit(character) )
SetEntityMatrix( unit, to )
end
end
end
end
end

end
end
)

--teleport code end -^
--teleport code end -^
--teleport code end -^
That's what does all the work. Munge your unit, your common sides, and your script, play the level, and rally/teleport your whole team to you! This code is written so that both sides can use the weapon simultaneously, and it will not teleport your human teammates when you are playing MP.

Credits:
Me, CavalryCaptainMike
[RDH]Zerted, for sharing the "teleport AI to player" code he made for the fake console.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Teleport Buff Tutorial

Post by Maveritchell »

CalvaryCptMike
Captain
Captain
Posts: 476
Joined: Sat Feb 19, 2011 3:10 pm
Projects :: Nothing--absolutely nothing
Location: Freed by alien robots, now living on Mars
Contact:

Re: Teleport Buff Tutorial

Post by CalvaryCptMike »

@Mav
I think you misunderstood what the tutorial is. It's a weapon that when fired, teleports (rallies) your entire team to your position. The FAQ only showed how to spawn units on your position. Additionally, the code I posted here allows both teams to have units with teleport weapons.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: Teleport Buff Tutorial

Post by Marth8880 »

Very interesting tutorial. I might actually be able to adopt this for my Combat Drones, hmm...

Off-topic: Could people seriously please stop not posting code in code tags? Code tags retain formatting and indentations, and it's super annoying and really a huge waste of time to have to constantly go in and indent everything manually. Thanks.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Teleport Buff Tutorial

Post by Maveritchell »

CalvaryCptMike wrote:@Mav
I think you misunderstood what the tutorial is. It's a weapon that when fired, teleports (rallies) your entire team to your position. The FAQ only showed how to spawn units on your position. Additionally, the code I posted here allows both teams to have units with teleport weapons.
I didn't misunderstand you. What you did was write a tutorial for a specific kind of lua weapon. The meat of your tutorial is "here's how you spawn people at your location," which is covered in the FAQ topic.

Also:
forums/viewtopic.php?f=27&t=13832
forums/viewtopic.php?f=27&t=11537
Post Reply