Skip to content
This repository was archived by the owner on Mar 21, 2021. It is now read-only.

Commit c5e9111

Browse files
author
Christopher
committed
Initial commit
Allows server owners to place vehicles into one of four predefined whitelists in the config, which will then require the respective password in-game before players can enter these vehicles. Passwords are set in the server file. Please note, that for players to enter a vehicle they have not got the password to, such as a suspect getting into a Police Car, they will need to be placed in the vehicle via an external script; this will likely be fixed in a future version.
1 parent 3ac83ba commit c5e9111

File tree

5 files changed

+334
-2
lines changed

5 files changed

+334
-2
lines changed

.travis.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Inferno Collection Vehicle Whitelist Version 1.0 Alpha
2+
#
3+
# Copyright (c) 2019, Christopher M, Inferno Collection. All rights reserved.
4+
5+
#
6+
# This file is used by Travis CI to make sure all the code is this project is error free, and up conventional standards.
7+
# This file does not do anything within FiveM, so feel free to delete it. Keeping it will not do any harm to the resource or your server.
8+
#
9+
10+
language: python
11+
sudo: false
12+
13+
env:
14+
- LUA="lua=5.1"
15+
- LUA="lua=5.2"
16+
- LUA="lua=5.3"
17+
- LUA="luajit=2.0"
18+
- LUA="luajit=2.1"
19+
20+
before_install:
21+
- pip install hererocks
22+
- hererocks lua_install -r^ --$LUA
23+
- export PATH=$PATH:$PWD/lua_install/bin
24+
25+
install:
26+
- luarocks install luacheck
27+
28+
script:
29+
- luacheck -g -a --no-max-line-length --no-max-comment-line-length [inferno-collection]/inferno-vehicle-whitelist
30+
31+
after_success:
32+
- wget https://raw.githubusercontent.com/DiscordHooks/travis-ci-discord-webhook/master/send.sh
33+
- chmod +x send.sh
34+
- ./send.sh success $WEBHOOK_URL
35+
after_failure:
36+
- wget https://raw.githubusercontent.com/DiscordHooks/travis-ci-discord-webhook/master/send.sh
37+
- chmod +x send.sh
38+
- ./send.sh failure $WEBHOOK_URL

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
1-
# Vehicle-Whitelist
2-
Allows server owners to restrict what vehicles players use via a password.
1+
![channels4_banner|690x114](https://i.ibb.co/CHMD8y6/channels4-banner.jpg)
2+
# Inferno Collection: Vehicle Whitelist
3+
[![Build Status](https://travis-ci.com/inferno-collection/Weapons.svg?branch=development)](https://travis-ci.com/inferno-collection/Vehicle-Whitelist)
4+
5+
__Public Alpha Version 1.0__
6+
7+
Allows server owners to place vehicles into one of four predefined whitelists in the config, which will then require the respective password in-game before players can enter these vehicles. Passwords are set in the server file. Please note, that for players to enter a vehicle they have not got the password to, such as a suspect getting into a Police Car, they will need to be placed in the vehicle via an external script; this will likely be fixed in a future version.
8+
9+
Presently, the following can be customized:
10+
- Which vehicles are in which whitelist.
11+
- The passwords for each whitelist
12+
13+
> The Inferno Collection Team
14+
* @ChristopherM
15+
* @Scott_UK
16+
* FrozenN00b
17+
***
18+
Interested in keeping up-to-date with what we are working on? [Check out our roadmap](https://inferno-collection.com/roadmap).
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Inferno Collection Vehicle Whitelist Version 1.0 Alpha
2+
--
3+
-- Copyright (c) 2019, Christopher M, Inferno Collection. All rights reserved.
4+
--
5+
-- This project is licensed under the following:
6+
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, and merge the software, under the following conditions:
7+
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
-- 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. THE SOFTWARE MAY NOT BE SOLD.
9+
--
10+
11+
-- Manifest Version
12+
resource_manifest_version "44febabe-d386-4d18-afbe-5e627f4af937"
13+
14+
-- Client Script
15+
client_script "client.lua"
16+
17+
-- Server Script
18+
server_script "server.lua"
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
-- Inferno Collection Vehicle Whitelist Version 1.0 Alpha
2+
--
3+
-- Copyright (c) 2019, Christopher M, Inferno Collection. All rights reserved.
4+
--
5+
-- This project is licensed under the following:
6+
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, and merge the software, under the following conditions:
7+
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
-- 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. THE SOFTWARE MAY NOT BE SOLD.
9+
--
10+
11+
--
12+
-- Resource Configuration
13+
-- Please note, there is also some configuration required in the
14+
-- `server.lua` file, so make sure to edit that file as well
15+
--
16+
-- PLEASE RESTART SERVER AFTER MAKING CHANGES TO THIS CONFIGURATION
17+
--
18+
19+
local Config = {} -- Do not edit this line
20+
Config.Whitelisted = {} -- Do not edit this line
21+
22+
-- List of vehicle names to be whitelisted to police
23+
Config.Whitelisted.Police = {
24+
"FBI",
25+
"FBI2",
26+
"PBus",
27+
"police",
28+
"police2",
29+
"police3",
30+
"police4",
31+
"PoliceOld1",
32+
"PoliceOld2",
33+
"PoliceT",
34+
"Policeb",
35+
"Polmav",
36+
"Pranger",
37+
"Predator",
38+
"Riot",
39+
"Sheriff",
40+
"Sheriff2"
41+
}
42+
43+
-- List of vehicle names to be whitelisted to Fire and EMS
44+
Config.Whitelisted.FireEMS = {
45+
"Ambulance",
46+
"FireTruk" -- Not a typo, this is the spawn name
47+
}
48+
49+
-- List of vehicle names to be whitelisted to Military
50+
Config.Whitelisted.Military = {
51+
"APC",
52+
"Barracks",
53+
"Barracks2",
54+
"Crusader",
55+
"Halftrack",
56+
"Rhino"
57+
}
58+
59+
-- Custom list of vehicle names to be whitelisted
60+
Config.Whitelisted.Custom = {
61+
"Insurgent",
62+
"Insurgent2",
63+
"Dump",
64+
"Blimp",
65+
"Blimp2"
66+
}
67+
68+
--
69+
-- Nothing past this point needs to be edited, all the settings for the resource are found ABOVE this line.
70+
-- Do not make changes below this line unless you know what you are doing!
71+
--
72+
73+
local Player = {}
74+
Player.Vehicle = {}
75+
76+
-- On client join server
77+
AddEventHandler("onClientMapStart", function()
78+
TriggerEvent("chat:addSuggestion", "/unlock", "Type a vehicle type/class and password to unlock that vehicle type/class.", {
79+
{ name = "type/class", help = "Police FireEMS Military Custom" },
80+
{ name = "password", help = "The password for this type/class" }
81+
})
82+
end)
83+
84+
-- Draw message on client screen
85+
RegisterNetEvent("Vehicle-Whitelist:Return:Message")
86+
AddEventHandler("Vehicle-Whitelist:Return:Message", function(Message, Flash)
87+
-- Tell GTA that a string will be passed
88+
SetNotificationTextEntry("STRING")
89+
-- Pass temporary variable to notification
90+
AddTextComponentString(Message)
91+
-- Draw new notification on client's screen
92+
DrawNotification(Flash, true)
93+
end)
94+
95+
-- Return for vehicle allowed check
96+
RegisterNetEvent("Vehicle-Whitelist:Return:Check")
97+
AddEventHandler("Vehicle-Whitelist:Return:Check", function(Allowed)
98+
if not Allowed then
99+
ClearPedTasksImmediately(Player.Ped)
100+
TriggerEvent("Vehicle-Whitelist:Return:Message", "~r~You are not allowed to use this vehicle.", true)
101+
Player.Vehicle.Allowed = false
102+
else
103+
Player.Vehicle.Allowed = true
104+
end
105+
end)
106+
107+
Citizen.CreateThread(function()
108+
while true do
109+
Citizen.Wait(0)
110+
111+
Player.Ped = PlayerPedId()
112+
Player.Vehicle.Entity = GetVehiclePedIsTryingToEnter(Player.Ped)
113+
114+
-- If player is trying to enter a vehicle
115+
if Player.Vehicle.Entity ~= 0 then
116+
if not Player.Vehicle.Allowed or Player.Vehicle.Last ~= Player.Vehicle.Entity then
117+
Player.Vehicle.Last = Player.Vehicle.Entity
118+
Player.Vehicle.Hash = GetEntityModel(Player.Vehicle.Entity)
119+
120+
local Found = false
121+
122+
-- Loop though all the police vehicles
123+
for _, Vehicle in ipairs(Config.Whitelisted.Police) do
124+
if not Found then
125+
local Key = GetHashKey(Vehicle)
126+
if Key == Player.Vehicle.Hash then
127+
Found = "police"
128+
break
129+
end
130+
end
131+
end
132+
133+
if not Found then
134+
-- Loop though all the fire/ems vehicles
135+
for _, Vehicle in ipairs(Config.Whitelisted.FireEMS) do
136+
if not Found then
137+
local Key = GetHashKey(Vehicle)
138+
if Key == Player.Vehicle.Hash then
139+
Found = "fireems"
140+
break
141+
end
142+
end
143+
end
144+
end
145+
146+
if not Found then
147+
-- Loop though all the military vehicles
148+
for _, Vehicle in ipairs(Config.Whitelisted.Military) do
149+
if not Found then
150+
local Key = GetHashKey(Vehicle)
151+
if Key == Player.Vehicle.Hash then
152+
Found = "military"
153+
break
154+
end
155+
end
156+
end
157+
end
158+
159+
if not Found then
160+
-- Loop though all the custom vehicles
161+
for _, Vehicle in ipairs(Config.Whitelisted.Custom) do
162+
if not Found then
163+
local Key = GetHashKey(Vehicle)
164+
if Key == Player.Vehicle.Hash then
165+
Found = "custom"
166+
break
167+
end
168+
end
169+
end
170+
end
171+
172+
if Found then
173+
TriggerServerEvent("Vehicle-Whitelist:Check", Found)
174+
else
175+
Player.Vehicle.Allowed = true
176+
end
177+
end
178+
end
179+
180+
end
181+
end)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
-- Inferno Collection Vehicle Whitelist Version 1.0 Alpha
2+
--
3+
-- Copyright (c) 2019, Christopher M, Inferno Collection. All rights reserved.
4+
--
5+
-- This project is licensed under the following:
6+
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, and merge the software, under the following conditions:
7+
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
-- 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. THE SOFTWARE MAY NOT BE SOLD.
9+
--
10+
11+
--
12+
-- Resource Configuration
13+
-- Please note, there is also some configuration required in the
14+
-- `client.lua` file, so make sure to edit that file as well
15+
--
16+
-- PLEASE RESTART SERVER AFTER MAKING CHANGES TO THIS CONFIGURATION
17+
--
18+
19+
local Config = {} -- Do not edit this line
20+
Config.Passwords = {} -- Do not edit this line
21+
22+
-- Password for Police vehicles
23+
Config.Passwords.police = "p"
24+
25+
-- Password for Fire/EMS vehicles
26+
Config.Passwords.fireems = "f"
27+
28+
-- Password for Military vehicles
29+
Config.Passwords.military = "m"
30+
31+
-- Password for custom vehicles
32+
Config.Passwords.custom = "c"
33+
34+
--
35+
-- Nothing past this point needs to be edited, all the settings for the resource are found ABOVE this line.
36+
-- Do not make changes below this line unless you know what you are doing!
37+
--
38+
39+
local Allowed = {}
40+
Allowed.police = {}
41+
Allowed.fireems = {}
42+
Allowed.military = {}
43+
Allowed.custom = {}
44+
45+
-- Unlock command
46+
RegisterCommand("unlock", function(source, Args)
47+
if Args[1] then
48+
local Class = Args[1]:lower()
49+
if Class == "police" or Class == "fireems" or Class == "military" or Class == "custom" then
50+
if Args[2] then
51+
if not Allowed[Class][source] then
52+
local Password = Args[2]
53+
54+
if Config.Passwords[Class] == Password then
55+
Allowed[Class][source] = true
56+
57+
TriggerClientEvent("Vehicle-Whitelist:Return:Message", source, "~g~Access to " .. Args[1] .. " vehicles granted!", false)
58+
else
59+
TriggerClientEvent("Vehicle-Whitelist:Return:Message", source, "~r~Password incorrect!", true)
60+
end
61+
else
62+
TriggerClientEvent("Vehicle-Whitelist:Return:Message", source, "~g~You already have access to " .. Args[1] .. " vehicles!", false)
63+
end
64+
else
65+
TriggerClientEvent("Vehicle-Whitelist:Return:Message", source, "~r~No password provided!", true)
66+
end
67+
else
68+
TriggerClientEvent("Vehicle-Whitelist:Return:Message", source, "~r~" .. Args[1] .. " is not a valid vehicle class!", true)
69+
end
70+
else
71+
TriggerClientEvent("Vehicle-Whitelist:Return:Message", source, "~r~No arguments provided!", true)
72+
end
73+
end)
74+
75+
-- Check if client is allowed to drive a vehicle type
76+
RegisterServerEvent("Vehicle-Whitelist:Check")
77+
AddEventHandler("Vehicle-Whitelist:Check", function(VehicleType)
78+
TriggerClientEvent("Vehicle-Whitelist:Return:Check", source, Allowed[VehicleType][source])
79+
end)

0 commit comments

Comments
 (0)