-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathvorpInventoryApi.lua
More file actions
172 lines (141 loc) · 5.1 KB
/
Copy pathvorpInventoryApi.lua
File metadata and controls
172 lines (141 loc) · 5.1 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
163
164
165
166
167
168
169
170
171
172
exports('vorp_inventoryApi',function()
local self = {}
self.subWeapon = function(source,weaponid)
TriggerEvent("vorpCore:subWeapon",source,tonumber(weaponid))
end
self.createWeapon = function(source,weaponName,ammoaux,compaux)
TriggerEvent("vorpCore:registerWeapon",source,tostring(string.upper(weaponName)),ammoaux,compaux)
end
self.giveWeapon = function(source,weaponid,target)
TriggerEvent("vorpCore:giveWeapon",source,weaponid,target)
end
self.addItem = function(source,itemName,cuantity)
TriggerEvent("vorpCore:addItem",source,tostring(itemName),tonumber(cuantity))
end
self.subItem = function(source,itemName,cuantity)
TriggerEvent("vorpCore:subItem",source,tostring(itemName),tonumber(cuantity))
end
self.getItem = function(source, itemName)
local item
TriggerEvent("vorpCore:getItem", source, tostring(itemName), function(responseItem)
item = responseItem
end)
return item
end
self.getItemCount = function(source,item)
local count = 0
TriggerEvent("vorpCore:getItemCount",source,function(itemcount)
count = itemcount
end,tostring(item))
return count
end
self.getDBItem = function(source, itemName)
local item
local done = false
exports.ghmattimysql:execute( "SELECT * FROM items WHERE item=@id;", {['@id'] = itemName},
function(result)
-- Add check for if the item exists.
if result[1] then
item = result[1]
else
print('Item does not exist in Items table. Item: '..itemName)
end
done = true
end)
-- Wait for the call to finish (aka makes this task more syncronous)
while done == false do
Wait(500)
end
return item
end
self.addBullets = function(source,weaponId,type,cuantity)
TriggerEvent("vorpCore:addBullets",source,weaponId,type,cuantity)
end
self.subBullets = function(source,weaponId,type,cuantity)
TriggerEvent("vorpCore:subBullets",source,weaponId,type,cuantity)
end
self.getWeaponBullets = function(source,weaponId)
local bull
TriggerEvent("vorpCore:getWeaponBullets",source,function(bullets)
bull = bullets
end,weaponId)
return bull
end
self.getWeaponComponents = function(source,weaponId)
local comp
TriggerEvent("vorpCore:getWeaponComponents",source,function(components)
comp = components
end,weaponId)
return comp
end
self.getUserWeapons = function(source)
local weapList
TriggerEvent("vorpCore:getUserWeapons",source,function(weapons)
weapList = weapons
end)
return weapList
end
self.canCarryItems = function(source, amount)
local can
TriggerEvent("vorpCore:canCarryItems",source,amount,function(data)
can = data
end)
return can
end
self.canCarryItem = function(source, item, amount)
local can = false
local done = false
-- Limit is a restricted field in sql. Query for it directly gives an error.
exports.ghmattimysql:execute( "SELECT * FROM items WHERE item=@id;", {['@id'] = item},
function(result)
-- Add check for if the item exists.
local itemcount = self.getItemCount(source, item)
local reqCount = itemcount + amount
if result[1] then
local limit = tonumber(result[1].limit)
if reqCount <= limit then
can = true
else
can = false
end
else
-- Object does not exist in inventory, it can not be added
print('Item does not exist in Items table. Item: '..item)
can = false
end
done = true
end)
-- Wait for the call to finish (aka makes this task more syncronous)
while done == false do
Wait(500)
end
return can
end
self.getUserWeapon = function(source,weaponId)
local weap
TriggerEvent("vorpCore:getUserWeapon",source,function(weapon)
weap = weapon
end,weaponId)
return weap
end
self.RegisterUsableItem = function(itemName,cb)
TriggerEvent("vorpCore:registerUsableItem",itemName,cb)
end
self.getUserInventory = function(source)
local inv
TriggerEvent("vorpCore:getUserInventory", source, function(invent)
inv = invent
end)
return inv
end
self.canCarryWeapons = function(source, amount, cb)
TriggerEvent("vorpCore:canCarryWeapons", source, amount, cb)
end
self.CloseInv = function(source)
TriggerClientEvent("vorp_inventory:CloseInv",source)
end
self.OpenInv = function(source)
TriggerClientEvent("vorp_inventory:OpenInv",source)
end
return self
end)