-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
162 lines (149 loc) · 6.43 KB
/
server.lua
File metadata and controls
162 lines (149 loc) · 6.43 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
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
-- Function to capitalize the first letter of a string
function capitalize(str)
if type(str) ~= "string" or str == "" then
return str
end
return str:sub(1, 1):upper() .. str:sub(2):lower()
end
RegisterServerEvent('codex-blackmarket:buyItem')
AddEventHandler('codex-blackmarket:buyItem', function(itemName, quantity, paymentMethod)
local xPlayer = ESX.GetPlayerFromId(source)
local item = nil
for _, v in ipairs(Config.Items) do
if v.name == itemName then
item = v
break
end
end
if item then
local totalPrice = item.price * quantity
local discount = item.discount or 0
local discountedPrice = totalPrice - (totalPrice * discount / 100)
if paymentMethod == 'cash' then
if xPlayer.getMoney() >= discountedPrice then
xPlayer.removeMoney(discountedPrice)
GiveItemToPlayer(xPlayer, itemName, quantity)
TriggerClientEvent('esx:showNotification', source, ('You bought %s x%d for $%d (Discounted)'):format(item.label, quantity, discountedPrice))
SendWebhookNotification(xPlayer.getName(), itemName, quantity, discountedPrice, 'cash')
else
TriggerClientEvent('esx:showNotification', source, 'Not enough cash')
end
elseif paymentMethod == 'bank' then
local bankAccount = xPlayer.getAccount('bank')
if bankAccount and bankAccount.money >= discountedPrice then
xPlayer.removeAccountMoney('bank', discountedPrice)
GiveItemToPlayer(xPlayer, itemName, quantity)
TriggerClientEvent('esx:showNotification', source, ('You bought %s x%d for $%d (Discounted) from your bank account'):format(item.label, quantity, discountedPrice))
SendWebhookNotification(xPlayer.getName(), itemName, quantity, discountedPrice, 'bank')
else
TriggerClientEvent('esx:showNotification', source, 'Not enough money in bank account')
end
elseif paymentMethod == 'black_money' then
local blackMoneyAccount = xPlayer.getAccount('black_money')
if blackMoneyAccount and blackMoneyAccount.money >= discountedPrice then
xPlayer.removeAccountMoney('black_money', discountedPrice)
GiveItemToPlayer(xPlayer, itemName, quantity)
TriggerClientEvent('esx:showNotification', source, ('You bought %s x%d for $%d (Discounted) in black money'):format(item.label, quantity, discountedPrice))
SendWebhookNotification(xPlayer.getName(), itemName, quantity, discountedPrice, 'black_money')
else
TriggerClientEvent('esx:showNotification', source, 'Not enough black money')
end
else
TriggerClientEvent('esx:showNotification', source, 'Invalid payment method')
end
else
TriggerClientEvent('esx:showNotification', source, 'Invalid item')
end
end)
function GiveItemToPlayer(xPlayer, itemName, quantity)
if itemName:find('weapon_') then
xPlayer.addWeapon(itemName, 0) -- No ammo given here; can be customized
else
xPlayer.addInventoryItem(itemName, quantity)
end
end
function SendWebhookNotification(playerName, itemName, quantity, totalPrice, paymentMethod)
local currentTime = os.date('%Y-%m-%d %H:%M:%S') -- Current date and time
local itemLabel = "Unknown Item"
-- Find the label for the item
for _, v in ipairs(Config.Items) do
if v.name == itemName then
itemLabel = v.label
break
end
end
local description = string.format(
'**Transaction Details:**\n' ..
'• **Player:** %s\n' ..
'• **Item Purchased:** %s\n' ..
'• **Quantity:** %d\n' ..
'• **Total Price:** $%d\n' ..
'• **Payment Method:** %s\n' ..
'• **Date/Time:** %s\n' ..
'• **Transaction Status:** %s',
playerName,
itemLabel,
quantity,
totalPrice,
paymentMethod,
currentTime,
totalPrice > 0 and 'Successful' or 'Failed'
)
local data = {
username = 'Black Market Notification',
embeds = {{
title = '🛒 Item Purchase Log',
description = description,
color = 3066993, -- Light Blue color for informational purposes
fields = {
{
name = 'Player Information',
value = string.format(
'**Player Name:** %s\n' ..
'**Transaction Time:** %s',
playerName,
currentTime
),
inline = true
},
{
name = 'Item Details',
value = string.format(
'**Item Name:** %s\n' ..
'**Quantity:** %d\n' ..
'**Total Price:** $%d',
itemLabel,
quantity,
totalPrice
),
inline = true
},
{
name = 'Payment Information',
value = string.format(
'**Payment Method:** %s',
paymentMethod
),
inline = true
}
},
footer = {
text = 'CustomCodex Black Market System',
icon_url = 'https://yourlogo.url/logo.png' -- Optional logo
}
}}
}
-- Print debug information
print("Sending webhook with the following data:")
print(json.encode(data))
-- Perform the HTTP request
PerformHttpRequest(Config.WebhookURL, function(statusCode, responseText, headers)
-- Log the response from the webhook service
print("Webhook response status code:", statusCode)
print("Webhook response body:", responseText)
end, 'POST', json.encode(data), { ['Content-Type'] = 'application/json' })
end
-- Log that the Black Market System has successfully started
print("\27[32mCodex-BlackMarket has successfully started\27[0m")