1. Post #1

    March 2012
    94 Posts
    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:
    [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)

  2. Post #2
    DaneSomdahl's Avatar
    April 2011
    266 Posts
    Code:
    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.

  3. Post #3
    Awesome Gmod Servers!
    brandonj4's Avatar
    September 2011
    2,073 Posts
    Code:
    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 now?
    It's always been Serverside.

  4. Post #4
    DaneSomdahl's Avatar
    April 2011
    266 Posts
    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.

  5. Post #5

    March 2012
    94 Posts
    yea thx.
    I have to work then with GetNWInt and SetNWInt right??
    Reply With Quote Edit / Delete Reply Windows 7 Germany Show Events Winner Winner x 1Agree Agree x 1 (list)

  6. Post #6
    Awesome Gmod Servers!
    brandonj4's Avatar
    September 2011
    2,073 Posts
    yea thx.
    I have to work then with GetNWInt and SetNWInt right??
    That agree would be a yes :P

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

    Edited:

    If you need help on a script:
    Edit: Changed font
    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
    
    Reply With Quote Edit / Delete Reply Windows 7 Canada Show Events Dumb Dumb x 1Informative Informative x 1Agree Agree x 1 (list)

  7. Post #7

    January 2012
    131 Posts
    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
    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
    
    Reply With Quote Edit / Delete Reply Windows 7 Estonia Show Events Disagree Disagree x 3Agree Agree x 1 (list)