-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.lua
More file actions
132 lines (125 loc) · 4.97 KB
/
server.lua
File metadata and controls
132 lines (125 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
local resourceName = GetCurrentResourceName() -- Get the name of the current resource
local url = 'https://raw.githubusercontent.com/Save5Bucks/race-cam/refs/heads/main/fxmanifest.lua'
local localVersion = GetResourceMetadata(resourceName, 'version', 0) -- Read the version from local fxmanifest
-- Function to check the resource version on server start
local function version_check()
-- Perform HTTP request to get the fxmanifest.lua from the remote GitHub repo
PerformHttpRequest(
url,
function(err, text, headers)
print('################## SAVE5BUCKS ##################')
print('[INFO] Performing Update Check for: ' .. resourceName)
if text ~= nil and err == 200 then
-- Extract the version from the remote fxmanifest.lua
local remoteVersion = string.match(text, "version '([%d%.]+)'")
if remoteVersion then
-- Compare the local and remote versions
if localVersion == remoteVersion then
print('[INFO] ' .. resourceName .. ' is up-to-date (Version: ' .. localVersion .. ').')
print('################## SAVE5BUCKS ##################')
else
print('[WARNING] A newer version of ' .. resourceName .. ' is available!')
print('[INFO] Current Version: ' .. localVersion)
print('[INFO] Latest Version : ' .. remoteVersion)
print('################## SAVE5BUCKS ##################')
end
else
print('[ERROR] Unable to find the version number in the remote fxmanifest.lua.')
print('################## SAVE5BUCKS ##################')
end
else
print('[ERROR] Unable to retrieve the remote fxmanifest.lua. HTTP Error Code: ' .. tostring(err))
print('################## SAVE5BUCKS ##################')
end
end,
'GET',
'',
''
)
end
-- Run the version check when the server starts
AddEventHandler(
'onResourceStart',
function(resourceName)
if GetCurrentResourceName() == resourceName then
version_check()
end
end
)
-- Check transmission type from the database using oxmysql
function checkVehicleTransmission(plate, callback)
MySQL.query(
'SELECT transmission FROM player_vehicles WHERE plate = ?',
{plate},
function(result)
if result and result[1] then
callback(result[1].transmission) -- Pass the transmission type back to the callback
else
callback(nil) -- Return nil if no result is found
end
end
)
end
-- Check transmission type from the database using oxmysql
function checkVehicleTransmission(plate, callback)
MySQL.query(
'SELECT tmission FROM player_vehicles WHERE plate = ?',
{plate},
function(result)
if result and result[1] then
local tmissionValue = result[1].tmission
-- Check if it's manual (1) or automatic (0), or another value
if tmissionValue == true then
callback(true) -- Manual transmission
elseif tmissionValue == false then
callback(false) -- Automatic transmission
else
callback(nil) -- Unknown transmission
end
else
callback(nil) -- No result found
end
end
)
end
-- Export function to set vehicle transmission in the database
-- 0 = automatic, 1 = manual
exports(
'setVehicleTransmission',
function(plate, transmissionType)
MySQL.update(
'UPDATE player_vehicles SET tmission = ? WHERE plate = ?',
{transmissionType, plate},
function(affectedRows)
if affectedRows > 0 then
print(
'Transmission type for plate ' ..
plate .. ' set to ' .. (transmissionType == 1 and 'Manual' or 'Automatic')
)
else
print('No vehicle found with plate: ' .. plate)
end
end
)
end
)
-- Event for checking vehicle transmission
RegisterNetEvent('checkVehicleTransmission')
AddEventHandler(
'checkVehicleTransmission',
function(plate)
local src = source
checkVehicleTransmission(
plate,
function(isManual)
if isManual ~= nil then
-- Trigger the client event with the transmission type
TriggerClientEvent('receiveTransmissionType', src, isManual)
else
-- If transmission type is unknown or no result
TriggerClientEvent('receiveTransmissionType', src, false)
end
end
)
end
)