Page 1 of 1
.Lua SetClassProperty Question
Posted: Wed Oct 24, 2007 6:03 pm
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?
Re: .Lua SetClassProperty Question
Posted: Wed Oct 24, 2007 11:13 pm
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.
Re: .Lua SetClassProperty Question
Posted: Wed Oct 24, 2007 11:30 pm
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.