Lua Confusion-LinkedTeams,EventSyntax and now function block

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
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Lua Confusion-LinkedTeams,EventSyntax and now function block

Post by Ace_Azzameen_5 »

I'm trying to get team 2 (cis) to lose a ticket everytime a member of the ambush team I added (team 5 "ATM") is killed.

Is there anyway to set to teams to share reinforcments, using a lua function similar to set team as ally?

If not, could someone explain the proper syntax to use to make the event
"TicketCountChange" trigger "AddReinforcements(2,-1)"?
The
"TicketCountChange: function (team, count)"
in the docs confused me. Am I supposed to put "AddReinforcements(2,-1)" where "function" is or where "function (team, count)" is? And what is count supposed to be, the increment by which the count changes?

Or is it supposed to be the ticket count number (IE: when reinfs reach #) when the function will be called?

If that's true I'll need to look for a new event.

Thanks in advance,

Ace
Last edited by Ace_Azzameen_5 on Thu Aug 17, 2006 11:30 pm, edited 3 times in total.
archer01

Post by archer01 »

Code: Select all

-- Creates callback that changes ticket count on another team
-- when a unit from team 5 is killed
OnCharacterDeathTeam(
	function (character, killer)
		if not killer then return end --protection against nil
		
		local onTeam = 2 --team 2 ticket count affected
		local tKiller = GetCharacterTeam(killer)
		local tChar = GetCharacterTeam(character)
		
		--if character == killer then return end --ignore suicides (uncomment if wanted)
		--if tKiller == tChar then return end --ignore suicides and teamkills (uncomment if wanted)
		--if tKiller == onTeam then return end --ignore "teamkills" from team affected  (uncomment if wanted)
		AddReinforcements(onTeam, -1)
	end,
	5
	)
Haven't tested it, but it should work
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Post by Ace_Azzameen_5 »

Thanks. Testing now.

It works. Thanks!

You win a credit in my map!
Last edited by Ace_Azzameen_5 on Sat Aug 12, 2006 2:56 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: Help:Sharing CIS

Post by [RDH]Zerted »

All Event's syntax: On + Event + [Filter] + ( + entire function or a call to the function + [, + filter value] )

An example:

Code: Select all

--function will display [Null] ingame if parameter team = 2
testFn = function( team, count )
 if team == CIS then
  ShowMessageTest("")
 end
end
The above function is being 'stored' in testFn. Doing it this way lets you call the function in most sections of code like this: testFn( 2, nil )

Thus, the TicketCountChange event could be:

Code: Select all

OnTicketCountChange( testFn(team, teamsCurrentTicketCountNumber) )     --when the event is triggered, it calls the function testFn.  
or

Code: Select all

OnTicketCountChange(     --start of event callback
  function( team, count )     --start of function
   if team == REP then     --if the team whose ticket count changed is of REP then...
    ShowMessageTest("")     --show "[null]" ingame
   end     --end of the if statement
  end     --end of the non-named function
) --end of the event callback
But notice that we never named this function, so we can't call it anywhere else in the code (which normally doesn't happen).

Teams can't share reinforcments. You could do what you want with TicketCountChange, but CharacterDeath would work better:

Code: Select all

OnCharacterDeathTeam(     --when a character death event is triggered and the team filter matches the team of the dead player
  function( player, killer )     --start of the unname function
    if GetReinforcementCount(2) > 1 then     --keep CIS out of neg. numbers
      AddReinforcements(2,-1)     --remove one count from team 2
    end     --end of if statement
  end    --end of unnamed function(player, killer)
  , 5     --the team filter.  The dead player needs to match this team (team 5) in order for the function to run.
)    --end of the event callback
edit: seems I was beaten to it. Bad slow loading previews...
Last edited by [RDH]Zerted on Sat Aug 12, 2006 3:07 pm, edited 1 time in total.
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

RE: Help:Sharing CIS

Post by Ace_Azzameen_5 »

Hopefully I'll be able to implement events on my own now, lol.

But, the way I have it set up now, using Archer's CharacterDeath Script, team 5 units are effectively members of team 2, but have their own unit count. Team 5, with infinite reinforcments, effectively uses team 2's reinforcements, and since this is a special campaign mode, where team 5 ambush spawns, and at that time team 2 is awarded 50 tickets (the same as the number of ambushers) it realistically emulates actual reinforcing battalions. Using OnfinishCapture checks I can give all cp's captured by 5 to 2 (My ambushers have the conquest goal) From the players POV, 50 CIS droids rush in to aid thier dwindling allies every 5 minutes.

The goal for the republic in this part of the campaign is to gain areal (is that a word?) superiority/control from a planet wide cis force. They have to dig themselves in before enemy reinforcments arrive, and should any arrive, deal with them while trying to capture command posts.
The player character can fight their way to a control console, and initiate a lock down (animated 'forcefields'-the blue bars from bespin- blocking off hallways) around the area (which is a city) to keep any significant cis ground forces out, effectively simulating the republic digging themselves in.
The republic then mops up remaining CIS cp's (the cis has an infinite supply of 5 units, remember from my other thread?) and the next major plot event is triggered, beging with a laat (animated armedbuilding) coming in to pick up the player character and transport them to the next objective.
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: Help:Sharing CIS

Post by [RDH]Zerted »

You could just ambush spawn units from team 2 instead of writing all the extra code to make team 5 look like team 2.
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

RE: Help:Sharing CIS

Post by Ace_Azzameen_5 »

Yeah, but I'd have to adjust the unit count and it's easier to manage this way. Still didn't know that, becuase XWGuy's thread says that the ambush team shouldn't CPs. Obviously he meant since their objective is set to deathmatch in his post. :oops:
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: RE: Help:Sharing CIS

Post by [RDH]Zerted »

Ace_Azzameen_5 wrote:...XWGuy's thread says that the ambush team shouldn't CPs. Obviously he meant since their objective is set to deathmatch in his post...
Hes just passing along the developer comments in Ambush.lua. You can 'ambush' whatever whenever on any path.
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

RE: Re: RE: Help:Sharing CIS

Post by Ace_Azzameen_5 »

I still can't figure out events yet, mostly becuase I can't tell when the examples are specifying actual words or variables, for example in
"CommandPostKill: function (post, killer)"

does it want me to replace the word function with the functions I want carried out or does it need the word function their? Actually, I'm pretty sure that one needs to be replaced by a predefined cp. OR the words post killer. Are those supposed to specify that the event should look for a specific command post and killing team, or do I love those exact words and input the strings later on in the code?

Right now, I am stuck on getting Destroyable CP's to trigger functions, specifically, 2 objects with the class "commandarmedbuilding" named mtttur and mtttur1. When both are neutralized I want some cp's to respawn. I tried OnObjectKill and OnCommandPostKill but had troubles specifying that I want it to be
certain objects, not just any, much less both destroyed. I also took a look at getobjectptr and thought that if the we're both dead it might return nil for both, but I'm not sure.
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: Re: RE: Help:Sharing CIS

Post by [RDH]Zerted »

Code: Select all

OnCommandPostKill(
   function( varPost, varKiller )
   end
)
or

Code: Select all

callToFunction = function( var1, var2 )
  end
and

Code: Select all

OnCommandPostKill( callToFunction(postVar, killerVar) )
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

RE: Re: RE: Help:Sharing CIS

Post by Ace_Azzameen_5 »

I'm trying to make a multi-callable set of functions, but I have failed. What have done wrong?
Couldn't find a good example in the asset scripts, unfortuantely.

Code: Select all

--Functions Triggered by REPUBLIC victory Triggers in AREA 1
RepWin1 = function(post)
if GetObjectTeam("cp2cam") == 1 then
if GetObjectTeam("cp3cam") == 1 then
if GetObjectTeam("cp5cam") == 1 then
PlayAnimation("LAAT")
KillObject("cp2cam")
KillObject("cp3cam")
KillObject("cp5cam")
RespawnObject("cp1cam")
RespawnObject("cprep")
RespawnObject("mtttur1")
RespawnObject("mtttur")
SetReinforcementCount (2, 200)
AddReinforcements(1, 50)
StartTimer("Gun_Fly1")
end
end --every time you add a command post if statement you must add another end here
end
end
--END OF REPWIN1!
OnFinishCapture("RepWin1")
archer01

RE: Re: RE: Help:Sharing CIS

Post by archer01 »

OnFinishCapture("RepWin1")

should be...

OnFinishCapture(RepWin1) --No quotes, it's a variable name, not a string


Does that help?
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

RE: Re: RE: Help:Sharing CIS

Post by Ace_Azzameen_5 »

Yes. Thanks. Again.]

Edit:

Is there anyway that I can setup those if statements as part of the call as opposed to the funciton? I'm setting it up so that function is triggerred by two things, a timer, or OnFinishCapture-but only if those thre if statments are true.
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: Re: RE: Help:Sharing CIS

Post by [RDH]Zerted »

If I'm understanding you right, you can try:

Code: Select all

OnFinishCapture(
   function( post )
      if GetObjectTeam("cp2cam") ~= 1 then return end
      if GetObjectTeam("cp3cam") ~= 1 then return end
      if GetObjectTeam("cp5cam") ~= 1 then return end

      RepWin1()      
   end
)

Code: Select all

RepWin1 = function()
   PlayAnimation("LAAT") 
   KillObject("cp2cam") 
   KillObject("cp3cam") 
   KillObject("cp5cam") 
   RespawnObject("cp1cam") 
   RespawnObject("cprep") 
   RespawnObject("mtttur1") 
   RespawnObject("mtttur") 
   SetReinforcementCount (2, 200) 
   AddReinforcements(1, 50) 
   StartTimer("Gun_Fly1") 
end
The FinishCapture will only call the function if the if statements pass and you can trigger the function whenever you want somewhere else in your code.
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

RE: Re: RE: Help:Sharing CIS

Post by Ace_Azzameen_5 »

K Thanks. All I needed were the brackets by the repwin1. I'm going to need to release this map to repay my debt to gametoastiety, specifically the coders who I keep bugging.

I think I'll stop with the lua now and work on making a really involving environment, you know, with wind sound regions, blowing dust and animals. Or maybe first I should get a good sky and ad da soon-or moon.
I wonder if I could place sky domes in zeroedit for night/day modes. . . *continues to ramble on about time consuming tasks* :3dcp:
Post Reply