Files
esx_core/client/main.lua
T
Jérémie N'gadi 6c44faa1ab Add files
2017-08-02 10:58:39 +02:00

262 lines
6.4 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 GUI = {}
GUI.Time = 0
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
end)
function OpenShopMenu()
TriggerEvent('esx_skin:openRestrictedMenu', function(data, menu)
menu.close()
ESX.UI.Menu.Open(
'default', GetCurrentResourceName(), 'shop_confirm',
{
title = 'Valider cet achat ?',
align = 'top-left',
elements = {
{label = 'Oui', value = 'yes'},
{label = 'Non', value = 'no'},
}
},
function(data, menu)
menu.close()
if data.current.value == 'yes' then
ESX.TriggerServerCallback('esx_clotheshop:checkMoney', function(hasEnoughMoney)
if hasEnoughMoney then
TriggerEvent('skinchanger:getSkin', function(skin)
TriggerServerEvent('esx_skin:save', skin)
end)
TriggerServerEvent('esx_clotheshop:pay')
ESX.TriggerServerCallback('esx_clotheshop:checkPropertyDataStore', function(foundStore)
if foundStore then
ESX.UI.Menu.Open(
'dialog', GetCurrentResourceName(), 'outfit_name',
{
title = 'Nom de la tenue ?',
},
function(data, menu)
menu.close()
TriggerEvent('skinchanger:getSkin', function(skin)
TriggerServerEvent('esx_clotheshop:saveOutfit', data.value, skin)
end)
end,
function(data2,menu)
menu.close()
end
)
end
end)
else
TriggerEvent('esx_skin:getLastSkin', function(skin)
TriggerEvent('skinchanger:loadSkin', skin)
end)
ESX.ShowNotification('Vous n\'avez pas assez d\'argent')
end
end)
end
if data.current.value == 'no' then
TriggerEvent('esx_skin:getLastSkin', function(skin)
TriggerEvent('skinchanger:loadSkin', skin)
end)
end
CurrentAction = 'shop_menu'
CurrentActionMsg = 'Appuez sur ~INPUT_CONTEXT~ pour accéder au menu'
CurrentActionData = {}
end,
function(data, menu)
menu.close()
CurrentAction = 'shop_menu'
CurrentActionMsg = 'Appuez sur ~INPUT_CONTEXT~ pour accéder au menu'
CurrentActionData = {}
end
)
end, function(data, menu)
menu.close()
CurrentAction = 'shop_menu'
CurrentActionMsg = 'Appuez sur ~INPUT_CONTEXT~ pour accéder au menu'
CurrentActionData = {}
end, {
'tshirt_1',
'tshirt_2',
'torso_1',
'torso_2',
'decals_1',
'decals_2',
'arms',
'pants_1',
'pants_2',
'shoes_1',
'shoes_2',
'chain_1',
'chain_2',
'helmet_1',
'helmet_2',
'glasses_1',
'glasses_2',
})
end
AddEventHandler('esx_clotheshop:hasEnteredMarker', function(zone)
CurrentAction = 'shop_menu'
CurrentActionMsg = 'Appuez sur ~INPUT_CONTEXT~ pour accéder au menu'
CurrentActionData = {}
end)
AddEventHandler('esx_clotheshop:hasExitedMarker', function(zone)
CurrentAction = nil
end)
-- Create Blips
Citizen.CreateThread(function()
for i=1, #Config.Shops, 1 do
local blip = AddBlipForCoord(Config.Shops[i].x, Config.Shops[i].y, Config.Shops[i].z)
SetBlipSprite (blip, 73)
SetBlipDisplay(blip, 4)
SetBlipScale (blip, 1.0)
SetBlipColour (blip, 47)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Vêtements")
EndTextCommandSetBlipName(blip)
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
if(v.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then
DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false)
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
for k,v in pairs(Config.Zones) do
if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x) then
isInMarker = true
currentZone = k
end
end
if (isInMarker and not HasAlreadyEnteredMarker) or (isInMarker and LastZone ~= currentZone) then
HasAlreadyEnteredMarker = true
LastZone = currentZone
TriggerEvent('esx_clotheshop:hasEnteredMarker', currentZone)
end
if not isInMarker and HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = false
TriggerEvent('esx_clotheshop:hasExitedMarker', LastZone)
end
end
end)
-- Key controls
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if CurrentAction ~= nil then
SetTextComponentFormat('STRING')
AddTextComponentString(CurrentActionMsg)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
if IsControlPressed(0, Keys['E']) and (GetGameTimer() - GUI.Time) > 300 then
if CurrentAction == 'shop_menu' then
OpenShopMenu()
end
CurrentAction = nil
GUI.Time = GetGameTimer()
end
end
end
end)