.Lua SetClassProperty Question

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
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

.Lua SetClassProperty Question

Post by Maveritchell »

Code: Select all

test = OnObjectKill(
		function(object, killer)
			if killer and IsCharacterHuman(killer) and GetObjectTeam(object) == DEF then
			             print("cheeseball")  --I used this to test whether the function was executing, and it was, because it printed this in the BF2log.
				killcount = killcount + 1
				SetClassProperty("tes_inf_test", "MaxHealth", 500)

			end
		end
	)
The function executes, but the unit's MaxHealth remains unmodified (I am using a unit from that class at the time of the function). What am I doing wrong?
MasterSaitek009
Black Sun Slicer
Posts: 619
Joined: Wed Aug 23, 2006 4:10 pm

Re: .Lua SetClassProperty Question

Post by MasterSaitek009 »

I think that as well as this one:

Code: Select all

SetClassProperty("tes_inf_test", "MaxHealth", 500)
You need to set this one:

Code: Select all

SetClassProperty("tes_inf_test", "CurHealth", 500)
Because I've found that if you set MaxHealth via LUA the current health is not really forced to stay under the MaxHealth limit.

Example:
A Bothan class has 5000 MaxHealth via odf
The map has your script in it
Bothan gets shot a few times and now has 4800 CurHealth
Human Bothan then kills someone on the other team and their MaxHealth is then set down to 500
After all this then the Bothan has:
500 MaxHealth
And 4800 CurHealth
So in other words MaxHealth and CurHealth are independent of each other.

Please correct me if I'm wrong Ace or Zerted.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: .Lua SetClassProperty Question

Post by Maveritchell »

The problem seems to be not that the code isn't taking effect, it just doesn't take immediate effect. When the character respawns or "re-selects" the same character at a spawn point, the health changes. What I'm not getting (even with adding in a CurHealth line) is the immediate change to the player's character.

EDIT: By using a similar line (SetProperty, and assigning it to the killer's unit), I can modify the current health "on the fly," if you will. The problem is not one of getting the health to change - I can make the character's health change to 500 when it kills a unit, but I can't get the character's max health to change unless it goes to a spawn point.

EDIT (again): Lol, nevermind. I just used the SetProperty function again to assign MaxHealth, instead of the code I mentioned above. I had tried this earlier, but I realize now the reason it was buggy was because I didn't also set the current health. Thanks for the pointer, Saitek.
Post Reply