-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.lua
More file actions
135 lines (111 loc) · 5.39 KB
/
Copy pathserver.lua
File metadata and controls
135 lines (111 loc) · 5.39 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
133
134
135
local Core <const> = exports.vorp_core:GetCore()
local LIB <const> = Import "/config"
local CONFIG <const> = LIB.CONFIG --[[@as vorp_housing_config]]
local Inventory <const> = exports.vorp_inventory
local function registerHouse(source, character)
local charId <const> = character.charIdentifier
for index, house in ipairs(CONFIG.HOUSES) do
local isOwner <const> = house.OWNERS[charId]
if isOwner then
SetTimeout(5000, function()
if isOwner.DOOR then
for _, door in ipairs(house.DOORS) do
exports.vorp_doorlocks:updateDoorPermission(source, door, true)
end
end
TriggerClientEvent("vorp_housing:Client:RegisterHouse", source, index, charId)
end)
if isOwner.STORAGE then
for _, storage in ipairs(house.STORAGES) do
local prefix <const> = "house_" .. storage.ID
local isStorageRegistered <const> = Inventory:isCustomInventoryRegistered(prefix)
if not isStorageRegistered then
Inventory:registerInventory({
id = prefix,
name = storage.LABEL,
limit = storage.MAX_SLOTS,
acceptWeapons = storage.WEAPONS,
shared = storage.SHARED, -- inventory is shared with owners of the house or should each have their own ?
ignoreItemStackLimit = true,
whitelistItems = false,
UsePermissions = false,
UseBlackList = #storage.BLACKLISTED_ITEMS > 0,
whitelistWeapons = false,
webhook = "" -- add here a webhook to monitor the houses inventories
})
if #storage.BLACKLISTED_ITEMS > 0 then
for _, item in ipairs(storage.BLACKLISTED_ITEMS) do
exports.vorp_inventory:BlackListCustomAny(prefix, item)
end
end
end
end
end
end
end
end
AddEventHandler("vorp:SelectedCharacter", function(source, character)
if CONFIG.DEV_MODE then return end
-- needs this to change door permissions when registering house
repeat Wait(1000) until Player(source).state.IsInSession
registerHouse(source, character)
end)
-- HERE WE HANDLE OPENING STORAGES FOR THE HOUSE
RegisterServerEvent("vorp_housing:Server:OpenStorage", function(index, storageIndex)
local _source <const> = source
local user <const> = Core.getUser(_source)
if not user then return end
local character <const> = user.getUsedCharacter
local charId <const> = character.charIdentifier
local house <const> = CONFIG.HOUSES[index]
if not house then return print("House not found") end
local isOwner <const> = house.OWNERS[charId]
if not isOwner then return print(CONFIG.TRANSLATION.not_owner) end
if not isOwner.STORAGE then return print("Player is not allowed to access storages") end
local houseCoords <const> = house.POSITION
local pedCoords <const> = GetEntityCoords(GetPlayerPed(_source))
if #(pedCoords - houseCoords) > 10.0 then return print("Player is not close to the house") end
local storage <const> = house.STORAGES[storageIndex]
if not storage then return print("Storage not found") end
local location <const> = storage.LOCATION
local distance <const> = #(pedCoords - location)
if distance > 3.0 then return print("Player is not close to this storage") end
local prefix <const> = "house_" .. storage.ID
local isStorageRegistered <const> = Inventory:isCustomInventoryRegistered(prefix)
if not isStorageRegistered then return print("Storage is not registered in the inventory") end
Inventory:openInventory(_source, prefix)
end)
RegisterServerEvent("vorp_housing:Server:OpenWardrobe", function(index)
local _source <const> = source
local config <const> = CONFIG.HOUSES[index]
if not config then
return print("House not found")
end
if not config.WARDROBE.ENABLE then
return print("Wardrobe is not enabled for this house")
end
local wardrobeCoords <const> = config.WARDROBE.LOCATION
local pedCoords <const> = GetEntityCoords(GetPlayerPed(_source))
if #(pedCoords - wardrobeCoords) > 10.0 then
return print("Player is not close to this wardrobe")
end
local result <const> = exports.vorp_character:OpenOutfitsMenu(_source)
if not result then return print("Failed to open wardrobe") end
end)
--FOR TESTS
if CONFIG.DEV_MODE then
RegisterServerEvent("vorp_housing:Server:DevMode", function()
local _source <const> = source
local user <const> = Core.getUser(_source)
if not user then return end
local character <const> = user.getUsedCharacter
registerHouse(_source, character)
end)
RegisterCommand(CONFIG.COMMAND, function(source)
local user <const> = Core.getUser(source)
if not user then return end
local group <const> = user.getGroup
if group ~= "admin" then return Core.NotifyObjective(CONFIG.TRANSLATION.not_admin, 5000) end
TriggerClientEvent("vorp_housing:Client:ShowHouses", source)
end, false)
end