-
Notifications
You must be signed in to change notification settings - Fork 1
/
shop.lua
203 lines (179 loc) Β· 6.35 KB
/
shop.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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
local QBCore = exports['qb-core']:GetCoreObject()
-- Helper function to load animation dictionary
local function loadAnimDict(dict)
RequestAnimDict(dict)
while not HasAnimDictLoaded(dict) do
Wait(5)
end
end
-- Helper function to load model
local function loadModel(model)
RequestModel(GetHashKey(model))
while not HasModelLoaded(GetHashKey(model)) do
Wait(5)
end
end
-- Create Dancers
CreateThread(function()
Wait(1000) -- Wait a bit to ensure everything is loaded
for _, dancer in ipairs(Config.Dancers) do
loadModel(dancer.model)
-- Get ground Z coordinate
local groundZ = 0
local ground, z = GetGroundZFor_3dCoord(dancer.coords.x, dancer.coords.y, dancer.coords.z, false)
if ground then
groundZ = z
else
groundZ = dancer.coords.z
end
local ped = CreatePed(4, GetHashKey(dancer.model),
dancer.coords.x,
dancer.coords.y,
groundZ,
dancer.coords.w,
false, true)
FreezeEntityPosition(ped, true)
SetEntityInvincible(ped, true)
SetBlockingOfNonTemporaryEvents(ped, true)
loadAnimDict(dancer.animation.dict)
TaskPlayAnim(ped, dancer.animation.dict, dancer.animation.name, 8.0, -8.0, -1, 1, 0, false, false, false)
end
end)
-- Create Budtender with Joint
CreateThread(function()
Wait(1000) -- Wait a bit to ensure everything is loaded
loadModel(Config.Budtender.model)
-- Get ground Z coordinate
local groundZ = 0
local ground, z = GetGroundZFor_3dCoord(Config.Budtender.coords.x, Config.Budtender.coords.y, Config.Budtender.coords.z, false)
if ground then
groundZ = z
else
groundZ = Config.Budtender.coords.z
end
local budtender = CreatePed(4, GetHashKey(Config.Budtender.model),
Config.Budtender.coords.x,
Config.Budtender.coords.y,
groundZ,
Config.Budtender.coords.w,
false, true)
FreezeEntityPosition(budtender, true)
SetEntityInvincible(budtender, true)
SetBlockingOfNonTemporaryEvents(budtender, true)
-- Load and play smoking animation
loadAnimDict(Config.Budtender.animation.dict)
TaskPlayAnim(budtender,
Config.Budtender.animation.dict,
Config.Budtender.animation.name,
8.0, -8.0, -1, 1, 0, false, false, false)
-- Attach joint prop
local jointProp = CreateObject(GetHashKey(Config.Budtender.prop.model), 0.0, 0.0, 0.0, true, true, true)
AttachEntityToEntity(jointProp, budtender,
GetPedBoneIndex(budtender, Config.Budtender.prop.bone),
Config.Budtender.prop.offset.x, Config.Budtender.prop.offset.y, Config.Budtender.prop.offset.z,
Config.Budtender.prop.rotation.x, Config.Budtender.prop.rotation.y, Config.Budtender.prop.rotation.z,
false, false, false, false, 2, true)
-- Add shop interaction
exports.ox_target:addLocalEntity(budtender, {
{
name = 'casino_shop',
icon = 'fas fa-shopping-cart',
label = 'Open Shop',
onSelect = function()
OpenShopMenu()
end
}
})
end)
-- Create Props
CreateThread(function()
for _, prop in ipairs(Config.Props) do
local propObject = CreateObject(GetHashKey(prop.model),
prop.coords.x,
prop.coords.y,
prop.coords.z,
true, false, false)
SetEntityHeading(propObject, prop.coords.w)
FreezeEntityPosition(propObject, true)
end
end)
-- Shop Menu with enhanced UI
function OpenShopMenu()
local options = {}
for _, item in ipairs(Config.ShopItems) do
table.insert(options, {
title = string.format('π·οΈ %s', item.label),
description = item.description,
icon = item.icon,
iconColor = GetItemColor(item.name),
metadata = {
{label = 'π° Price', value = string.format('$%d', item.price)},
{label = 'π¦ Item', value = item.name},
{label = 'π Description', value = item.description}
},
onSelect = function()
PurchaseConfirmation(item)
end
})
end
lib.registerContext({
id = 'casino_shop_menu',
title = 'π° Temp\'s Casino Shop',
options = options,
menu = 'casino_main_menu'
})
lib.showContext('casino_shop_menu')
end
-- Helper function to get color based on item type
function GetItemColor(itemName)
local colors = {
joint = '#00FF00', -- Green for cannabis
tosti = '#FFA500', -- Orange for food
dry_pscioblyn = '#9370DB', -- Purple for mushrooms
xtcbaggy = '#FF69B4', -- Pink for pills
whiskey = '#8B4513' -- Brown for whiskey
}
return colors[itemName] or '#FFFFFF'
end
-- Purchase confirmation dialog
function PurchaseConfirmation(item)
lib.registerContext({
id = 'purchase_confirmation',
title = 'π Confirm Purchase',
menu = 'casino_shop_menu',
options = {
{
title = string.format('Buy %s', item.label),
description = string.format('Confirm purchase for $%d?', item.price),
icon = item.icon,
iconColor = GetItemColor(item.name),
metadata = {
{label = 'π° Price', value = string.format('$%d', item.price)},
{label = 'π Description', value = item.description}
},
onSelect = function()
BuyItem(item)
end
},
{
title = 'β©οΈ Back to Shop',
description = 'Return to shop menu',
icon = 'fas fa-arrow-left',
onSelect = function()
OpenShopMenu()
end
}
}
})
lib.showContext('purchase_confirmation')
end
-- Buy Item Function
function BuyItem(item)
QBCore.Functions.TriggerCallback('casino:server:checkMoney', function(hasMoney)
if hasMoney then
TriggerServerEvent('casino:server:buyItem', item.name, item.price)
else
QBCore.Functions.Notify('Not enough money!', 'error')
end
end, item.price)
end