1. Sign up for news, events and more!

    You're currently visiting the official DarkRP Forums as a guest. Sign up now to participate in our community and we'll let you know when we have news.

Custom HUD, how to get Energy Value?

Discussion in 'DarkRP Modding Questions & Help' started by Trackster, Jan 9, 2018.

  1. Trackster

    Trackster Member

    When you write your own HUD and you want it to show Health or Armor you let it show the value. And the value is LocalPlayer():Health()

    But how can i get the value for hunger/energy? I KNOW in the darkrp wiki it shows
    Player:getDarkRPVar("Energy")

    but when i let it show that the lua script makes a error and doesnt work. heres the whole code for my hunger hud

    https://pastebin.com/P2DUfexi

    With health and armor it all works fine. But there im using LocalPlayer():Health() instead of Player:getDarkRPVar("Energy")


    Also if anyoner knows, how do i remove the darkrp standart hud? The Half life 2/gmod hud ican remove. but how do i remove the darkrp hud? thx for every answer
    --- Double Post Merged, Jan 9, 2018 ---
    Ok i figured it out. By extracting a other DarkRP Hud by someone else and look what they used to get the value..seems like the darkrp Wiki isnt that updated anymore? Cause it doesnt work with "Player:getDarkRPVar("Energy")" but with LocalPlayer().DarkRPVars.Energy

    SO FOR ANYONE WHO WANT TO FIGURE OUT THE SAME:

    local varname = LocalPlayer().DarkRPVars.Energy
     
    Last edited: Jan 9, 2018
  2. Sir Klutch

    Sir Klutch Active Member

    No, nothing is wrong with the DarkRP Wiki. The reason Player is throwing a nil value error is because Player does not exist. Player needs to be defined somewhere in the code. In your code previously, Player is nothing at all. You would need to define Player.

    Code (Lua):

    hook.Add("HUDPaint", "Hunger", function()
        local Player = LocalPlayer()
        local hunger = Player:getDarkRPVar("Energy")
        draw.SimpleText(hunger, "HUD", 10 + 150, 100, Color(255, 0, 0), 1, 1)
    end)
     
    As for the default DarkRP hud appearing, I do believe there is an option to disable it in the config file or the cl_hudreplacement.lua
     
    Last edited: Jan 9, 2018
    RFK_2018 likes this.
  3. RFK_2018

    RFK_2018 New Member

    Yeah, nothing's wrong with the Wiki. Player isn't being defined.
    "The server does not know who, or what "Player" Is."

    Also, I'm assuming you copy pasted from the Wiki without changing "Player." That is the worst way to get into coding.
    Go look up some Lua tutorials before you start copy/pasting code. At least that way, you'll know what you're doing.
     
  4. Trackster

    Trackster Member


    Thx, but ive been watching videos from thecodingbeast and Code Blue and they are REALLY helpfull. It was code blues recommendation to use gmod wiki, so thats what i did. ..actually, i used darkrp wiki for this one variable. Which didnt worked..but it worked with Sit Klutchs Answer
    --- Double Post Merged, Jan 11, 2018 ---

    thx for that. I changed it for armor, health, money and salary as well even tho i didnt had to. it worked great with my way. Just not with hunger but now it does
     
  5. RFK_2018

    RFK_2018 New Member

    That's most likely why, because it looks like you're copy pasting. The code won't work just by copy/pasting it in. You NEED To LEARN how to setup variables, and call Entities properly.
    The HUD does NOT know what "Player" is. Player is not automatically defined on the HUD/Client, just LocalPlayer() is.

    You setup your script wrong, there's nothing wrong with the wiki.
     
    Last edited: Jan 12, 2018
  6. Trackster

    Trackster Member


    Yea dude..i got it...i started lua like 1 week ago or 2...
     
    Sir Klutch likes this.
  7. Sir Klutch

    Sir Klutch Active Member

    Client. The client does not know what Player is.*
     

Share This Page