This is an optimized, simple, and effective door lock script! It allows server admins to create doors that can be locked and unlocked by players!
- Each door can have up to 3 jobs that can unlock it!
- Each door can have its own key item to open!
- Each door can be lockpicked with a lockpick item!
- Can set an unlimited amount of character IDs allowed to lock and unlock doors!
- Exports for other scripts to create and delete doors!
- Command
/ManageDoorLocksfor admins to manage doors! - Menu for creating and managing doors!
- To manage doors, use the
/ManageDoorLockscommand. - Create a door: Aim with a gun at the door you want to lock, press "G," and use the menu to configure the door.
- Delete a door: Select the door from the list in the menu and remove it.
- Once a door is created, walk up to it, and you will see prompts on the bottom right of your screen for interaction.
- Ensure the dependencies are installed and updated.
- Add the
bcc-doorlocksfolder to yourresourcesdirectory. - Add
ensure bcc-doorlocksto yourserver.cfg. - The database schema will automatically initialize.
- Restart your server.
- Dynamic API Integration:
- Added an API (
DoorLocksAPI) for retrieving, updating, and managing door data, such as:GetDoorByIdAddDoorUpdateAllowedJobsUpdateKeyItemUpdateAllowedIds
- Added an API (
- Editing and Managing Doors:
- Added client-side menus to dynamically edit:
- Allowed jobs.
- Key items.
- Allowed character IDs.
- These menus utilize input fields and RPC calls for real-time updates.
- Added client-side menus to dynamically edit:
- Enhanced RPCs:
- New RPC handlers for:
GetDoorFieldto fetch specific door fields.UpdateDoorlockfor updating specific properties (e.g.,jobsallowedtoopen,keyitem,ids_allowed).
- New RPC handlers for:
- Improved User Feedback:
- Notifications for successful or failed actions, ensuring clarity for users and admins.
RegisterCommand('createDoorTest', function()
local door = exports['bcc-doorlocks']:createDoor()
-- Creates a lock on the door and returns the door's table from `doorhashes.lua` for future deletion or storage.
end)RegisterCommand('deleteDoorTest', function()
exports['bcc-doorlocks']:deleteDoor()
-- Deletes a door that you aim at and confirm.
end)RegisterCommand('deleteSpecificDoorTest', function()
local doorTable = { ... } -- Provide the specific door table
exports['bcc-doorlocks']:deleteSpecificDoor(doorTable)
-- Deletes a specific door using its table.
end)RegisterCommand('addPlayerToDoorTest', function()
local playerId = 1 -- Replace with the actual player ID
local doorId = exports['bcc-doorlocks']:addPlayerToDoor(playerId)
-- Adds a player to the specified door and returns the updated door ID.
end)You can dynamically update door fields like jobsallowedtoopen, keyitem, and ids_allowed using RPC.
BccUtils.RPC:Call("bcc-doorlocks:UpdateDoorlock", {
doorId = 1, -- Replace with the door ID
field = "jobsallowedtoopen",
value = json.encode({"police", "doctor"})
}, function(success)
if success then
print("Jobs updated successfully.")
else
print("Failed to update jobs.")
end
end)BccUtils.RPC:Call("bcc-doorlocks:GetDoorField", {
doorId = 1, -- Replace with the door ID
field = "jobsallowedtoopen"
}, function(result)
if result then
print("Current jobs: " .. result)
else
print("Failed to fetch jobs.")
end
end)- Ensure all door data is properly stored and fetched using the provided API functions.
- Follow the installation and dependency requirements carefully to avoid compatibility issues.