Changing max HP for a player

RedSwordRedSword Join Date: 2006-12-07 Member: 58947Members, Reinforced - Shadow, WC 2013 - Supporter
edited September 2015 in Modding

I'm trying to change manually a single player's maximum health. I've seen that LiveMixin handles the health and that MaturityMixin overrides its maximum every second (or so) via LiveMixin:AdjustMaxHealth, so it isn't simply (as I want it to last) done via a LiveMixinSetMaxHealth. Since I'm trying to change the maximum, I've tried to override the LiveMixin:AdjustMaxHealth call. Since I want it to affect only one player I decided to add network vars. Here's how I'm doing it :
--File : RedTestModPlayer.lua ; mainly based off

-- add AlternateLiveMixin to player
local networkVars = {

	AddMixinNetworkVars(AlternateLiveMixin, networkVars)

	local overrideOnCreate = Player.OnCreate
	function Player:OnCreate()

		local alternateLiveMixinParameters = { useAlternateMaxHealth = false,
									 alternateMaxHealth = 101, }
		InitMixin(self, AlternateLiveMixin, alternateLiveMixinParameters)
Class_Reload("Player", networkVars)


AlternateLiveMixin = CreateMixin()
AlternateLiveMixin.type = "AlternateLive"

AlternateLiveMixin.networkVars = {
	useAlternateMaxHealth = "boolean",
	alternateMaxHealth = "integer (0 to 8191)",

function AlternateLiveMixin:__initmixin()

    self.useAlternateMaxHealth = false
    self.alternateMaxHealth = 101

-- override adjustmaxhealth
	local oldAdjustMaxHealth = LiveMixin.AdjustMaxHealth
	LiveMixin.AdjustMaxHealth = function(self, setMax) -- called a lot
		Print("=====::::: RedTestModLiveMixin::AdjustMaxHealth detected :::::Pre=====")
		Print("self.useAlternateMaxHealth = " .. tostring(self.useAlternateMaxHealth))
		Print("self.alternateMaxHealth = " .. tostring(self.alternateMaxHealth))
		Print("arg setMax = " .. setMax)
		if self.useAlternateMaxHealth then
			oldAdjustMaxHealth(self, self.alternateMaxHealth)
			oldAdjustMaxHealth(self, setMax)
		Print("=====::::: RedTestModLiveMixin::AdjustMaxHealth detected :::::Post=====")

-- for admin cmd
function AlternateLiveMixin:SetAlternateMaxHealth(aNewAlternateMaxHealth)

	self.useAlternateMaxHealth = true
	self.alternateMaxHealth = aNewAlternateMaxHealth


I also have in my RedTestModShared.lua :

The first piece of code should be adding the AlternateLiveMixin to the player, while the 2nd piece of code should be overriding the AdjustMaxHealth function when needed. The problem, and my question, comes from the fact that I keep seeing "self.useAlternateMaxHealth = nil" and "self.alternateMaxHealth = nil". I also see "arg setMax = X", where X is either around 360 or around 4k, while not being constant, so I'm thinking it's reading memory; and I think solving the first problem will solve that.

I don't know why, as I believe I correctly initiated (twice ?) those variables (via AlternateLiveMixin:__initmixin() and the local alternateLiveMixinParameters varaible @ RedTestModPlayer.lua). I also tried to do a call to the AlternateLiveMixin:SetAlternateMaxHealth, which doesn't seem to help.

Thanks for your help,



  • xDragonxDragon Join Date: 2012-04-04 Member: 149948Members, NS2 Playtester, Squad Five Gold, NS2 Map Tester, Reinforced - Shadow
    The biggest thing I see that you are doing is replacing a globally used function (AdjustMaxHealth). That is used by alot of things as you are seeing, but you are only concerned with players. Since you hook that directly, you get all entities which have AdjustMaxHealth called on them, probably cysts and hives you are seeing initially alot. Since you never init your new mixin on those classes, your values are always nil.

    Marines never change their HP so you would probably have an easier time just directly setting their new maximums. For aliens, you can replace GetBaseHealth easiest I suspect, since they only change their biomass HP in addition to that.
  • RedSwordRedSword Join Date: 2006-12-07 Member: 58947Members, Reinforced - Shadow, WC 2013 - Supporter
    Thanks for your answer xDragon; it made me realize I was making bad assumptions, thinking I was the only alive entities :$; making me modify a function I don't think I really wanted to change (hence my first post might seems confusing).

  • Soul_RiderSoul_Rider Mod Bean Join Date: 2004-06-19 Member: 29388Members, Constellation, Squad Five Blue
    Marine health values are set in BalanceHealth I believe. If you just want to change NS2 values, most are stored amongst the various 'balance' files.
Sign In or Register to comment.