-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.lua
119 lines (103 loc) · 3.42 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
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
Inventory = exports.vorp_inventory:vorp_inventoryApi()
local VorpCore = {}
TriggerEvent("getCore",function(core)
VorpCore = core
end)
data = {}
TriggerEvent("vorp_inventory:getData",function(call)
data = call
end)
RegisterServerEvent("scf_drugs:reward1")
AddEventHandler("scf_drugs:reward1", function()
local _source = source
local User = VorpCore.getUser(_source)
local Character = User.getUsedCharacter
Inventory.subItem(_source, "cannabis", 5)
Inventory.addItem(_source, "cannabis_pack", 1)
end)
RegisterServerEvent("scf_drugs:reward2")
AddEventHandler("scf_drugs:reward2", function()
local _source = source
local User = VorpCore.getUser(_source)
local Character = User.getUsedCharacter
Inventory.subItem(_source, "cocain", 5)
Inventory.addItem(_source, "cocain_pack", 1)
end)
RegisterServerEvent('scf_drugs:pack1')
AddEventHandler('scf_drugs:pack1', function()
local _source = source
local User = VorpCore.getUser(_source)
local Character = User.getUsedCharacter
local count = Inventory.getItemCount(_source, "cannabis")
if count >= 5 then
TriggerClientEvent("scf_drugs:progress1", _source)
else
TriggerClientEvent("vorp:Tip", _source, 'Not enough resources', 5000)
end
end)
RegisterServerEvent('scf_drugs:pack2')
AddEventHandler('scf_drugs:pack2', function()
local _source = source
local User = VorpCore.getUser(_source)
local Character = User.getUsedCharacter
local count = Inventory.getItemCount(_source, "cocain")
if count >= 5 then
TriggerClientEvent("scf_drugs:progress2", _source)
else
TriggerClientEvent("vorp:Tip", _source, 'Not enough resources', 5000)
end
end)
-- Sale
local DrugItems = {
cocain_pack = {
name = 'cocain_pack',
displayName = 'Cocain pack',
priceMin = 3,
priceMax = 5,
},
cannabis_pack = {
name = 'cannabis_pack',
displayName = 'Cannabis Pack',
priceMin = 3,
priceMax = 5,
}
}
DoPlayerHaveItems = function(player)
local item = false
for k, v in pairs(DrugItems) do
local itemName = v.name
local _source = source
local User = VorpCore.getUser(_source)
local Character = User.getUsedCharacter
local itemInformation = Inventory.getItemCount(_source,itemName)
if itemInformation > 0 then
item = v
break
end
end
return item, item ~= false
end
RegisterServerEvent('scf_drugs:sale')
AddEventHandler('scf_drugs:sale',function()
local _source = source
local User = VorpCore.getUser(_source)
local Character = User.getUsedCharacter
local item, hasItem = DoPlayerHaveItems(_source)
if hasItem then
local count = Inventory.getItemCount(_source,item.name)
local randomPayment = math.random(item.priceMin, item.priceMax)
local randomCount = math.random(1,3)
local amount = 0
if count <= randomCount then
amount = count
else
amount = randomCount
end
Inventory.subItem(_source, item.name, amount)
local price = randomPayment * amount
TriggerEvent("vorp:addMoney", _source, 0,price)
TriggerClientEvent("vorp:Tip", _source, 'You sold '..amount..'x '..item.displayName..' for $'..price, 5000)
else
TriggerClientEvent("vorp:Tip", _source, 'You dont have drugs', 5000)
end
end)