A lot of minor cleanup

This commit is contained in:
ElPumpo
2018-04-21 22:31:53 +02:00
parent 753be3a95f
commit 6d58d19d79
6 changed files with 232 additions and 242 deletions
View File
+30 -8
View File
@@ -1,16 +1,38 @@
# fxserver-esx_weashops
FXServer ESX Weapon Shops
# esx_weashops
[INSTALLATION]
## Download & Installation
1) CD in your resources/[esx] folder
2) Clone the repository
### Using [fvm](https://github.com/qlaffont/fvm-installer)
```
git clone https://github.com/FXServer-ESX/fxserver-esx_weashops.git esx_weashops
fvm install --save --folder=esx esx-org/esx_weashops
```
3) Import esx_weashops.sql in your database
4) Add this in your server.cfg :
### Using Git
```
cd resources
git clone https://github.com/ESX-Org/esx_weashops.git [esx]/esx_weashops
```
### Manually
- Download https://github.com/ESX-Org/esx_weashops/archive/master.zip
- Put it in the `[esx]` directory
## Installation
- Import `esx_weashops.sql` in your database
- Add this to your `server.cfg`:
```
start esx_weashops
```
# Legal
### License
esx_weashops - Legal or illegal gun shop
Copyright (C) 2015-2018 Jérémie N'gadi
This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version.
This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details.
You should have received a copy Of the GNU General Public License along with this program. If Not, see http://www.gnu.org/licenses/.
+21 -19
View File
@@ -1,26 +1,28 @@
description 'ESX Weashop'
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
version '1.0.1'
description 'ESX Weaponshop'
version '1.0.2'
client_scripts {
'@es_extended/locale.lua',
'locales/de.lua',
'locales/br.lua',
'locales/en.lua',
'locales/fr.lua',
'locales/es.lua',
'config.lua',
'client/main.lua'
'@es_extended/locale.lua',
'locales/de.lua',
'locales/br.lua',
'locales/en.lua',
'locales/fr.lua',
'locales/es.lua',
'config.lua',
'client/main.lua'
}
server_scripts {
'@es_extended/locale.lua',
'locales/de.lua',
'locales/br.lua',
'locales/en.lua',
'locales/fr.lua',
'locales/es.lua',
'@mysql-async/lib/MySQL.lua',
'config.lua',
'server/main.lua'
'@es_extended/locale.lua',
'locales/de.lua',
'locales/br.lua',
'locales/en.lua',
'locales/fr.lua',
'locales/es.lua',
'@mysql-async/lib/MySQL.lua',
'config.lua',
'server/main.lua'
}
+133 -153
View File
@@ -7,198 +7,178 @@ local CurrentActionData = {}
local Licenses = {}
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
RegisterNetEvent('esx_weashop:loadLicenses')
AddEventHandler('esx_weashop:loadLicenses', function (licenses)
for i = 1, #licenses, 1 do
Licenses[licenses[i].type] = true
end
for i = 1, #licenses, 1 do
Licenses[licenses[i].type] = true
end
end)
AddEventHandler('onClientMapStart', function()
ESX.TriggerServerCallback('esx_weashop:requestDBItems', function(ShopItems)
for k,v in pairs(ShopItems) do
Config.Zones[k].Items = v
end
end)
ESX.TriggerServerCallback('esx_weashop:requestDBItems', function(ShopItems)
for k,v in pairs(ShopItems) do
Config.Zones[k].Items = v
end
end)
end)
function OpenBuyLicenseMenu (zone)
ESX.UI.Menu.CloseAll()
function OpenBuyLicenseMenu(zone)
ESX.UI.Menu.CloseAll()
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'shop_license',
{
title = _U('buy_license'),
elements = {
{ label = _U('yes') .. ' ($' .. Config.LicensePrice .. ')', value = 'yes' },
{ label = _U('no'), value = 'no' },
}
},
function (data, menu)
if data.current.value == 'yes' then
TriggerServerEvent('esx_weashop:buyLicense')
end
menu.close()
end,
function (data, menu)
menu.close()
end
)
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop_license',
{
title = _U('buy_license'),
elements = {
{ label = _U('yes') .. ' ($' .. Config.LicensePrice .. ')', value = 'yes' },
{ label = _U('no'), value = 'no' },
}
}, function (data, menu)
if data.current.value == 'yes' then
TriggerServerEvent('esx_weashop:buyLicense')
end
menu.close()
end, function (data, menu)
menu.close()
end
)
end
function OpenShopMenu(zone)
local elements = {}
local elements = {}
for i=1, #Config.Zones[zone].Items, 1 do
local item = Config.Zones[zone].Items[i]
for i=1, #Config.Zones[zone].Items, 1 do
table.insert(elements, {
label = item.label .. ' - <span style="color:green;">$' .. item.price .. ' </span>',
realLabel = item.label,
value = item.name,
price = item.price
})
end
ESX.UI.Menu.CloseAll()
local item = Config.Zones[zone].Items[i]
table.insert(elements, {
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'),
elements = elements
},
function(data, menu)
TriggerServerEvent('esx_weashop:buyItem', data.current.value, data.current.price, zone)
end,
function(data, menu)
menu.close()
CurrentAction = 'shop_menu'
CurrentActionMsg = _U('shop_menu')
CurrentActionData = {zone = zone}
end
)
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop',
{
title = _U('shop'),
elements = elements
}, function(data, menu)
TriggerServerEvent('esx_weashop:buyItem', data.current.value, data.current.price, zone)
end, function(data, menu)
menu.close()
CurrentAction = 'shop_menu'
CurrentActionMsg = _U('shop_menu')
CurrentActionData = {zone = zone}
end
)
end
AddEventHandler('esx_weashop:hasEnteredMarker', function(zone)
CurrentAction = 'shop_menu'
CurrentActionMsg = _U('shop_menu')
CurrentActionData = {zone = zone}
CurrentAction = 'shop_menu'
CurrentActionMsg = _U('shop_menu')
CurrentActionData = {zone = zone}
end)
AddEventHandler('esx_weashop:hasExitedMarker', function(zone)
CurrentAction = nil
ESX.UI.Menu.CloseAll()
AddEventHandler('esx_weashop:hasExitedMarker', function(zone)´
CurrentAction = nil
ESX.UI.Menu.CloseAll()
end)
-- Create Blips
Citizen.CreateThread(function()
for k,v in pairs(Config.Zones) do
if v.legal==0 then
for i = 1, #v.Pos, 1 do
local blip = AddBlipForCoord(v.Pos[i].x, v.Pos[i].y, v.Pos[i].z)
SetBlipSprite (blip, 154)
SetBlipDisplay(blip, 4)
SetBlipScale (blip, 1.0)
SetBlipColour (blip, 2)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(_U('map_blip'))
EndTextCommandSetBlipName(blip)
end
end
end
for k,v in pairs(Config.Zones) do
if v.legal==0 then
for i = 1, #v.Pos, 1 do
local blip = AddBlipForCoord(v.Pos[i].x, v.Pos[i].y, v.Pos[i].z)
SetBlipSprite (blip, 154)
SetBlipDisplay(blip, 4)
SetBlipScale (blip, 1.0)
SetBlipColour (blip, 2)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(_U('map_blip'))
EndTextCommandSetBlipName(blip)
end
end
end
end)
-- Display markers
Citizen.CreateThread(function()
while true do
Wait(0)
local coords = GetEntityCoords(GetPlayerPed(-1))
for k,v in pairs(Config.Zones) do
for i = 1, #v.Pos, 1 do
if(Config.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, true) < Config.DrawDistance) then
DrawMarker(Config.Type, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.Size.x, Config.Size.y, Config.Size.z, Config.Color.r, Config.Color.g, Config.Color.b, 100, false, true, 2, false, false, false, false)
end
end
end
end
while true do
Citizen.Wait(0)
local coords = GetEntityCoords(GetPlayerPed(-1))
for k,v in pairs(Config.Zones) do
for i = 1, #v.Pos, 1 do
if(Config.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, true) < Config.DrawDistance) then
DrawMarker(Config.Type, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.Size.x, Config.Size.y, Config.Size.z, Config.Color.r, Config.Color.g, Config.Color.b, 100, false, true, 2, false, false, false, false)
end
end
end
end
end)
-- Enter / Exit marker events
Citizen.CreateThread(function()
while true do
Wait(0)
local coords = GetEntityCoords(GetPlayerPed(-1))
local isInMarker = false
local currentZone = nil
while true do
Citizen.Wait(0)
local coords = GetEntityCoords(GetPlayerPed(-1))
local isInMarker = false
local currentZone = nil
for k,v in pairs(Config.Zones) do
for i = 1, #v.Pos, 1 do
if(GetDistanceBetweenCoords(coords, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, true) < Config.Size.x) then
isInMarker = true
ShopItems = v.Items
currentZone = k
LastZone = k
end
end
end
if isInMarker and not HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = true
TriggerEvent('esx_weashop:hasEnteredMarker', currentZone)
end
if not isInMarker and HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = false
TriggerEvent('esx_weashop:hasExitedMarker', LastZone)
end
end
for k,v in pairs(Config.Zones) do
for i = 1, #v.Pos, 1 do
if(GetDistanceBetweenCoords(coords, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, true) < Config.Size.x) then
isInMarker = true
ShopItems = v.Items
currentZone = k
LastZone = k
end
end
end
if isInMarker and not HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = true
TriggerEvent('esx_weashop:hasEnteredMarker', currentZone)
end
if not isInMarker and HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = false
TriggerEvent('esx_weashop:hasExitedMarker', LastZone)
end
end
end)
-- Key Controls
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if CurrentAction ~= nil then
while true do
Citizen.Wait(0)
if CurrentAction ~= nil then
SetTextComponentFormat('STRING')
AddTextComponentString(CurrentActionMsg)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
SetTextComponentFormat('STRING')
AddTextComponentString(CurrentActionMsg)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
if IsControlJustReleased(0, 38) then
if IsControlJustReleased(0, 38) then
if CurrentAction == 'shop_menu' then
if Config.EnableLicense == true then
if Licenses['weapon'] ~= nil or Config.Zones[CurrentActionData.zone].legal == 1 then
OpenShopMenu(CurrentActionData.zone)
else
OpenBuyLicenseMenu()
end
else
OpenShopMenu(CurrentActionData.zone)
end
end
CurrentAction = nil
end
end
end
if CurrentAction == 'shop_menu' then
if Config.EnableLicense == true then
if Licenses['weapon'] ~= nil or Config.Zones[CurrentActionData.zone].legal == 1 then
OpenShopMenu(CurrentActionData.zone)
else
OpenBuyLicenseMenu()
end
else
OpenShopMenu(CurrentActionData.zone)
end
end
CurrentAction = nil
end
end
end
end)
+1 -1
View File
@@ -4,7 +4,7 @@ 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.EnableLicense = true
Config.EnableLicense = true -- only turn this on if you are using esx_license
Config.LicensePrice = 5000
Config.Zones = {
+47 -61
View File
@@ -17,79 +17,65 @@ end
RegisterServerEvent('esx_weashop:buyLicense')
AddEventHandler('esx_weashop:buyLicense', function ()
local _source = source
local xPlayer = ESX.GetPlayerFromId(source)
local _source = source
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.get('money') >= Config.LicensePrice then
xPlayer.removeMoney(Config.LicensePrice)
if xPlayer.get('money') >= Config.LicensePrice then
xPlayer.removeMoney(Config.LicensePrice)
TriggerEvent('esx_license:addLicense', _source, 'weapon', function ()
LoadLicenses(_source)
end)
else
TriggerClientEvent('esx:showNotification', _source, _U('not_enough'))
end
TriggerEvent('esx_license:addLicense', _source, 'weapon', function ()
LoadLicenses(_source)
end)
else
TriggerClientEvent('esx:showNotification', _source, _U('not_enough'))
end
end)
ESX.RegisterServerCallback('esx_weashop:requestDBItems', function(source, cb)
MySQL.Async.fetchAll('SELECT * FROM weashops',
{}, function(result)
local shopItems = {}
for i=1, #result, 1 do
MySQL.Async.fetchAll(
'SELECT * FROM weashops',
{},
function(result)
if shopItems[result[i].name] == nil then
shopItems[result[i].name] = {}
end
local shopItems = {}
table.insert(shopItems[result[i].name], {
name = result[i].item,
price = result[i].price,
label = ESX.GetWeaponLabel(result[i].item)
})
for i=1, #result, 1 do
end
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 = ESX.GetWeaponLabel(result[i].item)
})
end
cb(shopItems)
end
)
cb(shopItems)
end
)
end)
RegisterServerEvent('esx_weashop:buyItem')
AddEventHandler('esx_weashop:buyItem', function(itemName, price, zone)
local _source = source
local xPlayer = ESX.GetPlayerFromId(source)
local account = xPlayer.getAccount('black_money')
if zone=="BlackWeashop" then
if account.money >= price then
xPlayer.removeAccountMoney('black_money', price)
xPlayer.addWeapon(itemName, 42)
TriggerClientEvent('esx:showNotification', _source, _U('buy') .. ESX.GetWeaponLabel(itemName))
else
TriggerClientEvent('esx:showNotification', _source, _U('not_enough_black'))
end
else if xPlayer.get('money') >= price then
xPlayer.removeMoney(price)
xPlayer.addWeapon(itemName, 42)
TriggerClientEvent('esx:showNotification', _source, _U('buy') .. ESX.GetWeaponLabel(itemName))
else
TriggerClientEvent('esx:showNotification', _source, _U('not_enough'))
end
end
local _source = source
local xPlayer = ESX.GetPlayerFromId(source)
local account = xPlayer.getAccount('black_money')
if zone=="BlackWeashop" then
if account.money >= price then
xPlayer.removeAccountMoney('black_money', price)
xPlayer.addWeapon(itemName, 42)
TriggerClientEvent('esx:showNotification', _source, _U('buy') .. ESX.GetWeaponLabel(itemName))
else
TriggerClientEvent('esx:showNotification', _source, _U('not_enough_black'))
end
else
if xPlayer.get('money') >= price then
xPlayer.removeMoney(price)
xPlayer.addWeapon(itemName, 42)
TriggerClientEvent('esx:showNotification', _source, _U('buy') .. ESX.GetWeaponLabel(itemName))
else
TriggerClientEvent('esx:showNotification', _source, _U('not_enough'))
end
end
end)