Skip to content

Commit

Permalink
Fix stack = false items not removing
Browse files Browse the repository at this point in the history
server/main.lua
server/version.lua
config.lua
fxmanifest.lua
  • Loading branch information
IamLation committed Apr 27, 2024
1 parent 9bb10a3 commit 7eb2433
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
3 changes: 2 additions & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Config = {} -- Do not alter
-- 🔎 Looking for more high quality scripts?
-- 🛒 Shop Now: https://lationscripts.com/github
-- 💬 Join Discord: https://discord.gg/9EbY4nM5uu
Config.YouFoundTheBestScripts = true
-- 😢 How dare you leave this option false?!
Config.YouFoundTheBestScripts = false

-- Use only if needed, directed by support or know what you're doing
-- Notice: enabling debug features will significantly increase resmon
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lua54 'yes'

name 'lation_pawnshop'
author 'iamlation'
version '1.0.0'
version '1.0.1'
description 'A Pawn Shop script for ESX, QBCore & QBox using ox_inventory'

server_scripts {
Expand Down
26 changes: 26 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-- Initialize table to store inventories for hook filter
local inventories = {}

-- Initialize variable to track removal status of non-stackable items
local waiting = false

-- Function used to make numbers prettier (Credits to ESX for the function)
--- @param value number
local GroupDigits = function(value)
Expand All @@ -26,6 +29,25 @@ for shopId, data in pairs(Config.Shops) do
inventories[#inventories + 1] = shopId
end

-- Thread to handle removal of non-stackable items
-- A pretty hacky solution, but works nevertheless
--- @param source number
--- @param item string
--- @param count number
local AwaitRemoval = function(source, item, count)
local source = source
local wait = 5 -- Increase this number slightly if items failing to remove
while waiting do
Wait(0)
wait = wait - 1
if wait <= 0 then
exports.ox_inventory:RemoveItem(source, item, count)
waiting = false
break
end
end
end

-- Used to handle all movements and final transaction in inventory
--- @param payload table
local BeginTransaction = function(payload)
Expand Down Expand Up @@ -84,6 +106,10 @@ local BeginTransaction = function(payload)
Strings.Logs.colors.green
)
end
if not payload.stack then
waiting = true
CreateThread(function() AwaitRemoval(source, payload.fromSlot.name, payload.count) end)
end
return true
end
end
Expand Down
16 changes: 16 additions & 0 deletions server/version.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ local CheckVersion = function()
end)
end

-- Print a message
local PrintMessage = function()
SetTimeout(1500, function()
print('^1['..resourceName..'] ^2YOU DID IT! You set YouFoundTheBestScripts to true!^0')
print('^1['..resourceName..'] ^2Lation officially loves you, and as a thank you wants to give you a gift..^0')
print('^1['..resourceName..'] ^2Enjoy a secret 20% OFF any script of your choice on lationscripts.com/gift^0')
print('^1['..resourceName..'] ^2Using the coupon code: SECRETGIFT (one-time use coupon, choose wisely)^0')
print('^1['..resourceName..'] ^2There is only 1 catch.. do not spoil it for others! If you want to share^0')
print('^1['..resourceName..'] ^2This special moment feel free to do so, but without spoiling the details!^0')
end)
end

if Config.VersionCheck then
CheckVersion()
end

if Config.YouFoundTheBestScripts then
PrintMessage()
end

0 comments on commit 7eb2433

Please sign in to comment.