Skip to content

Commit

Permalink
convert: esx_basicneeds > bpt_basicneeds
Browse files Browse the repository at this point in the history
- convert esx_basicneeds > bpt_basicneeds
-
  • Loading branch information
bitpredator committed Jun 10, 2024
1 parent 15b9ff8 commit b525611
Show file tree
Hide file tree
Showing 27 changed files with 225 additions and 201 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Expand Down Expand Up @@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

esx_basicneeds
Copyright (C) 2015-2022 Jérémie N'gadi
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 2024 bitpredator

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -645,14 +645,14 @@ the "copyright" line and a pointer to where the full notice is found.
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

esx_basicneeds Copyright (C) 2015-2022 Jérémie N'gadi
<program> Copyright (C) 2024 bitpredator
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand All @@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.

The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.
19 changes: 19 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_basicneeds/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<h1 align='center'>bpt_basicneeds</a></h1>
<p align='center'><a href='https://discord.gg/ksGfNvDEfq'>Discord</a>

Copyright (C) 2024 bitpredator

This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version.

This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details.

ATTENTION:
You are not authorized to change the name of the resource and the resources within it.

If you want to contribute you can open a pull request.

You are not authorized to sell this software (this is free project).

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
INSERT INTO `items` (`name`, `label`, `weight`) VALUES
('bread', 'Bread', 1),
('water', 'Water', 1)
;
132 changes: 132 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_basicneeds/client/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
local IsDead = false
local IsAnimated = false

AddEventHandler("bpt_basicneeds:resetStatus", function()
TriggerEvent("bpt_status:set", "hunger", 500000)
TriggerEvent("bpt_status:set", "thirst", 500000)
end)

RegisterNetEvent("bpt_basicneeds:healPlayer")
AddEventHandler("bpt_basicneeds:healPlayer", function()
-- restore hunger & thirst
TriggerEvent("bpt_status:set", "hunger", 1000000)
TriggerEvent("bpt_status:set", "thirst", 1000000)

-- restore hp
local playerPed = PlayerPedId()
SetEntityHealth(playerPed, GetEntityMaxHealth(playerPed))
end)

AddEventHandler("esx:onPlayerDeath", function()
IsDead = true
end)

AddEventHandler("esx:onPlayerSpawn", function(spawn)
if IsDead then
TriggerEvent("bpt_basicneeds:resetStatus")
end

IsDead = false
end)

AddEventHandler("bpt_status:loaded", function(status)
TriggerEvent("bpt_status:registerStatus", "hunger", 1000000, "#CFAD0F", function(status)
return Config.Visible
end, function(status)
status.remove(100)
end)

TriggerEvent("bpt_status:registerStatus", "thirst", 1000000, "#0C98F1", function(status)
return Config.Visible
end, function(status)
status.remove(75)
end)
end)

AddEventHandler("bpt_status:onTick", function(data)
local playerPed = PlayerPedId()
local prevHealth = GetEntityHealth(playerPed)
local health = prevHealth

for k, v in pairs(data) do
if v.name == "hunger" and v.percent == 0 then
if prevHealth <= 150 then
health = health - 5
else
health = health - 1
end
elseif v.name == "thirst" and v.percent == 0 then
if prevHealth <= 150 then
health = health - 5
else
health = health - 1
end
end
end

if health ~= prevHealth then
SetEntityHealth(playerPed, health)
end
end)

AddEventHandler("bpt_basicneeds:isEating", function(cb)
cb(IsAnimated)
end)

RegisterNetEvent("bpt_basicneeds:onUse")
AddEventHandler("bpt_basicneeds:onUse", function(type, prop_name, anim)
if not IsAnimated then
local anim = anim
IsAnimated = true
if type == "food" then
prop_name = prop_name or "prop_cs_burger_01"
anim = anim
elseif type == "drink" then
prop_name = prop_name or "prop_ld_flow_bottle"
anim = anim
end

CreateThread(function()
local playerPed = PlayerPedId()
local x, y, z = table.unpack(GetEntityCoords(playerPed))
local prop = CreateObject(joaat(prop_name), x, y, z + 0.2, true, true, true)
local boneIndex = GetPedBoneIndex(playerPed, 18905)
AttachEntityToEntity(prop, playerPed, boneIndex, 0.12, 0.028, 0.001, 10.0, 175.0, 0.0, true, true, false, true, 1, true)

ESX.Streaming.RequestAnimDict(anim.dict, function()
TaskPlayAnim(playerPed, anim.dict, anim.name, anim.settings[1], anim.settings[2], anim.settings[3], anim.settings[4], anim.settings[5], anim.settings[6], anim.settings[7], anim.settings[8])
RemoveAnimDict(anim.dict)

Wait(3000)
IsAnimated = false
ClearPedSecondaryTask(playerPed)
DeleteObject(prop)
end)
end)
end
end)

-- Backwards compatibility
RegisterNetEvent("bpt_basicneeds:onEat")
AddEventHandler("bpt_basicneeds:onEat", function(prop_name)
local Invoke = GetInvokingResource()

print(("[^3WARNING^7] ^5%s^7 used ^5bpt_basicneeds:onEat^7, this method is deprecated and should not be used! Refer to ^5https://bitpredator.github.io/bptdevelopment/docs/FiveM/bpt_basicneeds/events/oneat^7 for more info!"):format(Invoke))

if not prop_name then
prop_name = "prop_cs_burger_01"
end
TriggerEvent("bpt_basicneeds:onUse", "food", prop_name)
end)

RegisterNetEvent("bpt_basicneeds:onDrink")
AddEventHandler("bpt_basicneeds:onDrink", function(prop_name)
local Invoke = GetInvokingResource()

print(("[^3WARNING^7] ^5%s^7 used ^5bpt_basicneeds:onDrink^7, this method is deprecated and should not be used! Refer to ^5https://bitpredator.github.io/bptdevelopment/docs/FiveM/bpt_basicneeds/events/ondrink^7 for more info!"):format(Invoke))

if not prop_name then
prop_name = "prop_ld_flow_bottle"
end
TriggerEvent("bpt_basicneeds:onUse", "drink", prop_name)
end)
21 changes: 21 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_basicneeds/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Config = {}
Config.Locale = GetConvar("esx:locale", "en")
Config.Visible = true

Config.Items = {
["bread"] = {
type = "food",
prop = "prop_cs_burger_01",
status = 200000,
remove = true,
anim = { dict = "mp_player_inteat@burger", name = "mp_player_int_eat_burger_fp", settings = { 8.0, -8, -1, 49, 0, 0, 0, 0 } },
},

["water"] = {
type = "drink",
prop = "prop_ld_flow_bottle",
status = 100000,
remove = true,
anim = { dict = "mp_player_intdrink", name = "loop_bottle", settings = { 1.0, -1.0, 2000, 0, 1, true, true, true } },
},
}
28 changes: 28 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_basicneeds/fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
fx_version("adamant")

game("gta5")

description("Adds a Hunger & Thrist system")
lua54("yes")
version("1.0.1")

shared_script("@es_extended/imports.lua")

server_scripts({
"@es_extended/locale.lua",
"locales/*.lua",
"config.lua",
"server/main.lua",
})

client_scripts({
"@es_extended/locale.lua",
"locales/*.lua",
"config.lua",
"client/main.lua",
})

dependencies({
"es_extended",
"bpt_status",
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Locales["en"] = {
["used_food"] = "You have eaten 1x %s",
["used_drink"] = "You have drinked 1x %s",
["got_healed"] = "You have been healed.",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Locales["it"] = {
["used_bread"] = "hai usato 1x panino",
["used_water"] = "hai usato 1x acqua",
["got_healed"] = "Sei stato curato.",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
INSERT INTO `items` (`name`, `label`, `weight`) VALUES
('bread', 'Pane', 1),
('water', 'Acqua', 1)
;
32 changes: 0 additions & 32 deletions server-data/resources/[esx_addons]/esx_basicneeds/README.md

This file was deleted.

72 changes: 0 additions & 72 deletions server-data/resources/[esx_addons]/esx_basicneeds/client/main.lua

This file was deleted.

3 changes: 0 additions & 3 deletions server-data/resources/[esx_addons]/esx_basicneeds/config.lua

This file was deleted.

Loading

0 comments on commit b525611

Please sign in to comment.