Skip to content

Commit

Permalink
added NUI
Browse files Browse the repository at this point in the history
  • Loading branch information
swkeep committed Jun 1, 2022
1 parent 96ef8f8 commit b6c62f6
Show file tree
Hide file tree
Showing 14 changed files with 489 additions and 37 deletions.
59 changes: 59 additions & 0 deletions client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,68 @@ CreateThread(function() -- Check if the player is in the garage area or not
end
end)

local receivedDoorData = false
local receivedData = nil

local closeNUI = function()
SetNuiFocus(false, false)
SendNUIMessage({ type = "newDoorSetup", enable = false })
Wait(10)
receivedDoorData = nil
end

RegisterNUICallback('saveNewVehicle', function(data, cb)
receivedDoorData = true
receivedData = data
closeNUI()
cb('ok')
end)

RegisterNUICallback('close', function(data, cb)
closeNUI()
cb('ok')
end)

local displayNUIText = function(text)
local selectedColor = closestDoor.data.locked and Config.LockedColor or Config.UnlockedColor
SendNUIMessage({ type = "display", text = text, color = selectedColor })
Wait(1)
end

local hideNUI = function()
SendNUIMessage({ type = "hide" })
Wait(1)
end

local function saveVehicle(receivedDoorData)
local plyPed = PlayerPedId()
local veh = GetVehiclePedIsIn(plyPed, false)
local c_car = QBCore.Functions.GetVehicleProperties(veh)
if not Config.VehicleWhiteList[currentgarage][tostring(c_car.model)] then return end

local required_data = {
vehicle = c_car,
plate = receivedDoorData.platevalue,
name = receivedDoorData.vehiclename,
grades = receivedDoorData.grades,
cids = receivedDoorData.cids,
hash = GetHashKey(veh),
garage = currentgarage,
info = Config.VehicleWhiteList[currentgarage][tostring(c_car.model)]
}
QBCore.Functions.TriggerCallback('keep-jobgarages:server:save_vehicle', function(result)
print(result)
end, required_data)
end

RegisterNetEvent('keep-jobgarages:client:newVehicleSetup', function()
receivedDoorData = false
SetNuiFocus(true, true)
SendNUIMessage({ type = "newDoorSetup", enable = true })
while receivedDoorData == false do Wait(250) DisableAllControlActions(0) end
if receivedDoorData == nil then return end
saveVehicle(receivedDoorData)
end)
-- --Garage Thread
-- CreateThread(function()
-- Wait(1000)
Expand Down
22 changes: 3 additions & 19 deletions client/menu/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function Open:categories(data)
}
}
}

print(data)
for key, DISTINCT in pairs(data.DISTINCT) do
openMenu[#openMenu + 1] = {
header = get_vehicle_label(DISTINCT.model),
Expand Down Expand Up @@ -255,7 +255,8 @@ RegisterCommand('+garage_menu', function()
if not IsPauseMenuActive() then
-- save vehicle
if IsPedInAnyVehicle(PlayerPedId(), false) and Config.AllowledList[1] then
Open:save_menu()
TriggerEvent('keep-jobgarages:client:newVehicleSetup')
-- Open:save_menu()
return
end
-- -- store vehicle
Expand Down Expand Up @@ -303,23 +304,6 @@ end)

-- restricted functions

local function saveVehicle()
local plyPed = PlayerPedId()
local veh = GetVehiclePedIsIn(plyPed, false)
local c_car = QBCore.Functions.GetVehicleProperties(veh)
if not Config.VehicleWhiteList[currentgarage][tostring(c_car.model)] then return end

local required_data = {
vehicle = c_car,
name = 'Sup',
hash = GetHashKey(veh),
garage = currentgarage,
info = Config.VehicleWhiteList[currentgarage][tostring(c_car.model)]
}
QBCore.Functions.TriggerCallback('keep-jobgarages:server:save_vehicle', function(result)
print(result)
end, required_data)
end

function Open:save_menu()
local openMenu = {
Expand Down
60 changes: 60 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,66 @@ Config.JobGarages = {
minz = 24.66,
maxz = 28.66,
},
['mrpd_out'] = {
label = 'Police Garage',
spawnPoint = {
vector4(449.54, -1025.0, 27.96, 186.01),
vector4(446.05, -1025.0, 28.03, 184.5),
vector4(442.55, -1026.0, 28.09, 184.49),
vector4(439.1, -1026.0, 28.16, 185.11),
vector4(435.67, -1026.0, 28.22, 184.95)
},
blippoint = vector3(441.64, -984.96, 25.7),
showBlip = false,
blipsprite = 357,
blipscale = 0.65,
blipcolour = 3,
job = 'police',
fullfix = {
active = true,
price = 250,
},
canStoreVehicle = {
''
},
zones = {
vector2(455.4, -1028.0),
vector2(455.0, -1012.7),
vector2(430.5, -1014.3),
vector2(430.9, -1029.8)
},
minz = 26.66,
maxz = 32.66,
},
['mrpd_back'] = {
label = 'Police Garage',
spawnPoint = {
vector4(475.95, -1026.46, 27.49, 329.57),
vector4(479.38, -1026.41, 27.42, 329.81),
vector4(483.16, -1025.68, 27.39, 328.76)
},
blippoint = vector3(441.64, -984.96, 25.7),
showBlip = false,
blipsprite = 357,
blipscale = 0.65,
blipcolour = 3,
job = 'police',
fullfix = {
active = true,
price = 250,
},
canStoreVehicle = {
''
},
zones = {
vector2(472, -1030.2),
vector2(487, -1028.4),
vector2(487, -1017),
vector2(472, -1017)
},
minz = 27,
maxz = 30.95,
},
}

Config.VehicleWhiteList = {
Expand Down
8 changes: 8 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,13 @@ server_script {
'server/server_lib/lib.lua' }

-- dependency 'oxmysql'
ui_page 'html/door.html'

files {
'html/*.html',
'html/*.js',
'html/*.css',
'html/sounds/*.ogg',
}

lua54 'yes'
65 changes: 65 additions & 0 deletions html/door.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<html>

<head>
<title>NUI Keep-jobgarages</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap" rel="stylesheet" />
</head>

<body>
<div id="container">
<div id="doorlock" style="display: none; background: rgb(19, 28, 74);"></div>
</div>

<audio id="sounds"><source type="audio/ogg"></audio>

<div id="formContainer" style="display: none;">
<form id="newDoor">
<div>
<text>Vehicle Name</text>
<input id="vehiclename" type="text" name="vehiclename" placeholder='Name In Menu'><br>
</div>

<div>
<text>Vehicle's Plate</text>
<div class="namegen">
<input id="platevalue" type="text" name="platevalue" placeholder='Plate'><br>
<button id="randomize" type="button">randomize</button>
</div>

</div>

<div>
<text>Plate Type</text>
<select id='platetype' name='platetype' class='dropdown'>
<option option value='none'>None</option>
<option value='PD'>PD</option>
<option value='SP'>SP</option>
</select>
</div>

<div>
<text>Job Authorisation</text>
<input id="job" type="text" name="job" placeholder='police'><br>
</div>

<div>
<text>Grade Authorisation</text>
<input id="grades" type="text" name="grades" placeholder='1,2,3,...'><br>
</div>

<div>
<text>CitizenID Authorisation</text>
<input id="cids" type="text" name="cids" placeholder='PZT37891,PZT37891,....'><br>
</div>

<div>
<button id="submit" type="submit">Submit</button>
</div>
</form>
</div>

<script src="main.js" type="text/javascript"></script>
</body>

</html>
123 changes: 123 additions & 0 deletions html/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
const formContainer = document.getElementById('formContainer');
const newDoorForm = document.getElementById('newDoor');
const doorlockContainer = document.getElementById('container');
const doorlock = document.getElementById('doorlock');

var formInfo = {
vehiclename: document.getElementById('vehiclename'),
platevalue: document.getElementById('platevalue'),
platetype: document.getElementById('doortype'),
job: document.getElementById('job'),
grades: document.getElementById('grades'),
cids: document.getElementById('cids'),
}

window.addEventListener('message', ({ data }) => {
if (data.color) {
doorlock.style.background = data.color;
}
if (data.type == "newDoorSetup") {
data.enable ? formContainer.style.display = "flex" : formContainer.style.display = "none";
data.enable ? doorlockContainer.style.display = "none" : doorlockContainer.style.display = "block";
return
}
if (data.type == "audio") {
var volume = (data.audio['volume'] / 10) * data.sfx
if (volume > 1.0) {
volume = 1.0
}
if (data.distance !== 0) {
var volume = volume / data.distance
}
var sound = new Audio('sounds/' + data.audio['file']);
sound.volume = volume;
sound.play();
} else if (data.type == "display") {
if (data.text !== undefined) {
doorlock.style.display = 'block';
doorlock.innerHTML = data.text;
doorlock.classList.add('slide-in');
}
} else if (data.type == "hide") {
doorlock.classList.add('slide-out');
setTimeout(function() {
doorlock.innerHTML = '';
doorlock.style.display = 'none';
doorlock.classList.remove('slide-in');
doorlock.classList.remove('slide-out');
}, 1000)
}
})

document.addEventListener('keyup', (e) => {
if (e.key == 'Escape') {
sendNUICB('close');
}
});

document.getElementById('newDoor').addEventListener('submit', (e) => {
e.preventDefault();
sendNUICB('saveNewVehicle', {
vehiclename: formInfo.vehiclename.value,
platevalue: formInfo.platevalue.value,
job: formInfo.job.value,
grades: formInfo.grades.value,
cids: formInfo.cids.value,
});
})

function sendNUICB(event, data = {}, cb = () => {}) {
fetch(`https://${GetParentResourceName()}/${event}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json; charset=UTF-8', },
body: JSON.stringify(data)
}).then(resp => resp.json()).then(resp => cb(resp));
}

function makeid(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() *
charactersLength));
}
return result;
}

const reandomize = document.getElementById('randomize')
reandomize.addEventListener('click', (event) => {
const platetype = document.getElementById('platetype')
const reandomize = document.getElementById('platevalue')

if (platetype.value === 'none') reandomize.value = makeid(8)
else if (platetype.value === 'PD') {
reandomize.value = makeid(6)
reandomize.value += 'PD'
} else if (platetype.value === 'SP') {
reandomize.value = makeid(6)
reandomize.value += 'SP'
}
});

window.onload = (event) => {
const reandomize = document.getElementById('platevalue')
const job = document.getElementById('job')
reandomize.value = makeid(8)
job.value = 'police'
};

const platetype = document.getElementById('platetype')
platetype.addEventListener('change', (event) => {
const platetype = document.getElementById('platetype')
const reandomize = document.getElementById('platevalue')

if (platetype.value === 'none') reandomize.value = makeid(8)
else if (platetype.value === 'PD') {
reandomize.value = makeid(6)
reandomize.value += 'PD'
} else if (platetype.value === 'SP') {
reandomize.value = makeid(6)
reandomize.value += 'SP'
}
});
Binary file added html/sounds/New folder/button-remote.ogg
Binary file not shown.
Binary file added html/sounds/button-remote-lock.ogg
Binary file not shown.
Binary file added html/sounds/button-remote-unlock.ogg
Binary file not shown.
Binary file added html/sounds/door-bolt-4.ogg
Binary file not shown.
Binary file added html/sounds/metal-locker.ogg
Binary file not shown.
Binary file added html/sounds/metallic-creak.ogg
Binary file not shown.
Loading

0 comments on commit b6c62f6

Please sign in to comment.