Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity:GetMaxHealth does not updates automatically #5372

Closed
aL1NaZ4R opened this issue Dec 19, 2022 · 4 comments
Closed

Entity:GetMaxHealth does not updates automatically #5372

aL1NaZ4R opened this issue Dec 19, 2022 · 4 comments
Labels
Net compat This issue requires breaking network compatibility to solve so it will be queued.

Comments

@aL1NaZ4R
Copy link

Details

When I was coding my HUD addon, I realized that Entity:GetMaxHealth does not updates immediately after Entity:SetMaxHealth.
You have to jump to update the value.

Steps to reproduce

Create a lua file in autorun directory, and paste these:

if SERVER then
	AddCSLuaFile()
	Entity( 1 ):SetMaxHealth(1000)
end

if LocalPlayer then
    local function Test()
        local myplayer = LocalPlayer()
        print(myplayer:GetMaxHealth())
    end
    hook.Add( 'HUDPaint', 'Test', Test )
end

Save.
Then type in console: developer 1
Modify the player's Maximum health (the number 1000) to anything you want, and save the file to apply them in game.
Now watch the developer 1 logs. The number will not change until you jump (jump is working for all weapons, if you have Crowbar, then you can do it by left clicking too.)

@aL1NaZ4R aL1NaZ4R changed the title Entity:GetMaxHealth updates too late. Entity:GetMaxHealth does not updates Dec 19, 2022
@aL1NaZ4R aL1NaZ4R changed the title Entity:GetMaxHealth does not updates Entity:GetMaxHealth does not updates automatically Dec 19, 2022
@Kefta
Copy link
Contributor

Kefta commented Dec 19, 2022

This is expected behaviour - you need to set it shared otherwise the client won't know about the value until a fullupdate.

@aL1NaZ4R
Copy link
Author

This is expected behaviour - you need to set it shared otherwise the client won't know about the value until a fullupdate.

so, i should run this code in if SERVER ?

@Kefta
Copy link
Contributor

Kefta commented Dec 22, 2022

No the opposite, it should be called shared in a predicted context if possible.

@robotboy655
Copy link
Contributor

You can learn about prediction here: https://wiki.facepunch.com/gmod/Prediction

@robotboy655 robotboy655 added the Net compat This issue requires breaking network compatibility to solve so it will be queued. label May 2, 2023
@aL1NaZ4R aL1NaZ4R closed this as completed May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Net compat This issue requires breaking network compatibility to solve so it will be queued.
Projects
None yet
Development

No branches or pull requests

3 participants