LUA if-then won't execute [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
jedimoose32
Field Commander
Field Commander
Posts: 938
Joined: Thu Jan 24, 2008 12:41 am
Projects :: Engineering Degree
Location: The Flatlands of Canada

LUA if-then won't execute [Solved]

Post by jedimoose32 »

Hi everyone.

I have 8 command posts. I want my code to produce the following effect: when the Republic captures all but the last CP (cp8), a message appears on-screen, the spawn weights change, and the number of CIS reinforcements and units change. However, once the conditions have been met, the code does not execute. Here is my ScriptPostLoad section, where the code is located. You should see it toward the bottom, above EnableSPheroRules.
Hidden/Spoiler:
[code]
function ScriptPostLoad()


--This defines the CPs. These need to happen first
cp1 = CommandPost:New{name = "cp1"}
cp2 = CommandPost:New{name = "cp2"}
cp3 = CommandPost:New{name = "cp3"}
cp4 = CommandPost:New{name = "cp4"}
cp5 = CommandPost:New{name = "cp5"}
cp6 = CommandPost:New{name = "cp6"}
cp7 = CommandPost:New{name = "cp7"}
cp8 = CommandPost:New{name = "cp8"}

DisableAIAutoBalance()

--This sets up the actual objective. This needs to happen after cp's are defined
conquest = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF,
textATT = "game.modes.con",
textDEF = "game.modes.con2",
multiplayerRules = true}

--This adds the CPs to the objective. This needs to happen after the objective is set up
conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
--conquest:AddCommandPost(cp4) THIS ONE STAYS OUT
conquest:AddCommandPost(cp5)
conquest:AddCommandPost(cp6)
conquest:AddCommandPost(cp7)
conquest:AddCommandPost(cp8)

--Trying to make it so that everyone spawns on one side of the gate until it is destroyed.
--Going to try this approach. The command posts are active but AI cannot spawn. This is short-term, maybe.
SetProperty("cp6", "AISpawnWeight", "0")
SetProperty("cp7", "AISpawnWeight", "0")
SetProperty("cp8", "AISpawnWeight", "0")

BlockPlanningGraphArcs("connection15gate")

conquest.OnStart = function(self)
conquest.goal1 = AddAIGoal(CIS, "Defend", 5, "thegate")
conquest.goal2 = AddAIGoal(REP, "Destroy", 300, "thegate")
end

conquest:Start()

SetUberMode(1);

SetProperty("thegate", "MaxHealth", 68000)
SetProperty("thegate", "CurHealth", 68000)

OnObjectKillName(GateDown, "thegate");

if GetCommandPostTeam("cp6") == 1 and GetCommandPostTeam("cp7") == 1 then

--Tell the humans where to go next.
ShowMessageText("level.dda.objectives.laststand1",1)
ShowMessageText("level.dda.objectives.laststand2",2)

--Let's muck around with the spawn weights to produce a better final battle sequence.
SetProperty("cp6", "AISpawnWeight", "500") --FOR THE REPUBLIIIIIC
SetProperty("cp7", "AISpawnWeight", "500") --ALSO FOR THE REPUBLIIIICCCC
SetProperty("cp8", "AISpawnWeight", "750") --For the CIS...

--And it's actually pretty vital that they try and fight over this particular CP.
SetProperty("cp8", "Value_DEF_CIS", "2000")
SetProperty("cp8", "Value_ATK_Republic", "2000")

--To avoid the Battle of Thermopylae...
SetReinforcementCount(DEF, -1)
SetUnitCount(DEF, 35)

end

EnableSPHeroRules()

end
[/code]
There are no errors when munging, and no errors in my BFront2 log. What have I done wrong with my syntax?
Last edited by jedimoose32 on Sat Nov 01, 2014 5:11 pm, edited 1 time in total.
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: LUA if-then won't execute

Post by [RDH]Zerted »

You need to put your if statement inside an event callback, such as the one for when a CP is captured (I forget the name).

Also, you might want to create a toggle. Do you want that code to execute only once per round or do you want to display the same message anytime some other CP changes while those two CPs are controlled by team 1?
jedimoose32
Field Commander
Field Commander
Posts: 938
Joined: Thu Jan 24, 2008 12:41 am
Projects :: Engineering Degree
Location: The Flatlands of Canada

Re: LUA if-then won't execute

Post by jedimoose32 »

Regarding the toggle, I'm juggling a few ideas around. I might have a timer so the CIS has to defend the CP for 5 minutes/Republic has 5 minutes to capture the CP. Or this might just be a point of no return on the map (i.e. I would lock the capture-ability of the other CPs).

I'll look into using an event callback. I'm sure your example finder will come in handy as I try to find the proper usage.

Edit: I'm assuming the callback would look something like OnCapturePost, as a hypothetical example?
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: LUA if-then won't execute

Post by [RDH]Zerted »

Yes, something like OnCapturePost. Look at the scripting documentation document. It'll have an example. You could also checkout ObjectiveConquest.lua (or whatever it's called). Stuff happens in Conquest mode when a CP is captured so they must use capture events.
jedimoose32
Field Commander
Field Commander
Posts: 938
Joined: Thu Jan 24, 2008 12:41 am
Projects :: Engineering Degree
Location: The Flatlands of Canada

Re: LUA if-then won't execute

Post by jedimoose32 »

Thanks for pointing me in the right direction. For anyone who may read this later, here is the correct code:
Hidden/Spoiler:
[code]
function ScriptPostLoad()


--This defines the CPs. These need to happen first
cp1 = CommandPost:New{name = "cp1"}
cp2 = CommandPost:New{name = "cp2"}
cp3 = CommandPost:New{name = "cp3"}
cp4 = CommandPost:New{name = "cp4"}
cp5 = CommandPost:New{name = "cp5"}
cp6 = CommandPost:New{name = "cp6"}
cp7 = CommandPost:New{name = "cp7"}
cp8 = CommandPost:New{name = "cp8"}
cp9 = CommandPost:New{name = "cp9"}

DisableAIAutoBalance()

--This sets up the actual objective. This needs to happen after cp's are defined
conquest = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF,
textATT = "game.modes.con",
textDEF = "game.modes.con2",
multiplayerRules = true}

--This adds the CPs to the objective. This needs to happen after the objective is set up
conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)
--conquest:AddCommandPost(cp4) THIS ONE STAYS OUT
conquest:AddCommandPost(cp5)
conquest:AddCommandPost(cp6)
conquest:AddCommandPost(cp7)
conquest:AddCommandPost(cp8)
conquest:AddCommandPost(cp9)

--Trying to make it so that everyone spawns on one side of the gate until it is destroyed.
--Going to try this approach. The command posts are active but AI cannot spawn. This is short-term, maybe.
SetProperty("cp6", "AISpawnWeight", "0")
SetProperty("cp7", "AISpawnWeight", "0")
SetProperty("cp8", "AISpawnWeight", "0")

BlockPlanningGraphArcs("connection15gate")

conquest.OnStart = function(self)
conquest.goal1 = AddAIGoal(CIS, "Defend", 5, "thegate")
conquest.goal2 = AddAIGoal(REP, "Destroy", 300, "thegate")
end

conquest:Start()

SetUberMode(1);

SetProperty("thegate", "MaxHealth", 68000)
SetProperty("thegate", "CurHealth", 68000)

OnObjectKillName(GateDown, "thegate");

OnFinishCaptureName(LastStand, "cp6");
OnFinishCaptureName(LastStand, "cp7");


EnableSPHeroRules()

end

function LastStand()
if GetObjectTeam("cp6") == ATT and GetObjectTeam("cp7") == ATT then
--Tell the humans where to go next.
ShowMessageText("level.dda.objectives.laststand1",1)
ShowMessageText("level.dda.objectives.laststand2",2)
--Let's muck around with the spawn weights to produce a better final battle sequence.
SetProperty("cp6", "AISpawnWeight", "500") --FOR THE REPUBLIIIIIC
SetProperty("cp7", "AISpawnWeight", "500") --ALSO FOR THE REPUBLIIIICCCC
SetProperty("cp8", "AISpawnWeight", "750") --For the CIS...
--And it's actually pretty vital that they try and fight over this particular CP.
SetProperty("cp8", "Value_DEF_CIS", "2000")
SetProperty("cp8", "Value_ATK_Republic", "2000")
--To avoid the Battle of Thermopylae...
SetReinforcementCount(DEF, -1)
SetUnitCount(DEF, 35)
else
ShowMessageText("level.dda.objectives.pushback1",1)
ShowMessageText("level.dda.objectives.pushback2",2)
end
end
[/code]
Post Reply