Skip to content

Commit

Permalink
V1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RedAlex committed Apr 9, 2019
0 parents commit 4124f85
Show file tree
Hide file tree
Showing 13 changed files with 956 additions and 0 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# esx_carkey

Allows you to use an "Smart Key" to lock or unlock the doors.
The key recognizes any vehicle you have purchased.
You can also register another car you drive in your key.
Note : Key memory is erased when you logout.

Items
-Smart Key


# Installation
1. Download the .Zip from this repository.
2. Extract it with your favorite program.
3. Copy the project to your ressource folder.
4. Don't forget to import the database.sql file to your database.
5. Add "start esx_carkey" in your `server.cfg`


# Required resource
- EssentialMode 5.0.3+
- Async 2.0+
- esx_vehicleshop v1.1.0+
- esx_shops v1.1.0+

# Created by
- Code - Alex Garcio https://github.com/RedAlex
- Anim/sound - RyuShin https://github.com/KingRyuShin

___
# esx_carkey

Vous permet d'utiliser une "Clé Intelligente" pour vérrouiller ou déverrouiller les portes.
La clé reconnais n'importe quel véhicule que vous avez acheté.
Vous pouvez également enregistrer une autre voiture que vous conduisez dans votre clé.
Remarque: la mémoire de clé est effacée lorsque vous vous déconnectez.

Items
-Clé Intelligente


# Installation
1. Téléchargez le .Zip
2. Extractez-le avec votre programme favori.
3. Copiez le projet dans votre dossier ressource.
4. N'oubliez pas d'importer le database.sql a votre base de données.
5. Ajoutez "start esx_carkey" dans votre `server.cfg`


# Ressource requis
- EssentialMode 5.0.3+
- Async 2.0+
- esx_vehicleshop v1.1.0+
- esx_shops v1.1.0+


# Créer par
- Code - Alex Garcio https://github.com/RedAlex
- Anim/sound - RyuShin https://github.com/KingRyuShin
32 changes: 32 additions & 0 deletions __resource.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'

description 'esx_ownedcarkey'

version '1.0.0'

server_scripts {
'@async/async.lua',
'@mysql-async/lib/MySQL.lua',
'server/main.lua'
}

client_scripts {
'@es_extended/locale.lua',
'locales/fr.lua',
'locales/en.lua',
'config.lua',
'client/main.lua'
}

dependencies {
'es_extended',
'esx_vehicleshop'
}

ui_page 'client/html/index.html'

files {
'client/html/index.html',
'client/html/sounds/lock.ogg',
'client/html/sounds/unlock.ogg'
}
22 changes: 22 additions & 0 deletions client/html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Code from Scott's InteractSound script : https://forum.fivem.net/t/release-play-custom-sounds-for-interactions/8282 -->
<html>
<head>
<script src="nui://game/ui/jquery.js" type="text/javascript"></script>
<script>
var audioPlayer = null;
window.addEventListener('message', function(event) {
if (event.data.transactionType == "playSound") {

if (audioPlayer != null) {
audioPlayer.pause();
}

audioPlayer = new Audio("./sounds/" + event.data.transactionFile + ".ogg");
audioPlayer.volume = event.data.transactionVolume;
audioPlayer.play();

}
});
</script>
</head>
</html>
Binary file added client/html/sounds/lock.ogg
Binary file not shown.
Binary file added client/html/sounds/unlock.ogg
Binary file not shown.
103 changes: 103 additions & 0 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
ESX = nil
local mycar = {}

Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)

RegisterNetEvent('esx_carkey:keyuse')
AddEventHandler('esx_carkey:keyuse', function()
local playerPed = PlayerPedId()
local vehicle = ESX.Game.GetVehicleInDirection()
if not vehicle then
vehicle = GetVehiclePedIsIn(playerPed, false)
end
if vehicle ~= 0 then
local vehdata = ESX.Game.GetVehicleProperties(vehicle)
local found = false
for i=1, #mycar, 1 do
if mycar[i] == vehdata.plate then
found = true
end
end
if found then
togglecarlock(vehicle)
elseif not found and GetPedInVehicleSeat(vehicle, -1) == playerPed then
table.insert(mycar,vehdata.plate)
ESX.ShowNotification(_U('vehicle_register'))
elseif not found and GetPedInVehicleSeat(vehicle) == playerPed then
ESX.ShowNotification(_U('not_driver'))
return
else
ESX.TriggerServerCallback('esx_carkey:ismycar', function (ismycar)
if ismycar then
togglecarlock(vehicle)
table.insert(mycar, vehdata.plate)
else
ESX.ShowNotification(_U('not_your_car'))
end
end, vehdata.plate)
end
else
ESX.ShowNotification(_U('no_proximity_car'))
end
end)

function togglecarlock(vehicle)
local playerPed = PlayerPedId()
local lockstate = GetVehicleDoorLockStatus(vehicle)
local incar = GetVehiclePedIsIn(playerPed, false)
if lockstate ~= 1 then
if incar == 0 then
loadAnimDict('anim@mp_player_intmenu@key_fob@')
TaskPlayAnim(playerPed, 'anim@mp_player_intmenu@key_fob@', 'fob_click', 8.0, -8, -1, 49, 0, 0, 0, 0)
SetVehicleDoorsLocked(vehicle, 1)
SetVehicleDoorsLockedForAllPlayers(vehicle, false)
Wait(1000)
SetVehicleDoorsLocked(vehicle, 1)
SetVehicleDoorsLockedForAllPlayers(vehicle, false)
ClearPedTasksImmediately(playerPed)
ESX.ShowNotification(_U('connect_to_car'))
Wait(3000)
end
SetVehicleDoorsLocked(vehicle, 1)
SetVehicleDoorsLockedForAllPlayers(vehicle, false)
TriggerServerEvent("InteractSound_SV:PlayWithinDistance", 10, "unlock", 1.0)
ESX.ShowNotification(_U('doors_unlock'))
else
if incar == 0 then
loadAnimDict('anim@mp_player_intmenu@key_fob@')
TaskPlayAnim(playerPed, 'anim@mp_player_intmenu@key_fob@', 'fob_click', 8.0, -8, -1, 49, 0, 0, 0, 0)
Wait(1000)
ClearPedTasksImmediately(playerPed)
end
SetVehicleDoorsLocked(vehicle, 2)
SetVehicleDoorsLockedForAllPlayers(vehicle, true)
TriggerServerEvent("InteractSound_SV:PlayWithinDistance", 10, "lock", 1.0)
ESX.ShowNotification(_U('doors_lock'))
end
end

function loadAnimDict(dict)
while (not HasAnimDictLoaded(dict)) do
RequestAnimDict(dict)
Citizen.Wait(0)
end
end

RegisterNetEvent('InteractSound_CL:PlayWithinDistance')
AddEventHandler('InteractSound_CL:PlayWithinDistance', function(playerNetId, maxDistance, soundFile, soundVolume)
local lCoords = GetEntityCoords(GetPlayerPed(-1))
local eCoords = GetEntityCoords(GetPlayerPed(GetPlayerFromServerId(playerNetId)))
local distIs = Vdist(lCoords.x, lCoords.y, lCoords.z, eCoords.x, eCoords.y, eCoords.z)
if(distIs <= maxDistance) then
SendNUIMessage({
transactionType = 'playSound',
transactionFile = soundFile,
transactionVolume = soundVolume
})
end
end)
2 changes: 2 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Config = {}
Config.Locale = 'fr' --Set lang (fr-en)
9 changes: 9 additions & 0 deletions databaseEN.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
INSERT INTO `items` (name, label, `limit`) VALUES
('carkey', "Smart Key", 1)
;

INSERT INTO `shops` (store, item, price) VALUES
('TwentyFourSeven','carkey',300),
('RobsLiquor','carkey',300),
('LTDgasoline','carkey',300)
;
9 changes: 9 additions & 0 deletions databaseFR.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
INSERT INTO `items` (name, label, `limit`) VALUES
('carkey', "Clé Intelligente", 1)
;

INSERT INTO `shops` (store, item, price) VALUES
('TwentyFourSeven','carkey',300),
('RobsLiquor','carkey',300),
('LTDgasoline','carkey',300)
;
9 changes: 9 additions & 0 deletions locales/en.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Locales['en'] = {
['no_proximity_car'] = 'No vehicle nearby.',
['not_your_car'] = 'This vehicle does not belong to you.',
['doors_lock'] = 'Doors ~r~Locked~s~',
['doors_unlock'] = 'Doors ~b~Unlocked~s~',
['vehicle_register'] = 'Vehicle now ~b~Recognized~s~ by the Smart Key.',
['not_driver'] = 'You must be a driver to do that.',
['connect_to_car'] = 'Connecting to vehicle in progress.........'
}
9 changes: 9 additions & 0 deletions locales/fr.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Locales['fr'] = {
['no_proximity_car'] = 'Pas de véhicule à proximité.',
['not_your_car'] = 'Ce véhicule de vous appartien pas.',
['doors_lock'] = 'Portes ~r~Vérrouillé~s~',
['doors_unlock'] = 'Portes ~b~Dévérrouillé~s~',
['vehicle_register'] = 'Véhicule maintenant ~b~Reconnu~s~ par la Clé Intelligente.',
['not_driver'] = 'Vous devez être conducteur pour faire ça.',
['connect_to_car'] = 'Connexion au véhicule en cours.........'
}
28 changes: 28 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

ESX.RegisterServerCallback('esx_carkey:ismycar', function (source, cb, plate)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE @plate = plate and @owner = owner',
{
['@plate'] = plate,
['@owner'] = xPlayer.getIdentifier(),
}, function (result)
if (result[1] ~= nil) then
cb(true)
else
cb(false)
end
end)
end)

RegisterServerEvent('InteractSound_SV:PlayWithinDistance')
AddEventHandler('InteractSound_SV:PlayWithinDistance', function(maxDistance, soundFile, soundVolume)
TriggerClientEvent('InteractSound_CL:PlayWithinDistance', -1, source, maxDistance, soundFile, soundVolume)
end)

ESX.RegisterUsableItem('carkey', function(source)
local _source = source
TriggerClientEvent('esx_carkey:keyuse', _source)
end)

1 comment on commit 4124f85

@EmiCzarnecki
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, you could add features that if you sit in the car and close the door you can not get out ??

Please sign in to comment.