Page 1 of 1

Alternating Command Posts [Solved]

Posted: Tue Sep 02, 2014 5:44 pm
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.

Re: Alternating Command Posts

Posted: Tue Sep 02, 2014 8:56 pm
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.

Re: Alternating Command Posts

Posted: Wed Sep 03, 2014 9:47 am
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.

Re: Alternating Command Posts

Posted: Wed Sep 03, 2014 10:32 am
by Marth8880
Did you make sure to set the region's class properties to the region's name?

Re: Alternating Command Posts

Posted: Wed Sep 03, 2014 10:39 am
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.

Re: Alternating Command Posts

Posted: Wed Sep 03, 2014 10:45 am
by Marth8880
The region's class properties in Zero Editor.
Hidden/Spoiler:
Image

Re: Alternating Command Posts

Posted: Wed Sep 03, 2014 2:26 pm
by AnthonyBF2
Yes I have it set.

Re: Alternating Command Posts

Posted: Wed Sep 03, 2014 4:01 pm
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

Re: Alternating Command Posts

Posted: Wed Sep 03, 2014 5:28 pm
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 :|

Re: Alternating Command Posts

Posted: Wed Sep 03, 2014 7:55 pm
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.

Re: Alternating Command Posts

Posted: Wed Sep 03, 2014 8:43 pm
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:

Re: Alternating Command Posts

Posted: Wed Sep 03, 2014 11:19 pm
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.

Re: Alternating Command Posts

Posted: Thu Sep 04, 2014 9:34 am
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:

Re: Alternating Command Posts [Solved]

Posted: Thu Sep 04, 2014 10:13 am
by Noobasaurus
It should work when a vehicle enters it as well.