-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
175 lines (151 loc) · 5.43 KB
/
main.lua
File metadata and controls
175 lines (151 loc) · 5.43 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
local QuickKeyCleaner = {}
-- Setup
QuickKeyCleaner.scriptName = 'QuickKeyCleaner'
QuickKeyCleaner.defaultConfig = {
keyOrder = { "removeRefIds", "restrictedCells", "hotkeyPlaceholder" },
values = {
removeRefIds = {},
restrictedCells = {},
hotkeyPlaceholder = {
type = "miscellaneous",
refId = "hotkey_placeholder",
name = "Empty",
icon = "m\\misc_dwrv_Ark_cube00.tga"
}
}
}
QuickKeyCleaner.config = DataManager.loadConfiguration(
QuickKeyCleaner.scriptName,
QuickKeyCleaner.defaultConfig.values,
QuickKeyCleaner.defaultConfig.keyOrder
)
QuickKeyCleaner.removeRefIds = {}
for i, v in pairs(QuickKeyCleaner.config.removeRefIds) do
QuickKeyCleaner.removeRefIds[v] = true
end
QuickKeyCleaner.restrictedCells = {}
for i, v in pairs(QuickKeyCleaner.config.restrictedCells) do
QuickKeyCleaner.restrictedCells[v] = true
end
QuickKeyCleaner.hotkeyPlaceholder = QuickKeyCleaner.config.hotkeyPlaceholder
QuickKeyCleaner.hotkeyPlaceholder.count = 1
QuickKeyCleaner.filters = {}
-- Methods
function QuickKeyCleaner.createHotkeyPlaceholder()
local recordStore = RecordStores[QuickKeyCleaner.config.hotkeyPlaceholder.type]
if recordStore.data.permanentRecords[QuickKeyCleaner.config.hotkeyPlaceholder.refId] == nil then
recordStore.data.permanentRecords[QuickKeyCleaner.config.hotkeyPlaceholder.refId] = QuickKeyCleaner.hotkeyPlaceholder
recordStore:Save()
end
end
function QuickKeyCleaner.getEmptyHotkey()
return {
keyType = 0,
itemId = QuickKeyCleaner.config.hotkeyPlaceholder.refId
}
end
function QuickKeyCleaner.isCellRestricted(cellName)
return QuickKeyCleaner.restrictedCells[cellName] == true
end
function QuickKeyCleaner.registerFilter(func)
table.insert(QuickKeyCleaner, func)
end
function QuickKeyCleaner.isBanned(refId)
if QuickKeyCleaner.removeRefIds[refId] == true then
return true
end
for _, f in pairs(QuickKeyCleaner.filters) do
if not f(refId) then
return true
end
end
return false
end
function QuickKeyCleaner.banItem(refId)
QuickKeyCleaner.removeRefIds[refId] = true
end
function QuickKeyCleaner.unbanItem(refId)
QuickKeyCleaner.removeRefIds[refId] = nil
end
function QuickKeyCleaner.addHotkeyPlaceholder(pid)
tes3mp.ClearInventoryChanges(pid)
tes3mp.SetInventoryChangesAction(pid, enumerations.inventory.ADD)
packetBuilder.AddPlayerInventoryItemChange(pid, QuickKeyCleaner.hotkeyPlaceholder)
tes3mp.SendInventoryChanges(pid)
end
function QuickKeyCleaner.removeHotkeyPlaceholder(pid)
tes3mp.ClearInventoryChanges(pid)
tes3mp.SetInventoryChangesAction(pid, enumerations.inventory.REMOVE)
packetBuilder.AddPlayerInventoryItemChange(pid, QuickKeyCleaner.hotkeyPlaceholder)
tes3mp.SendInventoryChanges(pid)
end
function QuickKeyCleaner.clearSlots(pid, slots)
if #slots == 0 then
return
end
local quickKeys = Players[pid].data.quickKeys
tes3mp.ClearQuickKeyChanges(pid)
for i = 1, #slots do
local k = slots[i]
quickKeys[k] = QuickKeyCleaner.getEmptyHotkey()
tes3mp.AddQuickKey(pid, k, quickKeys[k].keyType, quickKeys[k].itemId)
end
QuickKeyCleaner.addHotkeyPlaceholder(pid)
tes3mp.SendQuickKeyChanges(pid)
QuickKeyCleaner.removeHotkeyPlaceholder(pid)
end
function QuickKeyCleaner.filterQuickKeys(pid)
local quickKeys = Players[pid].data.quickKeys
local slots = {}
for k = 1, 9 do
if quickKeys[k] ~= nil and QuickKeyCleaner.isBanned(quickKeys[k].itemId) then
table.insert(slots, k)
end
end
QuickKeyCleaner.clearSlots(pid, slots)
end
-- Hooks
QuickKeyCleaner.allSlots = { 1, 2, 3, 4, 5, 6, 7, 8, 9}
customEventHooks.registerHandler("OnPlayerCellChange", function(eventStatus, pid)
local currentCell = tes3mp.GetCell(pid)
local cellCheck = QuickKeyCleaner.isCellRestricted(currentCell)
if cellCheck then
local allSlots = QuickKeyCleaner.allSlots
QuickKeyCleaner.clearSlots(pid, allSlots)
end
end)
customEventHooks.registerValidator("OnPlayerQuickKeys", function(eventStatus, pid)
local slots = {}
local currentCell = tes3mp.GetCell(pid)
local cellCheck = QuickKeyCleaner.isCellRestricted(currentCell)
if cellCheck then
local allSlots = QuickKeyCleaner.allSlots
QuickKeyCleaner.clearSlots(pid, allSlots)
return customEventHooks.makeEventStatus(false, false)
else
for index = 0, tes3mp.GetQuickKeyChangesSize(pid) - 1 do
tes3mp.LogMessage(2, tes3mp.GetQuickKeyItemId(pid, index))
if QuickKeyCleaner.isBanned(tes3mp.GetQuickKeyItemId(pid, index)) then
local slot = tes3mp.GetQuickKeySlot(pid, index)
table.insert(slots, slot)
end
end
if #slots > 0 then
QuickKeyCleaner.clearSlots(pid, slots)
return customEventHooks.makeEventStatus(false, false)
end
end
end)
customEventHooks.registerHandler("OnPlayerAuthentified", function(eventStatus, pid)
local currentCell = tes3mp.GetCell(pid)
local cellCheck = QuickKeyCleaner.isCellRestricted(currentCell)
if cellCheck then
QuickKeyCleaner.clearSlots(pid, QuickKeyCleaner.allSlots)
else
QuickKeyCleaner.filterQuickKeys(pid)
end
end)
customEventHooks.registerHandler("OnServerPostInit", function(eventStatus, pid)
QuickKeyCleaner.createHotkeyPlaceholder()
end)
return QuickKeyCleaner