Skip to content

Commit

Permalink
Id locking (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeyboi1 authored Jun 16, 2023
1 parent d9334c6 commit 476f117
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 11 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
- Each door can have upto 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 be able to create and delete doors!
- Commands for admins to create and delete doors!
- Menu for creating the doors!

# How to install
- Run the sql file
- ensure bcc-doorlocks in your resources file below all the required scripts

# How it works!
- Create a door by entering the /createDoor command then aim with a gun at the door you want put a lock on and press "G" you will then be created by the door creation menu!
- To delete a door simply enter the command /deleteDoor then aim at the door you wish to delete and press "G"!
Expand All @@ -22,4 +28,18 @@
- VORP utils
- VORP Core
- bcc-utils
- bcc-minigames
- bcc-minigames

# API
### Create door
```Lua
RegisterCommand('test50', function()
local door = exports['bcc-doorlocks']:createDoor()
end)
```
### Delete Door
```Lua
RegisterCommand('test50', function()
local door = exports['bcc-doorlocks']:deleteDoor()
end)
```
13 changes: 11 additions & 2 deletions client/MenuSetup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function doorCreationMenu(door)
TriggerEvent('bcc-doorlocks:MenuClose')
MenuData.CloseAll()

local jobs, keyItem = {}, nil
local jobs, keyItem, ids = {}, nil, {}
local myInput = {
type = "enableinput", -- don't touch
inputType = "textarea", -- input type
Expand All @@ -41,6 +41,7 @@ function doorCreationMenu(door)
{ label = _U("setJob"), value = 'setJob2', desc = _U("setJob_desc") },
{ label = _U("setJob"), value = 'setJob3', desc = _U("setJob_desc") },
{ label = _U("setKeyItem"), value = 'setKeyItem', desc = _U("setKeyItem_desc") },
{ label = _U("setIds"), value = 'setIds', desc = _U("setIds_desc") },
{ label = _U("confirm"), value = 'confirm', desc = _U("confirm_desc") },
}

Expand Down Expand Up @@ -86,8 +87,16 @@ function doorCreationMenu(door)
VORPcore.NotifyRightTip(_U("InvalidInput"), 4000)
end
end)
elseif data.current.value == 'setIds' then
TriggerEvent("vorpinputs:advancedInput", json.encode(myInput), function(result)
if result ~= '' and result then
table.insert(ids, tonumber(result))
else
VORPcore.NotifyRightTip(_U("InvalidInput"), 4000)
end
end)
elseif data.current.value == 'confirm' then
TriggerServerEvent('bcc-doorlocks:InsertIntoDB', door, jobs, keyItem)
TriggerServerEvent('bcc-doorlocks:InsertIntoDB', door, jobs, keyItem, ids)
inMenu = false
MenuData.CloseAll()
end
Expand Down
11 changes: 11 additions & 0 deletions client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,15 @@ CreateThread(function()
TriggerServerEvent('bcc-doorlocks:AdminCheck')
end)
end
end)

----- Exports -------
exports('createDoor', function()
local door = getDoor('creation')
doorCreationMenu(door)
end)

exports('deleteDoor', function()
local door = getDoor('deletion')
TriggerServerEvent('bcc-doorlocks:DeleteDoor', door)
end)
4 changes: 3 additions & 1 deletion doorlocks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ CREATE TABLE IF NOT EXISTS `doorlocks` (
`keyitem` varchar(50) NOT NULL DEFAULT 'none',
`locked` varchar(50) NOT NULL DEFAULT 'false',
PRIMARY KEY `doorid` (`doorid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE doorlocks ADD COLUMN IF NOT EXISTS (`ids_allowed` LONGTEXT DEFAULT NULL);
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ client_scripts {
'/client/MenuSetup.lua'
}

version '1.0.0'
version '1.0.1'
4 changes: 3 additions & 1 deletion languages/en_lang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ Locales["en_lang"] = {
setKeyItem_desc = 'Set a key item, that will be used to lock and unlock this door! You must enter the database name of the item!',
confirm = 'Confirm',
confirm_desc = 'Finish door creation!',
InvalidInput = 'Invalid Input'
InvalidInput = 'Invalid Input',
setIds = "Set Id's",
setIds_desc = "Set ID's allowed to lock and unlock the door. To set multiple Id's just choose this option again after you input an id."
}
23 changes: 18 additions & 5 deletions server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ VORPInv = exports.vorp_inventory:vorp_inventoryApi()
BccUtils = exports['bcc-utils'].initiate()

------ DataBase Handling ------
RegisterServerEvent('bcc-doorlocks:InsertIntoDB', function(doorTable, jobs, keyItem) --Handles door creation and locks the door for all clients upon creation
local kItem
RegisterServerEvent('bcc-doorlocks:InsertIntoDB', function(doorTable, jobs, keyItem, ids) --Handles door creation and locks the door for all clients upon creation
local kItem, pIds
if keyItem ~= nil then
kItem = keyItem
else
kItem = 'none'
end
local param = { ['jobs'] = json.encode(jobs), ['key'] = kItem, ['locked'] = 'true', ['doorinfo'] = json.encode(doorTable) }
if ids ~= nil then
pIds = ids
else
pIds = 'none'
end
local param = { ['jobs'] = json.encode(jobs), ['key'] = kItem, ['locked'] = 'true', ['doorinfo'] = json.encode(doorTable), ['ids'] = json.encode(pIds) }
local _source = source

exports.oxmysql:execute("SELECT * FROM doorlocks WHERE doorinfo=@doorinfo", param, function(result)
if not result[1] then
exports.oxmysql:execute("INSERT INTO doorlocks ( `jobsallowedtoopen`,`keyitem`,`locked`,`doorinfo` ) VALUES ( @jobs,@key,@locked,@doorinfo )", param)
exports.oxmysql:execute("INSERT INTO doorlocks ( `jobsallowedtoopen`,`keyitem`,`locked`,`doorinfo`,`ids_allowed` ) VALUES ( @jobs,@key,@locked,@doorinfo,@ids )", param)
TriggerClientEvent('bcc-doorlocks:ClientSetDoorStatus', -1, doorTable, true, true, false)
VORPcore.NotifyRightTip(_source, _U("doorCreated"), 4000)
else
Expand Down Expand Up @@ -67,7 +72,7 @@ RegisterServerEvent('bcc-doorlocks:ServDoorStatusSet', function(doorTable, locke
lockedparam = 'false'
end
local param = { ['doorinfo'] = json.encode(doorTable), ['locked'] = lockedparam }
local _source, jobFound = source, false
local _source, jobFound, keyFound = source, false, false
local character = VORPcore.getUser(_source).getUsedCharacter
local result = MySQL.query.await("SELECT * FROM doorlocks WHERE doorinfo=@doorinfo", param)
for k, v in pairs(json.decode(result[1].jobsallowedtoopen)) do
Expand All @@ -79,10 +84,18 @@ RegisterServerEvent('bcc-doorlocks:ServDoorStatusSet', function(doorTable, locke
end
if not jobFound then
if VORPInv.getItemCount(_source, result[1].keyitem) >= 1 then
keyFound = true
exports.oxmysql:execute("UPDATE doorlocks SET locked=@locked WHERE doorinfo=@doorinfo", param)
TriggerClientEvent('bcc-doorlocks:ClientSetDoorStatus', -1, doorTable, locked, true, false)
end
end
if not keyFound then
for k, v in pairs(json.decode(result[1].ids_allowed)) do
if character.charIdentifier == v then
TriggerClientEvent('bcc-doorlocks:ClientSetDoorStatus', -1, doorTable, locked, true, false) break
end
end
end
end)

RegisterServerEvent('bcc-doorlocks:LockPickCheck', function(doorTable) --Used to check for lockpick before allowing minigame to players
Expand Down

0 comments on commit 476f117

Please sign in to comment.