4 |
5 |
6 |
7 | mGarage
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | [](https://discord.gg/Vk7eY8xYV2)
4 | 
5 | [](https://hits.seeyoufarm.com)
6 |
7 | #
8 | # mVehicle 2.0.4
9 |
10 | # [Documents](https://mono-94.github.io/mDocuments/docs/mVehicle)
11 |
12 |
13 | 
14 |
--------------------------------------------------------------------------------
/resources/engineSound/client.lua:
--------------------------------------------------------------------------------
1 | --- Set Engine Sound
2 | ---@param entity number | integer
3 | ---@param soundName string | integer
4 | function Vehicles.SetEngineSound(entity, soundName)
5 | if not DoesEntityExist(entity) then return end
6 | TriggerServerEvent('mVehicle:SetEngineSound', VehToNet(entity), soundName)
7 | end
8 |
9 |
10 | AddStateBagChangeHandler('engineSound', nil, function(bagName, key, value)
11 | if not value then return end
12 | local entity = GetEntityFromStateBagName(bagName)
13 |
14 | ForceUseAudioGameObject(entity, value)
15 |
16 | Entity(entity).state:set('engineSound', nil, true)
17 | end)
18 |
19 |
20 | exports('SetEngineSound', Vehicles.SetEngineSound)
21 |
--------------------------------------------------------------------------------
/fxmanifest.lua:
--------------------------------------------------------------------------------
1 | fx_version 'cerulean'
2 | lua54 'yes'
3 | use_experimental_fxv2_oal 'yes'
4 | game 'gta5'
5 |
6 | name "mVehicle"
7 | description "Manage vehicles with ease functions | Vehicles persistent"
8 | author "aka_mono & .rawpaper"
9 |
10 |
11 | version "2.0.7"
12 |
13 |
14 | shared_scripts {
15 | 'shared/*',
16 | 'resources/scriptBridge/scriptBridge.lua',
17 | '@ox_lib/init.lua',
18 | }
19 |
20 | client_scripts {
21 | 'client/**/*.lua',
22 | 'resources/**/client.lua'
23 | }
24 |
25 | server_scripts {
26 | '@oxmysql/lib/MySQL.lua',
27 | 'server/**/*.lua',
28 | 'resources/**/server.lua'
29 | }
30 |
31 | ox_libs {
32 | 'locale',
33 | 'math',
34 | 'table',
35 | }
36 |
37 | files {
38 | 'import.lua',
39 | 'locales/*.json',
40 | 'web/build/index.html',
41 | 'web/build/**/*',
42 | }
43 |
44 | provide 'qbx_vehiclekeys'
45 |
46 |
47 |
48 | ui_page 'web/build/index.html'
49 |
--------------------------------------------------------------------------------
/web/build/assets/index-BoMALHTb.css:
--------------------------------------------------------------------------------
1 | @charset "UTF-8";body{margin:0;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;height:100vh;overflow:hidden;color:#ccc}code{font-family:source-code-pro,Menlo,Monaco,Consolas,Courier New,monospace}.card{padding:10px;background-color:#1a1b1e}.radio{position:absolute;width:100%;height:100%;border-radius:5px;display:flex;justify-content:center;align-items:flex-end}.player{background-color:#25262bfa;position:fixed;bottom:5px;left:50%;transform:translate(-50%);width:auto;height:auto;transition:width .4s ease-in-out}.menu{position:fixed;top:50%;right:10px;width:300px;height:auto;transform:translateY(-50%);padding:10px;display:flex;flex-direction:column;gap:10px;transition:transform .5s ease-in-out,opacity .5s ease-in-out;opacity:.5;background-color:#25262bfa;border-radius:5px}.visible{transform:translateY(-50%) translate(0);opacity:1}.no-visible{transform:translateY(-50%) translate(100%);opacity:0}
2 |
--------------------------------------------------------------------------------
/client/functions.lua:
--------------------------------------------------------------------------------
1 | Vehicles = {}
2 | Vehicles.Config = Config
3 |
4 | --Vehicle Label
5 | function Vehicles.GetVehicleLabel(model)
6 | if type(model) == 'string' then
7 | model = model:match("^%s*(.-)%s*$")
8 | model = model:gsub("%s+", " ")
9 | model = GetHashKey(model)
10 | end
11 |
12 | if not IsModelValid(model) then
13 | lib.print.warn(model .. ' - Model invalid')
14 | return 'Unknown'
15 | end
16 |
17 | local makeName = GetMakeNameFromVehicleModel(model)
18 |
19 | if not makeName then
20 | lib.print.warn(model .. ' - No Make Name')
21 | return 'Unknown'
22 | end
23 |
24 | makeName = makeName:sub(1, 1):upper() .. makeName:sub(2):lower()
25 |
26 | local displayName = GetDisplayNameFromVehicleModel(model)
27 |
28 | displayName = displayName:sub(1, 1):upper() .. displayName:sub(2):lower()
29 | return makeName .. ' ' .. displayName
30 | end
31 |
32 | function Vehicles.AddTemporalVehicleClient(entity)
33 | return lib.callback.await('mVehicle:ControlTemporal', 1000, VehToNet(entity))
34 | end
35 |
36 | exports('AddTemporalVehicleClient', Vehicles.AddTemporalVehicleClient)
37 |
38 | exports('vehicle', function()
39 | return Vehicles
40 | end)
41 |
--------------------------------------------------------------------------------
/sql.sql:
--------------------------------------------------------------------------------
1 |
2 | --- esx
3 |
4 | CREATE TABLE `owned_vehicles` (
5 | `id` int(11) NOT NULL AUTO_INCREMENT,
6 | `owner` varchar(46) DEFAULT NULL,
7 | `plate` varchar(12) NOT NULL,
8 | `vehicle` longtext DEFAULT NULL,
9 | `type` varchar(20) NOT NULL DEFAULT 'automobile',
10 | `job` varchar(20) DEFAULT NULL,
11 | `stored` tinyint(4) NOT NULL DEFAULT 0,
12 | `parking` varchar(60) DEFAULT NULL,
13 | `pound` varchar(60) DEFAULT NULL,
14 | `mileage` int(11) DEFAULT 0,
15 | `metadata` JSON DEFAULT '{"keys":{}}',
16 | `glovebox` JSON DEFAULT NULL,
17 | `trunk` JSON DEFAULT NULL,
18 | `carseller` int(11) DEFAULT 0,
19 | `private` tinyint(1) DEFAULT 0,
20 | PRIMARY KEY (`id`),
21 | UNIQUE KEY `unique_plate` (`plate`)
22 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
23 |
24 | -- uptade `metadata` in `owned_vehicles`
25 | ALTER TABLE `owned_vehicles`
26 | ALTER COLUMN `metadata` SET DEFAULT '{"keys":{}}';
27 |
28 |
29 |
30 |
31 |
32 |
33 | --- qbox
34 | ALTER TABLE `player_vehicles`
35 | ADD COLUMN `mileage` INT(11) DEFAULT 0,
36 | ADD COLUMN `metadata` JSON DEFAULT '{"keys":{}}',
37 | ADD COLUMN `pound` VARCHAR(60) DEFAULT NULL,
38 | ADD COLUMN `stored` TINYINT(4) DEFAULT 0,
39 | ADD COLUMN `type` varchar(20) DEFAULT 'automobile',
40 | ADD COLUMN `job` varchar(20) DEFAULT NULL;
41 |
42 | -- uptade `metadata` in `player_vehicles`
43 | ALTER TABLE `player_vehicles`
44 | ALTER COLUMN `metadata` SET DEFAULT '{"keys":{}}';
--------------------------------------------------------------------------------
/resources/engineIgnition/client.lua:
--------------------------------------------------------------------------------
1 | if not Config.VehicleEngine.ToggleEngine then return end
2 |
3 |
4 | lib.addKeybind({
5 | name = 'mVehice_toggle_engine',
6 | description = 'Keybin engine',
7 | defaultKey = Config.VehicleEngine.KeyBind,
8 | onPressed = function()
9 | local vehicle = cache.vehicle
10 |
11 | if not vehicle then return end
12 |
13 | local isDriver = GetPedInVehicleSeat(cache.vehicle, -1) == cache.ped
14 |
15 | if not isDriver then return end
16 |
17 | local key = Vehicles.HasKeyClient(vehicle)
18 |
19 | if not key then return end
20 |
21 | local vehicleClass = GetVehicleClass(vehicle)
22 |
23 | local engineStatus = GetIsVehicleEngineRunning(vehicle)
24 |
25 | if vehicleClass ~= 8 then
26 | TaskPlayAnim(cache.ped, 'veh@std@ds@fpsbase', 'start_engine', 8.0, 1.0, not engineStatus and 1500 or 1000, 49,
27 | 0, 0, 0, 0)
28 | end
29 |
30 |
31 | Citizen.Wait(not engineStatus and 1500 or 1000)
32 |
33 | SetVehicleEngineOn(vehicle, not engineStatus, true, true)
34 |
35 | if not engineStatus then
36 | local totalDuration = 500
37 | local waitTime = 10
38 | local iterations = totalDuration / waitTime
39 |
40 | for i = 1, iterations do
41 | SetVehicleCurrentRpm(vehicle, 1.0)
42 | Citizen.Wait(waitTime)
43 | end
44 | end
45 | end
46 | })
47 |
48 |
49 | lib.requestAnimDict('veh@std@ds@fpsbase')
50 |
--------------------------------------------------------------------------------
/locales/de.json:
--------------------------------------------------------------------------------
1 | {
2 | "Trailer Target": "",
3 | "flip_trailer": "Anhänger umdrehen",
4 | "up_dow_ramp": "Raise/Lower Ramp",
5 | "up_dow_platform": "Raise/Lower Platform",
6 | "attach_vehicle": "Hänger An-Kuppeln",
7 | "dettach_vehicle": "Hänger Ab-Kuppeln",
8 |
9 | "Vehicle doors": "",
10 | "open_door": "Auf-Geschlossen",
11 | "close_door": "Zu-Geschlossen",
12 |
13 | "Keys": "",
14 | "key_string": "Kennzeichen: %s",
15 | "key_targetdoors": "Auf/Ab Kuppeln",
16 |
17 | "GiveCar Command": "",
18 | "givecar_noty": "Sie sind jetzt Eigentümer dieses Fahrzeugs %s",
19 | "givecar_help": "Geben Sie einem Spieler ein Fahrzeug mit mehreren Optionen.",
20 | "givecar_playerveh ": "Legen Sie das Fahrzeug, in dem sich der Spieler befindet, als Eigentum fest",
21 | "givecar_yes": "Ja",
22 | "givecar_no": "Nein",
23 | "givecar_menu1": "Spawn name",
24 | "givecar_menu2": "Garage",
25 | "givecar_menu3": "Temporäre Fahrzeuge?",
26 | "givecar_menu4": "Datum",
27 | "givecar_menu5": "Uhrzeit",
28 | "givecar_menu6": "Minuten",
29 | "givecar_menu7": "Fahrzeug Farbe 1",
30 | "givecar_menu8": "Fahrzeug Farbe 2",
31 | "givecar_menu9": "Fahrzeug Job",
32 | "givecar_menu810": "Leer lassen für kein Job",
33 |
34 | "carkeyMenu": "",
35 | "carkey_menu1": "Perönliches Fahrzeug",
36 | "carkey_menu2": "Du hast keine Fahrzeuge.",
37 | "carkey_menu3": "Schlüssel Geben",
38 | "carkey_menu4": "Schlüssel einem Spieler anhand seiner ID hinzufügen.",
39 | "carkey_menu5": "Keiner hat einen Schlüssel zu diesem Fahrzeug 😪",
40 | "carkey_menu6": "Löschen",
41 |
42 |
43 |
44 | "Fake Plate": "",
45 | "fakeplate1": "Falsche Kennzeichen",
46 | "fakeplate2": "dieses Fahrzeug gehört dir Nicht...",
47 | "fakeplate3": "Orginales Kennzeichen",
48 | "fakeplate4": "Ändere Kennzeichen"
49 | }
--------------------------------------------------------------------------------
/locales/en.json:
--------------------------------------------------------------------------------
1 | {
2 | "Trailer Target": "",
3 | "flip_trailer": "Flip Trailer",
4 | "up_dow_ramp": "Raise/Lower Ramp",
5 | "up_dow_platform": "Raise/Lower Platform",
6 | "attach_vehicle": "Attach Vehicle",
7 | "dettach_vehicle": "Detach Vehicle",
8 |
9 | "Vehicle doors": "",
10 | "open_door": "Open Door",
11 | "close_door": "Close Door",
12 |
13 | "Keys": "",
14 | "key_string": "License Plate: %s",
15 | "key_targetdoors": "Open / Close Doors",
16 |
17 | "GiveCar Command": "",
18 | "givecar_noty": "You are now the owner of this vehicle %s",
19 | "givecar_help": "Give a vehicle to a player with multiple options.",
20 | "givecar_playerveh ": "Set the vehicle the player is in as owned",
21 | "givecar_yes": "Yes",
22 | "givecar_no": "No",
23 | "givecar_menu1": "Vehicle Model",
24 | "givecar_menu2": "Garage",
25 | "givecar_menu3": "Temporary Vehicle?",
26 | "givecar_menu4": "Date",
27 | "givecar_menu5": "Hour",
28 | "givecar_menu6": "Minutes",
29 | "givecar_menu7": "Vehicle Color 1",
30 | "givecar_menu8": "Vehicle Color 2",
31 | "givecar_menu9": "Vehicle Job",
32 | "givecar_menu10": "Leave blank for no JOB",
33 | "givecar_menu11": "Temporal",
34 |
35 | "carkeyMenu": "",
36 | "carkey_menu1": "Personal Vehicles",
37 | "carkey_menu2": "You have no vehicles.",
38 | "carkey_menu3": "Give Key",
39 | "carkey_menu4": "Add keys to a player by their ID.",
40 | "carkey_menu5": "Nobody has keys to this vehicle 😪",
41 | "carkey_menu6": "Delete",
42 | "carkey_menu7": "Change name",
43 | "carkey_menu8": "Mark GPS",
44 |
45 | "Fake Plate": "",
46 | "fakeplate1": "Fake Plate",
47 | "fakeplate2": "This vehicle is not owned by you...",
48 | "fakeplate3": "Original Plate",
49 | "fakeplate4": "Changing plate",
50 |
51 |
52 | "setBlip": "Vehicle marked on the map"
53 | }
--------------------------------------------------------------------------------
/locales/it.json:
--------------------------------------------------------------------------------
1 | {
2 | "Rimorchio Target": "",
3 | "flip_trailer": "Capovolgi Rimorchio",
4 | "up_dow_ramp": "Alza/Abbassa Rampe",
5 | "up_dow_platform": "Alza/Abbassa Piattaforma",
6 | "attach_vehicle": "Attacca Veicolo",
7 | "dettach_vehicle": "Stacca Veicolo",
8 |
9 | "Porte del veicolo": "",
10 | "open_door": "Apri Porta",
11 | "close_door": "Chiudi Porta",
12 |
13 | "Chiavi": "",
14 | "key_string": "Targa: %s",
15 | "key_targetdoors": "Apri / Chiudi Portiere",
16 |
17 | "Dare veicolo": "",
18 | "givecar_noty": "Ora sei il proprietario di questo veicolo %s",
19 | "givecar_help": "Dai un veicolo a un giocatore con molte opzioni.",
20 | "givecar_playerveh": "Imposta il veicolo in cui il giocatore si trova come di proprietà",
21 | "givecar_yes": "Sì",
22 | "givecar_no": "No",
23 | "givecar_menu1": "Modello Veicolo",
24 | "givecar_menu2": "Garage",
25 | "givecar_menu3": "Veicolo Temporaneo?",
26 | "givecar_menu4": "Data",
27 | "givecar_menu5": "Ora",
28 | "givecar_menu6": "Minuti",
29 | "givecar_menu7": "Colore Veicolo 1",
30 | "givecar_menu8": "Colore Veicolo 2",
31 | "givecar_menu9": "Vehicle Job",
32 | "givecar_menu10": "Leave blank for no JOB",
33 | "givecar_menu11": "Temporal",
34 |
35 | "Menu Chiavi Auto": "",
36 | "carkey_menu1": "Veicoli Personali",
37 | "carkey_menu2": "Non hai veicoli.",
38 | "carkey_menu3": "Dai Chiave",
39 | "carkey_menu4": "Aggiungi chiavi a un giocatore tramite il suo ID.",
40 | "carkey_menu5": "Nessuno ha le chiavi di questo veicolo 😪",
41 | "carkey_menu6": "Elimina",
42 |
43 | "Targa Falsa": "",
44 | "fakeplate1": "Targa Contraffatta",
45 | "fakeplate2": "Questo veicolo non è di tua proprietà...",
46 | "fakeplate3": "Targa Originale",
47 | "fakeplate4": "Cambio targa",
48 |
49 |
50 | "setBlip": "Vehicle marked on the map"
51 | }
52 |
--------------------------------------------------------------------------------
/locales/es.json:
--------------------------------------------------------------------------------
1 | {
2 | "Trailer Target": "",
3 | "flip_trailer": "Voltear Remolque",
4 | "up_dow_ramp": "Subir/Bajar Rampa",
5 | "up_dow_platform": "Subir/Bajar Plataforma",
6 | "attach_vehicle": "Acoplar Vehículo",
7 | "dettach_vehicle": "Desacoplar Vehículo",
8 |
9 | "Vehicle doors": "",
10 | "open_door": "Abrir Puerta",
11 | "close_door": "Cerrar Puerta",
12 |
13 | "Keys": "",
14 | "key_string": "Matrícula: %s",
15 | "key_targetdoors": "Abrir / Cerrar Puertas",
16 |
17 | "GiveCar Command": "",
18 | "givecar_noty": "Ahora eres propietario de este vehículo %s",
19 | "givecar_help": "Dar un vehículo a un jugador con múltiples opciones.",
20 | "givecar_playerveh": "Establecer como propiedad el vehículo en el que se encuentra un jugador",
21 | "givecar_yes": "Sí",
22 | "givecar_no": "No",
23 | "givecar_menu1": "Modelo del vehículo",
24 | "givecar_menu2": "Garaje",
25 | "givecar_menu3": "¿Vehículo temporal?",
26 | "givecar_menu4": "Fecha",
27 | "givecar_menu5": "Hora",
28 | "givecar_menu6": "Minutos",
29 | "givecar_menu7": "Color 1 Vehículo",
30 | "givecar_menu8": "Color 2 Vehículo",
31 | "givecar_menu9": "Trabajo",
32 | "givecar_menu10": "Deja en blanco para ningun trabajo",
33 | "givecar_menu11": "Temporal",
34 |
35 |
36 | "carkeyMenu": "",
37 | "carkey_menu1": "Vehículos personales",
38 | "carkey_menu2": "No tienes vehículos.",
39 | "carkey_menu3": "Dar Llave",
40 | "carkey_menu4": "Agrega las llaves a un jugador mediante su ID.",
41 | "carkey_menu5": "Nadie tiene llaves de este vehículo 😪",
42 | "carkey_menu6": "Eliminar",
43 |
44 | "Fake Plate": "",
45 | "fakeplate1": "Matrícula Falsa",
46 | "fakeplate2": "Este vehículo no es de tu propiedad...",
47 | "fakeplate3": "Matrícula Original",
48 | "fakeplate4": "Cambiando matrícula",
49 |
50 |
51 | "setBlip": "Vehicle marked on the map"
52 | }
53 |
--------------------------------------------------------------------------------
/locales/fr.json:
--------------------------------------------------------------------------------
1 | {
2 | "Trailer": "",
3 | "flip_trailer": "Retourner la Remorque",
4 | "up_dow_ramp": "Monter/Baisser la Rampe",
5 | "up_dow_platform": "Monter/Baisser la Plateforme",
6 | "attach_vehicle": "Attacher le Véhicule",
7 | "dettach_vehicle": "Détacher le Véhicule",
8 |
9 | "Vehicle doors": "",
10 | "open_door": "Ouvrir la Porte",
11 | "close_door": "Fermer la Porte",
12 |
13 | "Keys": "",
14 | "key_string": "Plaque d’immatriculation : %s",
15 | "key_targetdoors": "Ouvrir / Fermer les Portes",
16 |
17 | "GiveCar Command": "",
18 | "givecar_noty": "Vous êtes maintenant propriétaire de ce véhicule %s",
19 | "givecar_help": "Donner un véhicule à un joueur avec plusieurs options.",
20 | "givecar_playerveh": "Définir comme propriété le véhicule dans lequel se trouve un joueur",
21 | "givecar_yes": "Oui",
22 | "givecar_no": "Non",
23 | "givecar_menu1": "Modèle du véhicule",
24 | "givecar_menu2": "Garage",
25 | "givecar_menu3": "Véhicule temporaire ?",
26 | "givecar_menu4": "Date",
27 | "givecar_menu5": "Heure",
28 | "givecar_menu6": "Minutes",
29 | "givecar_menu7": "Couleur 1 du Véhicule",
30 | "givecar_menu8": "Couleur 2 du Véhicule",
31 | "givecar_menu9": "Vehicle Job",
32 | "givecar_menu10": "Leave blank for no JOB",
33 | "givecar_menu11": "Temporal",
34 |
35 |
36 | "Car Key Menu": "",
37 | "carkey_menu1": "Véhicules personnels",
38 | "carkey_menu2": "Vous n’avez pas de véhicules.",
39 | "carkey_menu3": "Donner une Clé",
40 | "carkey_menu4": "Donner une clé à un joueur par son ID.",
41 | "carkey_menu5": "Personne n’a de clés pour ce véhicule 😪",
42 | "carkey_menu6": "Supprimer",
43 |
44 | "Fake Plate": "",
45 | "fakeplate1": "Plaque d’immatriculation Factice",
46 | "fakeplate2": "Ce véhicule ne vous appartient pas...",
47 | "fakeplate3": "Plaque d’immatriculation d’Origine",
48 | "fakeplate4": "Changement de plaque",
49 |
50 |
51 | "setBlip": "Vehicle marked on the map"
52 | }
53 |
--------------------------------------------------------------------------------
/resources/personalMenu/server.lua:
--------------------------------------------------------------------------------
1 | if not Config.PersonalVehicleMenu then return end
2 |
3 |
4 | local function Update(metadata, id)
5 | return MySQL.update.await('UPDATE `owned_vehicles` SET `metadata` = ? WHERE id = ?', { json.encode(metadata), id })
6 | end
7 |
8 |
9 |
10 | lib.callback.register('mVehicle:VehicleMenu', function(source, action, data, targetPlayer)
11 | local Vehicle = Vehicles.GetVehicleByPlate(data.plate)
12 | local spawned = true
13 |
14 | local metadata = {}
15 |
16 | if not Vehicle then
17 | Vehicle = data.id and Vehicles.GetVehicleByID(data.id) or Vehicles.GetVehicleByPlate(data.plate, true)
18 | if Vehicle then
19 | metadata = json.decode(Vehicle.metadata) or { keys = {} }
20 | if not metadata.keys then
21 | metadata.keys = {}
22 | end
23 | spawned = false
24 | end
25 | end
26 |
27 |
28 | if not Vehicle then
29 | Utils.Debug('error', 'Vehicle not found')
30 | return false
31 | end
32 |
33 |
34 | if action == 'addkey' then
35 | local target = Identifier(targetPlayer)
36 | if target then
37 | if not spawned then
38 | if metadata.keys[target] then
39 | return false
40 | end
41 | metadata.keys[target] = GetName(targetPlayer)
42 | Update(metadata, data.id)
43 | else
44 | local adeed = Vehicle.AddKey(targetPlayer)
45 | return adeed
46 | end
47 |
48 | return true
49 | end
50 | elseif action == 'removekey' then
51 | if not spawned then
52 | if not metadata.keys[targetPlayer] then
53 | return false
54 | end
55 | metadata.keys[targetPlayer] = nil
56 | Update(metadata, data.id)
57 | else
58 | local remove = Vehicle.RemoveKey(targetPlayer)
59 | return remove
60 | end
61 |
62 | return true
63 | elseif action == 'setBlip' then
64 | if not spawned then
65 | local props = json.decode(Vehicle.vehicle)
66 | return { coords = metadata.coords, model = props.model}
67 | else
68 | return { coords = Vehicle.GetCoords(), model = Vehicle.vehicle.model }
69 | end
70 | end
71 |
72 | return false
73 | end)
74 |
--------------------------------------------------------------------------------
/resources/vehicleSteal/client.lua:
--------------------------------------------------------------------------------
1 | local animDictLockPick = "anim@amb@clubhouse@tutorial@bkr_tut_ig3@"
2 | local animLockPick = "machinic_loop_mechandplayer"
3 |
4 |
5 | lib.callback.register('mVehicle:PlayerItems', function(action, entity)
6 | local ped = cache.ped
7 | if action == 'changeplate' then
8 | if lib.progressBar({
9 | duration = Config.FakePlateItem.ChangePlateTime,
10 | label = locale('fakeplate4'),
11 | useWhileDead = false,
12 | canCancel = true,
13 | disable = {
14 | car = true,
15 | move = true,
16 | },
17 | anim = {
18 | dict = animDictLockPick,
19 | clip = animLockPick,
20 | flag = 1,
21 | },
22 | prop = {
23 | model = 'p_num_plate_01',
24 | pos = vec3(0.0, 0.2, 0.1),
25 | rot = vec3(100, 100.0, 0.0)
26 | },
27 | }) then
28 | return true
29 | else
30 | return false
31 | end
32 | elseif action == 'lockpick' then
33 | if not NetworkDoesNetworkIdExist(entity) then return false end
34 | local vehicle = NetToVeh(entity)
35 | local pedInVehicle = IsPedInVehicle(ped, vehicle)
36 | if pedInVehicle then return end
37 | local coords = GetEntityCoords(vehicle)
38 | local class = GetVehicleClass(vehicle)
39 |
40 | local skillCheck = Config.LockPickItem.skillCheck(vehicle, class)
41 |
42 | if skillCheck then
43 | Config.LockPickItem.dispatch(cache.serverId, vehicle, coords)
44 | end
45 |
46 | SetVehicleNeedsToBeHotwired(vehicle, false)
47 |
48 | return skillCheck
49 | elseif action == 'hotwire' then
50 | local vehicle = GetVehiclePedIsIn(ped, false)
51 | if not vehicle then return false end
52 |
53 | local pedInVehicle = IsPedInVehicle(ped, vehicle, -1)
54 | if not pedInVehicle then return false end
55 | local class = GetVehicleClass(vehicle)
56 |
57 |
58 | local coords = GetEntityCoords(vehicle)
59 | local skillCheck = Config.HotWireItem.skillCheck(vehicle, class)
60 |
61 | if skillCheck then
62 | Config.HotWireItem.dispatch(cache.serverId, vehicle, coords)
63 | SetVehicleEngineOn(vehicle, true, true, true)
64 | end
65 |
66 | return skillCheck
67 | end
68 | end)
69 |
--------------------------------------------------------------------------------
/resources/seatShuffle/client.lua:
--------------------------------------------------------------------------------
1 | local PlayerSeat
2 | local Vehicle
3 |
4 | lib.onCache('vehicle', function(entity)
5 | Vehicle = entity
6 | end)
7 |
8 | lib.onCache('seat', function(seat)
9 | PlayerSeat = seat
10 | if Config.SeatShuffle then
11 | if seat == 0 then
12 | SetPedIntoVehicle(cache.ped, Vehicle, 0)
13 | SetPedConfigFlag(cache.ped, 184, true)
14 | else
15 | SetPedConfigFlag(cache.ped, 184, false)
16 | end
17 |
18 | while true do
19 | if not PlayerSeat then break end
20 | if IsControlPressed(0, 21) and IsControlJustPressed(0, 38) then
21 | if PlayerSeat == 0 or PlayerSeat == -1 then
22 | TaskShuffleToNextVehicleSeat(cache.ped, Vehicle)
23 | elseif PlayerSeat == 1 then
24 | TaskWarpPedIntoVehicle(cache.ped, Vehicle, 2)
25 | elseif PlayerSeat == 2 then
26 | TaskWarpPedIntoVehicle(cache.ped, Vehicle, 1)
27 | end
28 | end
29 | Citizen.Wait(0)
30 | end
31 | end
32 | end)
33 |
34 |
35 | lib.onCache('TryEnterVehicle', function(veh)
36 | -- Prevents a player from entering a locked vehicle
37 | local lock = GetVehicleDoorLockStatus(veh)
38 | if lock == 2 then
39 | ClearPedTasks(cache.ped)
40 | return
41 | end
42 |
43 | if Config.TyrEnter.closeEnter then return end
44 |
45 | if lib.table.contains(Config.TyrEnter.blackListClass, GetVehicleClass(veh)) then
46 | return
47 | end
48 |
49 | local PlayerPed = cache.ped
50 | local coords = GetEntityCoords(PlayerPed)
51 | local doorIndex = nil
52 |
53 | for i = 0, GetNumberOfVehicleDoors(veh) do
54 | local doorCoords = GetEntryPositionOfDoor(veh, i)
55 | local dist = #(coords - doorCoords)
56 | if (doorIndex == nil or dist < #(coords - GetEntryPositionOfDoor(veh, doorIndex))) then
57 | doorIndex = i
58 | end
59 | end
60 |
61 | if doorIndex then
62 | TaskEnterVehicle(PlayerPed, veh, -1, doorIndex - 1, 1.0, 1, 0)
63 |
64 | local startTime = GetGameTimer()
65 |
66 | while true do
67 | Citizen.Wait(0)
68 | local currentTime = GetGameTimer()
69 |
70 | if currentTime - startTime >= 3000 then
71 | break
72 | end
73 |
74 | if IsControlPressed(0, 32) or -- W
75 | IsControlPressed(0, 33) or -- S
76 | IsControlPressed(0, 34) or -- A
77 | IsControlPressed(0, 35) or -- D
78 | IsControlPressed(0, 22) then -- Space
79 | Citizen.Wait(200)
80 | if IsControlPressed(0, 32) or -- W
81 | IsControlPressed(0, 33) or -- S
82 | IsControlPressed(0, 34) or -- A
83 | IsControlPressed(0, 35) or -- D
84 | IsControlPressed(0, 22) then -- Space
85 | ClearPedTasks(PlayerPed)
86 | end
87 |
88 | break
89 | end
90 | end
91 | end
92 | end)
93 |
--------------------------------------------------------------------------------
/resources/scriptBridge/scriptBridge.lua:
--------------------------------------------------------------------------------
1 | --[[
2 |
3 | Handle Resource Events
4 | This utility function is designed to manage and intercept exported functions
5 | from other resources in a FiveM server. It listens for events triggered by
6 | exported functions and redirects their execution to a custom callback, allowing
7 | developers to override or extend the behavior of existing functions from other resources.
8 |
9 | Example Usage:
10 | HandleFunctionResource('my_resource', 'MyExportedFunction', function(...)
11 | print("Intercepted MyExportedFunction:", ...)
12 | end)
13 |
14 | This would listen for calls to the exported function 'MyExportedFunction' from 'my_resource'
15 | and execute the provided callback instead.
16 |
17 | -Notes:
18 | -- This works by attaching an event listener to the internal `__cfx_export__` event.
19 | -- The callback should have the same parameters and expected return values as the original function.
20 | ]]
21 |
22 | --- HandleFunctionResource
23 | --- Registers a handler for an exported function from another resource.
24 | --- This function listens for exported function calls and safely executes a callback,
25 | --- ensuring that errors do not crash the script.
26 |
27 | --- @param resourceName string The name of the resource exporting the function.
28 | --- @param functionName string The name of the exported function.
29 | --- @param callBack function The function that will handle calls to the exported function.
30 | local function HandleFunctionResource(resourceName, functionName, callBack)
31 | AddEventHandler(('__cfx_export_%s_%s'):format(resourceName, functionName), function(...)
32 | local success, result = pcall(callBack, ...)
33 | if not success then
34 | print(("[ERROR] HandleFunctionResource: Failed to execute callback for %s:%s - %s"):format(resourceName,
35 | functionName, result))
36 | end
37 | end)
38 | end
39 |
40 | --------------------------------------------------------------------------------------------
41 |
42 | if not IsDuplicityVersion() then
43 | -- qbx_vehiclekeys has keys Client
44 | HandleFunctionResource('qbx_vehiclekeys', 'HasKeys', function(entity)
45 | return Vehicles.HasKeyClient(entity)
46 | end)
47 | else
48 | -- qbx_vehiclekeys has keys Server
49 | HandleFunctionResource('qbx_vehiclekeys', 'HasKeys', function(src, entity)
50 | return Vehicles.HasKey(src, entity)
51 | end)
52 |
53 | -- qbx_vehiclekeys give keys? best thing to do is to give temporary access
54 | HandleFunctionResource('qbx_vehiclekeys', 'GiveKeys', function(src, entity)
55 | return Vehicles.AddTemporalVehicle(src, entity)
56 | end)
57 | end
58 |
--------------------------------------------------------------------------------
/server/commands.lua:
--------------------------------------------------------------------------------
1 | lib.addCommand(Config.Commands.givecar, {
2 | help = locale('givecar_help'),
3 | params = { { name = 'target', type = 'number', help = 'Target Player' } },
4 | restricted = 'group.admin'
5 | }, function(source, args, raw)
6 | local identifier = Identifier(args.target)
7 | local plate = Vehicles.GeneratePlate()
8 |
9 | if identifier then
10 | local vehicleData = lib.callback.await('mVehicle:GivecarData', source)
11 |
12 | if not vehicleData then return lib.print.info('Command "givecar" action cancelled') end
13 |
14 | local CreateData = {
15 | plate = plate,
16 | source = args.target,
17 | intocar = true,
18 | setOwner = true,
19 | coords = GetCoords(args.target),
20 | vehicle = {
21 | fuelLevel = 100,
22 | model = vehicleData.model,
23 | }
24 | }
25 |
26 | if vehicleData.job == '' then
27 | CreateData.job = nil
28 | else
29 | CreateData.job = vehicleData.job
30 | end
31 |
32 | if vehicleData.isTemporary then
33 | local date = os.date('%Y%m%d', math.floor(vehicleData.date / 1000))
34 | local hour = os.date('%H:%M', math.floor(vehicleData.hour / 1000))
35 | local time = date .. ' ' .. hour
36 | CreateData.temporary = time
37 | end
38 |
39 |
40 | if vehicleData.parking then
41 | CreateData.parking = vehicleData.parking
42 | end
43 |
44 | Vehicles.CreateVehicle(CreateData, function(vehicle)
45 | if DoesEntityExist(vehicle.entity) then
46 | if Config.ItemKeys then
47 | Vehicles.ItemCarKeys(args.target, 'add', CreateData.plate)
48 | end
49 |
50 | Notification(args.target, {
51 | title = 'GiveCar',
52 | description = locale('givecar_noty'):format(args.target),
53 | type = 'success',
54 | icon = 'database',
55 | iconColor = 'green'
56 | })
57 | end
58 | end)
59 | else
60 | lib.print.error(("Command 'givecar' source [ %s ] not found "):format(args.target))
61 | end
62 | end)
63 |
64 |
65 | lib.addCommand(Config.Commands.setcarowner, {
66 | help = locale('givecar_playerveh'),
67 | params = {
68 | {
69 | name = 'target',
70 | type = 'number',
71 | help = 'Target Player',
72 | },
73 | },
74 | restricted = 'group.admin'
75 | }, function(source, args, raw)
76 | Vehicles.SetCurrentVehicleOwner(args.target)
77 | end)
78 |
79 |
80 |
81 | lib.addCommand(Config.Commands.saveallcars, {
82 | help = 'Save all vehicles, delete option ',
83 | params = {
84 | {
85 | name = 'delete',
86 | type = 'string',
87 | help = 'Delete Vehicles?',
88 | optional = true,
89 | },
90 | },
91 | restricted = 'group.admin'
92 | }, function(source, args, raw)
93 | if args.delete == 'true' then
94 | Vehicles.SaveAllVehicles(true)
95 | else
96 | Vehicles.SaveAllVehicles(false)
97 | end
98 | end)
99 |
100 |
101 | lib.addCommand(Config.Commands.spawnallcars, {
102 | help = 'Force to spawn all vehicles',
103 | restricted = 'group.admin'
104 | }, function(source, args, raw)
105 | Vehicles.SpawnVehicles()
106 | end)
107 |
--------------------------------------------------------------------------------
/resources/trailerAtach/client.lua:
--------------------------------------------------------------------------------
1 | if not Config.TargetTrailer then return end
2 |
3 | local trailer = nil
4 | local dist = 10.0
5 | local trailerModel = 2078290630 -- spawn name 'tr2'
6 |
7 | local canInteract = function(entity, distance, coords, name, bone)
8 | if GetVehicleClass(entity) == 11 and GetEntityModel(entity) == trailerModel then
9 | return true
10 | end
11 | end
12 |
13 | exports.ox_target:addGlobalVehicle({
14 | {
15 | distance = dist,
16 | canInteract = canInteract,
17 | label = locale('flip_trailer'),
18 | icon = 'fa-solid fa-trailer',
19 | onSelect = function(data)
20 | local carCoords = GetEntityRotation(data.entity, 2)
21 | SetEntityRotation(data.entity, carCoords[1], 0, carCoords[3], 2, true)
22 | SetVehicleOnGroundProperly(data.entity)
23 | end
24 | },
25 | {
26 | distance = dist,
27 | icon = 'fa-solid fa-up-down',
28 | canInteract = canInteract,
29 | label = locale('up_dow_ramp'),
30 | onSelect = function(data)
31 | if GetVehicleDoorAngleRatio(data.entity, 5) > 0.0 then
32 | SetVehicleDoorShut(data.entity, 5, true)
33 | else
34 | SetVehicleDoorOpen(data.entity, 5, false, false)
35 | end
36 | end
37 | },
38 |
39 | {
40 | distance = dist,
41 | icon = 'fa-solid fa-up-down',
42 | canInteract = canInteract,
43 | label = locale('up_dow_platform'),
44 | onSelect = function(data)
45 | if GetVehicleDoorAngleRatio(data.entity, 4) > 0.2 then
46 | SetVehicleDoorShut(data.entity, 4, false)
47 | else
48 | SetVehicleDoorOpen(data.entity, 4, false, false)
49 | end
50 | end
51 | },
52 |
53 | {
54 | distance = dist,
55 | label = locale('attach_vehicle'),
56 | icon = 'fa-solid fa-lock',
57 | canInteract = function(entity, distance, coords, name, bone)
58 | local retval = IsEntityAttachedToAnyVehicle(entity)
59 | if retval then return false end
60 | local vehicles = lib.getNearbyVehicles(coords, 10, true)
61 | for i, vehicle in ipairs(vehicles) do
62 | if vehicle.vehicle ~= entity then
63 | local model = GetEntityModel(vehicle.vehicle)
64 | if model == trailerModel then
65 | trailer = vehicle.vehicle
66 | return true
67 | end
68 | end
69 | end
70 | end,
71 | onSelect = function(data)
72 | local vehCoords = GetEntityCoords(data.entity)
73 | local vehRotation = GetEntityRotation(data.entity)
74 | local OffSetTrailer = GetOffsetFromEntityGivenWorldCoords(trailer, vehCoords)
75 | AttachVehicleOnToTrailer(data.entity, trailer, 0.0, 0.0, 0.0, OffSetTrailer, vehRotation.x, vehRotation.y, 0.0, false)
76 | end
77 | },
78 |
79 | {
80 | distance = dist,
81 | label = locale('dettach_vehicle'),
82 | icon = 'fa-solid fa-lock-open',
83 | canInteract = function(entity, distance, coords, name, bone)
84 | if GetVehicleClass(entity) == 11 and GetEntityModel(entity) == trailerModel then return false end
85 | local retval = IsEntityAttachedToAnyVehicle(entity)
86 | if retval then return true end
87 | end,
88 | onSelect = function(data)
89 | DetachEntity(data.entity, true, false)
90 | end
91 | },
92 |
93 | })
94 |
--------------------------------------------------------------------------------
/shared/VehicleClassOptions.lua:
--------------------------------------------------------------------------------
1 |
2 |
3 | -- default ox_lib skillcheck https://overextended.dev/ox_lib/Modules/Interface/Client/skillcheck
4 | local Dificult = {
5 | easy = { 'easy', 'easy' },
6 | medium = { 'easy', 'easy', 'medium', 'medium' },
7 | hard = { 'easy', 'easy', 'medium', 'medium', 'hard', 'hard' },
8 | very_hard = { 'easy', 'hard', 'medium', 'medium', 'hard' }
9 | }
10 |
11 | VehicleClass = {
12 | [0] = { -- Compact
13 | lockpickDificult = Dificult['easy'],
14 | hotWireDificult = Dificult['easy']
15 | },
16 | [1] = { -- Sedan
17 | lockpickDificult = Dificult['easy'],
18 | hotWireDificult = Dificult['easy']
19 | },
20 | [2] = { -- SUV
21 | lockpickDificult = Dificult['medium'],
22 | hotWireDificult = Dificult['medium']
23 | },
24 | [3] = { -- Coupe
25 | lockpickDificult = Dificult['medium'],
26 | hotWireDificult = Dificult['medium']
27 | },
28 | [4] = { -- Muscle
29 | lockpickDificult = Dificult['hard'],
30 | hotWireDificult = Dificult['medium']
31 | },
32 | [5] = { -- Sport Classic
33 | lockpickDificult = Dificult['hard'],
34 | hotWireDificult = Dificult['hard']
35 | },
36 | [6] = { -- Sport
37 | lockpickDificult = Dificult['hard'],
38 | hotWireDificult = Dificult['hard']
39 | },
40 | [7] = { -- Super
41 | lockpickDificult = Dificult['very_hard'],
42 | hotWireDificult = Dificult['very_hard']
43 | },
44 | [8] = { -- Motorcycle
45 | lockpickDificult = Dificult['medium'],
46 | hotWireDificult = Dificult['easy']
47 | },
48 | [9] = { -- Off-road
49 | lockpickDificult = Dificult['medium'],
50 | hotWireDificult = Dificult['medium']
51 | },
52 | [10] = { -- Industrial
53 | lockpickDificult = Dificult['hard'],
54 | hotWireDificult = Dificult['hard']
55 | },
56 | [11] = { -- Utility
57 | lockpickDificult = Dificult['hard'],
58 | hotWireDificult = Dificult['hard']
59 | },
60 | [12] = { -- Van
61 | lockpickDificult = Dificult['medium'],
62 | hotWireDificult = Dificult['medium']
63 | },
64 | [13] = { -- Cycle
65 | lockpickDificult = Dificult['easy'],
66 | hotWireDificult = Dificult['easy']
67 | },
68 | [14] = { -- Boat
69 | lockpickDificult = Dificult['hard'],
70 | hotWireDificult = Dificult['hard']
71 | },
72 | [15] = { -- Helicopter
73 | lockpickDificult = Dificult['very_hard'],
74 | hotWireDificult = Dificult['very_hard']
75 | },
76 | [16] = { -- Plane
77 | lockpickDificult = Dificult['very_hard'],
78 | hotWireDificult = Dificult['very_hard']
79 | },
80 | [17] = { -- Service
81 | lockpickDificult = Dificult['hard'],
82 | hotWireDificult = Dificult['hard']
83 | },
84 | [18] = { -- Emergency
85 | lockpickDificult = Dificult['hard'],
86 | hotWireDificult = Dificult['hard']
87 | },
88 | [19] = { -- Military
89 | lockpickDificult = Dificult['very_hard'],
90 | hotWireDificult = Dificult['very_hard']
91 | },
92 | [20] = { -- Commercial
93 | lockpickDificult = Dificult['hard'],
94 | hotWireDificult = Dificult['hard']
95 | },
96 | [21] = { -- Train
97 | lockpickDificult = Dificult['very_hard'],
98 | hotWireDificult = Dificult['very_hard']
99 | },
100 | [22] = { -- Open Wheel
101 | lockpickDificult = Dificult['very_hard'],
102 | hotWireDificult = Dificult['very_hard']
103 | },
104 | }
105 |
--------------------------------------------------------------------------------
/resources/carKeys/client.lua:
--------------------------------------------------------------------------------
1 | local KeyAnim = {
2 | dict = "anim@mp_player_intmenu@key_fob@",
3 | anim = "fob_click_fp",
4 | PropKey = "p_car_keys_01"
5 | }
6 |
7 | --- Give Car Keys (client)
8 | ---@param action string
9 | ---@param plate string
10 | function Vehicles.ItemCarKeysClient(action, plate)
11 | return lib.callback.await('mVehicle:GiveKey', false, action, plate)
12 | end
13 |
14 | function Vehicles.HasKeyClient(entity)
15 | if not DoesEntityExist(entity) then return false end
16 | if Config.ItemKeys then
17 | local havekey = false
18 | local plate = GetVehicleNumberPlateText(entity):gsub("%s+", "")
19 | if Config.Inventory == 'ox' then
20 | local item = exports.ox_inventory:Search('slots', Config.CarKeyItem)
21 | for _, v in pairs(item) do
22 | if v.metadata and v.metadata.plate and v.metadata.plate:gsub("%s+", "") == plate then
23 | havekey = true
24 | break
25 | end
26 | end
27 | elseif Config.Inventory == 'qs' then
28 | local items = exports['qs-inventory']:getUserInventory()
29 | for _, v in pairs(items) do
30 | if v.info and v.info.plate and v.info.plate:gsub("%s+", "") == plate then
31 | havekey = true
32 | break
33 | end
34 | end
35 | end
36 | return havekey
37 | else
38 | return lib.callback.await('mVehicle:HasKeys', Config.KeyDelay, VehToNet(entity))
39 | end
40 | end
41 |
42 | local ToggleVehicleDoors = function()
43 | local data = {}
44 | local ped = cache.ped
45 |
46 | data.entity = lib.getClosestVehicle(GetEntityCoords(ped), Config.KeyDistance, true)
47 |
48 | if not DoesEntityExist(data.entity) then return end
49 |
50 | data.Status = GetVehicleDoorLockStatus(data.entity)
51 |
52 | local HaveKey = Vehicles.HasKeyClient(data.entity)
53 |
54 | local inCar = IsPedInAnyVehicle(ped, false)
55 |
56 | if HaveKey then
57 | TriggerServerEvent('mVehicle:VehicleDoors', VehToNet(data.entity))
58 |
59 | Utils.Notification({
60 | title = Vehicles.GetVehicleLabel(GetEntityModel(data.entity)),
61 | description = (data.Status == 2 and locale('open_door') or locale('close_door')),
62 | icon = (data.Status == 2 and 'lock-open' or 'lock'),
63 | iconColor = (data.Status == 2 and '#77e362' or '#e36462'),
64 | })
65 |
66 | PlayVehicleDoorCloseSound(data.entity, 1)
67 |
68 | local soundEvent = data.Status == 2 and "Remote_Control_Close" or "Remote_Control_Fob"
69 |
70 | PlaySoundFromEntity(-1, soundEvent, data.entity, "PI_Menu_Sounds", 1, 0)
71 |
72 | if not inCar then
73 | local pedbone = GetPedBoneIndex(ped, 57005)
74 |
75 | lib.requestModel(KeyAnim.PropKey)
76 |
77 | local prop = CreateObject(KeyAnim.PropKey, 1.0, 1.0, 1.0, true, true, 0)
78 |
79 | AttachEntityToEntity(prop, ped, pedbone, 0.08, 0.039, 0.0, 0.0, 0.0, 0.0, true, true, false, true, 1, true)
80 |
81 | TaskPlayAnim(ped, KeyAnim.dict, KeyAnim.anim, 8.0, 8.0, -1, 48, 0, false, false, false)
82 |
83 | Citizen.Wait(1000)
84 |
85 | DeleteObject(prop)
86 | end
87 | end
88 | end
89 |
90 |
91 | lib.addKeybind({
92 | name = 'Vehicle_doors_control',
93 | description = 'Carkeys',
94 | defaultKey = Config.DoorKeyBind,
95 | onPressed = ToggleVehicleDoors,
96 | })
97 |
98 |
99 |
100 | lib.requestAnimDict(KeyAnim.dict)
101 |
102 |
103 | exports('ItemCarKeysClient', Vehicles.ItemCarKeysClient)
104 | exports('HasKeyClient', Vehicles.HasKeyClient)
105 |
--------------------------------------------------------------------------------
/server/convert.lua:
--------------------------------------------------------------------------------
1 | while not FrameWork do
2 | Wait(100)
3 | end
4 |
5 | if FrameWork ~= 'esx' then return end
6 |
7 |
8 |
9 |
10 | MySQL.ready(function()
11 | MySQL.query("SHOW COLUMNS FROM owned_vehicles LIKE 'keys'", {}, function(result)
12 | if result and #result > 0 then
13 | MySQL.query(
14 | "SELECT plate, metadata, `keys` FROM owned_vehicles WHERE `keys` IS NOT NULL AND TRIM(`keys`) <> ''",
15 | {}, function(vehicles)
16 | if vehicles and #vehicles > 0 then
17 | local pendingUpdates = #vehicles
18 | for _, vehicle in ipairs(vehicles) do
19 | local plate = vehicle.plate
20 | local metadata = vehicle.metadata and json.decode(vehicle.metadata) or {}
21 | local keys = json.decode(vehicle.keys)
22 |
23 | if keys then
24 | metadata.keys = keys
25 |
26 | MySQL.update(
27 | "UPDATE owned_vehicles SET metadata = ? WHERE plate = ?",
28 | { json.encode(metadata), plate },
29 | function(affectedRows)
30 | pendingUpdates = pendingUpdates - 1
31 | if pendingUpdates == 0 and true then
32 | MySQL.query("ALTER TABLE owned_vehicles DROP COLUMN `keys`")
33 | end
34 | end
35 | )
36 | end
37 | end
38 | else
39 | if true then
40 | MySQL.query("ALTER TABLE owned_vehicles DROP COLUMN `keys`")
41 | end
42 | end
43 | end)
44 | end
45 | end)
46 |
47 | MySQL.query("SHOW COLUMNS FROM owned_vehicles LIKE 'coords'", {}, function(result)
48 | if result and #result > 0 then
49 | MySQL.query(
50 | "SELECT plate, metadata, coords FROM owned_vehicles WHERE coords IS NOT NULL AND TRIM(coords) <> ''",
51 | {}, function(vehicles)
52 | if vehicles and #vehicles > 0 then
53 | local pendingUpdates = #vehicles
54 |
55 | for _, vehicle in ipairs(vehicles) do
56 | local plate = vehicle.plate
57 | local metadata = vehicle.metadata and json.decode(vehicle.metadata) or {}
58 | local coords = json.decode(vehicle.coords)
59 |
60 | if coords then
61 | metadata.coords = coords
62 |
63 | MySQL.update(
64 | "UPDATE owned_vehicles SET metadata = ? WHERE plate = ?",
65 | { json.encode(metadata), plate },
66 | function(affectedRows)
67 | pendingUpdates = pendingUpdates - 1
68 | if pendingUpdates == 0 and true then
69 | MySQL.query("ALTER TABLE owned_vehicles DROP COLUMN `coords`")
70 | end
71 | end
72 | )
73 | end
74 | end
75 | else
76 | if true then
77 | MySQL.query("ALTER TABLE owned_vehicles DROP COLUMN `coords`")
78 | end
79 | end
80 | end)
81 | end
82 | end)
83 | end)
84 |
--------------------------------------------------------------------------------
/shared/utils.lua:
--------------------------------------------------------------------------------
1 | Utils = {}
2 |
3 | ---@param type "debug"|"error"|"info"|"verbose"|"warn"
4 | ---@param text string
5 | ---@param ... any
6 | function Utils.Debug(type, text, ...)
7 | if not Config.Debug then return end
8 | lib.print[type](text:format(...))
9 | end
10 |
11 | -- Notifications
12 | function Utils.Notification(data)
13 | lib.notify({
14 | title = data.title,
15 | description = data.description,
16 | position = data.position or 'center-left',
17 | icon = data.icon or 'ban',
18 | type = data.type or 'warning',
19 | iconAnimation = data.iconAnimation or 'beat',
20 | iconColor = data.iconColor or '#C53030',
21 | duration = data.duration or 2000,
22 | showDuration = true,
23 | })
24 | end
25 |
26 | RegisterNetEvent('mVehicle:Notification', Utils.Notification)
27 |
28 | -- Get Vector4 from entity
29 | ---@param entity any
30 | ---@param encode? boolean return json string
31 | function Utils.GetVector4(entity, encode)
32 | local c, h = GetEntityCoords(entity), GetEntityHeading(entity)
33 | local coords = vec4(c.x, c.y, c.z, h)
34 | if encode then return json.encode(coords) end
35 | return coords
36 | end
37 |
38 | ---CreateVehicleServer
39 | function Utils.CreateVehicleServer(type, model, coords)
40 | if not IsDuplicityVersion() then
41 | return Utils.Debug('error', 'This function only works on server side')
42 | end
43 |
44 | local entity = CreateVehicleServerSetter(model, type, coords.x, coords.y, coords.z, coords.w)
45 | -- https://docs.fivem.net/natives/?_0x489E9162
46 | SetEntityOrphanMode(entity, 2)
47 |
48 | local validEntity = lib.waitFor(function()
49 | if DoesEntityExist(entity) then
50 | return entity
51 | end
52 | end, 'Invalid entity', 5000)
53 |
54 | return validEntity
55 | end
56 |
57 | ---Get Vehicle Type
58 | function Utils.VehicleType(value)
59 | if not IsDuplicityVersion() then
60 | return Utils.Debug('error', 'This function only works on server side')
61 | end
62 |
63 | if DoesEntityExist(value) then
64 | return GetVehicleType(value)
65 | end
66 |
67 | local tempVehicle = CreateVehicle(value, 0, 0, 0, 0, true, true)
68 |
69 | local validEntity = lib.waitFor(function()
70 | if DoesEntityExist(tempVehicle) then return tempVehicle end
71 | end, 'Invalid entity', 5000)
72 |
73 | local vehicleType = GetVehicleType(validEntity)
74 |
75 | DeleteEntity(validEntity)
76 |
77 | return vehicleType
78 | end
79 |
80 | --Get Player keys
81 | function Utils.KeyItem(plate)
82 | local havekey = false
83 |
84 | plate = plate:gsub("%s+", "")
85 |
86 | if Config.Inventory == 'ox' then
87 | local item = exports.ox_inventory:Search('slots', Config.CarKeyItem)
88 | for _, v in pairs(item) do
89 | if v.metadata and v.metadata.plate and v.metadata.plate:gsub("%s+", "") == plate then
90 | havekey = true
91 | break
92 | end
93 | end
94 | elseif Config.Inventory == 'qs' then
95 | local items = exports['qs-inventory']:getUserInventory()
96 | for _, v in pairs(items) do
97 | if v.info and v.info.plate and v.info.plate:gsub("%s+", "") == plate then
98 | havekey = true
99 | break
100 | end
101 | end
102 | end
103 |
104 | return havekey
105 | end
106 |
107 | function Utils.Round(value)
108 | local mult = 10 ^ (2 or 0)
109 | return math.floor(value * mult + 0.5) / mult
110 | end
111 |
112 | ---@param eventName string
113 | ---@param funct function
114 | function RegisterSafeEvent(eventName, funct)
115 | RegisterNetEvent(eventName, function(...)
116 | if GetInvokingResource() ~= nil then return end
117 | funct(...)
118 | end)
119 | end
120 |
--------------------------------------------------------------------------------
/server/main.lua:
--------------------------------------------------------------------------------
1 | local GetEntityType = GetEntityType
2 | local GetIsVehicleEngineRunning = GetIsVehicleEngineRunning
3 | local DoesEntityExist = DoesEntityExist
4 |
5 | local PlateCron = {}
6 |
7 | function DeleteTemporary(plate, hour, min)
8 | if PlateCron[plate] then return end
9 |
10 | local expression = ('%s %s * * *'):format(min, hour)
11 |
12 | lib.cron.new(expression, function(task, date)
13 | PlateCron[plate] = false
14 |
15 | MySQL.execute(Querys.deleteByPlate, { plate })
16 |
17 | local vehicle = Vehicles.GetVehicleByPlate(plate)
18 |
19 | if vehicle then vehicle.DeleteVehicle(false) end
20 |
21 | task:stop()
22 | end, { debug = Config.Debug })
23 |
24 | PlateCron[plate] = true
25 | end
26 |
27 | function CheckTemporary(data)
28 | if data.metadata.temporary then
29 | local datetime = data.metadata.temporary
30 | local date = datetime:sub(1, 8)
31 | local time = datetime:sub(10)
32 | local actualtime = os.time()
33 |
34 | local current_date = os.date('%Y%m%d', actualtime)
35 | local current_hour = os.date('%H', actualtime)
36 | local current_minute = os.date('%M', actualtime)
37 |
38 | local metadata_hour = tonumber(time:sub(1, 2))
39 | local metadata_minute = tonumber(time:sub(4))
40 |
41 | if current_date == date then
42 | if tonumber(current_hour) > metadata_hour or tonumber(current_minute) > metadata_minute then
43 | MySQL.execute(Querys.deleteByPlate, { data.plate })
44 | if DoesEntityExist(data.entity) then
45 | DeleteEntity(data.entity)
46 | end
47 | Vehicles.Vehicles[data.entity] = nil
48 | return true
49 | else
50 | DeleteTemporary(data.plate, metadata_hour, metadata_minute)
51 | return false
52 | end
53 | end
54 | end
55 | return false
56 | end
57 |
58 | lib.callback.register('mVehicle:VehicleState', function(source, action, data)
59 | local vehicle = nil
60 |
61 | if data and data.plate then
62 | vehicle = Vehicles.GetVehicleByPlate(data.plate)
63 | end
64 |
65 | if action == 'update' then
66 | if vehicle then
67 | vehicle.SaveLeftVehicle(data.coords, data.props, data.mileage)
68 | else
69 | local current = Vehicles.GetVehicleByPlate(data.plate, true)
70 |
71 | if not current then return end
72 | local metadata = json.decode(current.metadata) or { keys = {} }
73 |
74 | metadata.coords = json.decode(data.coords)
75 | metadata.mileage = math.floor(data.mileage * 100)
76 | MySQL.update(Querys.saveLeftVehicleMeta, { json.encode(data.props), json.encode(metadata), data.plate })
77 | end
78 | elseif action == 'savetrailer' then
79 | return vehicle and vehicle.CoordsAndProps(data.coords, data.props)
80 | elseif action == 'getkeys' then
81 | return Vehicles.GetAllPlayerVehicles(source, false, false)
82 | elseif action == 'getVeh' then
83 | local veh = Vehicles.GetVehicleByPlate(data.plate)
84 |
85 | if not veh then
86 | veh = Vehicles.GetVehicleByPlate(data.plate, true)
87 | end
88 |
89 | if veh then
90 | if type(veh.metadata) ~= "table" then
91 | veh.metadata = json.decode(veh.metadata)
92 | end
93 | return { vehicle = true, mileage = veh.metadata.mileage or 0 }
94 | else
95 | return false
96 | end
97 | end
98 | end)
99 |
100 | lib.versionCheck('Mono-94/mVehicle')
101 |
102 | if not Config.VehicleDensity.CloseAllVehicles then return end
103 |
104 | -- Close doors on entityCreated
105 | AddEventHandler('entityCreated', function(entity)
106 | if DoesEntityExist(entity) and GetEntityType(entity) == 2 and not GetIsVehicleEngineRunning(entity) then
107 | SetVehicleDoorsLocked(entity, 2)
108 | end
109 | end)
--------------------------------------------------------------------------------
/server/persistent.lua:
--------------------------------------------------------------------------------
1 | local GetPlayers = GetPlayers
2 |
3 | Persistent = {
4 | Debug = false,
5 | -- Refresh CoordsAvailable
6 | WaitRefresh = 10000,
7 | --- Player ped/vehicle culling. No entities will be created on
8 | --- clients outside a ‘focus zone’, which currently is hardcoded to 424 units around a player.
9 | --- (https://docs.fivem.net/docs/scripting-reference/onesync/)
10 | DistanceCooords = 400,
11 | -- Store Avaible zones for spawn
12 | CoordsAvailable = {},
13 | --- Store vehicles awaiting for client focus zone
14 | VehicleAwaiting = {}
15 | }
16 |
17 | local msg = function(msg, ...)
18 | return Persistent.Debug and print((msg):format(...))
19 | end
20 |
21 | local blip = function(id, coords, action, bucket)
22 | return Persistent.Debug and
23 | TriggerClientEvent('mvehicle:persistent:area:debug', -1, id, coords, Persistent.DistanceCooords, action, bucket)
24 | end
25 |
26 | local function check_coord(c1, c2)
27 | return #(vec3(c1.x, c1.y, c1.z) - vec3(c2.x, c2.y, c2.z)) < Persistent.DistanceCooords
28 | end
29 |
30 | function Persistent:SetNew(coords, id, bucket)
31 | Persistent.VehicleAwaiting[id] = { coords = coords, bucket = bucket }
32 | msg('Vehicle id [%s] wait', id)
33 | blip(id, coords, 'add', bucket)
34 | end
35 |
36 | function Persistent:DeletVehicle(id)
37 | if Persistent.VehicleAwaiting[id] then
38 | Persistent.VehicleAwaiting[id] = nil
39 | end
40 | end
41 |
42 | function Persistent:DeleteCoordAvaible(id)
43 | Persistent.CoordsAvaible[id] = nil
44 | end
45 |
46 | function Persistent:CreateVehicle(id, coords)
47 | Vehicles.CreateVehicleId({ id = id, coords = coords })
48 | msg('Vehicle id [%s] spawn correct', id)
49 | blip(id)
50 | Persistent:DeletVehicle(id)
51 | end
52 |
53 | function Persistent:Refresh()
54 | local allPlayers = GetPlayers()
55 | local newCoordsAvaible = {}
56 | for _, src in ipairs(allPlayers) do
57 | local coords = GetEntityCoords(GetPlayerPed(src))
58 | local bucket = GetPlayerRoutingBucket(src)
59 | newCoordsAvaible[src] = { coords = coords, bucket = bucket }
60 | end
61 |
62 | local toRemove = {}
63 | local referenceSet = false
64 | for src1, data1 in pairs(newCoordsAvaible) do
65 | for src2, data2 in pairs(newCoordsAvaible) do
66 | if src1 ~= src2 and data1.bucket == data2.bucket and check_coord(data1.coords, data2.coords) then
67 | if not referenceSet then
68 | referenceSet = true
69 | else
70 | toRemove[src2] = true
71 | end
72 | end
73 | end
74 | end
75 |
76 | for src in pairs(toRemove) do
77 | newCoordsAvaible[src] = nil
78 | end
79 |
80 | Persistent.CoordsAvaible = newCoordsAvaible
81 |
82 | if next(Persistent.VehicleAwaiting) ~= nil then
83 | Persistent:VehiclesAwaiting()
84 | end
85 | end
86 |
87 | function Persistent:Set(coords, id, bucket)
88 | local tooClose = false
89 | if not coords then
90 | msg('[ERROR] Vehicle ID:%s, invalid COORDS', id)
91 | end
92 |
93 | if next(Persistent.CoordsAvaible) then
94 | for _, data in pairs(Persistent.CoordsAvaible) do
95 | if data.bucket == bucket and check_coord(coords, data.coords) then
96 | tooClose = true
97 | break
98 | end
99 | end
100 | end
101 |
102 | if not tooClose then
103 | Persistent:SetNew(coords, id, bucket)
104 | else
105 | Persistent:CreateVehicle(id, coords)
106 | end
107 |
108 | return tooClose
109 | end
110 |
111 | function Persistent:VehiclesAwaiting()
112 | for id, data in pairs(Persistent.VehicleAwaiting) do
113 | local canSpawn = false
114 | for _, playerData in pairs(Persistent.CoordsAvaible) do
115 | if data.bucket == playerData.bucket and check_coord(data.coords, playerData.coords) then
116 | canSpawn = true
117 | break
118 | end
119 | end
120 |
121 | if canSpawn then
122 | Persistent:CreateVehicle(id, data.coords)
123 | end
124 | end
125 | end
126 |
127 | exports('RefreshAwait', function()
128 | Citizen.CreateThread(function(threadId)
129 | Wait(2000)
130 | Persistent:Refresh()
131 | end)
132 | end)
133 |
134 | Citizen.CreateThread(function()
135 | while true do
136 | Persistent:Refresh()
137 | Citizen.Wait(Persistent.WaitRefresh)
138 | end
139 | end)
140 |
141 | AddEventHandler('playerDropped', function(playerId)
142 | Persistent:DeleteCoordAvaible(playerId)
143 | end)
144 |
--------------------------------------------------------------------------------
/resources/vehicleSteal/server.lua:
--------------------------------------------------------------------------------
1 | -- Optimized Lockpick
2 | exports('lockpick', function(event, item, inventory, slot, data)
3 | if event ~= 'usingItem' then return end
4 |
5 | local player = GetPlayerPed(inventory.id)
6 | local coords = GetEntityCoords(player)
7 | local vehicleEntity = lib.getClosestVehicle(coords, 5.0, true)
8 | if not vehicleEntity then return end
9 |
10 | local vehicle = Vehicles.GetVehicle(vehicleEntity)
11 | local doorStatus = GetVehicleDoorLockStatus(vehicleEntity)
12 |
13 | local newStatus = (doorStatus == 2) and 0 or 2
14 | local icon, color = (newStatus == 0) and 'lock-open' or 'lock', (newStatus == 0) and '#77e362' or '#e36462'
15 |
16 | local skillCheck = lib.callback.await('mVehicle:PlayerItems', inventory.id, 'lockpick', NetworkGetNetworkIdFromEntity(vehicleEntity))
17 | if not skillCheck then return false end
18 |
19 | if vehicle then
20 | vehicle.SetMetadata('DoorStatus', newStatus)
21 | end
22 |
23 | SetVehicleDoorsLocked(vehicleEntity, newStatus)
24 |
25 | TriggerClientEvent('mVehicle:Notification', source, {
26 | title = 'Vehiculo',
27 | description = locale(newStatus == 0 and 'open_door' or 'close_door'),
28 | icon = icon,
29 | iconColor = color
30 | })
31 | end)
32 |
33 |
34 | --HotWire
35 | exports('hotwire', function(event, item, inventory, slot, data)
36 | if event == 'usingItem' then
37 | lib.callback.await('mVehicle:PlayerItems', inventory.id, 'hotwire')
38 | return false
39 | end
40 | end)
41 |
42 |
43 |
44 | -- Fake Plate
45 | exports('fakeplate', function(event, item, inventory, slot, data)
46 | if event == 'usingItem' then
47 | local player = GetPlayerPed(inventory.id)
48 | local coords = GetEntityCoords(player)
49 | local identifier = Identifier(inventory.id)
50 | local vehicles = lib.getClosestVehicle(coords, 5.0, true)
51 | local vehicle = Vehicles.GetVehicle(vehicles)
52 | local itemSlot = exports.ox_inventory:GetSlot(inventory.id, slot)
53 | if vehicle then
54 | if vehicle.owner == identifier then
55 | local metadata = vehicle.GetMetadata('fakeplate')
56 | if not metadata and not itemSlot.metadata.plate then
57 | local anim = lib.callback.await('mVehicle:PlayerItems', inventory.id, 'changeplate')
58 | if anim then
59 | exports.ox_inventory:SetMetadata(inventory.id, slot,
60 | {
61 | label = locale('fakeplate3'),
62 | plate = vehicle.plate,
63 | description = vehicle.plate,
64 | fakeplate = itemSlot.metadata.fakeplate
65 | })
66 | SetVehicleNumberPlateText(vehicles, itemSlot.metadata.fakeplate)
67 | vehicle.FakePlate(itemSlot.metadata.fakeplate)
68 |
69 | exports.ox_inventory:UpdateVehicle(vehicle.plate, itemSlot.metadata.fakeplate)
70 |
71 | return false
72 | end
73 | elseif vehicle.plate == itemSlot.metadata.plate then
74 | local anim = lib.callback.await('mVehicle:PlayerItems', inventory.id, 'changeplate')
75 | if anim then
76 | SetVehicleNumberPlateText(vehicles, vehicle.plate)
77 |
78 | vehicle.FakePlate()
79 |
80 | exports.ox_inventory:SetMetadata(inventory.id, slot,
81 | {
82 | description = itemSlot.metadata.fakeplate,
83 | fakeplate = itemSlot.metadata.fakeplate
84 | })
85 |
86 | exports.ox_inventory:UpdateVehicle(vehicle.plate, itemSlot.metadata.fakeplate)
87 | end
88 | end
89 | else
90 | Notification(inventory.id, {
91 | title = locale('fakeplate1'),
92 | description = locale('fakeplate2'),
93 | icon = 'user',
94 | })
95 | end
96 | else
97 | local plate = GetVehicleNumberPlateText(vehicles)
98 | end
99 |
100 | return
101 | end
102 | end)
103 |
104 | if GetResourceState('ox_inventory') == 'started' then
105 | exports.ox_inventory:registerHook('createItem', function(payload)
106 | local plate = Vehicles.GeneratePlate()
107 | local metadata = payload.metadata
108 | metadata.description = plate
109 | metadata.fakeplate = plate
110 | return metadata
111 | end, {
112 | itemFilter = {
113 | [Config.FakePlateItem.item] = true
114 | }
115 | })
116 | end
117 |
--------------------------------------------------------------------------------
/resources/personalMenu/client.lua:
--------------------------------------------------------------------------------
1 | local getVehicles = function()
2 | local cars = {}
3 |
4 | local data = lib.callback.await('mVehicle:VehicleState', false, 'getkeys')
5 |
6 | if #data == 0 then
7 | return Utils.Notification({
8 | title = locale('carkey_menu1'),
9 | description = locale('carkey_menu2'),
10 |
11 | })
12 | end
13 |
14 | for i = 1, #data do
15 | local row = data[i]
16 | local props = json.decode(row.vehicle)
17 |
18 | row.metadata = json.decode(row.metadata)
19 | row.vehlabel = Vehicles.GetVehicleLabel(props.model)
20 | row.model = GetDisplayNameFromVehicleModel(props.model)
21 |
22 | row.mileage = row.mileage / 100
23 |
24 | if props.bodyHealth and props.engineHealth then
25 | row.engineHealth = props.bodyHealth / 10
26 | row.bodyHealth = props.engineHealth / 10
27 | else
28 | row.engineHealth = 100
29 | row.bodyHealth = 100
30 | end
31 |
32 | cars[row.plate] = row
33 | end
34 |
35 | return cars
36 | end
37 |
38 |
39 | --- Personal vehicles menu
40 | local menuPromise = nil
41 | local keysmenu = false
42 | ---@param plate? string
43 | ---@param cb? function
44 | function Vehicles.VehicleKeysMenu(plate, cb)
45 | keysmenu = false
46 |
47 | local cars = getVehicles()
48 |
49 | if not cars then return false end
50 |
51 |
52 | if plate then
53 | OpenKeyModal(cars[plate])
54 |
55 |
56 | if cb then
57 | menuPromise = promise:new()
58 | Citizen.Await(menuPromise)
59 | cb()
60 | end
61 | else
62 | keysmenu = true
63 | SendNUI('vehicleKeys', cars)
64 | ShowNui('setVisibleMenu', true)
65 | end
66 | end
67 |
68 | RegisterNuiCallback('ui:Close', function(data, cb)
69 | ShowNui(data.name, false)
70 | if data.name == 'setVisibleMenu' then
71 | keysmenu = false
72 | elseif data.name == 'setVisibleModal' then
73 | if keysmenu then Vehicles.VehicleKeysMenu() end
74 | if menuPromise then
75 | menuPromise:resolve()
76 | end
77 | end
78 | cb(true)
79 | end)
80 |
81 | function OpenKeyModal(vehicle)
82 | SendNUI('manageKey', vehicle)
83 | ShowNui('setVisibleModal', true)
84 | end
85 |
86 | RegisterNuiCallback('show:VehicleKeys', function(data, cb)
87 | OpenKeyModal(data)
88 | cb(true)
89 | end)
90 |
91 | RegisterNuiCallback('mVehicle:VehicleMenu_ui', function(data, cb)
92 | local ret = lib.callback.await('mVehicle:VehicleMenu', false, data.action, data.data, data.key)
93 | cb(ret)
94 | end)
95 |
96 | RegisterNuiCallback('mVehicle:VehicleMenu_ui:setGPS', function(plate, cb)
97 | local ret = Vehicles.BlipOwnerCar(plate)
98 | cb(ret)
99 | end)
100 |
101 |
102 | exports('VehicleKeysMenu', Vehicles.VehicleKeysMenu)
103 |
104 | if Config.PersonalVehicleMenu then
105 | if Config.OpenPersonalMenu == 'radialmenu' then
106 | lib.addRadialItem({
107 | {
108 | id = 'vehicle_keys_menu',
109 | label = 'Your Vehicles',
110 | icon = 'car',
111 | onSelect = Vehicles.VehicleKeysMenu
112 | }
113 | })
114 | elseif Config.OpenPersonalMenu[1] == 'keybind' then
115 | lib.addKeybind({
116 | name = 'mVehiclePersonalMenu',
117 | description = ('To see your vehicles.'):format(Config.OpenPersonalMenu[2]),
118 | defaultKey = Config.OpenPersonalMenu[2],
119 | onPressed = function ()
120 | Vehicles.VehicleKeysMenu()
121 | end,
122 |
123 | })
124 | end
125 | end
126 |
127 | local blip = nil
128 | local timer
129 |
130 | function Vehicles.BlipOwnerCar(plate)
131 | local vehicle = lib.callback.await('mVehicle:VehicleMenu', false, 'setBlip', { plate = plate })
132 |
133 | if not vehicle then return false end
134 |
135 | if blip and DoesBlipExist(blip) then
136 | RemoveBlip(blip)
137 | SetBlipRoute(blip, false)
138 | timer:forceEnd(false)
139 | end
140 |
141 | local vehLabel = Vehicles.GetVehicleLabel(vehicle.model)
142 |
143 | blip = AddBlipForCoord(vehicle.coords.x, vehicle.coords.y, vehicle.coords.z)
144 |
145 | SetBlipSprite(blip, 523)
146 | SetBlipDisplay(blip, 2)
147 | SetBlipScale(blip, 1.0)
148 | SetBlipColour(blip, 49)
149 | SetBlipAsShortRange(blip, false)
150 | BeginTextCommandSetBlipName("STRING")
151 | AddTextComponentString(('%s - %s'):format(vehLabel, plate))
152 | EndTextCommandSetBlipName(blip)
153 | SetBlipRoute(blip, true)
154 |
155 | timer = lib.timer(60000 * 2, function()
156 | SetBlipRoute(blip, false)
157 | RemoveBlip(blip)
158 | end, true)
159 |
160 | if blip then
161 | Utils.Notification({
162 | title = 'Vehicles',
163 | description = locale('setBlip'),
164 | type = 'success'
165 | })
166 | return true
167 | end
168 | end
169 |
--------------------------------------------------------------------------------
/shared/config.lua:
--------------------------------------------------------------------------------
1 | --- mVehicle
2 | --- GitHub : https://github.com/Mono-94
3 | --- Discord : https://discord.gg/Vk7eY8xYV2
4 | --- Documents : https://mono-94.github.io/mDocuments/
5 | ----------------------------------------------------------------------
6 | --- Config -----------------------------------------------------------
7 | Config = {}
8 | --- Prints | Some extra dev tools
9 | Config.Debug = false
10 |
11 |
12 | --- Since many people have issues with vehicle properties,
13 | --- I decided to add the following configuration to give better control over how properties are applied.
14 | Config.VehicleProperties = {
15 | stateBag = true, -- Enables the use of a stateBag for applying properties.
16 | StateBagName = 'ox_lib:setVehicleProperties', -- ox_lib = ox_lib:setVehicleProperties | ESX = VehicleProperties
17 | event = false, -- Enables the use of a custom event for applying properties.
18 | eventname = 'ox_lib:setVehicleProperties' -- Default event name (uses ox_lib by default).
19 | --- Example of a Custom Event:
20 | --- RegisterNetEvent('myEventToSetProperties', function(VehicleNetworkId, VehicleProperties, EntityOwner)
21 | --- local entity = VehToNet(VehicleNetworkId)
22 | --- myFunctionToSetProperties(entity, VehicleProperties)
23 | --- end)
24 | }
25 |
26 | --- ox_inventory = 'ox' | qs-inventory = 'qs' not sure if it works
27 | --- check vehicle keys item metadata
28 | Config.Inventory = 'ox'
29 |
30 | --- Enable Bike Helmet
31 | Config.EnableBikeHelmet = true
32 |
33 | --- Personal Vehicle Menu
34 | Config.PersonalVehicleMenu = true
35 | Config.OpenPersonalMenu = { 'keybind', 'F1' } -- 'radialmenu' | {'keybind', 'E'}
36 |
37 | --- Vehicle Density | 0.0 min | 1.0 max - Increases CPU script to 0.01 / 0.02
38 | Config.VehicleDensity = {
39 | CloseAllVehicles = true,
40 | density = true,
41 | VehicleDensity = 0,
42 | RandomVehicleDensity = 0,
43 | ParkedVehicleDensity = 0
44 | }
45 |
46 | --- Persistent
47 | --- Vehicle persistents in world
48 | Config.Persistent = true
49 |
50 | --- Commands
51 | Config.Commands = {
52 | givecar = 'givecar',
53 | setcarowner = 'setcarowner',
54 | saveallcars = 'saveAllcars',
55 | spawnallcars = 'spawnAllcars'
56 | }
57 |
58 | --- Manage tr2 trailer
59 | Config.TargetTrailer = false
60 |
61 | ----------------------------------------------------------------------
62 | --- Carkeys
63 | Config.ItemKeys = false -- false = Vehicles DB
64 |
65 | Config.CarKeyItem = 'carkey' -- item name
66 |
67 | Config.DoorKeyBind = 'U'
68 |
69 | Config.KeyDelay = 500
70 |
71 | Config.KeyDistance = 5
72 |
73 | --- Engine ignition need keys or hotwire
74 | Config.VehicleEngine = {
75 | ToggleEngine = false,
76 | KeyBind = 'M',
77 | keepEngineOnWhenLeave = false,
78 | }
79 | ----------------------------------------------------------------------
80 | -- Seat Shuffle front + back seats | SHIFT + E
81 | Config.SeatShuffle = true
82 | ----------------------------------------------------------------------
83 | -- Try Enter vehicle | Enter closet door
84 | Config.TyrEnter = {
85 | closeEnter = true,
86 | blackListClass = { 14, 15, 16 }
87 | }
88 | ----------------------------------------------------------------------
89 | --- Vehicle Radio
90 | --- xSound Dependency | https://github.com/Xogy/xsound
91 | --- Increases CPU script to 0.04 / 0.06 in use
92 | Config.Radio = {
93 | command = false, -- false or string
94 | KeyBind = false, -- false or string
95 | radial = true, -- true/false
96 | distance = 5, -- distance sound
97 | }
98 |
99 | ----------------------------------------------------------------------
100 | -- Plate
101 | --MAX 8 CHAR
102 | Config.PlateGenerate = ".... ..."
103 | -- . = random number or letter
104 | -- 1 = random number
105 | -- A = random letter
106 | -- SPACE IS A CHAR
107 |
108 |
109 | -- Generate random plate in metadata item, only ox_inventory
110 | Config.FakePlateItem = {
111 | item = 'fakeplate',
112 | ChangePlateTime = 10000 -- in ms
113 | }
114 | ----------------------------------------------------------------------
115 |
116 | ---SetFuel / client side
117 | Config.SetFuel = function(vehicleEntity, fuelLevel)
118 | -- LegacyFuel example
119 | -- exports.LegacyFuel:SetFuel(vehicleEntity, fuelLevel)
120 |
121 | -- Native
122 | -- SetVehicleFuelLevel(vehicleEntity, fuelLevel)
123 | end
124 |
125 |
126 | Config.LockPickItem = {
127 | item = 'lockpick',
128 | skillCheck = function(VehicleEntity, Class)
129 | local dificult = VehicleClass[Class].lockpickDificult
130 | local success = lib.skillCheck(dificult)
131 | return success
132 | end,
133 | dispatch = function(plyServerId, vehicleEntity, coords)
134 | -- print(plyServerId, vehicleEntity, coords)
135 | end
136 | }
137 |
138 | Config.HotWireItem = {
139 | item = 'wirecutt',
140 | skillCheck = function(VehicleEntity, Class)
141 | local dificult = VehicleClass[Class].hotWireDificult
142 | local success = lib.skillCheck(dificult)
143 | return success
144 | end,
145 | dispatch = function(plyServerId, vehicleEntity, coords)
146 | -- print(plyServerId, vehicleEntity, coords)
147 | end
148 | }
149 |
150 | -------------------------------------------------------
151 | Config.VehicleTypes = {
152 | ['car'] = { 'automobile', 'bicycle', 'bike', 'quadbike', 'trailer', 'amphibious_quadbike', 'amphibious_automobile' },
153 | ['boat'] = { 'submarine', 'submarinecar', 'boat' },
154 | ['air'] = { 'blimp', 'heli', 'plane' },
155 | }
156 |
--------------------------------------------------------------------------------
/client/debug.lua:
--------------------------------------------------------------------------------
1 |
2 | local RadiusVehicleCoordsAwaitingClient = {}
3 |
4 | RegisterNetEvent('mvehicle:persistent:area:debug', function(id, coords, dist, action, bucket)
5 | if action == 'add' then
6 | if RadiusVehicleCoordsAwaitingClient[id] then return end
7 | RadiusVehicleCoordsAwaitingClient[id] = {}
8 | RadiusVehicleCoordsAwaitingClient[id].radius = AddBlipForRadius(coords.x, coords.y, coords.z, dist)
9 | SetBlipAlpha(RadiusVehicleCoordsAwaitingClient[id].radius, 50)
10 | SetBlipColour(RadiusVehicleCoordsAwaitingClient[id].radius, bucket == 0 and 11 or 14)
11 | RadiusVehicleCoordsAwaitingClient[id].blip = AddBlipForCoord(coords.x, coords.y, coords.z)
12 | SetBlipSprite(RadiusVehicleCoordsAwaitingClient[id].blip, 11)
13 | SetBlipDisplay(RadiusVehicleCoordsAwaitingClient[id].blip, 4)
14 | SetBlipScale(RadiusVehicleCoordsAwaitingClient[id].blip, 1.0)
15 | SetBlipColour(RadiusVehicleCoordsAwaitingClient[id].blip, bucket == 0 and 11 or 14)
16 | SetBlipAsShortRange(RadiusVehicleCoordsAwaitingClient[id].blip, true)
17 | BeginTextCommandSetBlipName("STRING")
18 | AddTextComponentString(('Vehicle ID [ %s ] | Bucket [ %s ] - Awaiting client in Scope'):format(id, bucket))
19 | EndTextCommandSetBlipName(RadiusVehicleCoordsAwaitingClient[id].blip)
20 | else
21 | if RadiusVehicleCoordsAwaitingClient[id] then
22 | RemoveBlip(RadiusVehicleCoordsAwaitingClient[id].blip)
23 | RemoveBlip(RadiusVehicleCoordsAwaitingClient[id].radius)
24 | RadiusVehicleCoordsAwaitingClient[id] = nil
25 | end
26 | end
27 | end)
28 |
29 | if not Config.Debug then return end
30 |
31 | local EngineSound = {
32 |
33 | --- Vehicle engine sounds from https://www.gta5-mods.com/vehicles/brabus-inspired-custom-engine-sound-add-on-sound
34 | --- only for debugging
35 |
36 | Engines = {
37 | { value = 'brabus850', label = 'Brabus 850 6.0L V8-TT v1.3 (brabus850)' },
38 | { value = 'toysupmk4', label = 'Toyota 2JZ-GTE 3.0L I6-T v1.3 (toysupmk4)' },
39 | { value = 'lambov10', label = 'Audi/Lamborghini 5.2L V10 v1.0 (lambov10)' },
40 | { value = 'rb26dett', label = 'Nissan RB26DETT 2.6L I6-TT v1.2 (rb26dett)' },
41 | { value = 'rotary7', label = 'Mazda 13B-REW 1.3L Twin-Rotor v1.0 (rotary7)' },
42 | { value = 'musv8', label = 'Dragster Twin-Charged V8SCT v1.0 (musv8)' },
43 | { value = 'm297zonda', label = 'Pagani-AMG M297 7.3L V12 v1.0 (m297zonda)' },
44 | { value = 'm158huayra', label = 'Pagani-AMG M158 6.0L V12TT v1.0 (m158huayra)' },
45 | { value = 'k20a', label = 'Honda K20A 2.0L I4 v1.0 (k20a)' },
46 | { value = 'gt3flat6', label = 'Porsche RS 4.0L Flat-6 v1.0 (gt3flat6)' },
47 | { value = 'predatorv8', label = 'Ford-Shelby Predator 5.2L V8SC v1.0 (predatorv8)' }
48 | },
49 |
50 | }
51 |
52 | exports.ox_target:addGlobalVehicle({
53 | {
54 | distance = 10.0,
55 | label = 'Change Sound',
56 | onSelect = function(data)
57 | local input = lib.inputDialog('Vehicle Sound', {
58 | { type = 'select', label = 'Select sound', options = EngineSound.Engines }
59 | })
60 |
61 | if not input then return end
62 |
63 | Vehicles.SetEnGineSound(data.entity, input[1])
64 | end
65 | },
66 | {
67 | distance = 10.0,
68 | label = 'type',
69 | onSelect = function(data)
70 | print(GetVehicleType(data.entity))
71 | end
72 | },
73 | {
74 | distance = 10.0,
75 | label = 'dooors',
76 | onSelect = function(data)
77 | print(GetVehicleDoorLockStatus(data.entity))
78 | end
79 | },
80 | {
81 | distance = 4,
82 | label = 'Set on Ground',
83 | icon = 'fa-solid fa-car',
84 | onSelect = function(data)
85 | local carCoords = GetEntityRotation(data.entity, 2)
86 | SetEntityRotation(data.entity, carCoords[1], 0, carCoords[3], 2, true)
87 | SetVehicleOnGroundProperly(data.entity)
88 | end
89 | },
90 | {
91 | distance = 10.0,
92 | label = 'Vehicle data',
93 | onSelect = function(data)
94 | local VehicleState = Entity(data.entity).state
95 | if VehicleState then
96 | if VehicleState.id then
97 | print(("ID: %s"):format(VehicleState.id))
98 | end
99 |
100 | print(("Plate: %s"):format(VehicleState.plate))
101 |
102 | if VehicleState.owner then
103 | print(("Owner: %s"):format(VehicleState.owner))
104 | end
105 |
106 | print(("Type: %s"):format(VehicleState.type))
107 |
108 | if VehicleState.job then
109 | print(("Job: %s"):format(VehicleState.job))
110 | end
111 |
112 | print(("Fuel Level: %s"):format(VehicleState.fuel))
113 |
114 | if VehicleState.mileage then
115 | print(("Mileage: %s"):format(VehicleState.mileage))
116 | end
117 |
118 | if VehicleState.engineSound then
119 | print(("Engine Sound: %s"):format(VehicleState.engineSound))
120 | end
121 | if VehicleState.metadata then
122 | print(("Metadata: %s"):format(json.encode(VehicleState.metadata, { indent = true })))
123 | end
124 | print(VehicleState.metadata.properties)
125 | print(VehicleState.metadata.parking)
126 | print(VehicleState.metadata.keys)
127 |
128 | --if VehicleState.keys then
129 | -- print(("Keys: %s"):format(json.encode(VehicleState.keys, { indent = true })))
130 | --end
131 | end
132 | end
133 | },
134 | })
135 |
--------------------------------------------------------------------------------
/resources/radioVehicle/server.lua:
--------------------------------------------------------------------------------
1 | if GetResourceState('xsound') ~= 'started' then return end
2 |
3 | RegisterNetEvent("mVehicle:SoundStatus", function(action, data)
4 | TriggerClientEvent("mVehicle:VehicleRadio", -1, action, data)
5 | end)
6 |
7 | lib.callback.register('mVehicle:radio:PlayList', function(source, action, data)
8 | local entity = NetworkGetEntityFromNetworkId(data.networkId)
9 |
10 | local vehicle = Vehicles.GetVehicle(entity)
11 |
12 | if action == 'saveSong' then
13 | if vehicle then
14 | local metadata = vehicle.GetMetadata('radio')
15 |
16 | for _, song in ipairs(metadata.playlist) do
17 | if song.link == data.songLink then
18 | return metadata.playlist
19 | end
20 | end
21 |
22 | table.insert(metadata.playlist, {
23 | name = data.songName,
24 | link = data.songLink,
25 | fav = false,
26 | })
27 |
28 | vehicle.SetMetadata('radio', metadata)
29 |
30 | return metadata.playlist
31 | else
32 | vehicle = Vehicles.GetVehicleByPlate(data.plate, true)
33 |
34 | if vehicle then
35 | local State = Entity(entity).state
36 | local metadata = json.decode(vehicle.metadata)
37 | if metadata and metadata.radio then
38 | for _, song in ipairs(metadata.radio.playlist) do
39 | if song.link == data.songLink then
40 | return metadata.radio.playlist
41 | end
42 | end
43 |
44 | State:set('metadata', metadata)
45 | MySQL.update(Querys.saveMetadata, json.encode(metadata), data.plate)
46 |
47 | return metadata.radio.playlist
48 | end
49 | end
50 | end
51 | elseif action == 'deleteSong' then
52 | if vehicle then
53 | local metadata = vehicle.GetMetadata('radio')
54 |
55 | for i, song in ipairs(metadata.playlist) do
56 | if song.link == data.songLink then
57 | table.remove(metadata.playlist, i)
58 | break
59 | end
60 | end
61 |
62 | vehicle.SetMetadata('radio', metadata)
63 |
64 | return metadata.playlist
65 | else
66 | vehicle = Vehicles.GetVehicleByPlate(data.plate, true)
67 |
68 | if vehicle then
69 | local State = Entity(entity).state
70 | local metadata = json.decode(vehicle.metadata)
71 | if metadata and metadata.radio then
72 | for i, song in ipairs(metadata.radio.playlist) do
73 | if song.link == data.songLink then
74 | table.remove(metadata.radio.playlist, i)
75 | break
76 | end
77 | end
78 |
79 | MySQL.update(Querys.saveMetadata, json.encode(metadata), data.plate)
80 | State:set('metadata', metadata)
81 |
82 | return metadata.radio.playlist
83 | end
84 | end
85 | end
86 | elseif action == 'favSong' then
87 | if vehicle then
88 | local metadata = vehicle.GetMetadata('radio')
89 |
90 | for i, song in ipairs(metadata.playlist) do
91 | if song.link == data.songLink then
92 | song.fav = not song.fav
93 | break
94 | end
95 | end
96 |
97 | vehicle.SetMetadata('radio', metadata)
98 |
99 | return metadata.playlist
100 | else
101 | vehicle = Vehicles.GetVehicleByPlate(data.plate, true)
102 |
103 | if vehicle then
104 | local State = Entity(entity).state
105 | local metadata = json.decode(vehicle.metadata)
106 | if metadata and metadata.radio then
107 | for i, song in ipairs(metadata.radio.playlist) do
108 | if song.link == data.songLink then
109 | table.remove(metadata.radio.playlist, i)
110 | break
111 | end
112 | end
113 |
114 | MySQL.update(Querys.saveMetadata, json.encode(metadata), data.plate)
115 |
116 | State:set('metadata', metadata)
117 | return metadata.radio.playlist
118 | end
119 | end
120 | end
121 | end
122 | end)
123 |
124 |
125 | exports('mradio', function(event, item, inventory, slot, data)
126 | local playerPed = GetPlayerPed(inventory.id)
127 | local entity = GetVehiclePedIsIn(playerPed, false)
128 | local playerSeat = GetPedInVehicleSeat(entity, -1)
129 | local isPedDriver = playerSeat == playerPed
130 | local plate = GetVehicleNumberPlateText(entity)
131 |
132 |
133 | if event == 'usingItem' then
134 | if not isPedDriver then return false end
135 |
136 | local vehicle = Vehicles.GetVehicle(entity)
137 |
138 | if vehicle then
139 | local metadata = vehicle.GetMetadata('radio')
140 |
141 | if metadata and metadata.install then return false end
142 |
143 | vehicle.SetMetadata('radio', { install = true, playlist = {} })
144 |
145 | exports.ox_inventory:RemoveItem(inventory.id, item.name, 1, nil, slot)
146 |
147 | return true
148 | else
149 | vehicle = Vehicles.GetVehicleByPlate(plate, true)
150 |
151 | if vehicle then
152 | local metadata = json.decode(vehicle.metadata)
153 | if not metadata then metadata = {} end
154 | if metadata.radio.install then return end
155 | metadata.radio = { install = true, playlist = {} }
156 | MySQL.update(Querys.saveMetadata, json.encode(metadata), plate)
157 | local State = Entity(entity).state
158 | State:set('metadata', metadata)
159 | exports.ox_inventory:RemoveItem(inventory.id, item.name, 1, nil, slot)
160 |
161 | return true
162 | end
163 | end
164 | end
165 | end)
166 |
--------------------------------------------------------------------------------
/server/framework.lua:
--------------------------------------------------------------------------------
1 | local FrameWorks = {
2 | esx = (GetResourceState("es_extended") == "started" and 'esx'),
3 | ox = (GetResourceState("ox_core") == "started" and 'ox'),
4 | qbx = (GetResourceState("qbx_core") == "started" and 'qbx')
5 | }
6 |
7 | FrameWork = FrameWorks.esx or FrameWorks.ox or FrameWorks.qbx or 'standalone'
8 |
9 | ESX, Ox = nil, nil
10 |
11 | if FrameWork == "esx" then
12 | ESX = exports["es_extended"]:getSharedObject()
13 | end
14 |
15 |
16 | function Notification(src, data)
17 | TriggerClientEvent('mVehicle:Notification', src, data)
18 | end
19 |
20 |
21 | function Identifier(src)
22 | if FrameWork == "esx" then
23 | local Player = ESX.GetPlayerFromId(src)
24 | if Player then
25 | return Player.identifier
26 | end
27 | elseif FrameWork == "qbx" then
28 | local Player = exports.qbx_core:GetPlayer(src)
29 | if Player then
30 | return Player.PlayerData.citizenid, Player.PlayerData.license
31 | end
32 | elseif FrameWork == "standalone" then
33 | return GetPlayerIdentifier(src, 'license')
34 | end
35 | end
36 |
37 |
38 | function GetName(src)
39 | if FrameWork == "esx" then
40 | local xPlayer = ESX.GetPlayerFromId(src)
41 | if xPlayer then
42 | return xPlayer.getName()
43 | end
44 | elseif FrameWork == "qbx" then
45 | local qbxPlayer = exports.qbx_core:GetPlayer(src)
46 | if qbxPlayer then
47 | return ('%s %s'):format(qbxPlayer.PlayerData.charinfo.firstname, qbxPlayer.PlayerData.charinfo.lastname)
48 | end
49 | elseif FrameWork == "standalone" then
50 | return GetPlayerName(src)
51 | end
52 | end
53 |
54 | function GetCoords(src, veh)
55 | local entity = src and GetPlayerPed(src) or veh
56 | if not DoesEntityExist(entity) then return end
57 | local coords, heading = GetEntityCoords(entity), GetEntityHeading(entity)
58 | return { x = coords.x, y = coords.y, z = coords.z, w = heading }
59 | end
60 |
61 | -- StandAlone uses the same table as esx
62 | local db = {
63 | ['esx'] = {
64 | getVehicleById = 'SELECT * FROM `owned_vehicles` WHERE `id` = ? LIMIT 1',
65 | getVehicleByPlate = 'SELECT * FROM `owned_vehicles` WHERE TRIM(`plate`) = TRIM(?) LIMIT 1',
66 | getVehicleByPlateOrFakeplate ="SELECT * FROM `owned_vehicles` WHERE TRIM(`plate`) = TRIM(?) OR JSON_UNQUOTE(JSON_EXTRACT(`metadata`, '$.fakeplate')) = TRIM(?) LIMIT 1",
67 | setOwner = 'INSERT INTO `owned_vehicles` (owner, plate, vehicle, type, job, metadata) VALUES (?, ?, ?, ?, ?, ?)',
68 | setOwnerParking ='INSERT INTO `owned_vehicles` (owner, plate, vehicle, type, job, metadata, parking) VALUES (?, ?, ?, ?, ?, ?, ?)',
69 | deleteByPlate = 'DELETE FROM `owned_vehicles` WHERE TRIM(`plate`) = TRIM(?)',
70 | deleteById = 'DELETE FROM `owned_vehicles` WHERE `id` = ?',
71 | saveMetadata = 'UPDATE `owned_vehicles` SET `metadata` = ? WHERE TRIM(`plate`) = TRIM(?)',
72 | saveMetadataId = 'UPDATE `player_vehicles` SET `metadata` = ? WHERE `id` = ?',
73 | saveProps = 'UPDATE `owned_vehicles` SET `vehicle` = ? WHERE TRIM(`plate`) = TRIM(?)',
74 | storeGarage ='UPDATE `owned_vehicles` SET `parking` = ?, `stored` = 1, `vehicle` = ?, `metadata` = ? WHERE TRIM(`plate`) = TRIM(?)',
75 | retryGarage = 'UPDATE `owned_vehicles` SET `stored` = 0 WHERE TRIM(`plate`) = TRIM(?)',
76 | setImpound = 'UPDATE `owned_vehicles` SET `parking` = ?, `stored` = 0, `pound` = 1 WHERE TRIM(`plate`) = TRIM(?)',
77 | retryImpound ='UPDATE `owned_vehicles` SET `stored` = 0, `parking` = ?, `pound` = NULL WHERE TRIM(`plate`) = TRIM(?)',
78 | saveLeftVehicle = 'UPDATE `owned_vehicles` SET `vehicle` = ? WHERE TRIM(`plate`) = TRIM(?)',
79 | saveLeftVehicleMeta ='UPDATE `owned_vehicles` SET `vehicle` = ?, `metadata` = ? WHERE TRIM(`plate`) = TRIM(?)',
80 | plateExist = 'SELECT 1 FROM `owned_vehicles` WHERE TRIM(`plate`) = TRIM(?)',
81 | saveAllPropsCoords = 'UPDATE `owned_vehicles` SET `vehicle` = ?, `metadata` = ? WHERE TRIM(`plate`) = TRIM(?)',
82 | getVehiclesbyOwner = "SELECT * FROM `owned_vehicles` WHERE `owner` = ?",
83 | getVehiclesbyOwnerAndhaveKeys ="SELECT * FROM `owned_vehicles` WHERE `owner` = ? OR JSON_KEYS(metadata, '$.keys') LIKE ?",
84 | selectAll = 'SELECT * FROM `owned_vehicles`',
85 | setVehicleJob = 'UPDATE `owned_vehicles` SET `job` = ? WHERE TRIM(`plate`) = TRIM(?)',
86 | },
87 |
88 | ['qbx'] = {
89 | getVehicleById = 'SELECT * FROM `player_vehicles` WHERE `id` = ? LIMIT 1',
90 | getVehicleByPlate = 'SELECT * FROM `player_vehicles` WHERE TRIM(`plate`) = TRIM(?) LIMIT 1',
91 | getVehicleByPlateOrFakeplate ="SELECT * FROM `player_vehicles` WHERE TRIM(`plate`) = TRIM(?) OR JSON_UNQUOTE(JSON_EXTRACT(`metadata`, '$.fakeplate')) = TRIM(?) LIMIT 1",
92 | setOwner = 'INSERT INTO `player_vehicles` (citizenid, plate, mods, type, job, metadata, license) VALUES (?, ?, ?, ?, ?, ?, ?)',
93 | setOwnerParking ='INSERT INTO `player_vehicles` (citizenid, plate, mods, type, job, metadata, garage, license) VALUES (?, ?, ?, ?, ?, ?, ?,?)',
94 | deleteByPlate = 'DELETE FROM `player_vehicles` WHERE TRIM(`plate`) = TRIM(?)',
95 | deleteById = 'DELETE FROM `player_vehicles` WHERE `id` = ?',
96 | saveMetadata = 'UPDATE `player_vehicles` SET `metadata` = ? WHERE TRIM(`plate`) = TRIM(?)',
97 | saveMetadataId = 'UPDATE `player_vehicles` SET `metadata` = ? WHERE `id` = ?',
98 | saveProps = 'UPDATE `player_vehicles` SET `mods` = ? WHERE TRIM(`plate`) = TRIM(?)',
99 | storeGarage ='UPDATE `player_vehicles` SET `garage` = ?, `stored` = 1, `mods` = ?, `metadata` = ? WHERE TRIM(`plate`) = TRIM(?)',
100 | retryGarage = 'UPDATE `player_vehicles` SET `stored` = 0 WHERE TRIM(`plate`) = TRIM(?)',
101 | setImpound ='UPDATE `player_vehicles` SET `garage` = ?, `stored` = 0, `pound` = 1 WHERE TRIM(`plate`) = TRIM(?)',
102 | retryImpound ='UPDATE `player_vehicles` SET `stored` = 0, `garage` = ?, `pound` = NULL WHERE TRIM(`plate`) = TRIM(?)',
103 | saveLeftVehicle = 'UPDATE `player_vehicles` SET `mods` = ? WHERE TRIM(`plate`) = TRIM(?)',
104 | saveLeftVehicleMeta = 'UPDATE `player_vehicles` SET `mods` = ?, `metadata` = ? WHERE TRIM(`plate`) = TRIM(?)',
105 | plateExist = 'SELECT 1 FROM `player_vehicles` WHERE TRIM(`plate`) = TRIM(?)',
106 | saveAllPropsCoords = 'UPDATE `player_vehicles` SET `mods` = ?, `metadata` = ? WHERE TRIM(`plate`) = TRIM(?)',
107 | getVehiclesbyOwner = "SELECT * FROM `player_vehicles` WHERE `citizenid` = ?",
108 | getVehiclesbyOwnerAndhaveKeys = "SELECT * FROM `player_vehicles` WHERE `citizenid` = ? OR JSON_KEYS(metadata, '$.keys') LIKE ?",
109 | selectAll = 'SELECT * FROM `player_vehicles`',
110 | setVehicleJob = 'UPDATE `player_vehicles` SET `job` = ? WHERE TRIM(`plate`) = TRIM(?)',
111 | },
112 | }
113 |
114 |
115 | Querys = db[FrameWork]
116 |
--------------------------------------------------------------------------------
/resources/radioVehicle/client.lua:
--------------------------------------------------------------------------------
1 | if GetResourceState('xsound') ~= 'started' then return end
2 |
3 | local xSound = exports.xsound
4 | local radioOpen = false
5 | local Radio = {}
6 |
7 | AddEventHandler('onResourceStop', function(rsc)
8 | if rsc == GetCurrentResourceName() then
9 | LocalPlayer.state.invBusy = false
10 | end
11 | end)
12 |
13 | function Radio:PlayList(playlist)
14 | SendNUIMessage({ action = 'playList', data = playlist })
15 | end
16 |
17 | function Radio:Data(data)
18 | SendNUIMessage({ action = 'radioData', data = data })
19 | end
20 |
21 | function Radio:Visible(visible)
22 | SetNuiFocus(visible, visible)
23 | SendNUIMessage({ action = 'radio', data = visible })
24 | radioOpen = visible
25 | LocalPlayer.state.invBusy = visible
26 | end
27 |
28 | function Radio:Vehicle(vehicle)
29 | SendNUIMessage({ action = 'radioVehicle', data = vehicle })
30 | end
31 |
32 | RegisterNetEvent("mVehicle:VehicleRadio", function(action, data)
33 | local exist = xSound:soundExists(data.plate)
34 |
35 | if action == "play" then
36 | local Vehicle = NetToVeh(data.networkId)
37 | local coords = GetEntityCoords(Vehicle)
38 | xSound:PlayUrlPos(data.plate, data.link, data.volume, coords)
39 | xSound:Distance(data.plate, data.distance)
40 | xSound:destroyOnFinish(data.plate, true)
41 | xSound:onPlayStart(data.plate, function()
42 | Citizen.CreateThread(function()
43 | while true do
44 | Citizen.Wait(0)
45 | if xSound:soundExists(data.plate) then
46 | coords = GetEntityCoords(Vehicle)
47 | xSound:Position(data.plate, vec3(coords.xyz))
48 | end
49 | if not DoesEntityExist(Vehicle) then
50 | xSound:Destroy(data.plate)
51 | break
52 | end
53 | end
54 | end)
55 | end)
56 | elseif action == "vol" and exist then
57 | xSound:setVolume(data.plate, data.volume)
58 | elseif action == "time" and exist then
59 | xSound:setTimeStamp(data.plate, data.timeStamp)
60 | elseif action == "pause" and exist then
61 | xSound:Pause(data.plate)
62 | elseif action == "resume" and exist then
63 | xSound:Resume(data.plate)
64 | elseif action == "destroy" and exist then
65 | xSound:Destroy(data.plate)
66 | end
67 | end)
68 |
69 |
70 | function OpenRadio()
71 | local data = {}
72 |
73 | data.entity = GetVehiclePedIsIn(cache.ped, false)
74 |
75 | if not DoesEntityExist(data.entity) then
76 | return Utils.Debug('info', 'no Vehicle Entity to play Sound')
77 | end
78 |
79 | data.networkId = VehToNet(data.entity)
80 |
81 | data.plate = GetVehicleNumberPlateText(data.entity)
82 |
83 | local metadata = Entity(data.entity).state.metadata
84 |
85 | local haveRadio = metadata.radio
86 | data.id = data.plate
87 |
88 | if haveRadio and haveRadio.install then
89 | Radio:Vehicle({ entity = data.entity, networkId = data.networkId, plate = data.plate })
90 |
91 | local current = xSound:getInfo(data.plate)
92 |
93 | if current then
94 | data.url = current.url
95 | data.timeStamp = current.timeStamp
96 | data.id = current.id
97 | data.soundExists = current.soundExists
98 | data.playing = current.playlist
99 | data.paused = current.paused
100 | data.maxDuration = current.maxDuration
101 | data.volume = current.volume
102 | end
103 |
104 |
105 | Radio:Data(data)
106 | Wait(200)
107 | Radio:PlayList(haveRadio.playlist)
108 | Radio:Visible(true)
109 |
110 | RadioOpen(data.plate)
111 | end
112 | end
113 |
114 | function RadioOpen(plate)
115 | local current = xSound:getInfo(plate)
116 |
117 | SetNuiFocusKeepInput(true)
118 |
119 | while radioOpen do
120 | current = xSound:getInfo(plate)
121 | if current then
122 | Radio:Data(current)
123 | end
124 |
125 | DisableControlAction(0, 1, true)
126 | DisableControlAction(0, 2, true)
127 | DisableFrontendThisFrame()
128 |
129 | if not radioOpen then
130 | Radio:Data(false)
131 | SetNuiFocusKeepInput(false)
132 |
133 | break
134 | end
135 | Citizen.Wait(0)
136 | end
137 | end
138 |
139 | RegisterNuiCallback('radioNui', function(data, cb)
140 | if data.action == 'saveSong' or data.action == 'deleteSong' or data.action == 'favSong' then
141 | local song = lib.callback.await('mVehicle:radio:PlayList', 500, data.action, data)
142 | if song then
143 | local metadata = Entity(data.entity).state.metadata
144 | Radio:PlayList(metadata.radio.playlist)
145 | end
146 | cb(song)
147 | return
148 | end
149 |
150 | if data.action == 'play' then
151 | data.volume = data.volume / 100.0
152 |
153 | data.distance = Config.Radio.distance
154 |
155 | data.entity = GetVehiclePedIsIn(cache.ped, false)
156 |
157 | if not DoesEntityExist(data.entity) then
158 | return
159 | end
160 |
161 | local plate = GetVehicleNumberPlateText(data.entity)
162 |
163 | if plate == data.plate then
164 | data.networkId = VehToNet(data.entity)
165 | TriggerServerEvent("mVehicle:SoundStatus", data.action, data)
166 | Citizen.Wait(100)
167 | RadioOpen(plate)
168 | end
169 | elseif data.action == 'close' then
170 | Radio:Visible(false)
171 | else
172 | if xSound:soundExists(data.plate) then
173 | if data.volume then
174 | data.volume = data.volume / 100.0
175 | end
176 | end
177 |
178 | TriggerServerEvent("mVehicle:SoundStatus", data.action, data)
179 | end
180 |
181 | cb(':)')
182 | end)
183 |
184 |
185 | if Config.Radio.command then
186 | RegisterCommand(Config.Radio.command, OpenRadio)
187 | end
188 |
189 | lib.onCache('seat', function(value)
190 | if value == -1 then
191 | if Config.Radio.radial then
192 | local metadata = Entity(cache.vehicle).state.metadata
193 | if not metadata then return end
194 | local haveRadio = metadata.radio
195 |
196 | if haveRadio and haveRadio.install then
197 | lib.addRadialItem({
198 | {
199 | id = 'vehicle_radio',
200 | label = 'Radio',
201 | icon = 'radio',
202 | onSelect = OpenRadio
203 | },
204 |
205 | })
206 | end
207 | end
208 | else
209 | if radioOpen then
210 | Radio:Visible(false)
211 | Radio:Vehicle(false)
212 | end
213 | if Config.Radio.radial then
214 | lib.removeRadialItem('vehicle_radio')
215 | end
216 | end
217 | end)
218 |
219 | if Config.Radio.KeyBind then
220 | lib.addKeybind({
221 | name = 'mRadio',
222 | description = 'press X to open radio',
223 | defaultKey = Config.Radio.KeyBind,
224 | onPressed = function(self)
225 | OpenRadio()
226 | end
227 | })
228 | end
229 |
--------------------------------------------------------------------------------
/client/main.lua:
--------------------------------------------------------------------------------
1 | local is_ox_fuel = GetResourceState('ox_fuel') == 'started'
2 |
3 | --- Set some flags on Player Ped
4 | local setPedFlags = function(ped)
5 | SetPedConfigFlag(ped, 380, Config.EnableBikeHelmet)
6 | SetPedConfigFlag(ped, 429, Config.VehicleEngine.ToggleEngine)
7 | SetPedConfigFlag(ped, 241, Config.VehicleEngine.keepEngineOnWhenLeave)
8 | end
9 |
10 | lib.onCache('ped', function(ped)
11 | setPedFlags(ped)
12 | end)
13 |
14 | setPedFlags(PlayerPedId())
15 |
16 | Citizen.CreateThread(function()
17 | local lastVehicle = nil
18 |
19 | while true do
20 | local vehicleEntity = GetVehiclePedIsTryingToEnter(cache.ped)
21 |
22 | if vehicleEntity ~= lastVehicle then
23 | lastVehicle = vehicleEntity
24 | cache:set('TryEnterVehicle', vehicleEntity ~= 0 and vehicleEntity or false)
25 | end
26 |
27 | Citizen.Wait(200)
28 | end
29 | end)
30 |
31 | --- Vehicle density loop
32 | Citizen.CreateThread(function()
33 | while Config.VehicleDensity.density do
34 | SetVehicleDensityMultiplierThisFrame(Config.VehicleDensity.VehicleDensity)
35 | SetRandomVehicleDensityMultiplierThisFrame(Config.VehicleDensity.RandomVehicleDensity)
36 | SetParkedVehicleDensityMultiplierThisFrame(Config.VehicleDensity.ParkedVehicleDensity)
37 | Citizen.Wait(0)
38 | end
39 | end)
40 |
41 |
42 | --- Request Props client to server
43 | RegisterNetEvent('mVehicles:RequestProps', function(id, entity)
44 | local props
45 | if entity then
46 | if NetworkDoesNetworkIdExist(entity) then
47 | entity = NetToVeh(entity)
48 | props = lib.getVehicleProperties(entity)
49 | else
50 | props = false
51 | end
52 | else
53 | local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
54 | if DoesEntityExist(vehicle) then
55 | props = lib.getVehicleProperties(vehicle)
56 | else
57 | props = false
58 | end
59 | end
60 |
61 | TriggerServerEvent('mVehicle:ReceiveProps', id, json.encode(props))
62 | end)
63 |
64 |
65 |
66 | --- Give Car CallBack
67 | lib.callback.register('mVehicle:GivecarData', function()
68 | local options = {}
69 | local disable = true
70 |
71 | local status, GarageZones = pcall(function()
72 | return exports.mGarage:GetGaragesData()
73 | end)
74 |
75 | if status then
76 | disable = false
77 | for _, garage in ipairs(GarageZones.garage) do
78 | local label = garage.jobname or garage.name
79 | table.insert(options, { value = garage.name, label = label })
80 | end
81 | end
82 |
83 | local input = lib.inputDialog('GiveCar', {
84 | { type = 'input', label = locale('givecar_menu1'), required = true },
85 | { type = 'input', label = locale('givecar_menu9'), description = locale('givecar_menu10'), required = false },
86 | { type = 'select', label = locale('givecar_menu2'), icon = 'hashtag', options = options, disabled = disable },
87 | { type = 'checkbox', label = locale('givecar_menu3') },
88 | })
89 |
90 |
91 | if not input then return false end
92 |
93 | local vehiclehash = joaat(input[1])
94 |
95 | local isModelValid = IsModelValid(vehiclehash)
96 |
97 | if not isModelValid then return false, print('Vehicle model invalid') end
98 |
99 | input[9] = GetVehicleClassFromName(input[1])
100 |
101 | local GiveCar = {
102 | model = input[1],
103 | job = input[2],
104 | parking = input[3],
105 | isTemporary = input[4],
106 | vehicleClass = input[9]
107 | }
108 |
109 | if input[4] then
110 | local date = lib.inputDialog(locale('givecar_menu11'), {
111 | { type = 'date', label = locale('givecar_menu4'), icon = { 'far', 'calendar' }, format = "DD/MM/YYYY", required = true },
112 | { type = 'time', label = locale('givecar_menu5'), icon = { 'far', 'calendar' }, format = "24", required = true },
113 | })
114 | if not date then return false, print('Invalid') end
115 |
116 | GiveCar.date = date[1]
117 | GiveCar.hour = date[2]
118 | end
119 |
120 |
121 |
122 | return GiveCar
123 | end)
124 |
125 |
126 | RegisterSafeEvent('mVehicle:FadeEntity', function(netId, action, fuelLevel)
127 | if NetworkDoesEntityExistWithNetworkId(netId) then
128 | local entity = NetToVeh(netId)
129 | if action == 'spawn' then
130 | NetworkFadeInEntity(entity, true)
131 | if not is_ox_fuel then
132 | Config.SetFuel(entity, fuelLevel)
133 | end
134 | elseif action == 'delete' then
135 | NetworkFadeOutEntity(entity, true, true)
136 | Citizen.Wait(1500)
137 | DeleteEntity(entity)
138 | end
139 | end
140 | end)
141 |
142 | --- Save Vehicle Coords And Props
143 | local playerPos
144 | local seat = nil
145 | local saveKHM = false
146 | lib.onCache('seat', function(value)
147 | local Player = cache.ped
148 | local vehicle = cache.vehicle
149 | local oldPos = nil
150 | seat = value
151 |
152 | if seat == -1 and DoesEntityExist(vehicle) then
153 | local data = {}
154 |
155 | saveKHM = true
156 |
157 | data.plate = GetVehicleNumberPlateText(vehicle)
158 |
159 | local vehicleDb = lib.callback.await('mVehicle:VehicleState', false, 'getVeh', data)
160 |
161 | if vehicleDb and vehicleDb.vehicle then
162 | data.mileage = vehicleDb.mileage / 100
163 | while true do
164 | if seat == -1 and saveKHM then
165 | if IsVehicleOnAllWheels(vehicle) then
166 | playerPos = GetEntityCoords(Player).xy
167 | if oldPos then
168 | local distance = #(oldPos - playerPos)
169 | if distance >= 10 then
170 | data.mileage = data.mileage + distance / 1000
171 | data.mileage = Utils.Round(data.mileage)
172 | oldPos = playerPos
173 | end
174 | else
175 | oldPos = playerPos
176 | end
177 | end
178 | Citizen.Wait(100)
179 | else
180 | data.coords = Utils.GetVector4(vehicle, false)
181 | data.props = lib.getVehicleProperties(vehicle)
182 |
183 | saveKHM = false
184 | seat = nil
185 | if type(data.props) == 'table' then
186 | lib.callback.await('mVehicle:VehicleState', false, 'update', data)
187 | end
188 | local IsTrailer, trailerEntity = GetVehicleTrailerVehicle(vehicle)
189 | if IsTrailer and trailerEntity then
190 | local State = Entity(trailerEntity).state
191 | if State and State.Spawned then
192 | local Trailer = {}
193 | Trailer.plate = GetVehicleNumberPlateText(trailerEntity)
194 | Trailer.coords = Utils.GetVector4(trailerEntity, true)
195 | Trailer.props = lib.getVehicleProperties(trailerEntity)
196 | if type(Trailer.props) == 'table' then
197 | lib.callback.await('mVehicle:VehicleState', false, 'savetrailer', Trailer)
198 | end
199 | end
200 | end
201 | break
202 | end
203 | end
204 | end
205 | end
206 | end)
207 |
208 |
209 |
210 | function ShowNui(action, shouldShow)
211 | SetNuiFocus(shouldShow, shouldShow)
212 | SendNUIMessage({ action = action, data = shouldShow })
213 | end
214 |
215 | function SendNUI(action, data)
216 | SendNUIMessage({ action = action, data = data })
217 | end
218 |
219 | AddEventHandler('ox_lib:setLocale', function(locale)
220 | SendNUIMessage({ action = 'ui:Lang', data = lib.getLocales() })
221 | end)
222 |
223 | RegisterNuiCallback('ui:Lang', function(data, cb)
224 | cb(lib.getLocales())
225 | end)
226 |
--------------------------------------------------------------------------------
/server/functions.lua:
--------------------------------------------------------------------------------
1 | Vehicles = {}
2 | Vehicles.Vehicles = {}
3 | Vehicles.Save = false
4 | Vehicles.Config = Config
5 |
6 | local ClientEvent = TriggerClientEvent
7 |
8 | function Vehicles.save()
9 | return Vehicles.Save
10 | end
11 |
12 | ---@return number
13 | function Vehicles.GetVehicleCount()
14 | local count = 0
15 | for _ in pairs(Vehicles.Vehicles) do
16 | count = count + 1
17 | end
18 | return count
19 | end
20 |
21 | ---DeleteFromTable
22 | ---@param entity any
23 | ---@param deleteVehicle? boolean
24 | function Vehicles.DeleteFromTable(entity, deleteVehicle)
25 | Vehicles.Vehicles[entity] = nil
26 | if deleteVehicle and DoesEntityExist(entity) then
27 | DeleteEntity(entity)
28 | end
29 | end
30 |
31 | ---@param data table
32 | ---@param cb? function
33 | function Vehicles.CreateVehicle(data, cb)
34 | if type(data.vehicle) ~= 'table' then
35 | data.vehicle = json.decode(data.vehicle)
36 | end
37 |
38 | if type(data.metadata) ~= 'table' then
39 | data.metadata = json.decode(data.metadata) or {}
40 | end
41 |
42 | if data.metadata.coords and not data.coords then
43 | data.coords = data.metadata.coords
44 | end
45 |
46 | if data.model then
47 | data.vehicle.model = data.model
48 | end
49 |
50 | if not data.plate or not data.vehicle.plate and data.setOwner then
51 | data.plate = Vehicles.GeneratePlate()
52 | end
53 |
54 | data.vehicle.plate = data.plate
55 |
56 | if not data.onlyData and (not data.vehicle or not data.plate or not data.coords) then
57 | Utils.Debug('warn', 'CreateVehicle vehicle plate or coords are NIL value [ coords: %s , plate: %s, ]',
58 | data.coords, data.plate, data.vehicle)
59 | return false
60 | end
61 |
62 | if Vehicles.GetVehicleByPlate(data.plate) then
63 | Utils.Debug('warn', 'CreateVehicle plate duplicated [ "%s" ]', data.plate)
64 | return false
65 | end
66 |
67 | if Config.VehicleTypes[data.type] or not data.type then
68 | data.type = Utils.VehicleType(data.vehicle.model)
69 | end
70 |
71 | if not data.onlyData then
72 | data.entity = Utils.CreateVehicleServer(data.type, data.vehicle.model, data.coords)
73 | end
74 |
75 | if not data.entity or not DoesEntityExist(data.entity) then
76 | Utils.Debug("error", "Invalid Entity %s", data.entity)
77 | return false
78 | end
79 |
80 | if data.metadata.RoutingBucket then
81 | SetEntityRoutingBucket(data.entity, data.metadata.RoutingBucket)
82 | end
83 |
84 | data.EntityOwner = NetworkGetEntityOwner(data.entity)
85 |
86 | while data.EntityOwner == -1 do
87 | data.EntityOwner = NetworkGetEntityOwner(data.entity)
88 | Wait(0)
89 | end
90 |
91 | local State = Entity(data.entity).state
92 |
93 | data.NetId = NetworkGetNetworkIdFromEntity(data.entity)
94 |
95 | if data.temporary then
96 | data.metadata.temporary = data.temporary
97 | end
98 |
99 | if CheckTemporary(data) then
100 | return false
101 | end
102 |
103 | if data.metadata.DoorStatus then
104 | SetVehicleDoorsLocked(data.entity, data.metadata.DoorStatus)
105 | end
106 |
107 | if data.metadata.fakeplate then
108 | data.vehicle.plate = data.metadata.fakeplate
109 | end
110 |
111 | if data.metadata.engineSound then
112 | State:set('engineSound', data.metadata.engineSound, true)
113 | end
114 |
115 | local fuel = data.vehicle and data.vehicle.fuelLevel or 100
116 |
117 | State:set('fuel', fuel, true)
118 |
119 | State:set('Spawned', true, true)
120 |
121 | if data.metadata.mileage then
122 | State:set('mileage', data.metadata.mileage)
123 | end
124 |
125 | if data.job then
126 | State:set('job', data.job, true)
127 | end
128 |
129 | if data.setOwner then
130 | local identifier, qbxlicense = Identifier(data.source)
131 |
132 | if FrameWork == 'qbx' then
133 | data.license = qbxlicense
134 | end
135 |
136 | data.owner = identifier
137 |
138 | if not data.owner then
139 | return false, Utils.Debug('error', 'Error CreateVehicle No Player Identifier by source!')
140 | end
141 |
142 | data.metadata.firstSpawn = os.date("%Y/%m/%d %H:%M:%S")
143 | data.metadata.firstOwner = GetName(data.source)
144 |
145 | data.id = Vehicles.SetVehicleOwner(data)
146 | end
147 |
148 | if data.id then
149 | State:set('id', data.id, true)
150 | end
151 |
152 | if data.metadata then
153 | State:set('metadata', data.metadata, true)
154 | end
155 |
156 | if data.owner then
157 | State:set('owner', data.owner, true)
158 | end
159 |
160 | Vehicles.Vehicles[data.entity] = data
161 |
162 | if Config.VehicleProperties.stateBag then
163 | State:set(Config.VehicleProperties.StateBagName, data.vehicle, true)
164 | elseif Config.VehicleProperties.event then
165 | ClientEvent('ox_lib:setVehicleProperties', data.EntityOwner, data.NetId, data.vehicle, data.EntityOwner)
166 | else
167 | lib.setVehicleProperties(data.entity, data.vehicle)
168 | end
169 |
170 | ClientEvent('mVehicle:FadeEntity', data.EntityOwner, data.NetId, 'spawn', data.vehicle.fuelLevel)
171 |
172 | if data.intocar then
173 | local plyPed = GetPlayerPed(data.source)
174 |
175 | while GetVehiclePedIsIn(plyPed, false) == 0 do
176 | SetPedIntoVehicle(plyPed, data.entity, -1)
177 | Citizen.Wait(0)
178 | end
179 | end
180 |
181 | SetVehicleNumberPlateText(data.entity, data.plate)
182 |
183 | if cb then
184 | cb(data, Vehicles.GetVehicle(data.entity))
185 | else
186 | return data, Vehicles.GetVehicle(data.entity)
187 | end
188 | end
189 |
190 | --- Spawn specific id
191 | --- @param data table | @{ id: number, coords: vector4, intocar?: boolean, source?: number|string }
192 | --- @param callback? function
193 | function Vehicles.CreateVehicleId(data, callback)
194 | if not data or not data.coords or not data.id then return end
195 |
196 | local dbvehicles = Vehicles.GetVehicleByID(data.id)
197 |
198 | if not dbvehicles then
199 | if callback then
200 | return callback(false, false)
201 | else
202 | return false, false
203 | end
204 | end
205 |
206 | if data.intocar then
207 | dbvehicles.intocar = data.intocar
208 | dbvehicles.source = data.source
209 | end
210 |
211 | dbvehicles.coords = data.coords
212 |
213 | local vehicleData, vehicle = Vehicles.CreateVehicle(dbvehicles)
214 |
215 | if callback then
216 | callback(vehicleData, vehicle)
217 | else
218 | return vehicleData, vehicle
219 | end
220 | end
221 |
222 | local randomEntity = {}
223 | function Vehicles.ControlVehicle(entity)
224 | if randomEntity[entity] then return false end
225 | if Vehicles.Vehicles[entity] then return false end
226 | local plate = GetVehicleNumberPlateText(entity)
227 | local vehicle = Vehicles.GetVehicleByPlate(plate, true)
228 | if vehicle then
229 | vehicle.onlyData = true
230 | vehicle.entity = entity
231 | local data, vehicleAction = Vehicles.CreateVehicle(vehicle)
232 | return vehicleAction
233 | else
234 | randomEntity[entity] = {}
235 | return false
236 | end
237 | end
238 |
239 | ---Get Vehicle DB from ID
240 | ---@param id number
241 | ---@return table
242 | function Vehicles.GetVehicleByID(id)
243 | local vehicle = MySQL.single.await(Querys.getVehicleById, { id })
244 | if FrameWork == 'qbx' and vehicle then
245 | vehicle.parking = vehicle.garage
246 | vehicle.vehicle = vehicle.mods
247 | vehicle.owner = vehicle.citizenid
248 | end
249 | return vehicle
250 | end
251 |
252 | ---Get Vehicle metadata DB from Plate
253 | ---@param plate string
254 | ---@param metadata table
255 | function Vehicles.UpdateMetadataPlate(plate, metadata)
256 | return MySQL.update(Querys.saveMetadata, { json.encode(metadata), plate })
257 | end
258 |
259 | function Vehicles.GetMetadataPlate(plate)
260 | local row = MySQL.single.await(Querys.selectMetadata, { plate })
261 | if row then
262 | local metadata = json.decode(row.metadata)
263 | if not metadata then
264 | metadata = {}
265 | end
266 | return metadata
267 | end
268 | return false
269 | end
270 |
271 | ---TransferVehicle
272 | ---@param src number
273 | ---@param vehicleid number
274 | ---@param newowner string
275 | ---@return boolean
276 | function Vehicles.TransfreVehicle(src, vehicleid, newowner)
277 | local transfer = false
278 | return transfer
279 | end
280 |
281 | ---Set Car owner
282 | ---@param PlayerId integer
283 | ---@param entity? integer
284 | function Vehicles.SetCurrentVehicleOwner(PlayerId, entity)
285 | local data = {}
286 | local playerped = GetPlayerPed(PlayerId)
287 | local identifier = Identifier(PlayerId)
288 |
289 | if not entity then
290 | data.entity = GetVehiclePedIsIn(playerped, false)
291 | end
292 |
293 | if not DoesEntityExist(data.entity) or not identifier or not playerped then
294 | return false, Utils.Debug('error', 'SetCurrentVehicleOwner Missing data')
295 | end
296 |
297 | if Vehicles.Vehicles[data.entity] then
298 | return false, Utils.Debug('error', 'SetCurrentVehicleOwner This vehicle already has an owner')
299 | end
300 |
301 | local props = Vehicles.GetClientProps(PlayerId, NetworkGetNetworkIdFromEntity(data.entity))
302 | data.metadata = {
303 | coords = GetCoords(PlayerId),
304 | keys = {}
305 | }
306 | data.plate = props.plate
307 | data.vehicle = props
308 | data.owner = identifier
309 | data.setOwner = true
310 | data.onlyData = true
311 | data.source = PlayerId
312 |
313 | if Config.ItemKeys then
314 | Vehicles.ItemCarKeys(PlayerId, 'add', props.plate)
315 | end
316 |
317 | return Vehicles.CreateVehicle(data)
318 | end
319 |
320 | function Vehicles.SetVehicleOwner(data)
321 | if not data.job then data.job = nil end
322 |
323 | local insert = {
324 | data.owner,
325 | data.plate,
326 | json.encode(data.vehicle),
327 | data.type,
328 | data.job,
329 | json.encode(data.metadata),
330 | data.parking
331 | }
332 |
333 | local query = ''
334 |
335 | if not data.parking then
336 | query = Querys.setOwner
337 | table.remove(insert, 7)
338 | else
339 | query = Querys.setOwnerParking
340 | end
341 |
342 | if FrameWork == 'qbx' then
343 | table.insert(insert, data.license)
344 | end
345 |
346 | return MySQL.insert.await(query, insert)
347 | end
348 |
349 | function Vehicles.GetVehicle(entity)
350 | if not Vehicles.Vehicles[entity] then
351 | return false
352 | end
353 |
354 | if not DoesEntityExist(entity) then
355 | Utils.Debug('error', 'GetVehicle No Entity')
356 | return
357 | end
358 |
359 | local State = Entity(entity).state
360 |
361 | local self = Vehicles.Vehicles[entity]
362 |
363 | self.EntityOwner = NetworkGetEntityOwner(entity)
364 |
365 | self.GetCoords = function()
366 | local c, h = GetEntityCoords(self.entity), GetEntityHeading(self.entity)
367 | return { x = c.x, y = c.y, z = c.z, w = h }
368 | end
369 |
370 | ---Save Metadata
371 | self.SaveMetaData = function()
372 | MySQL.update(Querys.saveMetadata, { json.encode(self.metadata), self.plate })
373 | State:set("metadata", self.metadata, true)
374 | end
375 |
376 | --- SetMetadata
377 | --- value:'delete_meta' = nil / remove table
378 | ---@param key string|table
379 | ---@param value any
380 | self.SetMetadata = function(key, value)
381 | if type(key) == "table" then
382 | for k, v in pairs(key) do
383 | if v == 'delete_meta' and self.metadata[k] then
384 | self.metadata[k] = nil
385 | else
386 | self.metadata[k] = v
387 | end
388 | end
389 | else
390 | self.metadata[key] = value == 'delete_meta' and nil or value
391 | end
392 | self.SaveMetaData()
393 | return self.metadata
394 | end
395 |
396 |
397 | --- DeleteMetadata
398 | ---@param key string|table
399 | ---@param value string|nil
400 | self.DeleteMetadata = function(key, value)
401 | local function deleteKey(k)
402 | if not self.metadata[k] then
403 | return false
404 | end
405 | if value then
406 | if type(self.metadata[k]) ~= "table" or not self.metadata[k][value] then
407 | return false
408 | end
409 | self.metadata[k][value] = nil
410 | if next(self.metadata[k]) == nil then
411 | self.metadata[k] = nil
412 | end
413 | else
414 | self.metadata[k] = nil
415 | end
416 | return true
417 | end
418 |
419 | if type(key) == "table" then
420 | for _, k in ipairs(key) do
421 | deleteKey(k)
422 | end
423 | else
424 | deleteKey(key)
425 | end
426 |
427 | self.SaveMetaData()
428 |
429 | return self.metadata
430 | end
431 | --- GetMetadata
432 | ---@param key? string
433 | self.GetMetadata = function(key)
434 | if not key then
435 | return self.metadata
436 | else
437 | return self.metadata[key]
438 | end
439 | end
440 | --- SetJob
441 | self.SetJob = function(job)
442 | self.SetMetadata('job', job)
443 | if FrameWork == 'esx' or FrameWork == 'qbx' then
444 | MySQL.update(Querys.setVehicleJob, { job, self.plate })
445 | end
446 | end
447 | ---AddKeys
448 | ---@param src number
449 | self.AddKey = function(src)
450 | local identifier = Identifier(src)
451 | if not self.metadata.keys then self.metadata.keys = {} end
452 | if identifier then
453 | self.metadata.keys[identifier] = GetName(src)
454 |
455 | self.SetMetadata('keys', self.metadata.keys)
456 |
457 | return true
458 | end
459 | return false
460 | end
461 | ---RemoveKey
462 | self.RemoveKey = function(identifier)
463 | if self.metadata.keys[identifier] then
464 | self.metadata.keys[identifier] = nil
465 | State:set('keys', self.metadata.keys, true)
466 |
467 | self.SetMetadata('keys', self.metadata.keys)
468 | return true
469 | end
470 | return false
471 | end
472 |
473 | self.GetKeys = self.metadata.keys
474 |
475 | ---SaveVehiclePrps
476 | ---@param props table
477 | self.SaveProps = function(props)
478 | self.vehicle = props
479 | MySQL.update(Querys.saveProps, { json.encode(props), self.plate })
480 | end
481 |
482 | self.DeleteVehicle = function(fromDatabase)
483 | if DoesEntityExist(entity) then
484 | ClientEvent('mVehicle:FadeEntity', self.EntityOwner, self.NetId, 'delete')
485 | State:set('Spawned', false, true)
486 | end
487 |
488 | if fromDatabase then
489 | MySQL.execute(Querys.deleteByPlate, { self.plate })
490 | end
491 |
492 | Vehicles.Vehicles[entity] = nil
493 | self = nil
494 | end
495 |
496 | ---StoreVehicle
497 | ---@param parking string
498 | ---@param props string|nil
499 | ---@return boolean
500 | self.StoreVehicle = function(parking, props)
501 | local store = false
502 |
503 | local affectedRows = MySQL.update.await(Querys.storeGarage,
504 | { parking, props, json.encode(self.metadata), self.plate })
505 |
506 | self.DeleteMetadata('coords')
507 |
508 | if affectedRows > 0 then
509 | ClientEvent('mVehicle:FadeEntity', self.EntityOwner, self.NetId, 'delete')
510 | Vehicles.Vehicles[entity] = nil
511 | self = nil
512 | store = true
513 | end
514 |
515 | return store
516 | end
517 |
518 | ---RetryVehicle
519 | self.RetryVehicle = function()
520 | local coords = self.GetCoords()
521 | MySQL.update(Querys.retryGarage, { self.plate })
522 | self.SetMetadata({ coords = coords, lastParking = self.parking })
523 | end
524 |
525 | ---ImpoundVehicle
526 | ---@param impound string
527 | ---@param price number
528 | ---@param note string
529 | ---@param date string
530 | ---@param endpound string
531 | self.ImpoundVehicle = function(impound, price, note, date, endpound)
532 | self.SetMetadata('pound', {
533 | price = price,
534 | reason = note,
535 | date = date,
536 | endPound = endpound
537 | })
538 |
539 | MySQL.update(Querys.setImpound, { impound, self.plate })
540 |
541 | if DoesEntityExist(entity) then
542 | ClientEvent('mVehicle:FadeEntity', self.EntityOwner, self.NetId, 'delete')
543 | end
544 |
545 | Vehicles.Vehicles[entity] = nil
546 | self = nil
547 | end
548 |
549 | ---RetryVehicle
550 | ---@param ToGarage string Garage name
551 | self.RetryImpound = function(ToGarage)
552 | MySQL.update(Querys.retryImpound, { ToGarage, self.plate })
553 |
554 | self.SetMetadata({
555 | pound = 'delete_meta',
556 | lastParking = self.parking,
557 | coords = self.GetCoords()
558 | })
559 | end
560 |
561 | --- Set Fake plate or delete
562 | ---@param fakeplate? string
563 | self.FakePlate = function(fakeplate)
564 | if fakeplate and type(fakeplate) == 'string' then
565 | self.SetMetadata('fakeplate', fakeplate)
566 | else
567 | self.DeleteMetadata('fakeplate')
568 | end
569 | end
570 |
571 | self.RoutingBucket = function(id)
572 | SetEntityRoutingBucket(self.entity, id)
573 | end
574 |
575 |
576 | self.Private = function(bucket, coords, parking)
577 | if bucket then
578 | self.RoutingBucket(bucket)
579 | self.SetMetadata({
580 | RoutingBucket = bucket,
581 | parking = parking,
582 | coords = coords,
583 | private = true,
584 | })
585 | else
586 | self.RoutingBucket(0)
587 | self.DeleteMetadata({ 'RoutingBucket', 'private' })
588 | end
589 | end
590 |
591 |
592 | -- Save Coords
593 | self.SaveLeftVehicle = function(coords, props, mileages)
594 | local inBucket = self.GetMetadata('RoutingBucket')
595 |
596 | self.coords = inBucket and self.coords or coords
597 |
598 | self.mileage = math.floor(mileages * 100)
599 |
600 | State:set('mileage', Utils.Round(self.mileage), true)
601 |
602 | MySQL.update(Querys.saveProps, { json.encode(props), self.plate })
603 |
604 | self.SetMetadata({ mileage = self.mileage, coords = coords })
605 | end
606 |
607 |
608 | self.CoordsAndProps = function(coords, props)
609 | self.coords = coords
610 |
611 | self.SetMetadata({
612 | coords = coords
613 | })
614 |
615 | return MySQL.update.await(Querys.saveProps, { json.encode(props), self.plate })
616 | end
617 |
618 | self.setName = function(name)
619 | self.SetMetadata('vehname', name)
620 | end
621 |
622 | self.SetEngineSound = function(name)
623 | self.SetMetadata('engineSound', name)
624 | State:set('engineSound', name, true)
625 | end
626 |
627 | return self
628 | end
629 |
630 | ---Get Vehicle By Plate, db true
631 | ---@param plate string
632 | ---@param db? boolean
633 | function Vehicles.GetVehicleByPlate(plate, db)
634 | if not db then
635 | local isVehicle = false
636 | plate = plate:match("^%s*(.-)%s*$")
637 | plate = plate:gsub("%s+", " ")
638 | for k, v in pairs(Vehicles.Vehicles) do
639 | v.plate = v.plate:match("^%s*(.-)%s*$")
640 | v.plate = v.plate:gsub("%s+", " ")
641 | if v.plate == plate then
642 | isVehicle = true
643 | return Vehicles.GetVehicle(v.entity)
644 | end
645 | end
646 |
647 | if not isVehicle then
648 | return false
649 | end
650 | else
651 | local vehicle = MySQL.single.await(Querys.getVehicleByPlateOrFakeplate, { plate, plate })
652 | if FrameWork == 'qbx' and vehicle then
653 | vehicle.parking = vehicle.garage
654 | vehicle.vehicle = vehicle.mods
655 | vehicle.owner = vehicle.citizenid
656 | end
657 | return vehicle
658 | end
659 | end
660 |
661 | ---GetAllPlayerVehicles
662 | ---@param PlayerSource number Player Source
663 | ---@param VehicleTable boolean true = internal mVehicle Table || false = DataBase
664 | ---@param haveKeys boolean Returns vehicles to which it has a key
665 | function Vehicles.GetAllPlayerVehicles(PlayerSource, VehicleTable, haveKeys)
666 | local identifier = Identifier(PlayerSource)
667 | if VehicleTable then
668 | if identifier then
669 | local veh = {}
670 | for k, v in pairs(Vehicles.Vehicles) do
671 | if v.owner == identifier then
672 | if haveKeys then
673 | veh[v.entity] = v
674 | return veh
675 | else
676 | return veh
677 | end
678 | end
679 | end
680 | end
681 | return Vehicles.Vehicles
682 | else
683 | if identifier then
684 | local AllVehicles = nil
685 | if haveKeys then
686 | AllVehicles = MySQL.query.await(Querys.getVehiclesbyOwnerAndhaveKeys,
687 | { identifier, '%"' .. identifier .. '"%' })
688 | else
689 | AllVehicles = MySQL.query.await(Querys.getVehiclesbyOwner, { identifier, })
690 | end
691 |
692 |
693 | if FrameWork == 'qbx' and AllVehicles then
694 | lib.array.forEach(AllVehicles, function(veh)
695 | veh.parking = veh.garage
696 | veh.vehicle = veh.mods
697 | veh.owner = veh.citizenid
698 | end)
699 | end
700 |
701 | return AllVehicles
702 | end
703 | end
704 | end
705 |
706 | --- PlateExist
707 | ---@param plate any
708 | ---@return boolean
709 | function Vehicles.PlateExist(plate)
710 | return not MySQL.scalar.await(Querys.plateExist, { plate })
711 | end
712 |
713 | --- GeneratePlate
714 | -- - Return a plate
715 | ---@return string
716 | function Vehicles.GeneratePlate()
717 | local plate
718 | local pattern = Config.PlateGenerate
719 |
720 | if #pattern < 8 then
721 | pattern = pattern .. string.rep(" ", 8 - #pattern)
722 | end
723 |
724 | repeat
725 | plate = ""
726 | for i = 1, #pattern do
727 | local char = pattern:sub(i, i)
728 | if char == "A" then
729 | plate = plate .. string.char(math.random(65, 90))
730 | elseif char == "1" then
731 | plate = plate .. tostring(math.random(0, 9))
732 | elseif char == "." then
733 | if math.random(2) == 1 then
734 | plate = plate .. string.char(math.random(65, 90))
735 | else
736 | plate = plate .. tostring(math.random(0, 9))
737 | end
738 | else
739 | plate = plate .. char
740 | end
741 | end
742 | until Vehicles.PlateExist(plate)
743 |
744 | return plate
745 | end
746 |
747 | ---SpawnVehicles
748 | -- - Spawn all vehicles from DB
749 | function Vehicles.SpawnVehicles()
750 | local dbvehicles = MySQL.query.await(Querys.selectAll)
751 | lib.array.forEach(dbvehicles, function(vehicle)
752 | if vehicle.stored == 0 and vehicle.pound == nil then
753 |
754 | if FrameWork == 'qbx' and vehicle then
755 | vehicle.parking = vehicle.garage
756 | vehicle.vehicle = vehicle.mods
757 | vehicle.owner = vehicle.citizenid
758 | end
759 |
760 | if type(vehicle.metadata) ~= 'table' then
761 | vehicle.metadata = json.decode(vehicle.metadata)
762 | end
763 |
764 | if vehicle.metadata.private or Config.Persistent then
765 | Persistent:Set(vehicle.metadata.coords, vehicle.id, vehicle.metadata.RoutingBucket or 0)
766 | end
767 |
768 | Citizen.Wait(200)
769 | end
770 | end)
771 | end
772 |
773 | ---SaveAllVehicles
774 | ---@param delete? boolean
775 | function Vehicles.SaveAllVehicles(delete)
776 | Vehicles.Save = true
777 |
778 | local savedCount = 0
779 | local parameters = {}
780 |
781 | for entity, veh in pairs(Vehicles.Vehicles) do
782 | if DoesEntityExist(entity) and not veh.private then
783 | local coords = GetCoords(false, entity)
784 | local props = Vehicles.GetClientProps(veh.EntityOwner, veh.NetId)
785 | if not props then props = veh.vehicle end
786 |
787 | veh.metadata.DoorStatus = GetVehicleDoorLockStatus(entity)
788 | veh.metadata.coords = coords
789 |
790 | parameters[#parameters + 1] = {
791 | json.encode(props),
792 | json.encode(veh.metadata),
793 | veh.plate
794 | }
795 |
796 | savedCount = savedCount + 1
797 |
798 | if delete then
799 | DeleteEntity(entity)
800 | Vehicles.Vehicles[entity] = nil
801 | end
802 |
803 | Wait(50)
804 | end
805 | end
806 |
807 | if not next(parameters) then
808 | Wait(500)
809 | Vehicles.Save = false
810 | return
811 | end
812 |
813 | MySQL.prepare(Querys.saveAllPropsCoords, parameters, function(results)
814 | if not results then return end
815 | Utils.Debug("info", "Total vehicles saved [ %s ] ", savedCount)
816 | end)
817 |
818 | Wait(500)
819 | Vehicles.Save = false
820 | end
821 |
822 | ---ItemCarKeys
823 | ---@param src number
824 | ---@param action string
825 | ---@param plate string
826 | function Vehicles.ItemCarKeys(src, action, plate)
827 | local metadata = { description = locale('key_string', plate), plate = plate }
828 |
829 | if action == 'add' then
830 | if Config.Inventory == 'ox' then
831 | local havekey = exports.ox_inventory:GetItem(src, Config.CarKeyItem, metadata, true)
832 | if havekey == 0 then
833 | exports.ox_inventory:AddItem(src, Config.CarKeyItem, 1, metadata)
834 | end
835 | elseif Config.Inventory == 'qs' then
836 | exports['qs-inventory']:AddItem(src, Config.CarKeyItem, 1, nil, metadata)
837 | end
838 | elseif action == 'delete' then
839 | if Config.Inventory == 'ox' then
840 | local Count = exports.ox_inventory:GetItem(src, Config.CarKeyItem, metadata, true)
841 | exports.ox_inventory:RemoveItem(src, Config.CarKeyItem, Count, metadata)
842 | elseif Config.Inventory == 'qs' then
843 | exports['qs-inventory']:RemoveItem(src, Config.CarKeyItem, 1, nil, metadata)
844 | end
845 | end
846 | end
847 |
848 | function Vehicles.HasKey(src, entity)
849 | local identifier = Identifier(src)
850 | local vehicle = Vehicles.GetVehicle(entity)
851 | if not vehicle then vehicle = Vehicles.ControlVehicle(entity) end
852 | if not vehicle then return false end
853 | return (identifier == vehicle.owner) or vehicle.metadata.keys and vehicle.metadata.keys[identifier] ~= nil or false
854 | end
855 |
856 | ---@param src number
857 | ---@param entity number
858 | ---@param data? table
859 | function Vehicles.AddTemporalVehicle(src, entity, data)
860 | if Vehicles.Vehicles[entity] or not DoesEntityExist(entity) then return false end
861 | local identifier = Identifier(src)
862 | if not identifier then return false end
863 | local PlayerName = GetName(src)
864 | local plate = GetVehicleNumberPlateText(entity)
865 |
866 | if Config.ItemKeys then
867 | Vehicles.ItemCarKeys(src, 'add', plate)
868 | return true
869 | end
870 |
871 | local vehicleData = {
872 | onlyData = true,
873 | plate = plate,
874 | owner = identifier,
875 | type = GetVehicleType(entity),
876 | entity = entity,
877 | metadata = {
878 | controledBy = { name = PlayerName, identifier = identifier },
879 | temporalControl = true,
880 | },
881 | vehicle = {
882 | fuelLevel = 100,
883 | }
884 | }
885 |
886 | if data then
887 | for k, v in pairs(data) do
888 | if vehicleData[k] == nil then
889 | vehicleData[k] = v
890 | end
891 | end
892 | end
893 |
894 | Vehicles.CreateVehicle(vehicleData)
895 | return true
896 | end
897 |
898 | -- if the temporary control vehicle is deleted, we remove it from the table
899 | AddEventHandler('entityRemoved', function(entity)
900 | local veh = Vehicles.Vehicles[entity]
901 | if veh and veh.metadata.temporalControl then
902 | Vehicles.DeleteFromTable(entity)
903 | end
904 | if randomEntity[entity] then
905 | randomEntity[entity] = nil
906 | end
907 | end)
908 |
909 |
910 | local Properties = {}
911 |
912 | RegisterNetEvent('mVehicle:ReceiveProps', function(id, data)
913 | local props = json.decode(data)
914 | if Properties[id] then
915 | Properties[id](props)
916 | Properties[id] = nil
917 | end
918 | end)
919 |
920 | ---Get Client props from server
921 | ---@param src number
922 | ---@param NetID number
923 | ---@return table
924 | function Vehicles.GetClientProps(src, NetID)
925 | local entity = NetworkGetEntityFromNetworkId(NetID)
926 | ---if the entity is at a great distance the props will be null, if the CullinRadius is increased they can be obtained without problems.
927 | SetEntityDistanceCullingRadius(entity, 99999.0)
928 |
929 | Citizen.Wait(50)
930 |
931 | local promise = promise.new()
932 |
933 | Properties[entity] = function(props)
934 | promise:resolve(props)
935 | end
936 |
937 | ClientEvent('mVehicles:RequestProps', src, entity, NetID)
938 |
939 | local result = Citizen.Await(promise)
940 |
941 | Properties[entity] = nil
942 |
943 | -- reset cullingRadius to avoid problems....
944 | SetEntityDistanceCullingRadius(entity, 0.0)
945 |
946 | return result
947 | end
948 |
949 | AddEventHandler("onResourceStart", function(Resource)
950 | if Resource == 'mVehicle' then
951 | Wait(1000)
952 | Vehicles.SpawnVehicles()
953 | end
954 | end)
955 |
956 |
957 |
958 | AddEventHandler("txAdmin:events:serverShuttingDown", function(delay, author, message)
959 | local vehicles = Vehicles.Vehicles
960 | local params = {}
961 |
962 | for _, veh in pairs(vehicles) do
963 | local coords = GetEntityCoords(veh.entity)
964 | local heading = GetEntityHeading(veh.entity)
965 | veh.metadata.coords = { x = coords.x, y = coords.y, z = coords.z, w = heading }
966 |
967 | params[#params + 1] = {
968 | json.encode(veh.metadata),
969 | veh.plate
970 | }
971 | end
972 |
973 | if not next(params) then return end
974 |
975 | MySQL.prepare(Querys.saveMetadata, params, function(results)
976 | if not results then return end
977 | Utils.Debug("info", "Total vehicles saved [ %s ] ", #params)
978 | end)
979 | end)
980 |
981 | AddEventHandler("txAdmin:events:scheduledRestart", function(eventData)
982 | if eventData.secondsRemaining == 60 and Config.Persistent then
983 | Citizen.CreateThread(function()
984 | Citizen.Wait(50000)
985 | Vehicles.SaveAllVehicles(true)
986 | end)
987 | end
988 | end)
989 |
990 | AddEventHandler('onResourceStop', function(resourceName)
991 | if resourceName == GetCurrentResourceName() then
992 | for k, v in pairs(Vehicles.Vehicles) do
993 | if DoesEntityExist(v.entity) then
994 | if Config.Persistent and not v.metadata.temporalControl then
995 | local coords = GetEntityCoords(v.entity)
996 | local w = GetEntityHeading(v.entity)
997 | v.metadata.coords = { x = coords.x, y = coords.y, z = coords.z, w = w }
998 | MySQL.update(Querys.saveMetadata, { json.encode(v.metadata), v.plate })
999 | end
1000 | DeleteEntity(v.entity)
1001 | end
1002 | end
1003 | end
1004 | end)
1005 |
1006 |
1007 | RegisterSafeEvent('mVehicle:VehicleDoors', function(netid)
1008 | local entity = NetworkGetEntityFromNetworkId(netid)
1009 | local vehicle = Vehicles.GetVehicle(entity)
1010 | if not vehicle then vehicle = Vehicles.ControlVehicle(entity) end
1011 | local status = GetVehicleDoorLockStatus(entity) == 0 and 2 or 0
1012 | SetVehicleDoorsLocked(entity, status)
1013 | if vehicle then vehicle.SetMetadata('DoorStatus', status) end
1014 | end)
1015 |
1016 | lib.callback.register('mVehicle:GiveKey', Vehicles.ItemCarKeys)
1017 |
1018 | lib.callback.register('mVehicle:HasKeys', function(src, netid)
1019 | return Vehicles.HasKey(src, NetworkGetEntityFromNetworkId(netid))
1020 | end)
1021 |
1022 | lib.callback.register('mVehicle:ControlTemporal', function(src, netid, data)
1023 | return Vehicles.AddTemporalVehicle(src, NetworkGetEntityFromNetworkId(netid), data)
1024 | end)
1025 |
1026 | exports('CreateVehicle', Vehicles.CreateVehicle)
1027 | exports('PlateExist', Vehicles.PlateExist)
1028 | exports('GeneratePlate', Vehicles.GeneratePlate)
1029 | exports('ItemCarKeys', Vehicles.ItemCarKeys)
1030 | exports('GetClientProps', Vehicles.GetClientProps)
1031 | exports('AddTemporalVehicle', Vehicles.AddTemporalVehicle)
1032 | exports('HasKey', Vehicles.HasKey)
1033 | exports('vehicle', function() return Vehicles end)
1034 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------