is there a version for the sheriff departments?
Hey everyone, I took the time to convert this to Essentialmode, Its synced with the DB and will only work if your a cop!
Requirments:
Essentialmode
Cops-FiveM
Although you can edit the SQL query if you dont use this cop system in the server.lua
Here is the code:
Client.lua
--[[
dnaFramework Door Manager
Coded by Darklandz
Version: 1.0
Allows cops to lock/unlock doors at the police stations/jail/...
Main Client File
]]
--
-- Used to initialise first time the client connects
--
local syncWithDb = true
--
-- Client Event : Shows notification if player has no rights to open door
--
RegisterNetEvent("doormanager:c_noDoorKey")
AddEventHandler("doormanager:c_noDoorKey", function(doorID)
if doorID == 1 then
ShowNotification( "Locker area door requires a key." )
elseif doorID == 2 then
ShowNotification( "Armory door requires a key." )
elseif doorID == 3 then
ShowNotification( "Captain's office door requires a key." )
else
ShowNotification( "Door requires a key." )
end
end)
--
-- Client Event : Sync client data from the server
--
RegisterNetEvent("doormanager:c_getSyncData")
AddEventHandler("doormanager:c_getSyncData", function(dBresult)
for i = 1, #dBresult do
if(dBresult[i].locked == 1) then
doorList[i]["locked"] = true
else
doorList[i]["locked"] = false
end
end
end)
--
-- Client Event : unlocks a door
--
RegisterNetEvent("doormanager:c_openDoor")
AddEventHandler("doormanager:c_openDoor", function(odID)
local closeDoor = GetClosestObjectOfType(doorList[odID]["x"], doorList[odID]["y"], doorList[odID]["z"], 1.0, GetHashKey(doorList[odID]["objName"]), false, false, false)
if doorList[odID]["locked"] == true then
FreezeEntityPosition(closeDoor, false)
doorList[odID]["locked"] = false
end
end)
--
-- Client Event : locks a door
--
RegisterNetEvent("doormanager:c_closeDoor")
AddEventHandler("doormanager:c_closeDoor", function(cdID)
local closeDoor = GetClosestObjectOfType(doorList[cdID]["x"], doorList[cdID]["y"], doorList[cdID]["z"], 1.0, GetHashKey(doorList[cdID]["objName"]), false, false, false)
if doorList[cdID]["locked"] == false then
FreezeEntityPosition(closeDoor, true)
doorList[cdID]["locked"] = true
end
end)
--
-- Main Thread
--
Citizen.CreateThread(function()
while true do
if(syncWithDb) then
TriggerServerEvent('doormanager:s_syncDoors')
syncWithDb = false
end
for i = 1, #doorList do
local playerCoords = GetEntityCoords( GetPlayerPed(-1) )
local closeDoor = GetClosestObjectOfType(doorList[i]["x"], doorList[i]["y"], doorList[i]["z"], 1.0, GetHashKey(doorList[i]["objName"]), false, false, false)
local objectCoordsDraw = GetEntityCoords( closeDoor )
local playerDistance = GetDistanceBetweenCoords(playerCoords.x, playerCoords.y, playerCoords.z, doorList[i]["x"], doorList[i]["y"], doorList[i]["z"], true)
if(playerDistance < 1) then
if doorList[i]["locked"] == true then
DrawText3d(doorList[i]["txtX"], doorList[i]["txtY"], doorList[i]["txtZ"], "[E] to unlock")
else
DrawText3d(doorList[i]["txtX"], doorList[i]["txtY"], doorList[i]["txtZ"], "[E] to lock")
end
-- Press E key
if IsControlJustPressed(1,51) then
if doorList[i]["locked"] == true then
TriggerServerEvent("doormanager:s_openDoor", i)
else
TriggerServerEvent("doormanager:s_closeDoor", i)
end
end
else
FreezeEntityPosition(closeDoor, doorList[i]["locked"])
end
end
Citizen.Wait(0)
end
end)
--
-- Doors Array
--
doorList = {
-- Mission Row To locker room & roof
[1] = { ["objName"] = "v_ilev_ph_gendoor004", ["x"]= 449.698, ["y"]= -986.469,["z"]= 30.689,["locked"]= true,["txtX"]=450.104,["txtY"]=-986.388,["txtZ"]=31.739},
-- Mission Row Armory
[2] = { ["objName"] = "v_ilev_arm_secdoor", ["x"]= 452.618, ["y"]= -982.702,["z"]= 30.689,["locked"]= true,["txtX"]=453.079,["txtY"]=-982.600,["txtZ"]=31.739},
-- Mission Row Captain Office
[3] = { ["objName"] = "v_ilev_ph_gendoor002", ["x"]= 447.238, ["y"]= -980.630,["z"]= 30.689,["locked"]= true,["txtX"]=447.200,["txtY"]=-980.010,["txtZ"]=31.739},
-- Mission Row To downstairs right
[4] = { ["objName"] = "v_ilev_ph_gendoor005", ["x"]= 443.97, ["y"]= -989.033,["z"]= 30.689,["locked"]= true,["txtX"]=444.020,["txtY"]=-989.445,["txtZ"]=31.739},
-- Mission Row To downstairs left
[5] = { ["objName"] = "v_ilev_ph_gendoor005", ["x"]= 445.37, ["y"]= -988.705,["z"]= 30.689,["locked"]= true,["txtX"]=445.350,["txtY"]=-989.445,["txtZ"]=31.739},
-- Mission Row Main cells
[6] = { ["objName"] = "v_ilev_ph_cellgate", ["x"]= 464.0, ["y"]= -992.265,["z"]= 24.9149,["locked"]= true,["txtX"]=463.465,["txtY"]=-992.664,["txtZ"]=25.064},
-- Mission Row Cell 1
[7] = { ["objName"] = "v_ilev_ph_cellgate", ["x"]= 462.381, ["y"]= -993.651,["z"]= 24.914,["locked"]= true,["txtX"]=461.806,["txtY"]=-993.308,["txtZ"]=25.064},
-- Mission Row Cell 2
[8] = { ["objName"] = "v_ilev_ph_cellgate", ["x"]= 462.331, ["y"]= -998.152,["z"]= 24.914,["locked"]= true,["txtX"]=461.806,["txtY"]=-998.800,["txtZ"]=25.064},
-- Mission Row Cell 3
[9] = { ["objName"] = "v_ilev_ph_cellgate", ["x"]= 462.704, ["y"]= -1001.92,["z"]= 24.914,["locked"]= true,["txtX"]=461.806,["txtY"]=-1002.450,["txtZ"]=25.064},
-- Mission Row Backdoor in
[10] = { ["objName"] = "v_ilev_gtdoor", ["x"]= 464.126, ["y"]= -1002.78,["z"]= 24.9149,["locked"]= true,["txtX"]=464.100,["txtY"]=-1003.538,["txtZ"]=26.064},
-- Mission Row Backdoor out
[11] = { ["objName"] = "v_ilev_gtdoor", ["x"]= 464.18, ["y"]= -1004.31,["z"]= 24.9152,["locked"]= true,["txtX"]=464.100,["txtY"]=-1003.538,["txtZ"]=26.064},
-- Mission Row Rooftop In
[12] = { ["objName"] = "v_ilev_gtdoor02", ["x"]= 465.467, ["y"]= -983.446,["z"]= 43.6918,["locked"]= true,["txtX"]=464.361,["txtY"]=-984.050,["txtZ"]=44.834},
-- Mission Row Rooftop Out
[13] = { ["objName"] = "v_ilev_gtdoor02", ["x"]= 462.979, ["y"]= -984.163,["z"]= 43.6919,["locked"]= true,["txtX"]=464.361,["txtY"]=-984.050,["txtZ"]=44.834},
}
--
-- Draws in the 3D Worldspace
--
function DrawText3d(x,y,z, text)
local onScreen,_x,_y=World3dToScreen2d(x,y,z)
local px,py,pz=table.unpack(GetGameplayCamCoords())
if onScreen then
SetTextScale(0.3, 0.3)
SetTextFont(0)
SetTextProportional(1)
SetTextColour(255, 255, 255, 255)
SetTextDropshadow(0, 0, 0, 0, 55)
SetTextEdge(2, 0, 0, 0, 150)
SetTextDropShadow()
SetTextOutline()
SetTextEntry("STRING")
SetTextCentre(1)
AddTextComponentString(text)
DrawText(_x,_y)
end
end
--
-- Show notification above minimap
--
function ShowNotification( text )
SetNotificationTextEntry( "STRING" )
AddTextComponentString( text )
DrawNotification( false, false )
end
Server.lua
--[[
dnaFramework Door Manager
Coded by Darklandz
Version: 0.1
Allows cops to lock/unlock doors at the police stations/jail/...
Main Server File
]]
--
-- Server Event : To unlock doors
--
RegisterServerEvent("doormanager:s_openDoor")
AddEventHandler("doormanager:s_openDoor", function(doorId)
local src = source
--local perms = CheckPermLevel(src)
local isDoorLocked = GetDoorStatus(doorId)
if isDoorLocked == 1 then
MySQL.Async.fetchAll("SELECT * FROM police WHERE identifier = '@identifier'", { ['@identifier'] = identifier}, function (result)
if(result == nil) then
TriggerClientEvent("doormanager:c_noDoorKey", src, doorId)
else
TriggerClientEvent("doormanager:c_openDoor", -1, doorId)
SetDoorStatus(doorId,0)
end
end)
end
end)
--
-- Server Event : To lock doors
--
RegisterServerEvent("doormanager:s_closeDoor")
AddEventHandler("doormanager:s_closeDoor", function(doorId)
local src = source
local isDoorLocked = GetDoorStatus(doorId)
if isDoorLocked == 0 then
MySQL.Async.fetchAll("SELECT * FROM police WHERE identifier = '@identifier'", { ['@identifier'] = identifier}, function (result)
if(result == nil) then
TriggerClientEvent("doormanager:c_noDoorKey", src, doorId)
else
TriggerClientEvent("doormanager:c_closeDoor", -1, doorId)
SetDoorStatus(doorId,1)
end
end)
end
end)
--
-- Sync door database with client
--
RegisterServerEvent("doormanager:s_syncDoors")
AddEventHandler('doormanager:s_syncDoors', function()
-- Source
local src = source
-- Get door status from DB
MySQL.Async.fetchAll("SELECT * FROM city_doors", {}, function(result)
if (result) then
TriggerClientEvent("doormanager:c_getSyncData", src,result)
end
end)
end)
--
-- Function to check if player is a cop
--
--function GetPlayerJob(sId)
-- return MySQL.Sync.fetchScalar("SELECT citizenStatus FROM characters WHERE steamId = @sid", {['@sid'] = sId})
--end
--
-- Function to check the door status
--
function GetDoorStatus(doorId)
return MySQL.Sync.fetchScalar("SELECT locked FROM city_doors WHERE id = @id", {['@id'] = doorId})
end
--
-- Function to update the door status
--
function SetDoorStatus(doorId,doorStatus)
local sql = "UPDATE city_doors SET locked = @dStatus WHERE id = @dId"
local param = {dId = doorId, dStatus = doorStatus}
MySQL.Async.execute(sql, param)
end
--
-- Functions to get player info
--
function getPlayerID(source)
local identifiers = GetPlayerIdentifiers(source)
local player = getIdentifier(identifiers)
return player
end
function getIdentifier(id)
for _, v in ipairs(id) do
return v
end
end
SQL just incase
CREATE TABLE `city_doors` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`locked` INT(1) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=43
;
@Darklandz feel free to pin this in the description.
Enjoy guys
What item do i need to spawn in, to open the door.
This script does NOT require essentialmode o.O
anyone have any luck with server.lua calls for GHMattiMySQL?
how to fix
[ERROR] [MySQL] An error happens on MySQL for query âSELECT citizenStatus FROM characters WHERE steamId = @sid {@sid=steam:110000136959d95}â: Table âvrpfx.charactersâ doesnât exist
check your database for that⌠the problem already says itâŚ
Table âvrpfx.charactersâ doesnât exist
How to add id to open the door
Help me
[ERROR] [MySQL] An error happens on MySQL for query âSELECT citizenStatus FROM city_doors WHERE steamId = @sid {@sid=steam:110000136959d95}â: Unknown column âcitizenStatusâ in âfield listâ
[quote="John_Smithy, post:101, topic:57854, f
Where is this file?
Some pictures please?
I am probably stupid and am not converting this correctly but is it possible to make it so it can open based on identifiers instead of a skin?
Maybe some pictures will be great?
instead of permissions per skin, would it be possible to permissions on id, work or something of the genre? [vrp mode]
I have actually edited Miss_Behavinâs script to work with Ace Permissions if you are interested.
Does it work?
any one else get a problem with performance ?
i never noticed it before but now i have this
not preatty
can you set steam ids to this so a set person can unlock the door and not a job roll
Since I have been asked a couple times, I am releasing my version of dRdoors. This is a modification of Darklandz, MissBehavin, and BritishBrotherhoods release but works with ACE Permissions and is Synced through a DB.
If you have any issues feel free to message me!