forked from Infinity-Core/infinity_stores
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
39 lines (37 loc) · 2.44 KB
/
Copy pathserver.lua
File metadata and controls
39 lines (37 loc) · 2.44 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
function roundValue(number, decimals)
local power = 10^decimals
return math.floor(number * power) / power
end
RegisterNetEvent("infinity_stores:buy")
AddEventHandler("infinity_stores:buy", function(_InfinitySource, itemdb, price, quantity, PlayerDatas)
local SourceSteamID, result = exports.infinity_core:GetPlayerSource(_InfinitySource)
local playerCash = tonumber(PlayerDatas and PlayerDatas._Cash) or 0
local priceNum = tonumber(price) or 0
local quantityNum = tonumber(quantity) or 0
if playerCash >= priceNum then
exports.infinity_core:RemoveCash(_InfinitySource, priceNum)
exports.infinity_needs:AddInventoryItem(_InfinitySource, itemdb, quantityNum, PlayerDatas and PlayerDatas._Inventory or {}, false)
exports.infinity_core:notification(_InfinitySource, "Item Buy", '<b class="text-danger">- '..roundValue(priceNum, 2)..'$</b>', 'center_right', 'infinitycore', 3000)
else
exports.infinity_core:notification(_InfinitySource,'<div class="text-danger">No Money</div>', '<small style="font-size:18px;">You dont have enough money</small>', 'center_right', 'infinitycore', 2500)
end
end)
RegisterNetEvent("infinity_stores:sell")
AddEventHandler("infinity_stores:sell", function(_InfinitySource, itemdb, price, quantity, Xp)
local SourceSteamID = exports.infinity_core:GetPlayerSource(_InfinitySource)
if SourceSteamID then
local PlayerDatas = exports.infinity_core:GetPlayerSession(tonumber(_InfinitySource))
local InventoryQT = exports.infinity_needs:CheckPlayerInventory(_InfinitySource, itemdb)
local quantityNum = tonumber(quantity) or 0
local priceNum = tonumber(price) or 0
local XP_Given = tonumber(Xp) or 0
if InventoryQT ~= nil and tonumber(InventoryQT) > 0 then
exports.infinity_core:AddXP(_InfinitySource, XP_Given)
exports.infinity_core:notification(_InfinitySource, "<b class='text-success'>Item Sell</b>", '<b class="text-light">+ '..roundValue(priceNum, 2)..'$ <br> +'..XP_Given..'XP</b>', 'center_right', 'redm_min', 2500)
exports.infinity_core:AddCash(_InfinitySource, priceNum)
exports.infinity_needs:RemoveInventoryItem(_InfinitySource, itemdb, quantityNum, PlayerDatas and PlayerDatas._Inventory or {}, false)
else
exports.infinity_core:notification(_InfinitySource, "<b class='text-danger'>ERROR</b>", 'You dont have this item', 'center_right', 'redm_min', 2500)
end
end
end)