Alternating Command Posts [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
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Alternating Command Posts [Solved]

Post by AnthonyBF2 »

Used site search, found nothing for this. Looked some-what at stock scripts but didn't see anything.

Would like a bit of code that can change the team of 2 or more command posts simultaneously (to the opposite teams) based on a defined interval (1 second would be nice)

The goal is to have 2 or more CPs swap team value every time the defined timer counts down
- Would like 1 second , so that picking the spawn you want is hard, but you can spawn easy and fast.

My desire is to add this to Jabbas Palace 1 flag, and Tantive 1 flag, so that the single CPs are constantly changing team value , 1 second is enough to give people time to click it, and for ai bots to spawn in.

-Or , make CPs alternate when a flag is captured, or an object is destroyed.

Thanks.
Last edited by AnthonyBF2 on Thu Sep 04, 2014 9:35 am, edited 1 time in total.
AQT
Gametoast Staff
Gametoast Staff
Posts: 4910
Joined: Sat Nov 03, 2007 4:55 pm
Location: SoCal, USA

Re: Alternating Command Posts

Post by AQT »

If you're asking what I think you're asking, then:

You will need two timers. Let the total running time of both timers each be one second long. When the first timer elapses, it does two things: 1) changes ownership of each CP to that of the opposite team via SetProperty and 2) starts the second timer. When the second timer elapses, it does two things: 1) changes ownership of each CP back to the original team via SetProperty and 2) restarts the first timer. This will create an infinite loop.
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: Alternating Command Posts

Post by AnthonyBF2 »

What I've been trying seems easier if it would work...
I have been trying to use OnEnterRegion but I'm sure something here is wrong...

ActivateRegion("cpswapregion")
testfunction = OnEnterRegion(
function(region, player)
if IsCharacterHuman(character) then
SetProperty("1flag_cp2", "Team", 1)
SetProperty("1flag_cp1", "Team", 2)
end
end,
"cpswapregion"
)

I pass through the region several times and nothing happens.
The timer thing sounds good and will try it.
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: Alternating Command Posts

Post by Marth8880 »

Did you make sure to set the region's class properties to the region's name?
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: Alternating Command Posts

Post by AnthonyBF2 »

Marth I don't understand your question.

There is 1 region I created, named it "cpswapregion".
When player enters region, each CP should swap Team value.
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: Alternating Command Posts

Post by Marth8880 »

The region's class properties in Zero Editor.
Hidden/Spoiler:
Image
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: Alternating Command Posts

Post by AnthonyBF2 »

Yes I have it set.
User avatar
Nedarb7
Lieutenant General
Lieutenant General
Posts: 676
Joined: Sat Sep 22, 2012 3:41 pm

Re: Alternating Command Posts

Post by Nedarb7 »

anthonybf2 wrote:What I've been trying seems easier if it would work...
I have been trying to use OnEnterRegion but I'm sure something here is wrong...

ActivateRegion("cpswapregion")
testfunction = OnEnterRegion(
function(region, player)
if IsCharacterHuman(character) then
SetProperty("1flag_cp2", "Team", 1)
SetProperty("1flag_cp1", "Team", 2)
end
end,
"cpswapregion"
)

I pass through the region several times and nothing happens.
The timer thing sounds good and will try it.
What I highlighted red should be changed to player
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: Alternating Command Posts

Post by AnthonyBF2 »

Nedarb, thank you very much! The code works and the mod works. I have yet 1 more question.

How may I alter the current code so the region can be triggered by humans and AI bots?
:faint:

EDIT: It seems to only work once per map, I don't know how to loop the code :|
AQT
Gametoast Staff
Gametoast Staff
Posts: 4910
Joined: Sat Nov 03, 2007 4:55 pm
Location: SoCal, USA

Re: Alternating Command Posts

Post by AQT »

It works the way it is supposed to be working with the way you have it set up. When you enter the region for the first time, 1flag_cp2 becomes controlled by team 1, whereas 1flag_cp1 becomes controlled by team 2. When you enter the region for a second time, nothing changes because 1flag_cp2 and 1flag_cp1 are still controlled by team 1 and team 2, respectively.

What you want to do is implement a check. Use GetCommandPostTeam or GetObjectTeam to check which team either one of the CPs belongs. e.g., if 1flag_cp2 belongs to team 1, switch its control over to team 2, and switch 1flag_cp1's control over to team 1. And if 1flag_cp2 belongs to team 2, do the opposite.
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: Alternating Command Posts

Post by AnthonyBF2 »

Gonna be blatantly honest and say I don't know how to set that up. I do understand it (Get object's team if it's this then make it that)

:runaway:
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Re: Alternating Command Posts

Post by Noobasaurus »

A slightly easier way to do it (IMO) is to make a variable that changes each time. Example code:

Code: Select all

ActivateRegion("cpswapregion")
x = 0
testfunction = OnEnterRegion(
function(region, player)
if x == 0 then
 SetProperty("1flag_cp2", "Team", 1)
 SetProperty("1flag_cp1", "Team", 2)
 x = 1
elseif x == 1 then
 SetProperty("1flag_cp2", "Team", 2)
 SetProperty("1flag_cp1", "Team", 1)
 x = 0
end
end,
"cpswapregion"
)
I also removed the code to check if the player is a human or not, like you said you wanted earlier.
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: Alternating Command Posts

Post by AnthonyBF2 »

Mission Accomplished. This will also spice up the space levels a bit, it does work when ships/vehicles enter the region correct?

Other than that... thanks! :funny2:
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Re: Alternating Command Posts [Solved]

Post by Noobasaurus »

It should work when a vehicle enters it as well.
Post Reply