[Release] Hunger/Thirst HUD V0.3.3 (Added inventory and food shops)

The demand for a script like this is raising up so I decided to release it without the source at the moment because I am not done with it. I want to add the animation in the script. You can call the animation when you trigger the event but I will add this feature in the future!

Feature list

  • HUD of the Hunger and the Thirst of the player.
  • Add Hunger or Thirst (Can’t go higher than 100%)
  • Possibility to die if you are starving. (Can be turned off in the config)
  • Walking, running multiplier (Can be modified in the config)
  • GlobalMultiplier, easier to config the time needed before reaching 0.

As I am not releasing the Source Code yet. Here is a VirusTotal

Download link : Here

Include inventory (useItem) and food shops. Don’t forget the Readme.
Github for externals resources : Here

Changelog

2017-05-20 V0.3.1
Release a modified version of frfuel to prevent it from crashing on client start. (Main link)
Fixed (Trying to) the DataReader mysql error causing by gb_foodshops (github)
Moved changedlog on github.

2017-05-20 V0.3.2
HOTFIX Huge bug causing to update the quantity to 1 after each use. Get the new version. vdkinv.lua updated.

2017-05-20 V0.3.3
HOTFIX Modified FrFuel Blip creation function. I was getting errors from it. The incompatibility seems fixed.
I decided to put both in the same resource when you download it. You can seperate if you need to.


Preview of the HUD. With FrFuel activated. As you can see, I used FrFuel as a base.


Installation process
Unzip the folder in your resources
Add foodhud to your AutoStartResources citmp-server.yml


Config explanation
HungerFactor and ThirstFactor are the value OnTick that will decreased the bar of the player. If you find that the Thirst/Hunger is going down enough you can multiply these by 1.5, 2, etc. Keep them in this format.

The formula is : HungerFactor * Running/WalkingMultiplier * GlobalMultiplier
GlobalMultiplier is 1.5. And can be modified in the config. It’s easier to change this than the Hunger/ThirstFactor. Customize it according to your needs


Here is the 4 TriggerClientEvent that you can use.

Used with a Lua table, 
for example with vdk_inventory you can send the whole item that you have created
item = {name="Bottle of Water", id=1, price=5, value=20}
TriggerEvent("food:eat", item)

             EventHandlers["food:eat"] += new Action<dynamic>((dynamic res) =>
             {
                 FoodLevel = FoodLevel + res.value >= 100 ? FoodLevel = 100 : FoodLevel += res.value;
             });

             EventHandlers["food:drink"] += new Action<dynamic>((dynamic res) =>
             {
                 WaterLevel = WaterLevel + res.value >= 100 ? WaterLevel = 100 : WaterLevel += res.value;
             });
Used with a int value,
For example you just want to send a value to be added to Hunger/Thirst of the player.
20
TriggerEvent("food:veat", 20)

             EventHandlers["food:veat"] += new Action<int>((int val) =>
             {
                 FoodLevel = FoodLevel + val >= 100 ? FoodLevel = 100 : FoodLevel += val;
             });

             EventHandlers["food:vdrink"] += new Action<int>((int val) =>
             {
                 WaterLevel = WaterLevel + val >= 100 ? WaterLevel = 100 : WaterLevel += val;
             });

This one is not playing the animation

Used with a int value,
For example you just want to send a value to be added to Hunger AND Thirst of the player 
20
TriggerEvent("food:death", 20)

            EventHandlers["food:death"] += new Action<int>((int val) =>
            {
                WaterLevel = WaterLevel + val >= 100 ? WaterLevel = 100 : WaterLevel += val;
                FoodLevel = FoodLevel + val >= 100 ? FoodLevel = 100 : FoodLevel += val;
            });

If you would like to contribute to this project, I will add it to github soon.
Keep in mind that I used FrFuel as a base for my script because I wanted to have the same HUD to keep it clean and I wanted to have a compatibility aspect with his resource.

Special mention for the creator of FrFuel, RiderSx, I kept his name in the assembly info.

If you have any question with FiveM Scripting, you can join me on the official Discord.
I have many more resources to share, but they are not “User friendly” at the moment.
All feedback is welcome. Take care and have fun!

*As many of you guys are requesting a “Sample Store, Inventory, UseItem Script” I will try to work on this and it will be something that will give you an idea of what you can do with this script. I’m also working on a Fishing Job at the moment.


Known Issues
If you have this kind of error
Be sure that everything is configured! That the database has the two fields type and value

24 Likes

Nice - Looking forward to test later :slight_smile:

1 Like

Hope to see more. Can’t wait until the source is released.

1 Like

Nice man, I can help in need even if I am very busy with my project

Not very familiar with dll’s, can you explain how we can use/install this?

Sure I will edit the post. But it’s the same as a Lua script!

it’s compatible with vdk_inventory ?

Yes I am using a modified version of vdk_inventory and it’s working fine!

You can send a exemple for me to implant a item to recup Thirst and Hungry :slight_smile: ?

hey can u share with me please I have vdk_inventory working

How to use this resource :

Add Drink :

TriggerEvent("food:vdrink", 20)
OR
TriggerEvent("food:drink", item)

Add Eat :

TriggerEvent("food:veat", 20)
OR
TriggerEvent("food:eat", item)

You can run from the server and the client

Come from the creator @Draziak :slight_smile:

1 Like

Like this ?

item = {name="Bottle of Water", id=1, value=20}

        EventHandlers["food:eat"] += new Action<dynamic>((dynamic res) =>
        {
            FoodLevel = FoodLevel + res.value >= 100 ? FoodLevel = 100 : FoodLevel += res.value;
        });

        EventHandlers["food:drink"] += new Action<dynamic>((dynamic res) =>
        {
            WaterLevel = WaterLevel + res.value >= 100 ? WaterLevel = 100 : WaterLevel += res.value;
        });

and after i put this ?

TriggerEvent("food:drink", Bottle of Water)

?

It is necessary to transmit the array, after the script will retrieve the “value” field of the array

item = {name="Bottle of Water", id=1, value=20}

Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
      if (IsControlJustPressed(1,38)) then
        TriggerEvent("food:vdrink", 20)
        TriggerEvent("food:drink", item)
      end
  end
end)

You can choose either one or the other

You can choose which way you want between the 4. The item array or a single value!

Hi just one thing good job for your work i have just one question when the player disconnect from the server and reconnect the thirst and hunger come back to 100% or it’s save ?

Come back to 100%. The data is not saving in the database. You could easily! implement that in your server

Ok thanks for fast answer :smiley:

Hello and thank you good job!

help me please :slight_smile:

-- flag to keep track of whether player died to prevent
-- multiple runs of player dead code
local playerdead = false
local maxCapacity = 64

-- register events, only needs to be done once
RegisterNetEvent("item:reset")
RegisterNetEvent("item:getItems")
RegisterNetEvent("item:updateQuantity")
RegisterNetEvent("item:setItem")
RegisterNetEvent("item:sell")
RegisterNetEvent("gui:getItems")

-- handles when a player spawns either from joining or after death
AddEventHandler("playerSpawned", function()
    TriggerServerEvent("item:getItems")
	TriggerServerEvent("food:eat", item)
	TriggerServerEvent("food:drink", item)
    -- reset player dead flag
    playerdead = false
end)

AddEventHandlers["food:eat"] += new Action<dynamic>((dynamic res) =>
             {
                 FoodLevel = FoodLevel + res.value >= 100 ? FoodLevel = 100 : FoodLevel += res.value;
             });
end)

AddEventHandlers["food:drink"] += new Action<dynamic>((dynamic res) =>
             {
                 WaterLevel = WaterLevel + res.value >= 100 ? WaterLevel = 100 : WaterLevel += res.value;
             });
end)

AddEventHandlers["food:veat"] += new Action<int>((int val) =>
             {
                 FoodLevel = FoodLevel + val >= 100 ? FoodLevel = 100 : FoodLevel += val;
             });
end)

AddEventHandlers["food:vdrink"] += new Action<int>((int val) =>
             {
                 WaterLevel = WaterLevel + val >= 100 ? WaterLevel = 100 : WaterLevel += val;
             });
end)

AddEventHandler("gui:getItems", function(THEITEMS)
    ITEMS = {}
    ITEMS = THEITEMS
end)

AddEventHandler("player:receiveItem", function(item, quantity)
    item = tonumber(item)
    if (ITEMS[item] == nil) then
        new(item, quantity)
    else
        add({ item, quantity })
    end
end)

AddEventHandler("player:looseItem", function(item, quantity)
    item = tonumber(item)
    if (ITEMS[item].quantity >= quantity) then
        delete({ item, quantity })
    end
end)

AddEventHandler("player:sellItem", function(item, price)
    item = tonumber(item)
    if (ITEMS[item].quantity > 0) then
        sell({ item, price })
    end
end)

function sell(arg)
    local itemId = tonumber(arg[1])
    local price = arg[2]
    local item = ITEMS[itemId]
    item.quantity = item.quantity - 1
    TriggerServerEvent("item:sell", itemId, item.quantity, price)
    InventoryMenu()
end

function delete(arg)
    local itemId = tonumber(arg[1])
    local qty = arg[2]
    local item = ITEMS[itemId]
    item.quantity = item.quantity - qty
    TriggerServerEvent("item:updateQuantity", item.quantity, itemId)
    InventoryMenu()
end

function add(arg)
    local itemId = tonumber(arg[1])
    local qty = arg[2]
    local item = ITEMS[itemId]
    item.quantity = item.quantity + qty
    TriggerServerEvent("item:updateQuantity", item.quantity, itemId)
    InventoryMenu()
end

function new(item, quantity)
    TriggerServerEvent("item:setItem", item, quantity)
    TriggerServerEvent("item:getItems")
end

function getQuantity(itemId)
    return ITEMS[tonumber(itemId)].quantity
end

function notFull()
    local pods = 0
    for _, v in pairs(ITEMS) do
        pods = pods + v.quantity
    end
    if (pods < maxCapacity) then return true end
end

function InventoryMenu()
    ped = GetPlayerPed(-1);
    MenuTitle = "Items:"
    ClearMenu()
    for ind, value in pairs(ITEMS) do
        if (value.quantity > 0) then
            Menu.addButton(tostring(value.libelle) .. " : " .. tostring(value.quantity), "ItemMenu", ind)
        end
    end
end

function ItemMenu(itemId)
    MenuTitle = "Details:"
    ClearMenu()
    Menu.addButton("Supprimer 1", "delete", { itemId, 1 })
    Menu.addButton("Ajouter 1", "add", { itemId, 1 })
end

Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
      if (IsControlJustPressed(1,38)) then
        TriggerEvent("food:vdrink", 21)
        TriggerEvent("food:drink", item)
      end
  end
end)

Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
      if (IsControlJustPressed(1,38)) then
        TriggerEvent("food:veat", 14)
        TriggerEvent("food:deat", item)
      end
  end
end)

Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
      if (IsControlJustPressed(1,38)) then
        TriggerEvent("food:veat", 23)
        TriggerEvent("food:deat", item)
      end
  end
end)

Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
      if (IsControlJustPressed(1,38)) then
        TriggerEvent("food:veat", 13)
        TriggerEvent("food:deat", item)
      end
  end
end)

Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
      if (IsControlJustPressed(1,38)) then
        TriggerEvent("food:veat", 20)
        TriggerEvent("food:deat", item)
      end
  end
end)

Citizen.CreateThread(function()
  while true do
    Citizen.Wait(0)
      if (IsControlJustPressed(1,38)) then
        TriggerEvent("food:veat", 25)
        TriggerEvent("food:deat", item)
      end
  end
end)

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        if IsControlJustPressed(1, 311) then
            InventoryMenu() -- Menu to draw
            Menu.hidden = not Menu.hidden -- Hide/Show the menu
        end
        Menu.renderGUI() -- Draw menu on each tick if Menu.hidden = false
        if IsEntityDead(PlayerPedId()) then
            PlayerIsDead()
            -- prevent the death check from overloading the server
            playerdead = true
        end
    end
end)

function PlayerIsDead()
    -- do not run if already ran
    if playerdead then
        return
    end
    TriggerServerEvent("item:reset")
end

1 Like

You don’t need to do this!
You can just call this on your client

TriggerEvent("food:vdrink", 20)

And you will gain 20% of your Thirst bar!

ok thank you i go test !