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()
[CODE]
surface.DrawTexturedRect( drawPos.x, drawPos.y + Rect.h, Rect.w * (ent:Health() / ent:GetMaxHealth()) , 5 )
[/CODE]
[CODE]
[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)
[/CODE]
[QUOTE=brandonj4;37379840]It's always been Serverside.[/QUOTE]
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??
[QUOTE=MaZy;37379867]yea thx.
I have to work then with GetNWInt and SetNWInt right??[/QUOTE]
That agree would be a yes :P
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]
Sorry, you need to Log In to post a reply to this thread.