here is a tutorial that I resolved, a small thank you does not hurt.
link :
Github no modified
esx_foodtruck\config.lua
Config = {}
Config.DrawDistance = 100.0
Config.Locale = 'fr'
local seconde = 1000
local minute = 60 * seconde
Config.Fridge = {
meat = 300,
packaged_chicken = 100,
bread = 200,
water = 100,
rivella = 100,
vegetables = 100
} -- maxquantity
Config.Recipes = {
tacos = {
Ingredients = {
bread = { "Pain" , 1 },
meat = { "Viande" , 2 },
vegetables = { "LĂ©gumes" , 1 }
},
Price = 100,
CookingTime = 30 * seconde,
Item = 'tacos',
Name = 'Tacos'
},
burger = {
Ingredients = {
bread = { "Pain" , 1 },
packaged_chicken = { "Poulet" , 1 },
vegetables = { "LĂ©gumes" , 1 }
},
Price = 100,
CookingTime = 15 * seconde,
Item = 'burger',
Name = 'Burger'
}
}
Config.Zones = {
Actions = {
Pos = {x = 189.525, y = -1445.308, z = 28.1416},
Size = {x = 1.5, y = 1.5, z = 0.4},
Color = {r = 102, g = 102, b = 204},
Type = 1
},
VehicleSpawnPoint = {
Pos = {x = 193.417, y = -1456.56, z = 28.1416},
Size = {x = 3.0, y = 3.0, z = 0.4},
Type = -1
},
VehicleDeleter = {
Pos = {x = 185.189, y = -1439.23, z = 28.1602},
Size = {x = 3.0, y = 3.0, z = 0.4},
Color = {r = 255, g = 0, b = 0},
Type = 1
},
Market = {
Pos = {x = -2511.07, y = 3615.16, z = 12.6714},
Size = {x = 1.5, y = 1.5, z = 0.4},
Color = {r = 0, g = 255, b = 0},
Type = 1
}
}
esx_foodtruck\server\main.lua
ESX = nil
PlayersHarvesting = {}
MarketPrices = {}
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
TriggerEvent('esx_phone:registerNumber', 'foodtruck', 'Client FoodTruck', false, false)
if Config.MaxInService ~= -1 then
TriggerEvent('esx_service:activateService', 'foodtruck', Config.MaxInService)
end
AddEventHandler('onMySQLReady', function ()
MySQL.Async.fetchAll("SELECT * FROM `shopsMarket` WHERE `name` = 'Market'",
{},
function(result)
MySQL.Async.fetchAll("SELECT * FROM `items`",
{},
function(result2)
for i=1, #result2, 1 do
for j=1, #result, 1 do
if result[j].item == result2[i].name then
table.insert(MarketPrices, {label = result2[i].label, item = result[j].item, price = result[j].price})
break
end
end
end
end
)
end
)
end)
ESX.RegisterServerCallback('esx_foodtruck:getStock', function(source, cb)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local fridge = {}
for k,v in pairs(Config.Fridge) do
for i=1, #xPlayer.inventory, 1 do
if xPlayer.inventory[i].name == k then
table.insert(fridge, xPlayer.inventory[i])
break
end
end
end
cb(fridge, MarketPrices)
end)
RegisterServerEvent('esx_foodtruck:buyItem')
AddEventHandler('esx_foodtruck:buyItem', function(qtty, item)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
for i=1, #MarketPrices, 1 do
if item == MarketPrices[i].item then
if qtty == -1 then -- ready for when I add the 'buy max' option
local delta = max - stock
local total = MarketPrices[i].price * delta
if xPlayer.getMoney() > total then
xPlayer.addInventoryItem(item, delta)
xPlayer.removeMoney(total)
TriggerClientEvent('esx:showNotification', _source, _U('purchased'))
else
TriggerClientEvent('esx:showNotification', _source, _U('no_money'))
end
else
local total = MarketPrices[i].price * qtty
if xPlayer.getMoney() > total then
xPlayer.addInventoryItem(item, qtty)
xPlayer.removeMoney(total)
TriggerClientEvent('esx:showNotification', _source, _U('purchased'))
else
TriggerClientEvent('esx:showNotification', _source, _U('no_money'))
end
end
break
end
end
TriggerClientEvent('esx_foodtruck:refreshMarket', _source)
end)
RegisterServerEvent('esx_foodtruck:removeItem')
AddEventHandler('esx_foodtruck:removeItem', function(item, count)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
xPlayer.removeInventoryItem(item, count)
end)
RegisterServerEvent('esx_foodtruck:addItem')
AddEventHandler('esx_foodtruck:addItem', function(item, count)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
xPlayer.addInventoryItem(item, count)
end)
---------------------------- register usable item --------------------------------------------------
ESX.RegisterUsableItem('rivella', function(source)
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.removeInventoryItem('rivella', 1)
TriggerClientEvent('esx_status:add', source, 'thirst', 300000)
TriggerClientEvent('esx_basicneeds:onDrink', source, 'prop_ecola_can')
TriggerClientEvent('esx:showNotification', source, _U('drank_rivella'))
end)
ESX.RegisterUsableItem('burger', function(source)
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.removeInventoryItem('burger', 1)
TriggerClientEvent('esx_status:add', source, 'hunger', 300000)
TriggerClientEvent('esx_basicneeds:onEat', source, 'prop_cs_burger_01')
TriggerClientEvent('esx:showNotification', source, _U('eat_burger'))
end)
ESX.RegisterUsableItem('tacos', function(source)
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.removeInventoryItem('tacos', 1)
TriggerClientEvent('esx_status:add', source, 'hunger', 300000)
TriggerClientEvent('esx_basicneeds:onEat', source, 'prop_taco_01')
TriggerClientEvent('esx:showNotification', source, _U('eat_taco'))
end)
SQL for ddb
SET @job_name = 'foodtruck';
SET @society_name = 'society_foodtruck';
SET @job_Name_Caps = 'Foodtruck';
INSERT INTO `addon_account` (name, label, shared) VALUES
(@society_name, @job_Name_Caps, 1)
;
INSERT INTO `jobs` (name, label, whitelisted) VALUES
(@job_name, @job_Name_Caps, 1)
;
INSERT INTO `job_grades` (job_name, grade, name, label, salary, skin_male, skin_female) VALUES
(@job_name, 0, 'cook', 'Cuisinier', 200, '{}', '{}'),
(@job_name, 1, 'boss', 'Patron', 300, '{}', '{}')
;
INSERT INTO `items` (`name`, `label`, `limit`) VALUES
('rivella', 'Rivella', 20),
('vegetables', 'LĂ©gume', 20),
('meat', 'Viande', 20),
('tacos', 'Tacos', 20),
('packaged_chicken', 'Chiken', 20),
--('bread', 'Pain', 20),
('burger', 'Burger', 20)
;
DROP TABLE IF EXISTS `shopsmarket`;
CREATE TABLE IF NOT EXISTS `shopsmarket` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`item` varchar(100) NOT NULL,
`price` int(11) NOT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=187 DEFAULT CHARSET=latin1;
INSERT INTO `shopsmarket` (`id`, `name`, `item`, `price`) VALUES
(1, 'Market', 'rivella', 30),
(2, 'Market', 'vegetables', 30),
(3, 'Market', 'meat', 30),
(4, 'Market', 'packaged_chicken', 30),
(5, 'Market', 'bread', 30);
;
esx_basicneeds\server\main.lua
add oder replace
ESX.RegisterUsableItem('bread', function(source)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
xPlayer.removeInventoryItem('bread', 1)
TriggerClientEvent('esx_status:add', source, 'hunger', 300000)
TriggerClientEvent('esx_basicneeds:onEat', source)
TriggerClientEvent('esx:showNotification', source, _U('used_bread'))
end)
ESX.RegisterUsableItem('tacos', function(source)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
xPlayer.removeInventoryItem('tacos', 1)
TriggerClientEvent('esx_status:add', source, 'hunger', 300000)
TriggerClientEvent('esx_basicneeds:onEat', source)
TriggerClientEvent('esx:showNotification', source, _U('used_tacos'))
end)
ESX.RegisterUsableItem('burger', function(source)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
xPlayer.removeInventoryItem('burger', 1)
TriggerClientEvent('esx_status:add', source, 'hunger', 300000)
TriggerClientEvent('esx_basicneeds:onEat', source)
TriggerClientEvent('esx:showNotification', source, _U('used_burger'))
end)
ESX.RegisterUsableItem('rivella', function(source)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
xPlayer.removeInventoryItem('rivella', 1)
TriggerClientEvent('esx_status:add', source, 'thirst', 300000)
TriggerClientEvent('esx_basicneeds:onDrink', source)
TriggerClientEvent('esx:showNotification', source, _U('used_rivella'))
end)