"Pairing" two teams in a Lua if...then statement? :O

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
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:

"Pairing" two teams in a Lua if...then statement? :O

Post by Marth8880 »

Hi guys. Here's what I'm trying to do: in Unification, the campaign ambushes are going to work in waves. For example: the player steps into an ambush region, the first wave spawns; after three of the four units in the first wave are killed, the second wave spawns, etc. This all works fine and dandy...for the most part. See, the problem is I have each enemy unit class in its own team so I can spawn each class where I want them, and some waves consist of more than one enemy class - or "team" - and I'm not quite sure how to pair two or more teams to a wave, if that makes any sense.


Here's the chunk:

Code: Select all

ScriptCB_PlayInGameMusic("ssv_prg_amb_obj1_1_explore")	-- begin playing first spawn music
	
	DisableBarriers("Ambush1_1");	-- make it so friendly ai can enter ambush arena
	DisableBarriers("Ambush1_2");
	
	ActivateRegion("ambush_1") -- begin first ambush wave
	ambushSquad1 = OnEnterRegion(
		function(region, player)
				print("AIGoal:: ambush_1")	-- ai goals
			ClearAIGoals(3)
			AddAIGoal(3, "Defend", 200, 0)
			
			ClearAIGoals(2)
			AddAIGoal(2, "Destroy", 500, 0)
			AddAIGoal(2, "Deathmatch", 500)
			
			BlockPlanningGraphArcs("Connection42");	-- ai aren't supposed to wander out of their closed-off positions
			BlockPlanningGraphArcs("Connection43");
			BlockPlanningGraphArcs("Connection44");
			BlockPlanningGraphArcs("Connection45");
			BlockPlanningGraphArcs("Connection46");
			BlockPlanningGraphArcs("Connection47");
			
			EnableBarriers("Ambush1_1");	-- enclose ambush arena so ai can't run away
			EnableBarriers("Ambush1_2");
			
			ScriptCB_PlayInGameMusic("ssv_prg_amb_obj1_1_combat")	-- begin playing combat music on ambush
			
			ShowMessageText("level.PRG.debug.ambush1a")
		end,
	"ambush_1"
	)
	
	SetupAmbushTrigger("ambush_1", "gth_troop_1", 4, 2)	-- ambush1a trigger: regionName=ambush_1, pathName=gth_troop_1, numDudes=4, teamNum=2
	
	geth_count_1a = 4	-- amount of units to subtract from in ambush1a
	Ambush1aGethKill = OnObjectKill(
		function(object, killer)
			if killer and GetObjectTeam(object) == 2 then	-- defines team to subtract units from; in this case team 2
				geth_count_1a = geth_count_1a - 1	-- subtract geth_count1a by 1 upon each kill made towards ambush wave
				if geth_count_1a == 1 then	-- once ambush1a unit count reaches 1, initiate ambush1b
					ClearAIGoals(4)
					AddAIGoal(4, "Destroy", 500, 0) -- ai goals
					AddAIGoal(4, "Deathmatch", 500)
					
					Ambush("gth_troop_1", 4, 4)	-- ambush1b: pathName=gth_troop_1, numDudes=4, teamNum=4
					
					ShowMessageText("level.PRG.debug.ambush1b")
					
					geth_count_1b = 4	-- amount of units to subtract from in ambush1b
					Ambush1bGethKill = OnObjectKill(
						function(object, killer)
							if killer and GetObjectTeam(object) == 4 then	-- defines team to subtract units from; in this case team 4
								geth_count_1b = geth_count_1b - 1	-- subtract geth_count1b by 1 upon each kill made towards ambush wave
								if geth_count_1b == 2 then	-- once ambush1b unit count reaches 2, initiate ambush1c
									ClearAIGoals(2)
									ClearAIGoals(4)
									AddAIGoal(2, "Destroy", 500, 0)	-- ai goals
									AddAIGoal(2, "Deathmatch", 500)
									AddAIGoal(4, "Destroy", 500, 0)
									AddAIGoal(4, "Deathmatch", 500)
									
									Ambush("gth_troop_1", 3, 2)	-- ambush1c: pathName=gth_troop_1, numDudes=3, teamNum=2
									Ambush("gth_troop_1", 1, 4)	-- ambush1c: pathName=gth_troop_1, numDudes=1, teamNum=4
									
									ShowMessageText("level.PRG.debug.ambush1c")
									
									geth_count_1c = 4	-- amount of units to subtract from in ambush1c; sum of units from team 2 and team 4
									Ambush1c2GethKill = OnObjectKill(
										function(object, killer)
											if killer and GetObjectTeam(object) == 2 then	-- defines team to subtract units from; in this case team 2
												geth_count_1c = geth_count_1c - 1	-- subtract geth_count1c by 1 upon each kill made towards team 2 in ambush1c
												
												Ambush1c4GethKill = OnObjectKill(
													function(object, killer)
														if killer and GetObjectTeam(object) == 4 then	-- defines team to subtract units from; in this case team 4
															geth_count_1c = geth_count_1c - 1	-- subtract geth_count1c by 1 upon each kill made towards team 4 in ambush1c
															if geth_count_1c == 0 then	-- once the amount of units in ambush1c reahces 0 play the explore music
																ShowMessageText("level.PRG.debug.ambush1end")
																ScriptCB_PlayInGameMusic("ssv_prg_amb_obj1_2_explore")	-- begin playing explore music
															end
														end
													end
												)
											end
										end
									)
									
									--
									-- THE FOLLOWING IS COMMENTED AND REDACTED
									--[[geth_count_1c = 4
									Ambush1c2GethKill = OnObjectKill(
										function(object, killer)
											if killer and GetObjectTeam(object) == 2 + 4 then -- argh, the problem is I don't know how to "pair" the two teams: 2 & 4
												geth_count_1c = geth_count_1c - 1
												
												if geth_count_1c == 0 then
													ShowMessageText("level.PRG.debug.ambush1end")
													ScriptCB_PlayInGameMusic("ssv_prg_amb_obj1_2_explore")
												end
											end
										end
									)]]
									--[[geth_count_1c2 = 3
									geth_count_1c4 = 1
									Ambush1c2GethKill = OnObjectKill(
										function(object, killer)
											if killer and GetObjectTeam(object) == 2 then
												geth_count_1c2 = geth_count_1c2 - 1
											end
										end
									)
									Ambush1c4GethKill = OnObjectKill(
										function(object, killer)
											if killer and GetObjectTeam(object) == 4 then
												geth_count_1c4 = geth_count_1c4 - 1
											end
										end
									)
									geth_count_1c = geth_count_1c2 + geth_count_1c4
									if geth_count_1c == 0 then
										ShowMessageText("level.PRG.debug.ambush1end")
										ScriptCB_PlayInGameMusic("ssv_prg_amb_obj1_2_explore")
									end]]
								end
							end
						end
					)
				end
			end
		end
	)
May or may not be easier to read in a separate LUA file.
https://dl.dropbox.com/u/38430663/Mass%20Effect%20Mod/Troubleshooting/ambush_chunk.lua

So this all works...almost. The second explore music plays when there are usually one or two geth remaining in ambush1c; it's not supposed to play until after there are no geth units remaining.
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: "Pairing" two teams in a Lua if...then statement? :O

Post by Locutus »

Not sure if i get this right...
How about

Code: Select all

if killer and (GetObjectTeam(object) == 2 or GetObjectTeam(object) == 4) then
total_geth_wave_count = total_geth_wave_count - 1
?

PS: I really appreciate your code comments :)


Edit: Just saying, but are you sure AddAIGoal(2, "Destroy", 500, 0) is correct?
I think the last value stands for the target the AI has to destroy, sth. like "destructible_object_in_ZE" or GetEntityClassName(GetCharacterUnit(player)).
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: "Pairing" two teams in a Lua if...then statement? :O

Post by Fiodis »

AFAIK, this:

Code: Select all

if killer and GetObjectTeam(object) == 2 + 4 then
is equivalent to this:

Code: Select all

if killer and GetObjectTeam(object) == 6 then
because LUA reads it as 2+4=6. Locutus's suggestion seem like it would work.
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: "Pairing" two teams in a Lua if...then statement? :O

Post by Marth8880 »

Locutus wrote:Not sure if i get this right...
How about

Code: Select all

if killer and (GetObjectTeam(object) == 2 or GetObjectTeam(object) == 4) then
total_geth_wave_count = total_geth_wave_count - 1
?
Hmm, that could work... If not that, then I'll try it but replacing "or" with "and".
Locutus wrote:Edit: Just saying, but are you sure AddAIGoal(2, "Destroy", 500, 0) is correct?
I think the last value stands for the target the AI has to destroy, sth. like "destructible_object_in_ZE" or GetEntityClassName(GetCharacterUnit(player)).
Eeeyup, it's correct. The last value can either be a game object pointer or a character index; in this case it's player one's character index. ;)
Fiodis wrote:AFAIK, this:

Code: Select all

if killer and GetObjectTeam(object) == 2 + 4 then
is equivalent to this:

Code: Select all

if killer and GetObjectTeam(object) == 6 then
because LUA reads it as 2+4=6. Locutus's suggestion seem like it would work.
Right. That's why I had that section commented out; I had tried it before and it, well, didn't really work lol.
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: "Pairing" two teams in a Lua if...then statement? :O

Post by Fiodis »

Replacing or with and would require that object be on both teams 4 and 2 at the same time, which seems unlikely, if not impossible.
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: "Pairing" two teams in a Lua if...then statement? :O

Post by Marth8880 »

First I tried this:

Code: Select all

									geth_count_1c = 4
									Ambush1cGethKill = OnObjectKill(
										function(object, killer)
											if killer and (GetObjectTeam(object) == 2 and GethObjectTeam(object) == 4) then -- argh, the problem is I don't know how to "pair" the two teams: 2 & 4
												geth_count_1c = geth_count_1c - 1
											if geth_count_1c == 0 then
												ShowMessageText("level.PRG.debug.ambush1end")
												ScriptCB_PlayInGameMusic("ssv_prg_amb_obj1_2_explore")
											end
										end
									)
and the same thing that used to happen just seemed to happen again: the explore music played at the wrong time, around when 2 units remained.


Then I tried this:

Code: Select all

									geth_count_1c = 4
									Ambush1cGethKill = OnObjectKill(
										function(object, killer)
											if killer and GetObjectTeam(object) == 2 then -- argh, the problem is I don't know how to "pair" the two teams: 2 & 4
												geth_count_1c = geth_count_1c - 1
											elseif killer and GetObjectTeam(object) == 4 then -- argh, the problem is I don't know how to "pair" the two teams: 2 & 4
												geth_count_1c = geth_count_1c - 1
											end
											if geth_count_1c == 0 then
												ShowMessageText("level.PRG.debug.ambush1end")
												ScriptCB_PlayInGameMusic("ssv_prg_amb_obj1_2_explore")
											end
										end
									)
and the explore music just doesn't start playing at all.


Gah, where's Zerted or THEMAVMAN when you need them? Or archer01? Or Firefang? Or umm. Penguin I guess? Sure, Penguin. Where's Penguin when you need her?
User avatar
ANDEWEGET
Ancient Force
Ancient Force
Posts: 1266
Joined: Tue Apr 01, 2008 8:42 am
Location: Germany
Contact:

Re: "Pairing" two teams in a Lua if...then statement? :O

Post by ANDEWEGET »

In your .lua file:
1st option (not commented out) will only work if the last Geth killed is on Team 4, otherwise the sound won't be played because the sound command is in the OnObjectKill event of team 4.

2nd option (commented out) can't work because no Geth is on team 6 (as already stated by Fiodis).

3rd option (commented out) can't work because you do this:
define OnObjectKill for team 2
define OnObjectKill for team 4
check if geth_count == 0 (still 4)
... gameplay starts ...
OnObjectKill event is triggered
!! missing check for geth_count == 0 !!

You'd have to check the count in the OnObjectKill event functions.

And in your last post:
1st option can't work because you call 'GethObjectTeam()' (unless you defined that one) and you're missing an 'end' in the first if-block.

The second one should work methinks although I would write it like this:

Code: Select all

OnObjectKill(
    function(object, killer)
        -- exists and (      geth in team 2         OR        geth in team 4       )
        if killer and ((GetObjectTeam(object) == 2) or (GetObjectTeam(object) == 4)) then
            geth_count_1c = geth_count_1c - 1
            if geth_count_1c == 0 then
                -- trigger sound
            end
        end
    end)
I dunno if print() works with SWBF2, if it does you could just print the team and the count to the console each time the functions gets called.
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: "Pairing" two teams in a Lua if...then statement? :O

Post by Marth8880 »

I actually decided to do something that is a WHOLE lot simpler and actually works correctly; using my previous method didn't have accidental enemy deaths, e.g., enemy A.I. killing themselves, in mind and those deaths weren't deducted from the unit counts.

Here's what I'm doing instead:

Code: Select all

ScriptCB_PlayInGameMusic("ssv_prg_amb_obj1_1_explore")	-- begin playing first spawn music
	
	ClearAIGoals(2)
	AddAIGoal(2, "Follow", 200, 0)
	
	ClearAIGoals(3)
	ClearAIGoals(4)
	ClearAIGoals(5)
	ClearAIGoals(6)
	ClearAIGoals(7)
	AddAIGoal(3, "Destroy", 500, 0)
	AddAIGoal(4, "Destroy", 500, 0)
	AddAIGoal(5, "Destroy", 500, 0)
	AddAIGoal(6, "Destroy", 500, 0)
	AddAIGoal(7, "Destroy", 500, 0)
	AddAIGoal(3, "Deathmatch", 500)
	AddAIGoal(4, "Deathmatch", 500)
	AddAIGoal(5, "Deathmatch", 500)
	AddAIGoal(6, "Deathmatch", 500)
	AddAIGoal(7, "Deathmatch", 500)
	
	
	--Ambush1 = function (self)
		
		
		DisableBarriers("Ambush1_1");	-- make it so friendly ai can enter ambush arena
		DisableBarriers("Ambush1_2");
		
		ActivateRegion("ambush_1") -- begin first ambush wave
		AmbushWave1 = OnEnterRegion(
			function(region, player)
					print("AIGoal:: ambush_1")	-- ai goals
				ClearAIGoals(2)
				AddAIGoal(2, "Defend", 200, 0)
				
				SetReinforcementCount(3, 4)
				
				BlockPlanningGraphArcs("Connection42");	-- ai aren't supposed to wander out of their closed-off positions
				BlockPlanningGraphArcs("Connection43");
				BlockPlanningGraphArcs("Connection44");
				BlockPlanningGraphArcs("Connection45");
				BlockPlanningGraphArcs("Connection46");
				BlockPlanningGraphArcs("Connection47");
				
				EnableBarriers("Ambush1_1");	-- enclose ambush arena so ai can't run away
				EnableBarriers("Ambush1_2");
				
				ScriptCB_PlayInGameMusic("ssv_prg_amb_obj1_1_combat")	-- begin playing combat music on ambush
				
				ShowMessageText("level.PRG.debug.ambush1a")
			end,
		"ambush_1"
		)
		
		SetupAmbushTrigger("ambush_1", "gth_troop_1", 4, 3)	-- ambush1a trigger: regionName=ambush_1, pathName=gth_troop_1, numDudes=4, teamNum=3
		
		Ambush1a_ReinforcementCount = GetReinforcementCount(3)
		Ambush1b_ReinforcementCount = GetReinforcementCount(4)
		Ambush1c_ReinforcementCount = GetReinforcementCount(3) + GetReinforcementCount(4)
		if Ambush1a_ReinforcementCount == 1 then
			Ambush("gth_troop_1", 4, 4)	-- ambush1b: pathName=gth_troop_1, numDudes=4, teamNum=4
			
			SetReinforcementCount(4, 4)
			
			ShowMessageText("level.PRG.debug.ambush1b")
			if Ambush1b_ReinforcementCount == 2 then
				Ambush("gth_troop_1", 3, 3)	-- ambush1c: pathName=gth_troop_1, numDudes=3, teamNum=3
				Ambush("gth_troop_1", 1, 4)	-- ambush1c: pathName=gth_troop_1, numDudes=1, teamNum=4
				
				SetReinforcementCount(3, 3)
				SetReinforcementCount(1, 4)
				
				ShowMessageText("level.PRG.debug.ambush1c")
				if Ambush1c_ReinforcementCount == 0 then
					ShowMessageText("level.PRG.debug.ambush1end")
					
					Ambush1EndTimer = CreateTimer("Ambush1EndTimer")
						SetTimerValue("Ambush1EndTimer", 1)
						StartTimer("Ambush1EndTimer")
						OnTimerElapse(
							function(timer)
								ScriptCB_PlayInGameMusic("ssv_prg_amb_obj1_2_explore")	-- begin playing explore music
								
								DestroyTimer(Timer)
							end,
						"Ambush1EndTimer"
					)
				end
			end
		end
	--end
The problem is now the the second and third ambush waves don't ambush the player, nor do the dumb in-game debug messages that I have set up show. :?


EDIT:

Hold up a minute, do ambush units have any effect on their team's reinforcement count? :o Because if not, then just...UGH, I'm gonna need to figure out a way to make it so that basically my old method is called whenever an ambush unit dies instead of when the player kills it. My other option seems to be to just force normal, non-ambush units to spawn in certain places at certain times...

EDIT2:

Ah-hah!! ^^ I knew it! Ambush units DON'T have any effect on their team's reinforcement count! :o Ugh, crap...
User avatar
ANDEWEGET
Ancient Force
Ancient Force
Posts: 1266
Joined: Tue Apr 01, 2008 8:42 am
Location: Germany
Contact:

Re: "Pairing" two teams in a Lua if...then statement? :O

Post by ANDEWEGET »

Is the code you posted in a event like OnObjectKill?
I can't see you updating the reinforcement variables anywhere. It seems you get the reinforcement values once after setting the wave up but the variable doesn't change in the code you posted.
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: "Pairing" two teams in a Lua if...then statement? :O

Post by Locutus »

Code: Select all

   OnObjectKill(
      function(object, killer)
         if GetEntityClassName(object) == YOUR_CLASS_IN_AMBUSH_TEAM_1 then
            geth_count_1a = geth_count_1a -1
            --[[stuff]]   
         elseif GetEntityClassName(object) == YOUR_CLASS_IN_AMBUSH_TEAM_2 then
            geth_count_1b = geth_count_1b -1
            --[[stuff]] 
         end
      end
   )
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: "Pairing" two teams in a Lua if...then statement? :O

Post by Fiodis »

ANDEWEGET wrote:I dunno if print() works with SWBF2, if it does you could just print the team and the count to the console each time the functions gets called.
I think I remember there being something like that which printed to the debug log if you ran the map through the debugging utility. That would come in very handy here.
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: "Pairing" two teams in a Lua if...then statement? :O

Post by Marth8880 »

Alright, so I fixed the problem. I'll post the working Lua block once on my computer in some-odd minutes.


EDIT:

Here's the block:

Code: Select all

Ambush1aGethKill = OnObjectKill(
			function(object, killer)
				local Ambush1a_ReinforcementCount = GetReinforcementCount(2)
				if GetObjectTeam(object) == 2 then
					AddReinforcements(2, -1)
					ShowMessageText("level.PRG.debug.ambushkill1")
				end
				
				if Ambush1a_ReinforcementCount == 1 then
					Ambush("gth_troop_1", 4, 4)	-- ambush1b: pathName=gth_troop_1, numDudes=4, teamNum=4
					
					SetReinforcementCount(4, 4)
					ShowMessageText("level.PRG.debug.ambush1b")
					
					Ambush1bGethKill = OnObjectKill(
						function(object, killer)
							local Ambush1b_ReinforcementCount = GetReinforcementCount(4)
							if GetObjectTeam(object) == 4 then
								AddReinforcements(4, -1)
								ShowMessageText("level.PRG.debug.ambushkill1")
							end
							
							if Ambush1b_ReinforcementCount == 2 then
								Ambush("gth_troop_1", 3, 2)	-- ambush1c: pathName=gth_troop_1, numDudes=3, teamNum=2
								Ambush("gth_troop_1", 1, 4)	-- ambush1c: pathName=gth_troop_1, numDudes=1, teamNum=4
								
								--SetReinforcementCount(2, 3)
								--SetReinforcementCount(4, 1)
								SetReinforcementCount(5, 4)
								ShowMessageText("level.PRG.debug.ambush1c")
								
								Ambush1cGethKill = OnObjectKill(
									function(object, killer)
										local Ambush1c_ReinforcementCount = GetReinforcementCount(5) --GetReinforcementCount(2) + GetReinforcementCount(4)
										if GetObjectTeam(object) == 2 then
											AddReinforcements(5, -1)
											ShowMessageText("level.PRG.debug.ambushkill1")
										elseif GetObjectTeam(object) == 4 then
											AddReinforcements(5, -1)
											ShowMessageText("level.PRG.debug.ambushkill1")
										end
										
										if Ambush1c_ReinforcementCount == 0 then
											ShowMessageText("level.PRG.debug.ambush1end")
											
											Ambush1EndTimer = CreateTimer("Ambush1EndTimer")
												SetTimerValue("Ambush1EndTimer", 1)
												StartTimer("Ambush1EndTimer")
												OnTimerElapse(
													function(timer)
														ScriptCB_PlayInGameMusic("ssv_prg_amb_obj1_2_explore")	-- begin playing explore music
														
														DestroyTimer(Timer)
													end,
												"Ambush1EndTimer"
											)
										end
									end
								)
							end
						end
					)
				end
			end
		)
Post Reply