mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 18:28:52 +00:00
200 lines
6.0 KiB
Lua
200 lines
6.0 KiB
Lua
local Keys = {
|
|
["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
|
|
["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
|
|
["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
|
|
["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
|
|
["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
|
|
["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
|
|
["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
|
|
["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
|
|
["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
|
|
}
|
|
|
|
ESX = nil
|
|
local HasAlreadyEnteredMarker = false
|
|
local LastZone = nil
|
|
local CurrentAction = nil
|
|
local CurrentActionMsg = ''
|
|
local CurrentActionData = {}
|
|
|
|
Citizen.CreateThread(function()
|
|
while ESX == nil do
|
|
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
|
Citizen.Wait(0)
|
|
end
|
|
|
|
ESX.TriggerServerCallback('esx_weaponshop:getShop', function(shopItems)
|
|
for k,v in pairs(shopItems) do
|
|
Config.Zones[k].Items = v
|
|
end
|
|
end)
|
|
end)
|
|
|
|
RegisterNetEvent('esx_weaponshop:sendShop')
|
|
AddEventHandler('esx_weaponshop:sendShop', function(shopItems)
|
|
for k,v in pairs(shopItems) do
|
|
Config.Zones[k].Items = v
|
|
end
|
|
end)
|
|
|
|
function OpenBuyLicenseMenu(zone)
|
|
ESX.UI.Menu.CloseAll()
|
|
|
|
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop_license', {
|
|
title = _U('buy_license'),
|
|
align = 'top-left',
|
|
elements = {
|
|
{ label = _U('no'), value = 'no' },
|
|
{ label = _U('yes', ('<span style="color: green;">%s</span>'):format((_U('shop_menu_item', ESX.Math.GroupDigits(Config.LicensePrice))))), value = 'yes' },
|
|
}
|
|
}, function(data, menu)
|
|
if data.current.value == 'yes' then
|
|
ESX.TriggerServerCallback('esx_weaponshop:buyLicense', function(bought)
|
|
if bought then
|
|
menu.close()
|
|
OpenShopMenu(zone)
|
|
end
|
|
end)
|
|
end
|
|
end, function(data, menu)
|
|
menu.close()
|
|
end)
|
|
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 = ('%s - <span style="color: green;">%s</span>'):format(item.label, _U('shop_menu_item', ESX.Math.GroupDigits(item.price))),
|
|
weaponName = item.item
|
|
})
|
|
end
|
|
|
|
ESX.UI.Menu.CloseAll()
|
|
|
|
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop', {
|
|
title = _U('shop'),
|
|
align = 'top-left',
|
|
elements = elements
|
|
}, function(data, menu)
|
|
TriggerServerEvent('esx_weaponshop:buyItem', data.current.weaponName, zone)
|
|
end, function(data, menu)
|
|
menu.close()
|
|
|
|
CurrentAction = 'shop_menu'
|
|
CurrentActionMsg = _U('shop_menu')
|
|
CurrentActionData = { zone = zone }
|
|
end)
|
|
end
|
|
|
|
AddEventHandler('esx_weaponshop:hasEnteredMarker', function(zone)
|
|
CurrentAction = 'shop_menu'
|
|
CurrentActionMsg = _U('shop_menu')
|
|
CurrentActionData = { zone = zone }
|
|
end)
|
|
|
|
AddEventHandler('esx_weaponshop: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 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, 110)
|
|
SetBlipDisplay(blip, 4)
|
|
SetBlipScale (blip, 1.0)
|
|
SetBlipColour (blip, 81)
|
|
SetBlipAsShortRange(blip, true)
|
|
|
|
BeginTextCommandSetBlipName("STRING")
|
|
AddTextComponentString(_U('map_blip'))
|
|
EndTextCommandSetBlipName(blip)
|
|
end
|
|
end
|
|
end
|
|
end)
|
|
|
|
-- Display markers
|
|
Citizen.CreateThread(function()
|
|
while true do
|
|
Citizen.Wait(0)
|
|
|
|
local coords = GetEntityCoords(PlayerPedId())
|
|
|
|
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
|
|
Citizen.Wait(0)
|
|
|
|
local coords = GetEntityCoords(PlayerPedId())
|
|
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_weaponshop:hasEnteredMarker', currentZone)
|
|
end
|
|
|
|
if not isInMarker and HasAlreadyEnteredMarker then
|
|
HasAlreadyEnteredMarker = false
|
|
TriggerEvent('esx_weaponshop:hasExitedMarker', LastZone)
|
|
end
|
|
end
|
|
end)
|
|
|
|
-- Key Controls
|
|
Citizen.CreateThread(function()
|
|
while true do
|
|
Citizen.Wait(0)
|
|
|
|
if CurrentAction ~= nil then
|
|
ESX.ShowHelpNotification(CurrentActionMsg)
|
|
|
|
if IsControlJustReleased(0, Keys['E']) then
|
|
if CurrentAction == 'shop_menu' then
|
|
if Config.LicenseEnable and Config.Zones[CurrentActionData.zone].legal then
|
|
ESX.TriggerServerCallback('esx_license:checkLicense', function(hasWeaponLicense)
|
|
if hasWeaponLicense then
|
|
OpenShopMenu(CurrentActionData.zone)
|
|
else
|
|
OpenBuyLicenseMenu(CurrentActionData.zone)
|
|
end
|
|
end, GetPlayerServerId(PlayerId()), 'weapon')
|
|
else
|
|
OpenShopMenu(CurrentActionData.zone)
|
|
end
|
|
end
|
|
CurrentAction = nil
|
|
end
|
|
end
|
|
end
|
|
end)
|