Change team of CP via LUA? [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
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Change team of CP via LUA? [Solved]

Post by commanderawesome »

Is it possible to change the starting team of a command post via the mission lua?

If not, how can I do it in ZE?
Last edited by commanderawesome on Thu Jun 05, 2014 3:45 pm, edited 2 times in total.
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: Another lua question.

Post by Marth8880 »

Code: Select all

SetObjectTeam("cpname", teamID)
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Another lua question.

Post by commanderawesome »

Marth8880 wrote:

Code: Select all

SetObjectTeam("cpname", teamID)
Thanks, man.
LRKfm946
Master Sergeant
Master Sergeant
Posts: 163
Joined: Sun Feb 02, 2014 6:13 pm
Projects :: Battlefront II Hunger Games
Games I'm Playing :: SWBF2 BF3
Contact:

Re: Change team of CP via LUA? [Solved]

Post by LRKfm946 »

A note for the OP or anyone who plans on doing this with a map that will be played online:

Changing CP team via LUA is tricky online. In order the client to see a CP change team, the CP must be taken "naturally", meaning that someone has to stand in the capture region and capture the region manually. If you just do SetObjectTeam("cp_name", 1) or SetProperty("cp_name", "Team", 1) or whatever, the server will change the Cp's team but the clients (the players) won't know about it. If you change the CP team this way and a client tries to change units at a CP that appears to still belong to thier team, they will get stuck. They'll open up the character selection menu on their screen, pick a unit, and click spawn and the menu will disappear. But when they send that information to the server, the server says "This isn't their CP, so they can't actually spawn here". The result is that the client will be unable to do anything, waiting for the server to say that they successfully spawned.

To get around this problem, you could set the neutralize and capture time to 0.0001 using SetProperty, spawn an AI at the position of the cp (or inside the cp capture region), run a timer for 1 second (Optional: set the timer rate to 3 or 4 since we only need it alive for .0002 seconds, not the full 1 second), and on timer elapse kill the bot and set the neuttralize and capture time back to what they were before.

This also applies to things like reinforcement count and object destruction. Figuring out how to sync up the server and clients is a whoooole new side of modding. :P
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Change team of CP via LUA? [Solved]

Post by commanderawesome »

Uh... that's not the kind of mod i'm making. I'm making an era mod.
LRKfm946
Master Sergeant
Master Sergeant
Posts: 163
Joined: Sun Feb 02, 2014 6:13 pm
Projects :: Battlefront II Hunger Games
Games I'm Playing :: SWBF2 BF3
Contact:

Re: Change team of CP via LUA? [Solved]

Post by LRKfm946 »

It was just extra info in case anyone was searching for the topic.
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Change team of CP via LUA?

Post by commanderawesome »

Hmm... it's not working for some reason.
My code:

Code: Select all

SetObjectTeam("cp2", 2)
also tried:

Code: Select all

SetObjectTeam("cp2", CIS)
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: Change team of CP via LUA?

Post by Marth8880 »

Make sure you're putting it in ScriptPostLoad.
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Change team of CP via LUA?

Post by commanderawesome »

Marth8880 wrote:Make sure you're putting it in ScriptPostLoad.
It works, I just need to figure out what all the cp's are.

I've also discovered that you can add a new team with this method.

EDIT
Does anyone know what the central CP on Mygeeto Conquest is called in the Lua?
LRKfm946
Master Sergeant
Master Sergeant
Posts: 163
Joined: Sun Feb 02, 2014 6:13 pm
Projects :: Battlefront II Hunger Games
Games I'm Playing :: SWBF2 BF3
Contact:

Re: Change team of CP via LUA?

Post by LRKfm946 »

commanderawesome wrote:Does anyone know what the central CP on Mygeeto Conquest is called in the Lua?
Go to BF2_ModTools\assets\worlds and copy MYG into BF2_ModTools\Data_XXX\worlds, then open the Mygeeto world in ZeroEditor and look at the CP names.
ZoomV
Rebel Warrant Officer
Rebel Warrant Officer
Posts: 308
Joined: Thu Aug 15, 2013 11:27 am
Projects :: Old Republic Map pack
Games I'm Playing :: BF2 SWTOR and GW2
xbox live or psn: No gamertag set
Location: Belsavis, Maximum Security Ward

Re: Change team of CP via LUA? [Solved]

Post by ZoomV »

LRKfm946 wrote:It was just extra info in case anyone was searching for the topic.
question
if you use lua to set a command post at the very beginning of the match would it still work for multiplayer? The reason I'm asking is I have a map where in one era one of the command post is supposed to start off with a locals team, but not in the other, and I would like to avoid having to set a bunch of different layers to the map just for it.
LRKfm946
Master Sergeant
Master Sergeant
Posts: 163
Joined: Sun Feb 02, 2014 6:13 pm
Projects :: Battlefront II Hunger Games
Games I'm Playing :: SWBF2 BF3
Contact:

Re: Change team of CP via LUA? [Solved]

Post by LRKfm946 »

ZoomV wrote:question
if you use lua to set a command post at the very beginning of the match would it still work for multiplayer? The reason I'm asking is I have a map where in one era one of the command post is supposed to start off with a locals team, but not in the other, and I would like to avoid having to set a bunch of different layers to the map just for it.
Yes, just do what I said above. Set the neutralize and capture time to .0001, spawn in a bot at the CP capture region, kill it a second later, then either reset the capture/neutralize time or remove the capture region, depending on whether or not you want the CP to belong to the locals for the whole round.
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Change team of CP via LUA?

Post by commanderawesome »

LRKfm946 wrote:
commanderawesome wrote:Does anyone know what the central CP on Mygeeto Conquest is called in the Lua?
Go to BF2_ModTools\assets\worlds and copy MYG into BF2_ModTools\Data_XXX\worlds, then open the Mygeeto world in ZeroEditor and look at the CP names.
I was kinda hoping someone would already know. I'm not good at using ZE.
AQT
Gametoast Staff
Gametoast Staff
Posts: 4910
Joined: Sat Nov 03, 2007 4:55 pm
Location: SoCal, USA

Re: Change team of CP via LUA? [Solved]

Post by AQT »

Just open up the conquest .lyr file in a text editor, and do a search for com_bldg_control_zone. That should give you the name of most CPs.

P.S. You don't have to always quote someone before replying to them. Only do so if the post won't be directly above yours, or if you are referring to something specific.
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Change team of CP via LUA? [Solved]

Post by commanderawesome »

AQT wrote:Just open up the conquest .lyr file in a text editor, and do a search for com_bldg_control_zone. That should give you the name of most CPs.

P.S. You don't have to always quote someone before replying to them. Only do so if the post won't be directly above yours, or if you are referring to something specific.
Thanks. Quick Question, can these files be used to modify properties of the map? (I.E command posts, vehicle spawns, etc)
LRKfm946
Master Sergeant
Master Sergeant
Posts: 163
Joined: Sun Feb 02, 2014 6:13 pm
Projects :: Battlefront II Hunger Games
Games I'm Playing :: SWBF2 BF3
Contact:

Re: Change team of CP via LUA? [Solved]

Post by LRKfm946 »

I've used them to do those kinds of things with mixed results. You can change the placement and class of an object, but you can't add or delete objects. This has something to do with the SequenceNo. but I haven't quite figured out how it works.
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Change team of CP via LUA? [Solved]

Post by commanderawesome »

LRKfm946 wrote:I've used them to do those kinds of things with mixed results. You can change the placement and class of an object, but you can't add or delete objects. This has something to do with the SequenceNo. but I haven't quite figured out how it works.
Thanks!
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: Change team of CP via LUA? [Solved]

Post by [RDH]Zerted »

Changing CP team via LUA is tricky online. In order the client to see a CP change team, the CP must be taken "naturally"...
Have you ever tried changing both the team and perceived team properties? Example:

Code: Select all

SetProperty("cp1", "Team", 1)
SetProperty("cp1", "PerceivedTeam", 1)
LRKfm946
Master Sergeant
Master Sergeant
Posts: 163
Joined: Sun Feb 02, 2014 6:13 pm
Projects :: Battlefront II Hunger Games
Games I'm Playing :: SWBF2 BF3
Contact:

Re: Change team of CP via LUA? [Solved]

Post by LRKfm946 »

[RDH]Zerted wrote:
Changing CP team via LUA is tricky online. In order the client to see a CP change team, the CP must be taken "naturally"...
Have you ever tried changing both the team and perceived team properties? Example:

Code: Select all

SetProperty("cp1", "Team", 1)
SetProperty("cp1", "PerceivedTeam", 1)
Yep I think so.
Post Reply