-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.lua
319 lines (277 loc) · 8.48 KB
/
init.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
server_cosmetics = {
cosmetics = {
default_cosmetics = {
hair = {
brown = "#472E16",
black = "#222" ,
grey = "#AAA" ,
blonde = "#E6CC7C",
},
eyes = {
blue = "#2859C5",
green = "#477C47",
brown = "#2D1400",
},
skin = {
_prefix = "Modify ",
tan = "#cca586",
dark_tan = "#6d4832",
brown = "#412d1b",
}
},
headwear = {
sunglasses = {
_prefix = "Wear ",
_description = "Sunglasses",
_texture = "server_cosmetics_sunglasses.png",
blue = {
append = true,
color = "#0056ff^server_cosmetics_sunglasses_shine.png",
},
red = {
append = true,
color = "#ff2222^server_cosmetics_sunglasses_shine.png",
},
green = {
append = true,
color = "#22ff22^server_cosmetics_sunglasses_shine.png",
},
black = {
append = true,
color = "#000000^server_cosmetics_sunglasses_shine.png",
},
tournament = {
append = true,
color = "#000000^(server_cosmetics_sunglasses_shine.png^[multiply:#ffe346)",
},
}
},
entity_cosmetics = {
santa_hat = {
_prefix = "Wear ",
_description = "Christmas Hat",
_model = "server_cosmetics_hat.b3d",
_preview_rot = {350, 315},
_anims = {
idle = {x = 1, y = 1},
bumpy = {x = 1, y = 14},
falling = {x = 15, y = 23},
},
_date_start = 2021,
["2021"] = {"server_cosmetics_santa_hat.png"},
["2022"] = {"server_cosmetics_santa_hat.png^(server_cosmetics_santa_hat_overlay.png^[multiply:green)"},
["2023"] = {"server_cosmetics_santa_hat.png^(server_cosmetics_santa_hat_overlay.png^[multiply:purple)"},
["2024"] = {"server_cosmetics_santa_hat.png^(server_cosmetics_santa_hat_overlay.png^[multiply:blue)"},
},
hallows_hat = {
_prefix = "Wear ",
_description = "Hallows Hat",
_model = "server_cosmetics_hat.b3d",
_preview_rot = {350, 315},
_anims = {
idle = {x = 24, y = 27},
bumpy = {x = 24, y = 32},
falling = {x = 33, y = 41},
},
_date_start = 2022,
["2022"] = {"server_cosmetics_hallows_hat.png^(server_cosmetics_hallows_hat_overlay.png^[multiply:#333)"},
["2023"] = {"server_cosmetics_hallows_hat.png^(server_cosmetics_hallows_hat_overlay.png^[multiply:purple)"},
["2024"] = {"server_cosmetics_hallows_hat.png^(server_cosmetics_hallows_hat_overlay.png^[multiply:red)"},
},
crown = {
_prefix = "Wear ",
_description = "Crown",
_model = "server_cosmetics_hat.b3d",
_preview_rot = {350, 315},
_anims = {
idle = {x = 1, y = 1},
},
["normal"] = {"server_cosmetics_crown.png"},
},
party_hat = {
_prefix = "Wear ",
_description = "Party Hat",
_model = "server_cosmetics_hat.b3d",
_preview_rot = {350, 315},
_anims = {
idle = {x = 1, y = 1},
},
["anniversary"] = {"blank.png", "server_cosmetics_party_hat.png"},
},
}
}
}
if os.date("%m/%d") == "04/01" then
server_cosmetics.cosmetics.default_cosmetics.skin.smurf = "#0085e8"
end
minetest.after(0, function()
for category, contents in pairs(server_cosmetics.cosmetics) do
for ctype, cosmetics in pairs(contents) do
for name, info in pairs(cosmetics) do
if name:sub(1, 1) ~= "_" then
if type(info) == "table" then
if info[1] then
server_cosmetics.cosmetics[category][ctype][name].color = {
[1] = info[1],
[2] = info[2] or "blank.png",
}
end
server_cosmetics.cosmetics[category][ctype][name]._key = name
elseif type(info) == "string" then
server_cosmetics.cosmetics[category][ctype][name] = {
_key = name,
color = info,
}
end
end
end
end
end
end)
local function include(file)
dofile(minetest.get_modpath(minetest.get_current_modname()).."/"..file)
end
include("hat.lua")
include("commands.lua")
local hatted = {}
local function update_entity_cosmetics(player, current)
player = PlayerObj(player)
if not player then return end
local pname = player:get_player_name()
if hatted[pname] then
hatted[pname]:remove()
hatted[pname] = nil
end
local hatname = false
for key in pairs(current) do
for cosmetic in pairs(server_cosmetics.cosmetics.entity_cosmetics) do
if key == cosmetic then
hatname = key
break
end
end
end
if hatname then
local hat = minetest.add_entity(player:get_pos(), "server_cosmetics:hat")
hat:set_attach(player, "Head", vector.new(0, 2, 0))
hat:set_properties({textures = current[hatname].color})
hat:get_luaentity().animr = server_cosmetics.cosmetics.entity_cosmetics[hatname]._anims
hatted[pname] = hat
end
end
local old_set_extra_clothing = ctf_cosmetics.set_extra_clothing
function ctf_cosmetics.set_extra_clothing(player, ...)
local ret = old_set_extra_clothing(player, ...)
update_entity_cosmetics(player, ctf_cosmetics.get_extra_clothing(player))
return ret
end
local old_get_clothing_texture = ctf_cosmetics.get_clothing_texture
function ctf_cosmetics.get_clothing_texture(player, texture, ...)
if texture == "skin" then
return "server_cosmetics_skin.png"
end
for cosmetic in pairs(server_cosmetics.cosmetics.entity_cosmetics) do
if texture == cosmetic then
return false
end
end
for cosmetic in pairs(server_cosmetics.cosmetics.headwear) do
if texture == cosmetic then
return server_cosmetics.cosmetics.headwear[cosmetic]._texture
end
end
return old_get_clothing_texture(player, texture, ...)
end
minetest.register_on_joinplayer(function(player)
local current = ctf_cosmetics.get_extra_clothing(player)
if current._unset then
ctf_cosmetics.set_extra_clothing(player, {
hair = server_cosmetics.cosmetics.default_cosmetics.hair["brown"],
eyes = server_cosmetics.cosmetics.default_cosmetics.eyes["blue"],
})
player_api.set_texture(player, 1, ctf_cosmetics.get_skin(player))
end
minetest.after(1, update_entity_cosmetics, player:get_player_name(), current)
end)
-- Used for testing with //lua
-- Put through https://mothereff.in/lua-minifier before running
-- local ocu = server_cosmetics.can_use
-- function server_cosmetics.can_use(p, ...)
-- if p:get_player_name() == "LandarVargan" then
-- return true
-- else
-- return ocu(p, ...)
-- end
-- end
function server_cosmetics.can_use(player, clothing, color)
if not color then return false end
local meta = player:get_meta()
if (server_cosmetics.cosmetics.default_cosmetics[clothing] and
server_cosmetics.cosmetics.default_cosmetics[clothing][color]) or
meta:get_int("server_cosmetics:entity:"..clothing..":"..color) ~= 0 or
meta:get_int("server_cosmetics:headwear:"..clothing..":"..color) ~= 0 then
return true
else
return false
end
end
-- Legacy cosmetic format conversion
local old_get_extra_clothing = ctf_cosmetics.get_extra_clothing
function ctf_cosmetics.get_extra_clothing(player, ...)
local pmeta = PlayerObj(player):get_meta()
local meta = pmeta:get_string("ctf_cosmetics:extra_clothing")
if meta ~= "" then
meta = minetest.deserialize(meta)
if not meta then
pmeta:set_string("ctf_cosmetics:extra_clothing", "")
return old_get_extra_clothing(player, ...)
end
for costype, color in pairs(meta) do
-- Add compat for two entity materials
if meta[costype] and costype == "santa_hat" or costype == "hallows_hat" then
if type(color.color) == "string" then
color.color = {color.color, "blank.png"}
meta[costype] = color
elseif type(color.color) == "table" and color.color[1] and color.color[1][1] then
local temp = color.color
repeat
temp = temp[1]
until not temp[1][1]
color.color = temp
meta[costype].color = temp
end
end
if type(color) == "string" then
local breakout = false
for category, contents in pairs(server_cosmetics.cosmetics) do
for ctype, cosmetics in pairs(contents) do
for name, info in pairs(cosmetics) do
if name:sub(1, 1) ~= "_" then
if info.color == color then
meta[costype] = info
color = info
breakout = true
break
end
end
end
if breakout then break end
end
if breakout then break end
end
if not breakout then -- couldn't find the cosmetic, but it's in the wrong format, so remove it
meta[costype] = nil
end
end
-- Remove cosmetics players can no longer use
if meta[costype] and not server_cosmetics.can_use(player, costype, color._key) then
meta[costype] = nil
end
end
pmeta:set_string("ctf_cosmetics:extra_clothing", minetest.serialize(meta))
end
return old_get_extra_clothing(player, ...)
end
include("inv_tab.lua")
include("graves.lua")
include("ranking_reset.lua")