forked from qbcore-framework/qb-vineyard
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.lua
70 lines (65 loc) · 2.94 KB
/
server.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
local QBCore = exports['qb-core']:GetCoreObject()
RegisterNetEvent('qb-vineyard:server:getGrapes', function()
local Player = QBCore.Functions.GetPlayer(source)
local amount = math.random(Config.GrapeAmount.min, Config.GrapeAmount.max)
Player.Functions.AddItem("grape", amount)
TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['grape'], "add")
end)
QBCore.Functions.CreateCallback('qb-vineyard:server:loadIngredients', function(source, cb)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local grape = Player.Functions.GetItemByName('grapejuice')
if Player.PlayerData.items ~= nil then
if grape ~= nil then
if grape.amount >= 23 then
Player.Functions.RemoveItem("grapejuice", 23, false)
TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['grapejuice'], "remove")
cb(true)
else
TriggerClientEvent('QBCore:Notify', source, Lang:t("error.invalid_items"), 'error')
cb(false)
end
else
TriggerClientEvent('QBCore:Notify', source, Lang:t("error.invalid_items"), 'error')
cb(false)
end
else
TriggerClientEvent('QBCore:Notify', source, Lang:t("error.no_items"), "error")
cb(false)
end
end)
QBCore.Functions.CreateCallback('qb-vineyard:server:grapeJuice', function(source, cb)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local grape = Player.Functions.GetItemByName('grape')
if Player.PlayerData.items ~= nil then
if grape ~= nil then
if grape.amount >= 16 then
Player.Functions.RemoveItem("grape", 16, false)
TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['grape'], "remove")
cb(true)
else
TriggerClientEvent('QBCore:Notify', source, Lang:t("error.invalid_items"), 'error')
cb(false)
end
else
TriggerClientEvent('QBCore:Notify', source, Lang:t("error.invalid_items"), 'error')
cb(false)
end
else
TriggerClientEvent('QBCore:Notify', source, Lang:t("error.no_items"), "error")
cb(false)
end
end)
RegisterNetEvent('qb-vineyard:server:receiveWine', function()
local Player = QBCore.Functions.GetPlayer(tonumber(source))
local amount = math.random(Config.WineAmount.min, Config.WineAmount.max)
Player.Functions.AddItem("wine", amount, false)
TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['wine'], "add")
end)
RegisterNetEvent('qb-vineyard:server:receiveGrapeJuice', function()
local Player = QBCore.Functions.GetPlayer(tonumber(source))
local amount = math.random(Config.GrapeJuiceAmount.min, Config.GrapeJuiceAmount.max)
Player.Functions.AddItem("grapejuice", amount, false)
TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items['grapejuice'], "add")
end)