Add files

This commit is contained in:
Jérémie N'gadi
2017-08-02 10:58:39 +02:00
parent 679a484c9e
commit 6c44faa1ab
4 changed files with 377 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
description 'ESX ClotheShop'
server_scripts {
'@mysql-async/lib/MySQL.lua',
'config.lua',
'server/main.lua'
}
client_scripts {
'config.lua',
'client/main.lua'
}
+262
View File
@@ -0,0 +1,262 @@
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)
+38
View File
@@ -0,0 +1,38 @@
Config = {}
Config.Price = 250
Config.DrawDistance = 100.0
Config.MarkerSize = {x = 1.5, y = 1.5, z = 1.0}
Config.MarkerColor = {r = 102, g = 102, b = 204}
Config.MarkerType = 1
Config.Zones = {}
Config.Shops = {
{x=72.254, y=-1399.102, z=28.376},
{x=-703.776, y=-152.258, z=36.415},
{x=-167.863, y=-298.969, z=38.733},
{x=428.694, y=-800.106, z=28.491},
{x=-829.413, y=-1073.710, z=10.328},
{x=-1447.797, y=-242.461, z=48.820},
{x=11.632, y=6514.224, z=30.877},
{x=123.646, y=-219.440, z=53.557},
{x=1696.291, y=4829.312, z=41.063},
{x=618.093, y=2759.629, z=41.088},
{x=1190.550, y=2713.441, z=37.222},
{x=-1193.429, y=-772.262, z=16.324},
{x=-3172.496, y=1048.133, z=19.863},
{x=-1108.441, y=2708.923, z=18.107},
}
for i=1, #Config.Shops, 1 do
Config.Zones['Shop_' .. i] = {
Pos = Config.Shops[i],
Size = Config.MarkerSize,
Color = Config.MarkerColor,
Type = Config.MarkerType
}
end
+63
View File
@@ -0,0 +1,63 @@
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
RegisterServerEvent('esx_clotheshop:pay')
AddEventHandler('esx_clotheshop:pay', function()
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.removeMoney(Config.Price)
TriggerClientEvent('esx:showNotification', source, 'Vous avez payé $' .. Config.Price)
end)
RegisterServerEvent('esx_clotheshop:saveOutfit')
AddEventHandler('esx_clotheshop:saveOutfit', function(label, skin)
local xPlayer = ESX.GetPlayerFromId(source)
TriggerEvent('esx_datastore:getDataStore', 'property', xPlayer.identifier, function(store)
local dressing = store.get('dressing')
if dressing == nil then
dressing = {}
end
table.insert(dressing, {
label = label,
skin = skin
})
store.set('dressing', dressing)
end)
end)
ESX.RegisterServerCallback('esx_clotheshop:checkMoney', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.get('money') >= Config.Price then
cb(true)
else
cb(false)
end
end)
ESX.RegisterServerCallback('esx_clotheshop:checkPropertyDataStore', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
local foundStore = false
TriggerEvent('esx_datastore:getDataStore', 'property', xPlayer.identifier, function(store)
foundStore = true
end)
cb(foundStore)
end)