Changing max HP for a player
RedSword
Join Date: 2006-12-07 Member: 58947Members, Reinforced - Shadow, WC 2013 - Supporter
Hi,
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 :
and
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,
Red
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 http://forums.unknownworlds.com/discussion/comment/2131807/#Comment_2131807 Script.Load("lua/RedTestModLiveMixin.lua") -- add AlternateLiveMixin to player local networkVars = { } do AddMixinNetworkVars(AlternateLiveMixin, networkVars) local overrideOnCreate = Player.OnCreate function Player:OnCreate() overrideOnCreate(self) local alternateLiveMixinParameters = { useAlternateMaxHealth = false, alternateMaxHealth = 101, } InitMixin(self, AlternateLiveMixin, alternateLiveMixinParameters) end end Class_Reload("Player", networkVars)
and
Script.Load("lua/LiveMixin.lua") AlternateLiveMixin = CreateMixin() AlternateLiveMixin.type = "AlternateLive" AlternateLiveMixin.networkVars = { useAlternateMaxHealth = "boolean", alternateMaxHealth = "integer (0 to 8191)", } function AlternateLiveMixin:__initmixin() self.useAlternateMaxHealth = false self.alternateMaxHealth = 101 end -- override adjustmaxhealth do 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) else oldAdjustMaxHealth(self, setMax) end Print("=====::::: RedTestModLiveMixin::AdjustMaxHealth detected :::::Post=====") end end -- for admin cmd function AlternateLiveMixin:SetAlternateMaxHealth(aNewAlternateMaxHealth) self.useAlternateMaxHealth = true self.alternateMaxHealth = aNewAlternateMaxHealth end
I also have in my RedTestModShared.lua :
Script.Load("lua/RedTestModLiveMixin.lua") Script.Load("lua/RedTestModPlayer.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,
Red
Comments
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.
Red