I want to record a video but I'm starting a Livestream soon and I try not to broadcast Garry's Mod, I have other games on my list right now.
I'll try to explain without a video. Sometimes when I shoot an enemy, I see the health value drop immediately. Sometimes I have to wait a few seconds without shooting them to see the change. This even applies to when other NPC's are attacking the one in focus. Some NPCs just never update, like npc_manhack and npc_headcrab*.
local vHP = v:Health() or 0
local vMH = v:GetMaxHealth() or 40
local Redout = 0
if vHP < (vMH/3) then Redout = math.Clamp( (vMH/5)/vHP, 0, 1 ) end
surface.DrawRect( -96, -36, math.floor(100*math.Clamp(vHP/vMH,0,1)), 20 )
surface.DrawRect( -96+200-math.floor(100*math.Clamp(vHP/vMH,0,1)), -36, math.floor(100*math.Clamp(vHP/vMH,0,1)), 20 )
The bar is designed to spread out, leaving an empty middle representing the missing health.
https://files.facepunch.com/forum/upload/337562/e19d6983-9c96-41a2-a2ac-6f92c3e12804/health.png
Design note, I'm trying to make the NPC health bars resemble my health bar in the corner. Same for PC health bars above their heads, but I might change that idea later.
This is still a problem. Restarting the game seems to have made a huge difference, but the bar is still slow to update in NPC vs NPC battles
I've always felt that non net variables are slow to update.
My guess would be that the engine 'marks' variables like health as 'non important' and only sends the data out now and then.
It might also be because Valves NPC's have always been costly as they network a bunch of data at all times. The engine might favor animation-data over simple Health() data.
This makes sense, HP may indeed not be networked frequently under the assumption that no visual indication of the health indicated for the client (so it wasn't important), but that's exactly what you're doing. If it's really important to you, you can network the data you need (preferably via net.SendPVS) on the take damage hook
So...
if SERVER then send :Health() value. if CLIENT then receive that value. Yeah?
If you want just the attacker to see the immediate change (and let everyone else see it when the server naturally updates it. which is more optimized) then do something along the lines of
On EntityTakeDamage (target, dmgInfo) if target is NPC and dmgInfo attacker is player then net.Start(your network string ID) net.writeEntity(target) net.writeInt(npcHealth) net.Send(dmgInfo attacker) end
And then on the client youd need to receive it and see that it works well with your script (updates hud): net.Receive(your networking string ID) npc = net.readentity, health = net.readInt, npc:SetHealth(health) end
Hopefully just setting the health on the client will update it correctly in a way that doesnt make it jitter in any way
Sounds good. Why not just read the actual value that's returned, instead of constantly polling an inaccurate Health value? Save the last known value as a local variable, every time it updates.
Sorry, you need to Log In to post a reply to this thread.