-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.lua
78 lines (64 loc) · 2.17 KB
/
server.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
local QBCore = exports['qb-core']:GetCoreObject()
local hydration = Config.hydrationValue or 10
local excessive_drink = Config.excessiveDrinkCount or 3
local Players = {}
-- get player data
local function localGetPlayer(src)
return QBCore.Functions.GetPlayer(src)
end
-- Function to kill player
local function KillPlayer(src)
local player = localGetPlayer(src)
-- kill player logic here
end
local function notify(src, message, messageType)
TriggerClientEvent('QBCore:Notify', src, message, messageType)
end
-- Function to handle excessive drinking
local function handleExcessiveDrinking(src)
local currentTime = os.time()
if not Players[src] then
Players[src] = { count = 1, lastDrinkTime = currentTime }
else
Players[src].count = Players[src].count + 1
Players[src].lastDrinkTime = currentTime
end
local drinksInPastMinute = 0
for _, playerData in pairs(Players) do
if currentTime - playerData.lastDrinkTime <= 60 then
drinksInPastMinute = drinksInPastMinute + playerData.count
end
end
if drinksInPastMinute > excessive_drink then
KillPlayer(src)
else
notify(src, "You're drinking excessive watter!", 'error')
end
end
local function updateClientHUD(src, hunger, thirst)
TriggerClientEvent('hud:client:UpdateNeeds', src, hunger, thirst)
end
-- set player's thirst metadata
local function setThirst(src, player, newThirst)
player.Functions.SetMetaData('thirst', newThirst)
notify(src, "You feel refreshed", 'success')
end
-- handle drinking
local function drink(src)
local player = localGetPlayer(src)
if not player then return end
local currentThirst = player.PlayerData.metadata['thirst']
if currentThirst < 100 then
local newThirst = currentThirst + hydration
if newThirst > 100 then newThirst = 100 end
setThirst(src, player, newThirst)
updateClientHUD(src, player.PlayerData.metadata.hunger, newThirst)
elseif currentThirst >= 100 then
handleExcessiveDrinking(src)
end
end
-- Register drink event
RegisterNetEvent('keep-watercooler:server:drink', function()
local src = source
drink(src)
end)