Page 1 of 1

Attack/Defend mode

Posted: Sat Dec 22, 2012 2:47 am
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.

Re: Attack/Defend mode

Posted: Sat Dec 22, 2012 2:50 am
by Cleb
What about randomizing the att and def teams? I thought you could do that.

Re: Attack/Defend mode

Posted: Sat Dec 22, 2012 2:52 am
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

Re: Attack/Defend mode

Posted: Sat Dec 22, 2012 3:35 am
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

Re: Attack/Defend mode

Posted: Sat Dec 22, 2012 6:08 am
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.

Re: Attack/Defend mode

Posted: Sat Dec 22, 2012 11:42 am
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?

Re: Attack/Defend mode

Posted: Sat Dec 22, 2012 12:23 pm
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.

Re: Attack/Defend mode

Posted: Sat Dec 22, 2012 12:29 pm
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]

Re: Attack/Defend mode

Posted: Sat Dec 22, 2012 2:09 pm
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.

Re: Attack/Defend mode

Posted: Sat Dec 22, 2012 2:13 pm
by kinetosimpetus
Ah, good idea. Test the mode without extra complexity.