Trying to index the player's Maximum Health, ran into this problem when converting code over to gmod13
[code]
local oldmaxhealth = debug.getregistry()["Player"].GetMaxHealth
[/code]
What am i doing wrong?
What is the actual problem?
GetMaxHealth is a function of Entity, I believe, not Player.
Is debug.getregistry().Player better than FindMetaTable("Player")? They both appear to do the same thing, though FindMetaTable has been around for years and is what Garry uses.
Nebual is right, GetMaxHealth is defined in the Entity metatable, and there is no real difference in the 2 methods of getting it, I even believe debug.getregistry() is a tad faster since it's more or less a direct Lua binding.
[editline]19th October 2012[/editline]
Thread can be closed.
Crap, didnt post an error. Simply says that "OldMaxHealth" is a nil value.
In your code, oldmaxhealth is all lowercase.
[QUOTE=Chessnut;38106770]In your code, oldmaxhealth is all lowercase.[/QUOTE]
That was just me un-neccesarily capitalizing letters.
[editline]20th October 2012[/editline]
Apparently is supposed to be entity anyways.
debug.getregistry()["Entity"].GetMaxHealth
Fixed my issue.
[editline]20th October 2012[/editline]
Actually, i should probably post the whole function im using here. I'm just trying to convert some code for a public gamemode.
[lua]
local oldmaxhealth = debug.getregistry()["Entity"].GetMaxHealth
function meta:GetMaxHealth()
if self:Team() == TEAM_UNDEAD then
return self:GetMaxZombieHealth()
end
return oldmaxhealth(self)
end
[/lua]
I'm sure oldmaxhealth(self) is not how it should be called. Calling it simply as oldmaxhealth also errors with a nil value.
Oh I See Your Trying To Make A AntiCheat Sorry But Its Not Going To Work
[highlight](User was permabanned for this post ("Alt of permabanned user" - MaxOfS2D))[/highlight]
what.
this is for a gamemode.
Man, you just don't stop, do you?
are you being paid for this?
Not sure if you're still having an issue due to your last edit :v:
[lua]
local meta = FindMetaTable( "Entity" )
meta.GetOldMaxHealth = meta.GetOldMaxHealth or meta.GetMaxHealth
function meta:GetMaxHealth()
if IsValid(self) and self:IsPlayer() and self:Team() == TEAM_UNDEAD then
return self:GetMaxZombieHealth()
end
return self:GetOldMaxHealth()
end[/lua]
Still, I don't get why you would override that function like that, if it's supposed to return that max health when you're an undead, might as well set it via player:SetMaxHealth() on spawn.
I could understand if that code was clientside, since the function doesn't exist in that realm, but GetMaxHealth is serverside only.
it's creating the function clientside.
Sorry, you need to Log In to post a reply to this thread.