TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
MySQL.ready(function()
MySQL.Async.fetchAll('SELECT * FROM m3_taco', {}, function(result)
if result[1].gang ~= nil then
currentgang = result[1].gang
end
end)
end)
RegisterCommand('taco', function(source, args)
if IsPlayerAceAllowed(source, 'm3admin.revive') or IsPlayerAceAllowed(source, 'm3admin.fullperm') then --if xPlayer.getGroup() == 'admin' then
if args[1] == nil or args[1] == '' then return end
for k, v in pairs(gangs) do
if v == args[1] then
MySQL.Async.execute('UPDATE m3_taco SET gang = @gang', {['@gang'] = args[1]}, function(result)
if result then
currentgang = args[1]
local players = GetPlayers()
for i, player in pairs(players) do
TriggerClientEvent('m3:taco:client:setCurrentGang', player, currentgang)
end
end
end)
return
end
end
end
end)
ESX.RegisterServerCallback('m3:taco:server:getCurrentGang', function(source, cb)
cb(currentgang)
end)
ESX.RegisterServerCallback('m3:taco:server:checkItem', function(source, cb, itemname)
local xPlayer = ESX.GetPlayerFromId(source)
cb(xPlayer.getInventoryItem(itemname).count)
end)
RegisterServerEvent('m3:taco:server:addTacoPackage')
AddEventHandler('m3:taco:server:addTacoPackage', function()
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.removeInventoryItem('cola', 1)
xPlayer.removeInventoryItem('taco', 1)
xPlayer.addInventoryItem('tacobag', 1)
end)
RegisterServerEvent('m3:taco:server:addDrink')
AddEventHandler('m3:taco:server:addDrink', function()
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.addInventoryItem('cola', 1)
end)
RegisterServerEvent('m3:taco:server:addTaco')
AddEventHandler('m3:taco:server:addTaco', function()
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.removeInventoryItem('tacomeat', 1)
xPlayer.addInventoryItem('taco', 1)
end)
RegisterServerEvent('m3:taco:server:sell')
AddEventHandler('m3:taco:server:sell', function()
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
local taco = xPlayer.getInventoryItem('tacobag').count
local weed = xPlayer.getInventoryItem('weed').count
if taco > 0 then
xPlayer.removeInventoryItem('tacobag', 1)
xPlayer.addMoney(cfg.tacoprice)
TriggerClientEvent('mythic_notify:client:SendAlert', src, { type = 'inform', text = 'Taco satışından '..cfg.tacoprice..'$ kazandın.'})
dclog(xPlayer, '1x taco sattı. Kazanç: ' ..cfg.tacoprice..'$')
if weed > cfg.minweed then
xPlayer.removeInventoryItem('weed', cfg.minweed)
xPlayer.addMoney(cfg.weedprice * cfg.minweed)
TriggerClientEvent('mythic_notify:client:SendAlert', src, { type = 'inform', text = 'El altından '..cfg.minweed..'x esrar sattın. Kazancın: ' ..cfg.weedprice * cfg.minweed..'$ karapara'})
dclog(xPlayer, 'El altından '..cfg.minweed..'x esrar sattı: Kazanç: '..cfg.weedprice * cfg.minweed..'$')
else
TriggerClientEvent('mythic_notify:client:SendAlert', src, { type = 'error', text = 'Müşterinin istediği kadar esrar üzerinde yok!'})
end
else
TriggerClientEvent('mythic_notify:client:SendAlert', src, { type = 'error', text = 'Üzerinde hiç taco yok!'})
end
end)
function dclog(xPlayer, text)
local playerName = Sanitize(xPlayer.getName())
local discord_webhook = tacos.DiscordWebhook
if discord_webhook == '' then
return
end
local headers = {
['Content-Type'] = 'application/json'
}
local data = {
["username"] = tacos.WebhookName,
["avatar_url"] = tacos.WebhookAvatarUrl,
["embeds"] = {{
["author"] = {
["name"] = playerName .. ' - ' .. xPlayer.identifier
},
["color"] = 1942002,
["timestamp"] = os.date("!%Y-%m-%dT%H:%M:%SZ")
}}
}
data['embeds'][1]['description'] = text
PerformHttpRequest(discord_webhook, function(err, text, headers) end, 'POST', json.encode(data), headers)
end
function Sanitize(str)
local replacements = {
['&' ] = '&',
['<' ] = '<',
['>' ] = '>',
['\n'] = '<br/>'
}
return str
:gsub('[&<>\n]', replacements)
:gsub(' +', function(s)
return ' '..(' '):rep(#s-1)
end)
end