mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 18:28:52 +00:00
Fixed having more than you can carry, closes #9
- Translation improvements with formatting - General improvements
This commit is contained in:
+8
-15
@@ -23,38 +23,31 @@ AddEventHandler('onClientMapStart', function()
|
||||
end)
|
||||
|
||||
function OpenShopMenu(zone)
|
||||
|
||||
local elements = {}
|
||||
|
||||
for i=1, #Config.Zones[zone].Items, 1 do
|
||||
|
||||
|
||||
local item = Config.Zones[zone].Items[i]
|
||||
|
||||
table.insert(elements, {
|
||||
label = item.label .. ' - <span style="color:green;">$' .. item.price .. ' </span>',
|
||||
label = item.label .. ' - <span style="color: green;">' .. item.price .. '$</span>',
|
||||
realLabel = item.label,
|
||||
value = item.name,
|
||||
price = item.price
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
|
||||
ESX.UI.Menu.CloseAll()
|
||||
|
||||
ESX.UI.Menu.Open(
|
||||
'default', GetCurrentResourceName(), 'shop',
|
||||
{
|
||||
title = _U('shop'),
|
||||
title = _U('shop'),
|
||||
align = 'bottom-right',
|
||||
elements = elements
|
||||
},
|
||||
function(data, menu)
|
||||
TriggerServerEvent('esx_shop:buyItem', data.current.value, data.current.price)
|
||||
end,
|
||||
function(data, menu)
|
||||
|
||||
menu.close()
|
||||
|
||||
CurrentAction = 'shop_menu'
|
||||
CurrentActionMsg = _U('press_menu')
|
||||
CurrentActionData = {zone = zone}
|
||||
@@ -97,7 +90,7 @@ end)
|
||||
-- Display markers
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Wait(0)
|
||||
Citizen.Wait(10)
|
||||
local coords = GetEntityCoords(GetPlayerPed(-1))
|
||||
for k,v in pairs(Config.Zones) do
|
||||
for i = 1, #v.Pos, 1 do
|
||||
@@ -112,7 +105,7 @@ end)
|
||||
-- Enter / Exit marker events
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Wait(0)
|
||||
Citizen.Wait(10)
|
||||
local coords = GetEntityCoords(GetPlayerPed(-1))
|
||||
local isInMarker = false
|
||||
local currentZone = nil
|
||||
@@ -141,7 +134,7 @@ end)
|
||||
-- Key Controls
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(0)
|
||||
Citizen.Wait(10)
|
||||
if CurrentAction ~= nil then
|
||||
|
||||
SetTextComponentFormat('STRING')
|
||||
@@ -160,4 +153,4 @@ Citizen.CreateThread(function()
|
||||
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
||||
+1
-1
@@ -4,7 +4,7 @@ Config.DrawDistance = 100
|
||||
Config.Size = {x = 1.5, y = 1.5, z = 1.5}
|
||||
Config.Color = {r = 0, g = 128, b = 255}
|
||||
Config.Type = 1
|
||||
Config.Locale = 'fr'
|
||||
Config.Locale = 'en'
|
||||
|
||||
Config.Zones = {
|
||||
|
||||
|
||||
+5
-6
@@ -1,9 +1,8 @@
|
||||
Locales['en'] = {
|
||||
|
||||
['shop'] = 'shop',
|
||||
['shops'] = 'shops',
|
||||
['press_menu'] = 'press ~INPUT_CONTEXT~ to access the store.',
|
||||
['bought'] = 'you bought ~b~1x ',
|
||||
['not_enough'] = 'you do not ~r~have enough~s~ money.'
|
||||
|
||||
}
|
||||
['press_menu'] = 'press ~INPUT_CONTEXT~ to access the ~y~store~s~.',
|
||||
['bought'] = 'you just bought ~y~1x~s~ ~b~%s~s~ for ~r~$%s~s~',
|
||||
['not_enough'] = 'you do not have ~r~enough~s~ money, you\'re ~y~missing~s~ ~r~$%s~s~!',
|
||||
['player_cannot_hold'] = 'you do ~r~not~s~ have enough ~y~free space~s~ in your inventory!',
|
||||
}
|
||||
+18
-18
@@ -12,7 +12,7 @@ AddEventHandler('onMySQLReady', function()
|
||||
|
||||
for i=1, #result, 1 do
|
||||
ItemsLabels[result[i].name] = result[i].label
|
||||
end--
|
||||
end
|
||||
|
||||
end
|
||||
)
|
||||
@@ -25,25 +25,19 @@ ESX.RegisterServerCallback('esx_shop:requestDBItems', function(source, cb)
|
||||
'SELECT * FROM shops',
|
||||
{},
|
||||
function(result)
|
||||
|
||||
local shopItems = {}
|
||||
|
||||
for i=1, #result, 1 do
|
||||
|
||||
if shopItems[result[i].name] == nil then
|
||||
shopItems[result[i].name] = {}
|
||||
end
|
||||
|
||||
|
||||
table.insert(shopItems[result[i].name], {
|
||||
name = result[i].item,
|
||||
price = result[i].price,
|
||||
label = ItemsLabels[result[i].item]
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
cb(shopItems)
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
@@ -53,17 +47,23 @@ RegisterServerEvent('esx_shop:buyItem')
|
||||
AddEventHandler('esx_shop:buyItem', function(itemName, price)
|
||||
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
if xPlayer.get('money') >= price then
|
||||
|
||||
xPlayer.removeMoney(price)
|
||||
xPlayer.addInventoryItem(itemName, 1)
|
||||
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('bought') .. ItemsLabels[itemName])
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
local sourceItem = xPlayer.getInventoryItem(itemName)
|
||||
|
||||
-- can the player afford this item?
|
||||
if xPlayer.getMoney() >= price then
|
||||
|
||||
-- can the player carry the said amount of x item?
|
||||
if sourceItem.limit ~= -1 and (sourceItem.count + 1) > sourceItem.limit then
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('player_cannot_hold'))
|
||||
else
|
||||
xPlayer.removeMoney(price)
|
||||
xPlayer.addInventoryItem(itemName, 1)
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('bought', ItemsLabels[itemName], price))
|
||||
end
|
||||
else
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('not_enough'))
|
||||
local missingMoney = price - xPlayer.getMoney()
|
||||
TriggerClientEvent('esx:showNotification', _source, _U('not_enough', missingMoney))
|
||||
end
|
||||
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user