Linking team 3 kills
Moderator: Moderators
- jangoisbaddest
- Lieutenant General

- Posts: 661
- Joined: Mon Feb 27, 2006 12:10 am
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: All Along The Watchtower
Linking team 3 kills
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.
- Frisbeetarian
- Jedi

- Posts: 1233
- Joined: Wed Sep 12, 2007 3:13 pm
Re: Linking team 3 kills
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.
The second weapon would be the same with the health part replaced with a different function, probably AddTeamPoints, found the same place as GetCharacterTeam.
- jangoisbaddest
- Lieutenant General

- Posts: 661
- Joined: Mon Feb 27, 2006 12:10 am
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: All Along The Watchtower
Re: Linking team 3 kills
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: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,
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.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.
There is also the small detail that there's no way to know who spawned the bots from team 3...right?
- Fiodis
- Master of the Force

- Posts: 4145
- Joined: Wed Nov 12, 2008 9:27 pm
- Projects :: Rannoch + Tientia + Tools Programming
Re: Linking team 3 kills
SetProperty, "CurHealth"?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.
- Frisbeetarian
- Jedi

- Posts: 1233
- Joined: Wed Sep 12, 2007 3:13 pm
Re: Linking team 3 kills
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 HealthFiodis wrote:SetProperty, "CurHealth"?
For this you can just use an OR statement to check if the killer is on team 3 or the character.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).
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.jangoisbaddest wrote: There is also the small detail that there's no way to know who spawned the bots from team 3...right?
- jangoisbaddest
- Lieutenant General

- Posts: 661
- Joined: Mon Feb 27, 2006 12:10 am
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: All Along The Watchtower
Re: Linking team 3 kills
Yes.Fiodis wrote:SetProperty, "CurHealth"?
My big problem is still: if two or more players are using the hero, how will I know who to give the health to?
- Frisbeetarian
- Jedi

- Posts: 1233
- Joined: Wed Sep 12, 2007 3:13 pm
Re: Linking team 3 kills
Only one person can be a hero at a time.
-
kinetosimpetus
- Imperial Systems Expert

- Posts: 2381
- Joined: Wed Mar 25, 2009 4:15 pm
- Projects :: A secret project
Re: Linking team 3 kills
unless its hero assault mode
- jangoisbaddest
- Lieutenant General

- Posts: 661
- Joined: Mon Feb 27, 2006 12:10 am
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: All Along The Watchtower
Re: Linking team 3 kills
Not in hero assault.Frisbeetarian wrote:Only one person can be a hero at a time.
Edit: sorry, you must have posted just as i was writing my reply.
- Frisbeetarian
- Jedi

- Posts: 1233
- Joined: Wed Sep 12, 2007 3:13 pm
Re: Linking team 3 kills
Then don't use it in hero assault, since you are correct; there is no way to tell who spawned the units.
- jangoisbaddest
- Lieutenant General

- Posts: 661
- Joined: Mon Feb 27, 2006 12:10 am
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: All Along The Watchtower
Re: Linking team 3 kills
I was afraid of that. Hopefully there's a workaround.Frisbeetarian wrote:Then don't use it in hero assault, since you are correct; there is no way to tell who spawned the units.
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
)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!
- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: Linking team 3 kills
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.
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.
- Maveritchell
- Jedi Admin

- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: Linking team 3 kills
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.[RDH]Zerted wrote:Error 2: GetCharacterClass wants a character, not a unit. Do GetCharacterClass(characterIndex). Also, I think GetCharacterClass() returns a number.
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")- jangoisbaddest
- Lieutenant General

- Posts: 661
- Joined: Mon Feb 27, 2006 12:10 am
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: All Along The Watchtower
Re: Linking team 3 kills
That is PRECISELY what I needed. Thank you!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")
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.
