-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Contract system for the resale of vehicles
- Loading branch information
1 parent
ceb1479
commit 4fcfb17
Showing
11 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Fred Richter | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# esx_contract | ||
With this script you can sell a vehicle to another person. You just need a contract in your inventory. | ||
There is no moneytransaction included. | ||
It´s just a simple script to change the owner of a vehicle |
38 changes: 38 additions & 0 deletions
38
server-data/resources/[esx_addons]/esx_contract/client/main.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
ESX = exports["es_extended"]:getSharedObject() | ||
|
||
RegisterNetEvent("esx_contract:getVehicle") | ||
AddEventHandler("esx_contract:getVehicle", function() | ||
local playerPed = PlayerPedId() | ||
local coords = GetEntityCoords(playerPed) | ||
local closestPlayer, playerDistance = ESX.Game.GetClosestPlayer() | ||
|
||
if closestPlayer ~= -1 and playerDistance <= 3.0 then | ||
local vehicle = ESX.Game.GetClosestVehicle(coords) | ||
local vehiclecoords = GetEntityCoords(vehicle) | ||
local vehDistance = GetDistanceBetweenCoords(coords, vehiclecoords, true) | ||
if DoesEntityExist(vehicle) and (vehDistance <= 3) then | ||
local vehProps = ESX.Game.GetVehicleProperties(vehicle) | ||
ESX.ShowNotification(TranslateCap("writingcontract", vehProps.plate)) | ||
TriggerServerEvent("esx_clothes:sellVehicle", GetPlayerServerId(closestPlayer), vehProps.plate) | ||
else | ||
ESX.ShowNotification(TranslateCap("nonearby")) | ||
end | ||
else | ||
ESX.ShowNotification(TranslateCap("nonearbybuyer")) | ||
end | ||
end) | ||
|
||
RegisterNetEvent("esx_contract:showAnim") | ||
AddEventHandler("esx_contract:showAnim", function(player) | ||
LoadAnimDict("anim@amb@nightclub@peds@") | ||
TaskStartScenarioInPlace(PlayerPedId(), "WORLD_HUMAN_CLIPBOARD", 0, false) | ||
Citizen.Wait(20000) | ||
ClearPedTasks(PlayerPedId()) | ||
end) | ||
|
||
function LoadAnimDict(dict) | ||
while not HasAnimDictLoaded(dict) do | ||
RequestAnimDict(dict) | ||
Citizen.Wait(0) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Config = {} | ||
|
||
Config.Locale = "en" |
2 changes: 2 additions & 0 deletions
2
server-data/resources/[esx_addons]/esx_contract/contract-sql.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
INSERT INTO `items` (`name`, `label`, `limit`, `rare`, `can_remove`) VALUES | ||
('contract', 'Contract', '5', '0', '1'); |
24 changes: 24 additions & 0 deletions
24
server-data/resources/[esx_addons]/esx_contract/fxmanifest.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
fx_version("adamant") | ||
|
||
game("gta5") | ||
|
||
description("esx_contract") | ||
|
||
version("1.0.1") | ||
|
||
shared_script("@es_extended/imports.lua") | ||
|
||
server_scripts({ | ||
"@mysql-async/lib/MySQL.lua", | ||
"@es_extended/locale.lua", | ||
"locales/*.lua", | ||
"config.lua", | ||
"server/*.lua", | ||
}) | ||
|
||
client_scripts({ | ||
"@es_extended/locale.lua", | ||
"locales/*.lua", | ||
"config.lua", | ||
"client/*.lua", | ||
}) |
8 changes: 8 additions & 0 deletions
8
server-data/resources/[esx_addons]/esx_contract/locales/br.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Locales["br"] = { | ||
["writingcontract"] = "Contrato para a seguinte placa de veículo: %s", | ||
["soldvehicle"] = "Você vendeu o veículo com o número de registro ~r~%s~s~", | ||
["boughtvehicle"] = "Você comprou o veículo com o número de registro ~g~%s~s~", | ||
["notyourcar"] = "Este veículo não é seu", | ||
["nonearby"] = "Nenhum veículo nas proximidades", | ||
["nonearbybuyer"] = "Nenhum comprador nas proximidades", | ||
} |
8 changes: 8 additions & 0 deletions
8
server-data/resources/[esx_addons]/esx_contract/locales/de.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Locales["de"] = { | ||
["writingcontract"] = "Vertrag für folgendes Kennzeichen: %s", | ||
["soldvehicle"] = "Du hast das Fahrzeug mit dem Kennzeichen ~r~%s~s~ verkauft", | ||
["boughtvehicle"] = "Du hast das Fahrzeug mit dem Kennzeichen ~g~%s~s~ gekauft", | ||
["notyourcar"] = "Das ist nicht dein Fahrzeug", | ||
["nonearby"] = "Kein Fahrzeug in der Nähe", | ||
["nonearbybuyer"] = "Kein Käufer in der Nähe", | ||
} |
8 changes: 8 additions & 0 deletions
8
server-data/resources/[esx_addons]/esx_contract/locales/en.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Locales["en"] = { | ||
["writingcontract"] = "Contract for the following license plate: %s", | ||
["soldvehicle"] = "You sold the vehicle with the registration number ~r~%s~s~", | ||
["boughtvehicle"] = "You bought the vehicle with the registration number ~g~%s~s~", | ||
["notyourcar"] = "This is not your vehicle", | ||
["nonearby"] = "No vehicle nearby", | ||
["nonearbybuyer"] = "No buyer nearby", | ||
} |
8 changes: 8 additions & 0 deletions
8
server-data/resources/[esx_addons]/esx_contract/locales/tr.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Locales["en"] = { | ||
["writingcontract"] = "%s plakası için kontrat yazılıyor.", | ||
["soldvehicle"] = "Aracı sicil numarasıyla sattınız. ~r~%s~s~", | ||
["boughtvehicle"] = "Aracı sicil numarasıyla satın aldınız. ~g~%s~s~", | ||
["notyourcar"] = "Bu araç senin değil!", | ||
["nonearby"] = "Yakında araç bulunamadı.", | ||
["nonearbybuyer"] = "Yakında alıcı bulunamadı.", | ||
} |
38 changes: 38 additions & 0 deletions
38
server-data/resources/[esx_addons]/esx_contract/server/main.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
ESX = exports["es_extended"]:getSharedObject() | ||
|
||
RegisterServerEvent("esx_clothes:sellVehicle") | ||
AddEventHandler("esx_clothes:sellVehicle", function(target, plate) | ||
local _source = source | ||
local xPlayer = ESX.GetPlayerFromId(_source) | ||
local _target = target | ||
local tPlayer = ESX.GetPlayerFromId(_target) | ||
local result = MySQL.Sync.fetchAll("SELECT * FROM owned_vehicles WHERE owner = @identifier AND plate = @plate", { | ||
["@identifier"] = xPlayer.identifier, | ||
["@plate"] = plate, | ||
}) | ||
if result[1] ~= nil then | ||
MySQL.Async.execute("UPDATE owned_vehicles SET owner = @target WHERE owner = @owner AND plate = @plate", { | ||
["@owner"] = xPlayer.identifier, | ||
["@plate"] = plate, | ||
["@target"] = tPlayer.identifier, | ||
}, function(rowsChanged) | ||
if rowsChanged ~= 0 then | ||
TriggerClientEvent("esx_contract:showAnim", _source) | ||
Wait(22000) | ||
TriggerClientEvent("esx_contract:showAnim", _target) | ||
Wait(22000) | ||
TriggerClientEvent("esx:showNotification", _source, TranslateCap("soldvehicle", plate)) | ||
TriggerClientEvent("esx:showNotification", _target, TranslateCap("boughtvehicle", plate)) | ||
xPlayer.removeInventoryItem("contract", 1) | ||
end | ||
end) | ||
else | ||
TriggerClientEvent("esx:showNotification", _source, TranslateCap("notyourcar")) | ||
end | ||
end) | ||
|
||
ESX.RegisterUsableItem("contract", function(source) | ||
local _source = source | ||
local xPlayer = ESX.GetPlayerFromId(_source) | ||
TriggerClientEvent("esx_contract:getVehicle", _source) | ||
end) |