-
-
Save Jordach/71675276c68f7fafa639f6717dc6cdee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- wardrobe formspec | |
wardrobe = {} | |
wardrobe.player_materials = {} | |
wardrobe.formspec_selections = {} | |
wardrobe.formspec_selections["singleplayer"] = {1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} | |
--clothing | |
wardrobe.undershirt_names = {} | |
wardrobe.shirt_names = {} | |
wardrobe.under_trousers = {} | |
wardrobe.trousers = {} | |
wardrobe.sock_names = {} | |
wardrobe.shoe_names = {} | |
wardrobe.accessories = {} | |
--biological features | |
wardrobe.mouth_parts = {} | |
wardrobe.hair_styles = {} | |
wardrobe.eyes = {} | |
-- preset names | |
wardrobe.shirt_names[1] = "Sam's Shirt" | |
wardrobe.shirt_names[2] = "Plain T-Shirt" | |
wardrobe.shirt_names[3] = "Tank" | |
wardrobe.shirt_names[4] = "Tank" | |
function wardrobe.formspec_meta( | |
eye, | |
hair, | |
ushirt, ushirt2, | |
utrou, utrou2, | |
socks, socks2, | |
jacket, jacket2, | |
trous, trous2, | |
shoes, shoes2, | |
acc1, acc2, acc3, acc4, acc5, acc6 ) | |
local formspec = | |
"size[14,10]".. | |
"label[1, 0; "..wardrobe.shirt_names[ushirt].."]".. | |
"button[1, 1; 1, 1; mouthd; <-]".. | |
"field[2.05, 1.32; 1.75, 1; entry1; ; RRGGBB]".. | |
"button[3.27, 1; 1, 1; mouthu; ->]" | |
return formspec | |
end | |
minetest.register_node("wardrobe:node", { | |
description = "Wardrobe", | |
tiles = {"wardrobe.png"}, | |
groups = {crumbly=3}, | |
after_place_node = function(pos, placer) | |
local meta = minetest.get_meta(pos) | |
meta:set_string("ushirt", 1) | |
end, | |
on_rightclick = function(pos, node, clicker) | |
local meta = minetest.get_meta(pos) | |
local pname = clicker:get_player_name() | |
local pchoices = {} | |
for i, fsel in ipairs (wardrobe.formspec_selections[pname]) do | |
pchoices[i] = fsel | |
end | |
minetest.show_formspec( | |
clicker:get_player_name(), | |
"wardrobe_"..minetest.pos_to_string(pos), | |
wardrobe.formspec_meta( | |
pchoices[1], | |
pchoices[2], | |
pchoices[3], pchoices[4], | |
pchoices[5], pchoices[6], | |
pchoices[7], pchoices[8], | |
pchoices[9], pchoices[10], | |
pchoices[11], pchoices[12], | |
pchoices[13], pchoices[14], | |
pchoices[15], pchoices[16], pchoices[17], pchoices[18], pchoices[19], pchoices[20] | |
) | |
) | |
end, | |
}) | |
function wardrobe.table_incrementer(arraynum, by, form_choices, operator, position, player1) | |
local pchoices = {} | |
for i, fsel in ipairs (form_choices) do | |
pchoices[i] = fsel | |
end | |
if operator then | |
pchoices[arraynum] = pchoices + by | |
else | |
pchoices[arraynum] = pchoices - by | |
end | |
minetest.show_formspec( | |
player1:get_player_name(), | |
"wardrobe_"..minetest.pos_to_string(position), | |
wardrobe.formspec_meta( | |
pchoices[1], | |
pchoices[2], | |
pchoices[3], pchoices[4], | |
pchoices[5], pchoices[6], | |
pchoices[7], pchoices[8], | |
pchoices[9], pchoices[10], | |
pchoices[11], pchoices[12], | |
pchoices[13], pchoices[14], | |
pchoices[15], pchoices[16], pchoices[17], pchoices[18], pchoices[19], pchoices[20] | |
) | |
) | |
end | |
minetest.register_on_player_receive_fields(function(player, formname, fields) | |
if string.sub(formname, 0, string.len("wardrobe_")) == "wardrobe_" then | |
--print ("Meow") | |
local pos_s = string.sub(formname,string.len("wardrobe_") + 1) | |
local pos = minetest.string_to_pos(pos_s) | |
local meta = minetest.get_meta(pos) | |
local pname = player:get_player_name() | |
local ush1 = minetest.get_meta(pos):get_string("ushirt") | |
if fields.mouthd then | |
wardrobe.table_incrementer(3, 1, wardrobe.formspec_selections[pname], false, pos, player) | |
end | |
if fields.mouthu then | |
wardrobe.table_incrementer(3, 1, wardrobe.formspec_selections[player_name], true, pos, player) | |
end | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment