GetMaxHealth() NPC GMOD 13

Hello, doesn’t have a NPC like npc_barney GetMaxHealth()?

I get error in console GetMaxHealth a nil value if I try to make npc:GetMaxHealth()



surface.DrawTexturedRect( drawPos.x, drawPos.y + Rect.h, Rect.w * (ent:Health() / ent:GetMaxHealth()) , 5 )




[gamemodes/texas/gamemode/cl_init.lua:114] attempt to call method 'GetMaxHealth' (a nil value)(Hook: HUDPaint)

	1. lua/includes/modules/hook.lua:111 (unknown)




Finding 'MaxHealth' SERVERSIDE:

	Entity.GetMaxHealth - (function - function: 0458BAB8)
	Entity.SetMaxHealth - (function - function: 0452A6F0)
	Vehicle.MetaBaseClass.GetMaxHealth - (function - function: 0458BAB8)
	Vehicle.MetaBaseClass.SetMaxHealth - (function - function: 0452A6F0)
	Player.MetaBaseClass.GetMaxHealth - (function - function: 0458BAB8)
	Player.MetaBaseClass.SetMaxHealth - (function - function: 0452A6F0)
	NPC.MetaBaseClass.GetMaxHealth - (function - function: 0458BAB8)
	NPC.MetaBaseClass.SetMaxHealth - (function - function: 0452A6F0)
	Weapon.MetaBaseClass.GetMaxHealth - (function - function: 0458BAB8)
	Weapon.MetaBaseClass.SetMaxHealth - (function - function: 0452A6F0)


Finding 'MaxHealth' CLIENTSIDE:





It appears that function is Serverside only.

It’s always been Serverside.

I know, sorry I’m not in my head atm. I just corrected it just before I saw your post.

yea thx.
I have to work then with GetNWInt and SetNWInt right??

That agree would be a yes :stuck_out_tongue:

Edit:
Or usermessages but i’m not sure which one would be faster.

[editline]23rd August 2012[/editline]

If you need help on a script:
Edit: Changed font
[lua]
if CLIENT then
function DrawHPInfo()
local ply = LocalPlayer()
local tr = ply:GetEyeTrace()
if tr.HitWorld or not tr.Hit then return end
local NPCHP = LocalPlayer():GetNWInt(“NPCHealth”)
local NPCMaxHP = LocalPlayer():GetNWInt(“NPCMaxHealth”)
local NPCPos = tr.Entity:GetPos()
local NPCMaxs = tr.Entity:OBBMaxs()
NPCPos.z = NPCPos.z + NPCMaxs.z + 2.5
local NPCPosToScr = NPCPos:ToScreen()
local TxtLen = surface.GetTextSize(NPCHP…"/"…NPCMaxHP)
draw.SimpleTextOutlined(NPCHP…"/"…NPCMaxHP, “Trebuchet22”, NPCPosToScr.x + (TxtLen/2), NPCPosToScr.y, Color(0,0,0,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM, 1, Color(255,255,255,150))
end
hook.Add(“HUDPaint”, “DrawMaxHP”, DrawHPInfo)
else
AddCSLuaFile(“healthmod.lua”)
function SendHPInfo()
for k,v in ipairs(player.GetAll()) do
local tr = v:GetEyeTrace()
if tr.HitWorld or not tr.Hit then return end
if tr.Entity:IsNPC() then
v:SetNWInt(“NPCHealth”, tr.Entity:Health())
v:SetNWInt(“NPCMaxHealth”, tr.Entity:GetMaxHealth())
end
end
end
hook.Add(“Think”, “FindMaxHP”, SendHPInfo)
end
[/lua]

You’d be better off defining a table clientside with all the maximum healths of the given NPC’s and then define a GetMaxHealth function clientside on the entity metatable.

e.g
[lua]
EntityMaxHealth =
{
“default” = 100,
“npc_zombie” = 100,
“npc_watever” = 275
}

function _R.Entity:GetMaxHealth()

local class = self:GetClass()
if EntityMaxHealth[class] then return EntityMaxHealth[class] end

return EntityMaxHealth["default"]

end
[/lua]