Attack/Defend mode

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
Dreadnot9
Chief Warrant Officer
Chief Warrant Officer
Posts: 341
Joined: Wed Jun 06, 2012 2:05 pm
Projects :: Rising Conflict CW v2.0
Games I'm Playing :: Skyrim TF2 FTL
xbox live or psn: Steam is Dreadnot9

Attack/Defend mode

Post by Dreadnot9 »

Hey all, I'm attempting to create an Attack/Defend mode in which one team controls 2-3 CPs and the other team attempts to capture them. If the team successfully defend within a specified time-limit, they win. If the other team captures all CPs, they win.
Essentially I'm asking the following:
1. Would it be easier to start out with a pre-existing mode like ObjectiveConquest and doing scripting from there, or would it be easier to create a new game mode (something like ObjectiveATT/DEF)?
2. Is it possible to prevent one team from capturing CPs? I'm well aware of the ODF code that'll do the trick, the catch here is that I would like to randomize the teams (so it isn't always the same team attacking or defending)?
3. Does an objective like this work (I've tested it, with inconclusive results):
Hidden/Spoiler:
--sets objective
Objective1CP = CommandPost:New{name = "CP1"}
Objective1CP = CommandPost:New{name = "CP6"}
Objective1CP = CommandPost:New{name = "CP3"}
Objective1 = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF, text = "level.COR.siege.1"}
Objective1:AddCommandPost(Objective1CP)

--tells what happens on start of your objective
Objective1.OnStart = function(self)

--sets AI-goal
AIGoalATT1 = AddAIGoal(ATT, "Defend", 10, "CP1")
AIGoalDEF1 = AddAIGoal(DEF, "Defend", 100, "CP1")
AIGoalATT2 = AddAIGoal(ATT, "Defend", 10, "CP6")
AIGoalDEF2 = AddAIGoal(DEF, "Defend", 100, "CP6")
AIGoalATT3 = AddAIGoal(ATT, "Defend", 10, "CP3")
AIGoalDEF3 = AddAIGoal(DEF, "Defend", 100, "CP3")
end

-- says what happens after the objective is complete
Objective1.OnComplete = function(self)

these "SetProperty" functions were an attempt to prevent defending team CP capture...
SetProperty ("CP1", "CaptureRegion", " ")
SetProperty ("CP3", "CaptureRegion", " ")
SetProperty ("CP6", "CaptureRegion", " ")

MissionVictory(ATT)
DeleteAIGoal(AIGoalATT1)
DeleteAIGoal(AIGoalDEF1)
DeleteAIGoal(AIGoalATT2)
DeleteAIGoal(AIGoalDEF2)
DeleteAIGoal(AIGoalATT3)
DeleteAIGoal(AIGoalDEF3)
end
Thanks for any help in advance.
User avatar
Cleb
Lieutenant General
Lieutenant General
Posts: 711
Joined: Sun Jun 17, 2012 10:12 pm
Projects :: Learning how to use 3DS Max
Games I'm Playing :: BF2 CIV4 MC
xbox live or psn: ˙. ˙. ˙. ˙. ˙. ˙
Location: Somewhere
Contact:

Re: Attack/Defend mode

Post by Cleb »

What about randomizing the att and def teams? I thought you could do that.
Dreadnot9
Chief Warrant Officer
Chief Warrant Officer
Posts: 341
Joined: Wed Jun 06, 2012 2:05 pm
Projects :: Rising Conflict CW v2.0
Games I'm Playing :: Skyrim TF2 FTL
xbox live or psn: Steam is Dreadnot9

Re: Attack/Defend mode

Post by Dreadnot9 »

Cleb wrote:What about randomizing the att and def teams? I thought you could do that.
Oh I'm totally aware of that. I've got this snippet of code going right now for that (though I'm not using it now...I'm trying to get the game mode working first):
Hidden/Spoiler:
if not ScriptCB_InMultiplayer() == 0 then
ALL = math.random(1,2)
IMP = (3 - ALL)
else
ATT = 1
DEF = 2
end
I'm really asking on the logistics of the game mode itself.

Edit: Haha, actually, thanks for asking about that, because I've got the code wrong for randomizing teams... :runaway: , but the game mode is still in question.
Fixed code:
Hidden/Spoiler:
-- Empire Attacking (attacker is always #1)
if not ScriptCB_InMultiplayer() == 0 then
ALL = 1 --math.random(1,2)
IMP = 2 --(3 - ALL)
else
-- These variables do not change
ALL = 1
IMP = 2
end

ATT = 1
DEF = 2
User avatar
Cleb
Lieutenant General
Lieutenant General
Posts: 711
Joined: Sun Jun 17, 2012 10:12 pm
Projects :: Learning how to use 3DS Max
Games I'm Playing :: BF2 CIV4 MC
xbox live or psn: ˙. ˙. ˙. ˙. ˙. ˙
Location: Somewhere
Contact:

Re: Attack/Defend mode

Post by Cleb »

I know theres a code for preventing cp capture, but I don't know what it exactly does... Ill look it up in the morning. Oh and your welcome :D
Bob
Brigadier General
Brigadier General
Posts: 633
Joined: Thu May 27, 2010 4:28 am
Location: at home

Re: Attack/Defend mode

Post by Bob »

For AI not beeing able to capture posts I found this in the stock campain LUAs:

Code: Select all

AICanCaptureCP("cam_cp3", ATT, false)
The first parameter should be the name of your CP, second the team that is to be affected and the third is even more obvious.
For 1.:
You can simply copy a conquest LUA and change some things. Deny CP capturing for the defenders, give them something like "Deathmatch" as AIGoal so they don't even try, set up a victory/defeat timer and you should be fine.
Dreadnot9
Chief Warrant Officer
Chief Warrant Officer
Posts: 341
Joined: Wed Jun 06, 2012 2:05 pm
Projects :: Rising Conflict CW v2.0
Games I'm Playing :: Skyrim TF2 FTL
xbox live or psn: Steam is Dreadnot9

Re: Attack/Defend mode

Post by Dreadnot9 »

Bob wrote:For AI not beeing able to capture posts I found this in the stock campain LUAs:

Code: Select all

AICanCaptureCP("cam_cp3", ATT, false)
The first parameter should be the name of your CP, second the team that is to be affected and the third is even more obvious.
That should work great for singleplayer if you're the attacking team, but will human players still be able to capture command posts if you're the defending team, or if you're online (though I doubt I'll be playing it online, but ya never know)? I could always set up the SetClassProperty functions in junction with the math random function that disallow one team to capture command posts.
Bob wrote:For 1.:
You can simply copy a conquest LUA and change some things. Deny CP capturing for the defenders, give them something like "Deathmatch" as AIGoal so they don't even try, set up a victory/defeat timer and you should be fine.
Thanks Bob, that should work just fine. Would there be any advantage to using a specific "ObjectiveAttackDefend" game mode lua? Or would that just be unnecessary work?
Bob
Brigadier General
Brigadier General
Posts: 633
Joined: Thu May 27, 2010 4:28 am
Location: at home

Re: Attack/Defend mode

Post by Bob »

Dreadnot9 wrote: will human players still be able to capture command posts if you're the defending team, or if you're online (though I doubt I'll be playing it online, but ya never know)?
Nope, the whole team can't cap anymore, be it players or AI.
Dreadnot9 wrote: Would there be any advantage to using a specific "ObjectiveAttackDefend" game mode lua? Or would that just be unnecessary work?
If you put your stuff in an extra LUA you would save about 5 seconds of copypasting and some bytes memory. I don't think that's necessary if it's just a little bit of code.
kinetosimpetus
Imperial Systems Expert
Imperial Systems Expert
Posts: 2381
Joined: Wed Mar 25, 2009 4:15 pm
Projects :: A secret project
Games I'm Playing :: Warframe STO

Re: Attack/Defend mode

Post by kinetosimpetus »

Dreadnot9 wrote:
Cleb wrote:What about randomizing the att and def teams? I thought you could do that.
Oh I'm totally aware of that. I've got this snippet of code going right now for that (though I'm not using it now...I'm trying to get the game mode working first):
Hidden/Spoiler:
if not ScriptCB_InMultiplayer() == 0 then
ALL = math.random(1,2)
IMP = (3 - ALL)
else
ATT = 1
DEF = 2
end
I'm really asking on the logistics of the game mode itself.

Edit: Haha, actually, thanks for asking about that, because I've got the code wrong for randomizing teams... :runaway: , but the game mode is still in question.
Fixed code:
Hidden/Spoiler:
-- Empire Attacking (attacker is always #1)
if not ScriptCB_InMultiplayer() == 0 then
ALL = 1 --math.random(1,2)
IMP = 2 --(3 - ALL)
else
-- These variables do not change
ALL = 1
IMP = 2
end

ATT = 1
DEF = 2
Your fixed code may as well just be the stock code
Hidden/Spoiler:
[code]ATT = 1
DEF = 2

ALL = 1
IMP = 2[/code]
Without the math.random(1,2) you can't get randomized teams.

Here is the correct code from the project I first made it up on, with added comments.
Hidden/Spoiler:
[code]ATT = 1
DEF = 2

if ScriptCB_InMultiplayer() == 0 then --randomizing only works well in singleplayer
ALL = math.random(1,2) --set Rebels to team 1 or 2
IMP = (3 - ALL) --set Empire to whatever team the Rebels aren't
else
IMP = 1 --multiplayer settings
ALL = 2
end
--tada, now the teams will randomly switch which side of the map they are on :D
--not for use it space, campaigns, or multiplayer.[/code]
Dreadnot9
Chief Warrant Officer
Chief Warrant Officer
Posts: 341
Joined: Wed Jun 06, 2012 2:05 pm
Projects :: Rising Conflict CW v2.0
Games I'm Playing :: Skyrim TF2 FTL
xbox live or psn: Steam is Dreadnot9

Re: Attack/Defend mode

Post by Dreadnot9 »

kinetosimpetus wrote:Your fixed code may as well just be the stock code
Oh...Well I had (well, still have) the math.random function commented out until I get the game mode working, but thank you.
Thanks guys for all the help.
kinetosimpetus
Imperial Systems Expert
Imperial Systems Expert
Posts: 2381
Joined: Wed Mar 25, 2009 4:15 pm
Projects :: A secret project
Games I'm Playing :: Warframe STO

Re: Attack/Defend mode

Post by kinetosimpetus »

Ah, good idea. Test the mode without extra complexity.
Post Reply