Refactor: DMV School - Optimisations

This commit is contained in:
Mycroft
2022-03-02 20:00:07 +00:00
parent 0923fea172
commit f990e29f3d
5 changed files with 50 additions and 115 deletions
+5 -26
View File
@@ -1,36 +1,15 @@
# esx_dmvschool
Realistic DMV school for ESX
## Requirements
- [esx_license](https://github.com/ESX-Org/esx_license)
## Download & Installation
- [esx_license](https://github.com/esx-framework/esx-legacy/tree/main/%5Besx_addons%5D/esx_license)
### Using [fvm](https://github.com/qlaffont/fvm-installer)
```
fvm install --save --folder=esx esx-org/esx_dmvschool
```
## Legal
### Using Git
```
cd resources
git clone https://github.com/ESX-Org/esx_dmvschool [esx]/esx_dmvschool
```
### Manually
- Download https://github.com/ESX-Org/esx_dmvschool/archive/master.zip
- Put it in the `[esx]` directory
## Installation
- Import `esx_dmvschool.sql` in your database
- Add this in your `server.cfg`:
```
start esx_dmvschool
```
# Legal
### License
esx_dmvschool - realistic DMV school for ESX
Copyright (C) 2015-2022 Jérémie N'gadi
@@ -39,4 +18,4 @@ This program Is free software: you can redistribute it And/Or modify it under th
This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details.
You should have received a copy Of the GNU General Public License along with this program. If Not, see http://www.gnu.org/licenses/.
You should have received a copy Of the GNU General Public License along with this program. If Not, see <http://www.gnu.org/licenses/>.
+44 -85
View File
@@ -215,99 +215,30 @@ end)
-- Display markers
CreateThread(function()
while true do
Wait(0)
local coords = GetEntityCoords(PlayerPedId())
local sleep = 1500
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
for k,v in pairs(Config.Zones) do
local Pos = vector3(v.Pos.x, v.Pos.y, v.Pos.z)
if(v.Type ~= -1 and #(coords - Pos) < Config.DrawDistance) then
sleep = 0
DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false)
end
end
end
end)
-- Enter / Exit marker events
CreateThread(function()
while true do
Wait(100)
local coords = GetEntityCoords(PlayerPedId())
local isInMarker = false
local currentZone = nil
for k,v in pairs(Config.Zones) do
local Pos = vector3(v.Pos.x, v.Pos.y, v.Pos.z)
if(#(coords - Pos) < v.Size.x) then
isInMarker = true
currentZone = k
end
end
if (isInMarker and not HasAlreadyEnteredMarker) or (isInMarker and LastZone ~= currentZone) then
HasAlreadyEnteredMarker = true
LastZone = currentZone
TriggerEvent('esx_dmvschool:hasEnteredMarker', currentZone)
end
if not isInMarker and HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = false
TriggerEvent('esx_dmvschool:hasExitedMarker', LastZone)
end
end
end)
-- Block UI
CreateThread(function()
while true do
Wait(0)
if CurrentTest == 'theory' then
local playerPed = PlayerPedId()
sleep = 0
DisableControlAction(0, 1, true) -- LookLeftRight
DisableControlAction(0, 2, true) -- LookUpDown
DisablePlayerFiring(playerPed, true) -- Disable weapon firing
DisableControlAction(0, 142, true) -- MeleeAttackAlternate
DisableControlAction(0, 106, true) -- VehicleMouseControlOverride
else
Wait(500)
end
end
end)
-- Key Controls
CreateThread(function()
while true do
Wait(0)
if CurrentAction then
ESX.ShowHelpNotification(CurrentActionMsg)
if IsControlJustReleased(0, 38) then
if CurrentAction == 'dmvschool_menu' then
OpenDMVSchoolMenu()
end
CurrentAction = nil
end
else
Wait(500)
end
end
end)
-- Drive test
CreateThread(function()
while true do
Wait(0)
if CurrentTest == 'drive' then
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
sleep = 0
local nextCheckPoint = CurrentCheckPoint + 1
if Config.CheckPoints[nextCheckPoint] == nil then
@@ -325,7 +256,6 @@ CreateThread(function()
StopDriveTest(false)
end
else
if CurrentCheckPoint ~= LastCheckPoint then
if DoesBlipExist(CurrentBlip) then
RemoveBlip(CurrentBlip)
@@ -349,20 +279,51 @@ CreateThread(function()
CurrentCheckPoint = CurrentCheckPoint + 1
end
end
else
-- not currently taking driver test
Wait(500)
end
if CurrentAction then
sleep = 0
ESX.ShowHelpNotification(CurrentActionMsg)
if (IsControlJustReleased(0, 38)) and (CurrentAction == 'dmvschool_menu') then
OpenDMVSchoolMenu()
CurrentAction = nil
end
end
local isInMarker = false
local currentZone = nil
for k,v in pairs(Config.Zones) do
local Pos = vector3(v.Pos.x, v.Pos.y, v.Pos.z)
if(#(coords - Pos) < v.Size.x) then
sleep = 0
isInMarker = true
currentZone = k
end
end
if (isInMarker and not HasAlreadyEnteredMarker) or (isInMarker and LastZone ~= currentZone) then
HasAlreadyEnteredMarker = true
LastZone = currentZone
TriggerEvent('esx_dmvschool:hasEnteredMarker', currentZone)
end
if not isInMarker and HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = false
TriggerEvent('esx_dmvschool:hasExitedMarker', LastZone)
end
Wait(sleep)
end
end)
-- Speed / Damage control
CreateThread(function()
while true do
Wait(0)
local sleep = 1500
if CurrentTest == 'drive' then
sleep = 0
local playerPed = PlayerPedId()
if IsPedInAnyVehicle(playerPed, false) then
@@ -402,9 +363,7 @@ CreateThread(function()
Wait(1500)
end
end
else
-- not currently taking driver test
Wait(500)
end
Wait(sleep)
end
end)
+1 -1
View File
@@ -1,5 +1,5 @@
Config = {}
Config.DrawDistance = 100.0
Config.DrawDistance = 10.0
Config.MaxErrors = 5
Config.SpeedMultiplier = 3.6
Config.Locale = 'en'
@@ -1,5 +1,3 @@
USE `es_extended`;
INSERT INTO `licenses` (`type`, `label`) VALUES
('dmv', 'Code de la route'),
('drive', 'Permis de conduire'),
@@ -10,7 +10,6 @@ ESX.RegisterServerCallback('esx_dmvschool:canYouPay', function(source, cb, type)
end
end)
AddEventHandler('esx:playerLoaded', function(source)
TriggerEvent('esx_license:getLicenses', source, function(licenses)
TriggerClientEvent('esx_dmvschool:loadLicenses', source, licenses)