-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateFlag.lua
165 lines (98 loc) · 4.04 KB
/
createFlag.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
--@name createFlag
--@author Ax25 :3
--@shared
-- to create a new flag do in chat: !f size (size must be a number)
local vertical = true -- true make the line vertical, false make it horizontal
local colors = { -- FR, the flag will be rendered following the color order from first to last, can add any number of colors
Color(0, 38, 84),
Color(255, 255, 255),
Color(237, 41, 57),
}
if CLIENT then
render.createRenderTarget("screenRT1")
local screenMat1 = material.create("UnlitGeneric")
screenMat1:setTextureRenderTarget("$basetexture", "screenRT1")
screenMat1:setInt("$flags", 2097152)
local height = 1023/#colors
hook.add("renderoffscreen", "renderflag", function()
render.selectRenderTarget("screenRT1")
render.clear(Color(0, 0, 0, 0))
render.setFilterMag(1)
render.setFilterMin(1)
for i, color in ipairs(colors) do
render.setColor(color)
if vertical then
render.drawRect((i-1)*height, 0, height, 1024)
else
render.drawRect(0, (i-1)*height, 1024, height)
end
end
hook.remove("renderoffscreen", "renderflag")
end)
local waits = {}
function awaitUntilValid(entIndex, func)
local index = #waits+1
waits[index] = {}
waits[index].callback = func
waits[index].entIndex = entIndex
end
timer.create("validCheck", 0.5, 0, function()
for k,data in pairs(waits) do
local ent = entity(data.entIndex)
if ent:isValid() then
data.callback()
--print(ent, " is valid")
waits[k] = nil
end
end
end)
local function createFlag(base, scale)
local screen = hologram.create(base:getPos()+Vector(0, 0, 0), base:getAngles(), "models/holograms/plane.mdl", Vector(scale/1.5, scale, 0))
screen:suppressEngineLighting(true)
screen:setFilterMag(1)
screen:setFilterMin(1)
screen:setMaterial("!" .. screenMat1:getName())
screen:setColor(Color(255, 255, 255, 254))
screen:setParent(base)
end
local function queueFlag(entIndex, scale)
awaitUntilValid(entIndex, function()
createFlag(entity(entIndex), scale)
end)
end
net.receive("newFlag", function()
local entIndex = net.readInt(32)
local scale = net.readInt(32)
queueFlag(entIndex, scale)
end)
net.receive("initFlags", function()
local flags = net.readTable()
for i, data in ipairs(flags) do
queueFlag(data[1], data[2])
end
end)
else
local flags = {}
local function createFlag(pos, scale)
local base = prop.create( pos+Vector(0, 0, 5*scale), Angle(90), "models/hunter/plates/plate1x1.mdl", true )
base:setMaterial("Models/effects/vol_light001")
base:setNocollideAll(true)
net.start("newFlag")
net.writeInt(base:entIndex(), 32)
net.writeInt(scale, 32)
net.send()
table.insert(flags, {base:entIndex(), scale})
end
hook.add("ClientInitialized", "sendFlag", function(ply)
net.start("initFlags")
net.writeTable(flags)
net.send(ply)
end)
hook.add("PlayerSay", "addFlag", function(ply, text)
if ply == owner() and string.sub(text, 0, 2) == "!f" then
local scale = string.explode(" ", text)[2]
createFlag( (owner():getEyeTrace().HitPos or owner():getPos() ), tonumber(scale) )
return ""
end
end)
end