-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoneway_prop.lua
176 lines (135 loc) · 4.27 KB
/
oneway_prop.lua
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
176
--@name oneway prop
--@author Ax25 :3
--@server
--[[
To make a prop oneway write in chat !oneway while looking at it
you can do the command !undo while looking at the prop to restore it
--]]
local exteriorMat = "brick/brick_model" -- People on the other way of the props will see this material
local interiorMat = "models/props_combine/com_shield001a" -- This material has to be a shader material to be able to see trough world glow props
local saved = false
local ents = {}
local extQueue = {}
timer.create("extqeue", 0.05, 0, function()
local data = extQueue[1]
if not data then return end
local ent = data.ent
try(function()
local ext = prop.create(ent:getPos() + (data.offset * data.obbz / 4 ), ent:getAngles(), ent:getModel())
ext:setMaterial(exteriorMat)
ext:setSolid(false)
ext:setRenderMode(9)
ext:setParent(ent)
ext:doNotDuplicate()
ents[ent:entIndex()].ext = ext
table.remove(extQueue, 1)
setUserdata(bit.tableToString(ents))
end)
end)
local function onewayify(ent, saveTbl)
if saveTbl then
ents[ent:entIndex()] = saveTbl
else
ents[ent:entIndex()] = {
ent = ent,
oldMat = ent:getMaterial(),
}
end
local obb = ent:obbSize()
local offset = ents[ent:entIndex()].offset
if not offset then
offset = ( owner():getPos():setZ(0) - ent:getPos():setZ(0) ):getNormalized()
offset:round(0)
offset = offset * -1
ents[ent:entIndex()].offset = offset
end
extQueue[#extQueue + 1] = {
offset = offset,
obbz = obb.z,
ent = ent
}
ent:setSolid(false)
ent:setMaterial(interiorMat)
ents[ent:entIndex()].ext = ext
setUserdata(bit.tableToString(ents))
end
local function restore(ent)
local data = ents[ent:entIndex()]
data.ext:remove()
data.ent:setMaterial(data.oldMat)
data.ent:setSolid(true)
ents[ent:entIndex()] = nil
setUserdata(bit.tableToString(ents))
end
--[[
hook.add("KeyPress", "onewayify", function(ply, key)
if ply == owner() and key == IN_KEY.RELOAD then
local tr = owner():getEyeTrace()
if tr.Entity and hasPermission("entities.canTool", tr.Entity) then
onewayify(tr.Entity)
else
print("Invalid prop or doesn't have permission to tool the prop")
end
end
end)
]]
hook.add("Removed", "restore", function()
if not saved then
for i, data in pairs(ents) do
local ent = data.ent
if ent and ent:isValid() then
restore(ent)
end
end
end
end)
hook.add("DupeFinished", "restore", function(entTbl)
if getUserdata() ~= "" then
local oldEnts = bit.stringToTable(getUserdata())
for oldIndex, ent in pairs(entTbl) do
if oldEnts[oldIndex] then
oldEnts[oldIndex].ent = ent
onewayify(ent, oldEnts[oldIndex])
end
end
end
end)
local CMDS = {}
local prefixs = {
["!"] = true,
["/"] = true,
["."] = true,
}
hook.add("playersay", "cmd", function(ply, text)
if ply ~= owner() then return end
local prefix = string.sub(text, 1, 1)
if prefixs[prefix] then
text = string.sub(text, 2, -1)
local args = string.explode(" ", text)
local name = args[1]
table.remove(args, 1)
if CMDS[name] then
CMDS[name](unpack(args))
return ""
end
end
end)
CMDS["undo"] = function()
local entities = find.inRay(owner():getEyePos(), owner():getEyePos() + owner():getAimVector() * 2000, Vector(-1, -1, -1), Vector(1, 1, 1), function(ent)
return ent ~= owner() and ent:getOwner() and ent:getOwner() == owner()
end)
for i, ent in ipairs(entities) do
if ent and ent:isValid() and ents[ent:entIndex()] then
restore(ent)
break
end
end
end
CMDS["oneway"] = function()
local tr = owner():getEyeTrace()
if tr.Entity and hasPermission("entities.canTool", tr.Entity) then
onewayify(tr.Entity)
else
print("Invalid prop or doesn't have permission to tool the prop")
end
end