Skip to content

Instantly share code, notes, and snippets.

@kaeza

kaeza/asdf.lua Secret

Created February 12, 2017 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaeza/a3625a7e72c1c93cf5730e5033084723 to your computer and use it in GitHub Desktop.
Save kaeza/a3625a7e72c1c93cf5730e5033084723 to your computer and use it in GitHub Desktop.
local E = minetest.formspec_escape
local hair_styles = {
"Long",
"Short 1",
"Short 2",
"Beads tail",
}
local hair_colors = {
{ "Black", "#000000" },
{ "Blonde", "#FFFF00" },
{ "Brown", "#804020" },
{ "Red", "#FF0000" },
{ "White", "#FFFFFF" },
}
local skin_colors = {
{ "Pale", "#FFE0C0" },
{ "Fair", "#FFB0A0" },
{ "Dark", "#806040" },
}
local iris_colors = {
{ "Black", "#000000" },
{ "Brown", "#804020" },
{ "Dark Blue", "#000060" },
{ "Blue", "#0000C0" },
{ "Light Blue", "#0000FF" },
{ "Dark Green", "#006000" },
{ "Green", "#00C000" },
{ "Light Green", "#00FF00" },
{ "Dark Amber", "#404000" },
{ "Amber", "#808000" },
{ "Light Amber", "#A0A000" },
{ "White", "#C0C0C0" },
}
local clothing = {
"Shirt and jeans",
}
local clothing_colors = {
{ "Black", "#000000" },
{ "Brown", "#804020" },
{ "Dark Blue", "#000060" },
{ "Blue", "#0000C0" },
{ "Light Blue", "#0000FF" },
{ "Dark Green", "#006000" },
{ "Green", "#00C000" },
{ "Light Green", "#00FF00" },
{ "Yellow", "#A0A000" },
{ "Orange", "#FF8000" },
{ "Pink", "#FF0080" },
{ "Magenta", "#FF00FF" },
{ "White", "#FFFFFF" },
}
local function rnditem(l)
return l[math.random(1, #l)]
end
local ent = { }
function ent:reset_state()
local st = pmp.state.new()
self.state = st
st.skin_color = rnditem(skin_colors)[2]
st.iris_color = rnditem(iris_colors)[2]
st.hair_style = math.random(1, #hair_styles)
st.hair_color = rnditem(hair_colors)[2]
st.clothing = math.random(0, #clothing)
st.clothing_color = rnditem(clothing_colors)[2]
end
local function create_dropdown(x, y, w, name, items, fmt, sel, addnone)
fmt = fmt or "$0"
local t = { }
for i, item in ipairs(items) do
t[i] = E(fmt:gsub("%$(%d+)", function(n)
n = tonumber(n)
if n == 0 then
return tostring(item)
else
return tostring(item[n]) or "$"..n
end
end))
end
if addnone then table.insert(t, 1, "(None)") end
return ("dropdown["..x..","..y..";"..w..";"..E(name)..";"
..table.concat(t, ",")..";"..sel.."]")
end
local function find_item(list, item, key)
for i, it in ipairs(list) do
if key then it = it[key] end
if it == item then return i end
end
return 0
end
function ent:on_rightclick(obj)
if obj:is_player() then
local pn = obj:get_player_name()
local st = self.state
local sc = find_item(skin_colors, st.skin_color, 2)
local hs = find_item(hair_styles, st.hair_style)
local hc = find_item(hair_colors, st.hair_color, 2)
local ic = find_item(iris_colors, st.iris_color, 2)
local ot = find_item(clothing, st.clothing)
local oc = find_item(clothing_colors, st.clothing_color, 2)
local fs = table.concat({
pmpfs.size(12, 8),
pmpfs.image(0, 0, 4, 2, generate_texture(st, true)),
pmpfs.label(4, 0, "Skin"),
create_dropdown(8, 0, 2, "skin_c", skin_colors, "$1", sc),
pmpfs.label(4, 1, "Hair"),
create_dropdown(6, 1, 2, "hair_s", hair_styles, "$0", hs),
create_dropdown(8, 1, 2, "hair_c", hair_colors, "$1", hc),
pmpfs.label(4, 2, "Iris"),
create_dropdown(8, 2, 2, "iris_c", iris_colors, "$1", ic),
pmpfs.label(4, 3, "Clothing"),
create_dropdown(6, 3, 2, "over_t", clothing, "$0", ot+1, true),
})
minetest.show_formspec(pn, "blah", fs)
end
end
minetest.register_entity("foobar", ent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment