Skip to content

Commit d7f87c1

Browse files
committed
add extra checks to server event for tradeitems
1 parent b7a70f6 commit d7f87c1

File tree

1 file changed

+50
-32
lines changed

1 file changed

+50
-32
lines changed

server/server.lua

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
1-
onResourceStart(function()
2-
Wait(100)
3-
for k in pairs(Config.Other.Prices.Items) do
4-
if not Items[k] then
5-
print("^5Debug^7: ^6Prices^7: ^2Missing Item from ^5Shared Items^7: '^6"..k.."^7'")
6-
end
7-
end
8-
if not Items["recyclablematerial"] then
9-
print("^5Debug^7: ^2Missing Item from ^5Shared Items^7: '^6recyclablematerial^7'")
10-
end
11-
end, true)
12-
13-
RegisterServerEvent("jim-recycle:Server:DoorCharge", function()
14-
local src = source
15-
chargePlayer(Config.RecyclingCenter.PayAtDoor, "cash", src)
16-
end)
17-
18-
RegisterServerEvent("jim-recycle:Server:TradeItems", function(data)
19-
local src = source
20-
local table = {}
21-
for i = 1, #Config.Other.RecycleAmounts["Trade"] do
22-
if Config.Other.RecycleAmounts["Trade"][i].amount == data.amount then
23-
table = Config.Other.RecycleAmounts["Trade"][i]
24-
break
25-
end
26-
end
27-
removeItem("recyclablematerial", data.amount, src)
28-
Wait(1000)
29-
for i = 1, table.itemGive do
30-
addItem(data.item, math.random(table.Min, table.Max), nil, src)
31-
Wait(100)
32-
end
1+
onResourceStart(function()
2+
Wait(100)
3+
for k in pairs(Config.Other.Prices.Items) do
4+
if not Items[k] then
5+
print("^5Debug^7: ^6Prices^7: ^2Missing Item from ^5Shared Items^7: '^6"..k.."^7'")
6+
end
7+
end
8+
if not Items["recyclablematerial"] then
9+
print("^5Debug^7: ^2Missing Item from ^5Shared Items^7: '^6recyclablematerial^7'")
10+
end
11+
12+
end, true)
13+
14+
RegisterServerEvent("jim-recycle:Server:DoorCharge", function()
15+
local src = source
16+
chargePlayer(Config.RecyclingCenter.PayAtDoor, "cash", src)
17+
end)
18+
19+
20+
RegisterServerEvent("jim-recycle:Server:TradeItems", function(data)
21+
local src = source
22+
23+
local tradeInfo
24+
for _, v in pairs(Config.Other.RecycleAmounts["Trade"]) do
25+
if v.amount == data.amount then
26+
tradeInfo = v
27+
break
28+
end
29+
end
30+
31+
if not tradeInfo then
32+
print("TradeInfo not found for amount: "..tostring(data.amount))
33+
return
34+
end
35+
36+
local hasAll, _ = hasItem("recyclablematerial", data.amount, src)
37+
38+
if hasAll then
39+
removeItem("recyclablematerial", data.amount, src)
40+
41+
Wait(500)
42+
43+
for i = 1, tradeInfo.itemGive do
44+
local count = math.random(tradeInfo.Min, tradeInfo.Max)
45+
addItem(data.item, count, nil, src)
46+
Wait(100)
47+
end
48+
else
49+
triggerNotify(nil, "Not Enough Items", "error", src)
50+
end
3351
end)

0 commit comments

Comments
 (0)