-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
78 lines (65 loc) · 3.21 KB
/
client.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 function PlayPillAnimation(gender, duration)
local animDict = "mp_suicide"
local animName = "pill" -- Use the same animation for both genders
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
Citizen.Wait(10)
end
TaskPlayAnim(PlayerPedId(), animDict, animName, 8.0, -8.0, duration, 1, 0, false, false, false)
end
-- Determine character's gender
local function GetPlayerGender()
local model = GetEntityModel(PlayerPedId())
if model == GetHashKey("mp_f_freemode_01") then
return "female"
elseif model == GetHashKey("mp_m_freemode_01") then
return "male"
else
return "unknown" -- For custom models or if unable to determine
end
end
RegisterNetEvent('consume:pill', function(pillType)
local playerPed = PlayerPedId()
local gender = GetPlayerGender()
PlayPillAnimation(gender, 5000) -- Duration parameter adjusted to match the progress bar
QBCore.Functions.Progressbar("taking_pill", "Taking Pill...", 5000, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {}, {}, {}, function()
ClearPedTasks(playerPed) -- Ensure the animation is stopped after the progress bar completes
local overdoseChance = math.random(1, 100) -- Random chance for overdose
local overdosed = overdoseChance <= 10 -- 10% chance to overdose
-- Check for overdose
if overdosed then
QBCore.Functions.Notify("You've overdosed!", "error")
SetEntityHealth(playerPed, 0)
return
end
QBCore.Functions.Notify("You start feeling relaxed.", "primary", 5000)
-- Initial screen effect upon successful pill consumption
StartScreenEffect("DrugsTrevorClownsFight", 120000, true)
-- Heal over time logic with screen effect on each cycle
local endTime = GetGameTimer() + (20 * 60000) -- 20 minutes in milliseconds
Citizen.CreateThread(function()
while GetGameTimer() < endTime and GetEntityHealth(playerPed) > 0 do
Citizen.Wait(300000) -- Wait 5 minutes
local maxHealth = GetEntityMaxHealth(playerPed)
local healAmount = math.random(8, 16) / 100 * maxHealth -- 8-16% of max health
local newHealth = math.min(GetEntityHealth(playerPed) + healAmount, maxHealth)
SetEntityHealth(playerPed, newHealth)
QBCore.Functions.Notify("You're feeling better.", "primary", 5000)
-- Re-trigger the screen effect for each health regeneration cycle
StartScreenEffect("DrugsTrevorClownsFight", 120000, false)
end
-- Once the 20 minutes have passed, stop the screen effect to return to normal
StopScreenEffect("DrugsTrevorClownsFight")
QBCore.Functions.Notify("The effects have worn off.", "primary", 5000)
end)
end, function() -- Cancelled
QBCore.Functions.Notify("Cancelled..", "error")
ClearPedTasks(playerPed)
end)
end)