adding new scripts
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Jared
|
||||
|
||||
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.
|
||||
@@ -0,0 +1,5 @@
|
||||
# VehicleTrustSystem
|
||||
## Continued Documentation
|
||||
https://docs.badger.store/fivem-misc.-scripts/vehicletrustsystem
|
||||
## Discontinued Documentation
|
||||
All information: https://forum.fivem.net/t/release-vehicletrustsystem/674066
|
||||
@@ -0,0 +1,8 @@
|
||||
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
|
||||
|
||||
client_script "client.lua"
|
||||
client_script "config.lua"
|
||||
|
||||
server_script "server.lua"
|
||||
|
||||
file "whitelist.json"
|
||||
@@ -0,0 +1,90 @@
|
||||
local identifiers = {}
|
||||
function ShowInfo(text)
|
||||
SetNotificationTextEntry("STRING")
|
||||
AddTextComponentSubstringPlayerName(text)
|
||||
DrawNotification(false, false)
|
||||
end
|
||||
Citizen.CreateThread(function()
|
||||
local myIdss = getIdentifiers()
|
||||
print(myIdss)
|
||||
while true do
|
||||
Citizen.Wait(10000)
|
||||
TriggerServerEvent('primerp_vehwl:reloadwl')
|
||||
TriggerServerEvent('primerp_vehwl:Server:Check')
|
||||
end
|
||||
end)
|
||||
function getConfig()
|
||||
return LoadResourceFile(GetCurrentResourceName(), "whitelist.json")
|
||||
end
|
||||
AddEventHandler("playerSpawned", function()
|
||||
TriggerServerEvent("primerp_vehwl:reloadwl")
|
||||
end)
|
||||
|
||||
function getIdentifiers()
|
||||
return identifiers
|
||||
end
|
||||
|
||||
RegisterNetEvent('primerp_vehwl:RunCode:Client')
|
||||
AddEventHandler('primerp_vehwl:RunCode:Client', function(cfg)
|
||||
--
|
||||
local ped = GetPlayerPed(-1)
|
||||
local inVeh = IsPedInAnyVehicle(ped, false)
|
||||
local veh = GetVehiclePedIsUsing(ped)
|
||||
local driver = GetPedInVehicleSeat(veh, -1)
|
||||
local spawncode = GetEntityModel(veh)
|
||||
local allowed = false
|
||||
local exists = false
|
||||
local myIds = {}
|
||||
myIds = getIdentifiers()
|
||||
if (inVeh) and (driver == ped) then
|
||||
for pair,_ in pairs(cfg) do
|
||||
-- Pair
|
||||
for _,vehic in ipairs(cfg[pair]) do
|
||||
--print("Checking if exists with vehic.spawncode == " .. string.upper(vehic.spawncode) .. " and spawncode == "
|
||||
--.. string.upper(spawncode))
|
||||
if (GetHashKey(vehic.spawncode) == spawncode) then
|
||||
exists = true
|
||||
end
|
||||
end
|
||||
if (pair == myIds[1]) then
|
||||
for _,v in ipairs(cfg[pair]) do
|
||||
--print(v.allowed)
|
||||
--print("The vehicle is " .. v.spawncode .. " and allowed = " .. tostring(v.allowed) .. " with ID as " .. tostring(pair))
|
||||
if (spawncode == GetHashKey(v.spawncode)) and (v.allowed) then
|
||||
allowed = true
|
||||
print("Allowed was set to true with vehicle == " .. v.spawncode)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
--print("Value of exists == " .. tostring(exists) .. " and value of allowed == " .. tostring(allowed))
|
||||
if (exists and not allowed) then
|
||||
--print("It should delete the vehicle for " .. GetPlayerName(source))
|
||||
DeleteEntity(veh)
|
||||
ClearPedTasksImmediately(ped)
|
||||
TriggerEvent('primerp_vehwl:RunCode:Success', source)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('primerp_vehwl:RunCode:Success')
|
||||
AddEventHandler('primerp_vehwl:RunCode:Success', function()
|
||||
ShowInfo('~r~ERROR: You do not have access to this personal vehicle')
|
||||
end)
|
||||
|
||||
RegisterNetEvent("primerp_vehwl:loadIdentifiers")
|
||||
AddEventHandler("primerp_vehwl:loadIdentifiers", function(id)
|
||||
identifiers = id
|
||||
end)
|
||||
|
||||
RegisterCommand("reloadwl", function(source)
|
||||
TriggerServerEvent("primerp_vehwl:reloadwl")
|
||||
end)
|
||||
|
||||
--[[
|
||||
Commands:
|
||||
/setOwner <id> <spawncode>
|
||||
/trust <id> <spawncode>
|
||||
/untrust <id> <spawncode>
|
||||
/vehicle list
|
||||
--]]--
|
||||
@@ -0,0 +1,325 @@
|
||||
|
||||
prefix = '^0[^6VehicleTrustSystem^0] '
|
||||
|
||||
-- Code --
|
||||
RegisterServerEvent("primerp_vehwl:reloadwl")
|
||||
AddEventHandler("primerp_vehwl:reloadwl", function()
|
||||
local _source = source
|
||||
local identifiers = GetPlayerIdentifiers(_source)
|
||||
TriggerClientEvent("primerp_vehwl:loadIdentifiers", _source, identifiers)
|
||||
end)
|
||||
|
||||
AddEventHandler("playerSpawned", function()
|
||||
TriggerEvent("primerp_vehwl:getIdentifiers")
|
||||
end)
|
||||
|
||||
RegisterServerEvent("primerp_vehwl:saveFile")
|
||||
AddEventHandler("primerp_vehwl:saveFile", function(data)
|
||||
SaveResourceFile(GetCurrentResourceName(), "whitelist.json", json.encode(data, { indent = true }), -1)
|
||||
end)
|
||||
function has_value (tab, val)
|
||||
for index, value in ipairs(tab) do
|
||||
if value == val then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
function get_index (tab, val)
|
||||
local counter = 1
|
||||
for index, value in ipairs(tab) do
|
||||
if value == val then
|
||||
return counter
|
||||
end
|
||||
counter = counter + 1
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
RegisterNetEvent('primerp_vehwl:Server:Check')
|
||||
AddEventHandler('primerp_vehwl:Server:Check', function()
|
||||
local config = LoadResourceFile(GetCurrentResourceName(), "whitelist.json")
|
||||
local cfg = json.decode(config)
|
||||
TriggerClientEvent('primerp_vehwl:RunCode:Client', source, cfg)
|
||||
end)
|
||||
|
||||
--- COMMANDS ---
|
||||
RegisterCommand("vehicles", function(source, args, rawCommand)
|
||||
-- Get the vehicles they can drive
|
||||
local al = LoadResourceFile(GetCurrentResourceName(), "whitelist.json")
|
||||
local cfg = json.decode(al)
|
||||
local allowed = {}
|
||||
local myIds = GetPlayerIdentifiers(source)
|
||||
for pair,_ in pairs(cfg) do
|
||||
-- Pair
|
||||
if (pair == myIds[1]) then
|
||||
for _,v in ipairs(cfg[pair]) do
|
||||
--print(v.allowed)
|
||||
--print("The vehicle is " .. v.spawncode .. " and allowed = " .. tostring(v.allowed) .. " with ID as " .. tostring(pair))
|
||||
if (v.allowed) then
|
||||
table.insert(allowed, v.spawncode)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if #allowed > 0 then
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^2You are allowed access to drive the following vehicles:")
|
||||
TriggerClientEvent('chatMessage', source, "^0" .. table.concat(allowed, ', '))
|
||||
else
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^1Sadly no one has gave you access to drive a personal vehicle :(")
|
||||
end
|
||||
end)
|
||||
RegisterCommand("clear", function(source, args, rawCommand)
|
||||
-- /clear <spawncode> == Basically reset a vehicle's data (owners and allowed to drive)
|
||||
if IsPlayerAceAllowed(source, "VehwlCommands.Access") then
|
||||
-- Check args
|
||||
if #args < 1 then
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^1ERROR: Not enough arguments... ^1Valid: /clear <spawncode>")
|
||||
return;
|
||||
end
|
||||
local vehicle = string.upper(args[1])
|
||||
local al = LoadResourceFile(GetCurrentResourceName(), "whitelist.json")
|
||||
local cfg = json.decode(al)
|
||||
for pair,_ in pairs(cfg) do
|
||||
-- Pair
|
||||
local ind = 0
|
||||
for _,veh in ipairs(cfg[pair]) do
|
||||
ind = ind + 1
|
||||
if string.upper(veh.spawncode) == string.upper(vehicle) then
|
||||
table.remove(cfg[pair], ind)
|
||||
end
|
||||
end
|
||||
end
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^2Success: Removed all data of vehicle ^5" .. vehicle .. "^2")
|
||||
TriggerClientEvent('vehwl:Cache:Update:ClearVeh', -1, vehicle)
|
||||
TriggerEvent("primerp_vehwl:saveFile", cfg)
|
||||
end
|
||||
end)
|
||||
RegisterCommand("setOwner", function(source, args, rawCommand)
|
||||
-- Needs a staff Ace perm to do this
|
||||
if IsPlayerAceAllowed(source, "VehwlCommands.Access") then
|
||||
if #args < 2 then
|
||||
-- Too low args
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^1ERROR: Not enough arguments... ^1Valid: /setOwner <id> <vehicleSpawncode>")
|
||||
return;
|
||||
end
|
||||
local id = tonumber(args[1])
|
||||
--print(GetPlayerIdentifiers(id)[1])
|
||||
if GetPlayerIdentifiers(id)[1] == nil then
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^1ERROR: That is not a valid server ID of a player...")
|
||||
return;
|
||||
end
|
||||
-- /setOwner <id> <vehicle>
|
||||
local vehicle = string.upper(args[2])
|
||||
local identifiers = GetPlayerIdentifiers(id)
|
||||
local steam = identifiers[1]
|
||||
local al = LoadResourceFile(GetCurrentResourceName(), "whitelist.json")
|
||||
local cfg = json.decode(al)
|
||||
-- Check that no one owns this vehicle before setting it:
|
||||
local vehicledOwned = false
|
||||
-- Check below:
|
||||
for pair,_ in pairs(cfg) do
|
||||
-- Pair
|
||||
for _,veh in ipairs(cfg[pair]) do
|
||||
if string.upper(veh.spawncode) == string.upper(vehicle) then
|
||||
if veh.owner == true then
|
||||
vehicledOwned = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Is it owned already?
|
||||
if not vehicledOwned then
|
||||
local vehiclesList = cfg[steam]
|
||||
if vehiclesList == nil then
|
||||
cfg[steam] = {}
|
||||
vehiclesList = {}
|
||||
end
|
||||
local hasValue = false
|
||||
local index = nil
|
||||
for i = 1, #vehiclesList do
|
||||
if string.upper(vehicle) == string.upper(vehiclesList[i].spawncode) then
|
||||
hasValue = true
|
||||
index = i
|
||||
end
|
||||
end
|
||||
if not hasValue then
|
||||
-- Doesn't have it, add it
|
||||
table.insert(vehiclesList, {
|
||||
owner=true,
|
||||
allowed=true,
|
||||
spawncode=vehicle,
|
||||
})
|
||||
else
|
||||
-- It does have it, set it
|
||||
vehiclesList[index].owner = true
|
||||
vehiclesList[index].allowed = true
|
||||
end
|
||||
cfg[steam] = vehiclesList
|
||||
TriggerEvent("primerp_vehwl:saveFile", cfg)
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^2Success: You have set ^5"
|
||||
.. GetPlayerName(id) .. "^2 as the owner to the vehicle ^5" .. vehicle)
|
||||
TriggerClientEvent('chatMessage', id, prefix .. "^2You have been set "
|
||||
.. " to the owner of vehicle ^5" .. vehicle .. "^2 by ^5" .. GetPlayerName(source))
|
||||
else
|
||||
-- Vehicle is owned, need to /clear it first
|
||||
TriggerClientEvent('chatMessage', source, prefix ..
|
||||
"^1ERROR: That vehicle is owned by someone already... Use /clear <spawncode> to clear it's data")
|
||||
end
|
||||
end -- Can't use it if not allowed
|
||||
end)
|
||||
function isOwner(src)
|
||||
-- Check if they own the vehicle
|
||||
end
|
||||
RegisterCommand("trust", function(source, args, rawCommand)
|
||||
local al = LoadResourceFile(GetCurrentResourceName(), "whitelist.json")
|
||||
local cfg = json.decode(al)
|
||||
-- /trust <id> <vehicle>
|
||||
local vehicle = string.upper(args[2])
|
||||
local id = tonumber(args[1])
|
||||
-- Check args
|
||||
if #args < 2 then
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^1ERROR: Not enough arguments... ^1Valid: /trust <id> <vehicleSpawncode>")
|
||||
return;
|
||||
end
|
||||
-- Check if valid id
|
||||
if id == source then
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^1ERROR: You cannot trust yourself...")
|
||||
return;
|
||||
end
|
||||
if GetPlayerIdentifiers(id)[1] == nil then
|
||||
-- It's invalid
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^1ERROR: That is not a valid server ID of a player...")
|
||||
return;
|
||||
end
|
||||
local steam = GetPlayerIdentifiers(id)[1]
|
||||
-- Check if has vehicle ownership and can do this command
|
||||
local vehicledOwned = false
|
||||
-- Check below:
|
||||
for pair,_ in pairs(cfg) do
|
||||
-- Pair
|
||||
if tostring(GetPlayerIdentifiers(source)[1]) == tostring(pair) then
|
||||
for _,veh in ipairs(cfg[pair]) do
|
||||
if string.upper(veh.spawncode) == string.upper(vehicle) then
|
||||
if veh.owner == true then
|
||||
vehicledOwned = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if not vehicledOwned then
|
||||
-- They do not own it, end this
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^1ERROR: You do not own this vehicle...")
|
||||
return;
|
||||
end
|
||||
local vehiclesList = cfg[steam]
|
||||
if vehiclesList == nil then
|
||||
cfg[steam] = {}
|
||||
vehiclesList = {}
|
||||
end
|
||||
local hasValue = false
|
||||
local index = nil
|
||||
for i = 1, #vehiclesList do
|
||||
if string.upper(vehicle) == string.upper(vehiclesList[i].spawncode) then
|
||||
hasValue = true
|
||||
index = i
|
||||
end
|
||||
end
|
||||
if not hasValue then
|
||||
-- Doesn't have it, add it
|
||||
table.insert(vehiclesList, {
|
||||
owner=false,
|
||||
allowed=true,
|
||||
spawncode=vehicle,
|
||||
})
|
||||
else
|
||||
-- It does have it, set it
|
||||
vehiclesList[index].owner = false
|
||||
vehiclesList[index].allowed = true
|
||||
end
|
||||
cfg[steam] = vehiclesList
|
||||
TriggerEvent("primerp_vehwl:saveFile", cfg)
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^2Success: You have given player ^5"
|
||||
.. GetPlayerName(id) .. "^2 permission to drive your vehicle ^5"
|
||||
.. vehicle)
|
||||
TriggerClientEvent('chatMessage', id, prefix .. "^2You have been trusted "
|
||||
.. " to use the vehicle, ^5" .. vehicle .. "^2 by owner ^5" .. GetPlayerName(source))
|
||||
end)
|
||||
|
||||
RegisterCommand("untrust", function(source, args, rawCommand)
|
||||
local al = LoadResourceFile(GetCurrentResourceName(), "whitelist.json")
|
||||
local cfg = json.decode(al)
|
||||
-- /untrust <id> <vehicle>
|
||||
local vehicle = string.upper(args[2])
|
||||
local id = tonumber(args[1])
|
||||
-- Check args
|
||||
if #args < 2 then
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^1ERROR: Not enough arguments... ^1Valid: /untrust <id> <vehicleSpawncode>")
|
||||
return;
|
||||
end
|
||||
-- Check if valid id
|
||||
if id == source then
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^1ERROR: You cannot untrust yourself...")
|
||||
return;
|
||||
end
|
||||
if GetPlayerIdentifiers(id)[1] == nil then
|
||||
-- It's invalid
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^1ERROR: That is not a valid server ID of a player...")
|
||||
return;
|
||||
end
|
||||
local steam = GetPlayerIdentifiers(id)[1]
|
||||
-- Check if has vehicle ownership and can do this command
|
||||
local vehicledOwned = false
|
||||
-- Check below:
|
||||
for pair,_ in pairs(cfg) do
|
||||
-- Pair
|
||||
if tostring(GetPlayerIdentifiers(source)[1]) == tostring(pair) then
|
||||
for _,veh in ipairs(cfg[pair]) do
|
||||
if string.upper(veh.spawncode) == string.upper(vehicle) then
|
||||
if veh.owner == true then
|
||||
vehicledOwned = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if not vehicledOwned then
|
||||
-- They do not own it, end this
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^1ERROR: You do not own this vehicle...")
|
||||
return;
|
||||
end
|
||||
local vehiclesList = cfg[steam]
|
||||
if vehiclesList == nil then
|
||||
cfg[steam] = {}
|
||||
vehiclesList = {}
|
||||
end
|
||||
local hasValue = false
|
||||
local index = nil
|
||||
for i = 1, #vehiclesList do
|
||||
if string.upper(vehicle) == string.upper(vehiclesList[i].spawncode) then
|
||||
hasValue = true
|
||||
index = i
|
||||
end
|
||||
end
|
||||
if not hasValue then
|
||||
-- Doesn't have it, add it
|
||||
table.insert(vehiclesList, {
|
||||
owner=false,
|
||||
allowed=false,
|
||||
spawncode=vehicle,
|
||||
})
|
||||
else
|
||||
-- It does have it, set it
|
||||
vehiclesList[index].owner = false
|
||||
vehiclesList[index].allowed = false
|
||||
end
|
||||
cfg[steam] = vehiclesList
|
||||
TriggerEvent("primerp_vehwl:saveFile", cfg)
|
||||
TriggerClientEvent('chatMessage', source, prefix .. "^2Success: ^1Player "
|
||||
.. GetPlayerName(id) .. "^1 no longer has permission to drive your vehicle ^5"
|
||||
.. vehicle)
|
||||
TriggerClientEvent('chatMessage', id, prefix .. "^1Your "
|
||||
.. " trust to use the vehicle ^5" .. vehicle .. " ^1has been revoked by owner ^5" .. GetPlayerName(source))
|
||||
end)
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
Reference in New Issue
Block a user