-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
175 lines (162 loc) · 6.35 KB
/
client.lua
File metadata and controls
175 lines (162 loc) · 6.35 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
ESX = nil
local isMenuOpen = false
local originalText = "~w~Press E to interact with the black market"
local menuLines = {
"Hi gangsta,",
"Select your weapon with ammo.",
"Bro don't get shot this time oke?"
}
local menuTextDisplayed = false
local menuTextStartTime = 0
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
-- Load NPC model and create NPCs
Citizen.CreateThread(function()
RequestModel('a_m_m_business_01')
while not HasModelLoaded('a_m_m_business_01') do
Citizen.Wait(500)
end
for _, npc in ipairs(Config.NPCs) do
local ped = CreatePed(4, 'a_m_m_business_01', npc.coords, npc.heading, false, true)
SetEntityAsMissionEntity(ped, true, true)
SetPedCanRagdoll(ped, false)
SetPedCanRagdollFromPlayerImpact(ped, false)
SetBlockingOfNonTemporaryEvents(ped, true)
TaskSetBlockingOfNonTemporaryEvents(ped, true)
FreezeEntityPosition(ped, true)
-- Create a text label above the NPC's head
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local playerPed = PlayerPedId()
local npcCoords = GetEntityCoords(ped)
local playerCoords = GetEntityCoords(playerPed)
local npcHeight = npcCoords.z + 1.0
if not isMenuOpen then
if Vdist(playerCoords, npcCoords) < 2.0 then
-- Animate text
local time = GetGameTimer()
local offset = math.sin(time / 500) * 0.05 -- Animation effect
DrawText3D(npcCoords.x, npcCoords.y, npcHeight + offset, originalText)
end
else
if menuTextDisplayed then
if Vdist(playerCoords, npcCoords) < 2.0 then
-- Display typing text
local time = GetGameTimer()
local elapsed = (time - menuTextStartTime) / 1000 -- Elapsed time in seconds
local currentLineIndex = math.floor(elapsed / 2) + 1 -- Show new line every 2 seconds
local textToDisplay = menuLines[currentLineIndex] or ""
DrawText3D(npcCoords.x, npcCoords.y, npcHeight, textToDisplay)
end
end
end
end
end)
end
end)
-- Show 3D text function with multi-line support
function DrawText3D(x, y, z, text)
local onScreen, _x, _y = World3dToScreen2d(x, y, z)
local px, py, pz = table.unpack(GetGameplayCamCoords())
local distance = Vdist(px, py, pz, x, y, z)
local scale = (1 / distance) * 2
local fov = (1 / GetGameplayCamFov()) * 100
local scale = scale * fov
if onScreen then
SetTextScale(0.0, scale * 0.3) -- Smaller text size
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215) -- White color
SetTextEntry("STRING")
-- Draw the current line
SetTextEntry("STRING")
AddTextComponentString(text)
DrawText(_x, _y)
end
end
-- Open menu and manage interaction
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
for _, npc in ipairs(Config.NPCs) do
local npcCoords = npc.coords
if Vdist(coords, npcCoords) < 2.0 and not isMenuOpen then
if IsControlJustReleased(0, 38) then -- E key
isMenuOpen = true
menuTextDisplayed = false -- Start typing effect
TriggerEvent('showMenuText') -- Show new text after 2 seconds
OpenBlackMarketMenu()
end
end
end
end
end)
function OpenBlackMarketMenu()
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'black_market_menu',
{
title = 'Black Market',
align = 'top-left',
elements = GetMenuElements()
},
function(data, menu)
local item = data.current
if item.value then
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'black_market_confirm',
{
title = ('Buy %s for $%d'):format(item.label, item.price),
align = 'top-left',
elements = {
{ label = 'Cash', value = 'cash' },
{ label = 'Bank', value = 'bank' },
{ label = 'Black Money', value = 'black_money' }
}
},
function(confirmData, confirmMenu)
if confirmData.current.value then
TriggerServerEvent('codex-blackmarket:buyItem', item.value, 1, confirmData.current.value)
end
confirmMenu.close()
isMenuOpen = false
menuTextDisplayed = false -- Restore the original text
end,
function(data, menu)
menu.close()
isMenuOpen = false
menuTextDisplayed = false -- Restore the original text
end
)
end
end,
function(data, menu)
menu.close()
isMenuOpen = false
menuTextDisplayed = false -- Restore the original text
end
)
end
-- Trigger event to show menu text after a delay
AddEventHandler('showMenuText', function()
Citizen.Wait(2000) -- Wait for 2 seconds
menuTextDisplayed = true
menuTextStartTime = GetGameTimer() -- Start typing effect timer
end)
function GetMenuElements()
local elements = {}
for _, item in ipairs(Config.Items) do
table.insert(elements, {
label = item.label,
value = item.name,
price = item.price
})
end
return elements
end