Linking team 3 kills

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
User avatar
jangoisbaddest
Lieutenant General
Lieutenant General
Posts: 661
Joined: Mon Feb 27, 2006 12:10 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: All Along The Watchtower

Linking team 3 kills

Post by jangoisbaddest »

I have a hero that has a special weapon which spawns members of team 3 to his location (who are allied with him). I was hoping that there was a way to rig the system so that every time a member of that team gets a kill, a) the hero gets a health boost (if it is not hero assault) or b) if you're playing hero assault, the hero's team ges a point. I've been digging around the point scripts, but I'm no closer to figuring this out. And it may not be possible, but it would be a very nice touch.
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Linking team 3 kills

Post by Frisbeetarian »

They would both be Lua weapons. The first would work with OnCharacterDeath, found in the Battlefront2_scripting_system.doc., followed by checking if the killer were on team 3 by using GetCharacterTeam, found in LUA Functions under the LUA section of the The FAQ / Everything You Need Thread Version 2.0, and then adding health to the unit using SetProperty for killer with the argument "AddHealth" and the third argument being how much you want to add, found by doing a search on the site.

The second weapon would be the same with the health part replaced with a different function, probably AddTeamPoints, found the same place as GetCharacterTeam.
User avatar
jangoisbaddest
Lieutenant General
Lieutenant General
Posts: 661
Joined: Mon Feb 27, 2006 12:10 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: All Along The Watchtower

Re: Linking team 3 kills

Post by jangoisbaddest »

Frisbeetarian wrote:They would both be Lua weapons. The first would work with OnCharacterDeath, found in the Battlefront2_scripting_system.doc., followed by checking if the killer were on team 3 by using GetCharacterTeam, found in LUA Functions under the LUA section of the The FAQ / Everything You Need Thread Version 2.0,
Indeed I had thought of this approach, but I didn't think there was a function for adding both team and individual points (though I could live without the latter, so I guess I'm good).
Frisbeetarian wrote:and then adding health to the unit using SetProperty for killer with the argument "AddHealth" and the third argument being how much you want to add, found by doing a search on the site.
Using SetProperty for the health addition won't work. If you use setProperty to change the AddHealth value, that will mean that the target will constantly regenerate health by whatever value you place in the argument each (second?). I don't want that - all I want is to add a set amount of health once.

There is also the small detail that there's no way to know who spawned the bots from team 3...right?
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: Linking team 3 kills

Post by Fiodis »

jangoisbaddest wrote:Using SetProperty for the health addition won't work. If you use setProperty to change the AddHealth value, that will mean that the target will constantly regenerate health by whatever value you place in the argument each (second?). I don't want that - all I want is to add a set amount of health once.
SetProperty, "CurHealth"?
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Linking team 3 kills

Post by Frisbeetarian »

Fiodis wrote:SetProperty, "CurHealth"?
I would have suggested that, but he has to retrieve the health first to use that. CurHealth is used to set the players health to that amount, not add health. I found this using search though: Adding Health
jangoisbaddest wrote:Indeed I had thought of this approach, but I didn't think there was a function for adding both team and individual points (though I could live without the latter, so I guess I'm good).
For this you can just use an OR statement to check if the killer is on team 3 or the character.
jangoisbaddest wrote: There is also the small detail that there's no way to know who spawned the bots from team 3...right?
I haven't looked into it since the way you described it being set up, you don't need to know who spawns them, as only one unit, the hero spawns them.
User avatar
jangoisbaddest
Lieutenant General
Lieutenant General
Posts: 661
Joined: Mon Feb 27, 2006 12:10 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: All Along The Watchtower

Re: Linking team 3 kills

Post by jangoisbaddest »

Fiodis wrote:SetProperty, "CurHealth"?
Yes. :oops:

My big problem is still: if two or more players are using the hero, how will I know who to give the health to?
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Linking team 3 kills

Post by Frisbeetarian »

Only one person can be a hero at a time.
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: Linking team 3 kills

Post by kinetosimpetus »

unless its hero assault mode
User avatar
jangoisbaddest
Lieutenant General
Lieutenant General
Posts: 661
Joined: Mon Feb 27, 2006 12:10 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: All Along The Watchtower

Re: Linking team 3 kills

Post by jangoisbaddest »

Frisbeetarian wrote:Only one person can be a hero at a time.
Not in hero assault. :?

Edit: sorry, you must have posted just as i was writing my reply.
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Linking team 3 kills

Post by Frisbeetarian »

Then don't use it in hero assault, since you are correct; there is no way to tell who spawned the units.
User avatar
jangoisbaddest
Lieutenant General
Lieutenant General
Posts: 661
Joined: Mon Feb 27, 2006 12:10 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: All Along The Watchtower

Re: Linking team 3 kills

Post by jangoisbaddest »

Frisbeetarian wrote:Then don't use it in hero assault, since you are correct; there is no way to tell who spawned the units.
I was afraid of that. Hopefully there's a workaround.

Along those same lines though, I am unable to find a function to return the hero character. If I use OnCharacterDeath, that only passes the killer and the victem (I assume...it says player, killer in the documentation), and not the hero. So is there any way to find the hero character through the LUA? Otherwise I'd have to set up a for loop and toggle through every player on the CIS team and check if they are the hero class.

Edit: Okay, apparently I don't know enough about what format the game's functions need to have passed to them. Here's my "give life" function:

Code: Select all

OnCharacterDeath(
	function(player, killer)
		if GetCharacterTeam(killer) == 3 then
			local heroTeam = 2
			local teamSize = GetTeamSize(2)
			local heroUnit = GetCharacterUnit(killer)
			for i = 0, teamSize-1 do
				local characterIndex = GetTeamMember(2, i)
				local charUnit = GetCharacterUnit(characterIndex)
				if GetCharacterClass(charUnit) == "ksh_hero_oom9" then
					print("Player using hero class found!")
					heroUnit = charUnit
				end
			end
			if heroUnit == GetCharacterUnit(killer) then
				print("Could not find a hero unit ingame.")
				return
			end
                                      local heroHealth = GetObjectHealth(heroUnit)
			if heroHealth >= 1500 then
				print("Hero is at max health.")
				return
			else
				SetProperty(heroUnit, "CurHealth", heroHealth + 200)
				print("Hero gained 200 health")
			end
		end
	end
)
And the errors I'm getting:

Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetCharacterTeam' (number expected, got nil)
stack traceback:
[C]: in function `GetCharacterTeam'
(none): in function <(none):202>


Message Severity: 3
.\Source\LuaHelper.cpp(312)
CallProc failed: bad argument #1 to `GetCharacterClass' (number expected, got userdata)
stack traceback:
[C]: in function `GetCharacterClass'
(none): in function <(none):202>

I've tried both numbers and the actual team/class name in both of those instances as wll, and still the same error. Apparently, the function GetCharacterClass is not the function to use when dealing with heroes, and I couldn't find a function that deals with returning hero characters. Help please!
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: Linking team 3 kills

Post by [RDH]Zerted »

Error Fixes:
Error 1: I believe that if the player kills himself or if you manually kill a unit, there is no killer. You need to check for when killer is nil and handle this case.
Error 2: GetCharacterClass wants a character, not a unit. Do GetCharacterClass(characterIndex). Also, I think GetCharacterClass() returns a number.

You have the max health check at 1500, so the real max health is 1500+200 right? If not, then a unit with 1400 health will pass the check and gain 200 putting him at 1600 health. Of course, I still don't know if anything bad would happen if it is over the max health anyway...

Different Way To Do It:
So you have a weapon that spawns 3 units. I'll assume it works by dispense something, then force spawning the units. You can manually track the players. Create a table, lets call it weaponUnits. When the player triggers the weapon, the event callback tells you which player did it. Now when you spawn each new unit, add that unit to the weaponUnits table and give it a reference to the player that spawned it: weaponUnits[newUnitsId] = playersId. Now OnCharacterDeath, loop through each unit in weaponUnits and look for the unit that died. If you find it, you have a reference to the player that spawned him. Check to see that this player is still alive and is of the correct hero class. If it is, give him some health. Now that you have processed this unit, clear his player from the table: weaponUnits[newUnit] = nil. You could structure the table differently if want to.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: Linking team 3 kills

Post by Maveritchell »

[RDH]Zerted wrote:Error 2: GetCharacterClass wants a character, not a unit. Do GetCharacterClass(characterIndex). Also, I think GetCharacterClass() returns a number.
GetCharacterClass does return a number - the number is the position (on the team) starting at 0 - first unit loaded for its team returns 0, second 1, etc.

If you want to check against a specific class, another way to do it is like this:

Code: Select all

GetEntityClass(charUnit) == FindEntityClass("ksh_hero_oom9")
User avatar
jangoisbaddest
Lieutenant General
Lieutenant General
Posts: 661
Joined: Mon Feb 27, 2006 12:10 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set
Location: All Along The Watchtower

Re: Linking team 3 kills

Post by jangoisbaddest »

Maveritchell wrote:If you want to check against a specific class, another way to do it is like this:

Code: Select all

GetEntityClass(charUnit) == FindEntityClass("ksh_hero_oom9")
That is PRECISELY what I needed. Thank you! :D

And thanks for the tracking tips, Zerted! Turns out I wont need it for the Hero Assault mode, but I'm sure it will come in handy for my next project.

EDIT: GetEntityClass(charUnit) didn't work. I changed the paramiter to characterIndex, and now I'm getting all sorts of

Message Severity: 2
.\Source\LuaCallbacks_Mission.cpp(635)
Entity "66" not found

these. It's like the for loop is going way past the team count for team 2 for a reason I can't fathom.
Post Reply