wielded items can now be set using inventory slots
This commit is contained in:
parent
952ed84733
commit
48482ce23f
156
fs_fashion.lua
156
fs_fashion.lua
@ -187,7 +187,7 @@ yl_speak_up.get_fs_fashion = function(pname)
|
|||||||
end
|
end
|
||||||
local formspec = {
|
local formspec = {
|
||||||
"formspec_version[3]",
|
"formspec_version[3]",
|
||||||
"size[13.4,9.5]",
|
"size[13.4,15]",
|
||||||
"dropdown[0.3,0.2;4,0.75;set_skin;",
|
"dropdown[0.3,0.2;4,0.75;set_skin;",
|
||||||
mainlist,
|
mainlist,
|
||||||
";",
|
";",
|
||||||
@ -204,10 +204,10 @@ yl_speak_up.get_fs_fashion = function(pname)
|
|||||||
";",
|
";",
|
||||||
capeindex,
|
capeindex,
|
||||||
"]",
|
"]",
|
||||||
"field[0.3,3.2;4,0.75;set_sword;;",
|
"label[0.3,3.2;",
|
||||||
textures[4],
|
textures[4],
|
||||||
"]",
|
"]",
|
||||||
"field[9.1,3.2;4,0.75;set_shield;;",
|
"label[9.1,3.2;",
|
||||||
textures[3],
|
textures[3],
|
||||||
"]",
|
"]",
|
||||||
"field_close_on_enter[set_sword;false]",
|
"field_close_on_enter[set_sword;false]",
|
||||||
@ -228,7 +228,17 @@ yl_speak_up.get_fs_fashion = function(pname)
|
|||||||
preview,
|
preview,
|
||||||
"]",
|
"]",
|
||||||
"button_exit[0.3,8.4;3,0.75;button_cancel;"..button_cancel.."]",
|
"button_exit[0.3,8.4;3,0.75;button_cancel;"..button_cancel.."]",
|
||||||
"button[10.1,8.4;3,0.75;button_save;Save]"
|
"button[10.1,8.4;3,0.75;button_save;Save]",
|
||||||
|
"list[current_player;main;1.8,10;8,4;]",
|
||||||
|
-- set wielded items
|
||||||
|
"label[0.3,9.7;Wield\nleft:]",
|
||||||
|
"label[12.0,9.7;Wield\nright:]",
|
||||||
|
"list[detached:yl_speak_up_player_"..tostring(pname)..";wield;0.3,10.5;1,1;]",
|
||||||
|
"list[detached:yl_speak_up_player_"..tostring(pname)..";wield;12.0,10.5;1,1;1]",
|
||||||
|
"button[0.3,11.7;1,0.6;button_wield_left;Set]",
|
||||||
|
"button[12.0,11.7;1,0.6;button_wield_right;Set]",
|
||||||
|
"tooltip[button_wield_left;Set and store what your NPC shall wield in its left hand.]",
|
||||||
|
"tooltip[button_wield_right;Set and store what your NPC shall wield in its right hand.]",
|
||||||
}
|
}
|
||||||
return table.concat(formspec, "")
|
return table.concat(formspec, "")
|
||||||
end
|
end
|
||||||
@ -241,75 +251,73 @@ yl_speak_up.input_fashion = function(player, formname, fields)
|
|||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
local textures = yl_speak_up.speak_to[pname].textures
|
local textures = yl_speak_up.speak_to[pname].textures
|
||||||
|
|
||||||
if fields then
|
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||||
-- catch ESC as well
|
|
||||||
if fields.quit or fields.button_cancel or fields.button_exit then
|
|
||||||
-- is the player editing this npc? then we need to go back to the edit menu
|
|
||||||
if( yl_speak_up.edit_mode[pname]
|
|
||||||
and yl_speak_up.edit_mode[pname] == yl_speak_up.speak_to[pname].n_id) then
|
|
||||||
yl_speak_up.show_fs(player, "talk", {n_id = yl_speak_up.speak_to[pname].n_id,
|
|
||||||
d_id = yl_speak_up.speak_to[pname].d_id})
|
|
||||||
return
|
|
||||||
end
|
|
||||||
yl_speak_up.speak_to[pname] = nil
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
-- is the player editing this npc? if not: abort
|
||||||
|
if(not(yl_speak_up.edit_mode[pname])
|
||||||
|
or (yl_speak_up.edit_mode[pname] ~= n_id)) then
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
|
||||||
-- only change cape if there really is a diffrent one selected
|
-- catch ESC as well
|
||||||
if fields.set_cape and fields.set_cape ~= textures[1] then
|
if(not(fields) or (fields.quit or fields.button_cancel or fields.button_exit)) then
|
||||||
-- only set the cape if it is part of the list of allowed capes
|
yl_speak_up.show_fs(player, "talk", {n_id = yl_speak_up.speak_to[pname].n_id,
|
||||||
local capetable, capelist, capeindex = get_npc_capes(textures[1])
|
d_id = yl_speak_up.speak_to[pname].d_id})
|
||||||
for _, v in pairs(capetable) do
|
return
|
||||||
if(v == fields.set_cape) then
|
|
||||||
textures[1] = fields.set_cape
|
elseif(fields.button_wield_left
|
||||||
|
or fields.button_wield_right) then
|
||||||
|
local trade_inv = minetest.get_inventory({type="detached", name="yl_speak_up_player_"..pname})
|
||||||
|
local left_stack = trade_inv:get_stack("wield", 1)
|
||||||
|
local right_stack = trade_inv:get_stack("wield", 2)
|
||||||
|
if(left_stack and left_stack:get_name() and fields.button_wield_left) then
|
||||||
|
textures[4] = yl_speak_up.get_wield_texture(left_stack:get_name())
|
||||||
yl_speak_up.log_change(pname, n_id,
|
yl_speak_up.log_change(pname, n_id,
|
||||||
"(fashion) cape changed to "..tostring(fields.set_cape)..".")
|
|
||||||
-- we have found it
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- only change the skin if there really is a diffrent new one selected
|
|
||||||
if fields.set_skin and fields.set_skin ~= textures[2] then
|
|
||||||
-- only set the skin if it is part of the list of allowed skins
|
|
||||||
local maintable, mainlist, mainindex = get_npc_skins(textures[2])
|
|
||||||
for _, v in pairs(maintable) do
|
|
||||||
if(v == fields.set_skin) then
|
|
||||||
textures[2] = fields.set_skin
|
|
||||||
yl_speak_up.log_change(pname, n_id,
|
|
||||||
"(fashion) skin changed to "..tostring(fields.set_skin)..".")
|
|
||||||
-- we have found it
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if fields.set_shield then
|
|
||||||
textures[3] = fields.set_shield
|
|
||||||
yl_speak_up.log_change(pname, n_id,
|
|
||||||
"(fashion) shield changed to "..tostring(fields.set_shield)..".")
|
|
||||||
end
|
|
||||||
if fields.set_sword then
|
|
||||||
textures[4] = fields.set_sword
|
|
||||||
yl_speak_up.log_change(pname, n_id,
|
|
||||||
"(fashion) sword changed to "..tostring(fields.set_sword)..".")
|
"(fashion) sword changed to "..tostring(fields.set_sword)..".")
|
||||||
end
|
end
|
||||||
|
if(right_stack and right_stack:get_name() and fields.button_wield_right) then
|
||||||
|
textures[3] = yl_speak_up.get_wield_texture(right_stack:get_name())
|
||||||
|
yl_speak_up.log_change(pname, n_id,
|
||||||
|
"(fashion) shield changed to "..tostring(fields.set_shield)..".")
|
||||||
|
end
|
||||||
|
|
||||||
if fields.button_save then
|
-- only change cape if there really is a diffrent one selected
|
||||||
local obj = yl_speak_up.speak_to[pname].obj
|
elseif(fields.set_cape and fields.set_cape ~= textures[1]) then
|
||||||
if obj ~= nil and obj:get_luaentity() ~= nil then
|
-- only set the cape if it is part of the list of allowed capes
|
||||||
-- save textures
|
local capetable, capelist, capeindex = get_npc_capes(textures[1])
|
||||||
yl_speak_up.speak_to[pname].skins = textures2skin(textures)
|
for _, v in pairs(capetable) do
|
||||||
set_textures(obj, textures)
|
if(v == fields.set_cape) then
|
||||||
yl_speak_up.log_change(pname, n_id,
|
textures[1] = fields.set_cape
|
||||||
|
y_speak_up.log_change(pname, n_id,
|
||||||
|
"(fashion) cape changed to "..tostring(fields.set_cape)..".")
|
||||||
|
-- we have found it
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- only change the skin if there really is a diffrent new one selected
|
||||||
|
elseif(fields.set_skin and fields.set_skin ~= textures[2]) then
|
||||||
|
-- only set the skin if it is part of the list of allowed skins
|
||||||
|
local maintable, mainlist, mainindex = get_npc_skins(textures[2])
|
||||||
|
for _, v in pairs(maintable) do
|
||||||
|
if(v == fields.set_skin) then
|
||||||
|
textures[2] = fields.set_skin
|
||||||
|
yl_speak_up.log_change(pname, n_id,
|
||||||
|
"(fashion) skin changed to "..tostring(fields.set_skin)..".")
|
||||||
|
-- we have found it
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif fields.button_save then
|
||||||
|
local obj = yl_speak_up.speak_to[pname].obj
|
||||||
|
if obj ~= nil and obj:get_luaentity() ~= nil then
|
||||||
|
-- save textures
|
||||||
|
yl_speak_up.speak_to[pname].skins = textures2skin(textures)
|
||||||
|
set_textures(obj, textures)
|
||||||
|
yl_speak_up.log_change(pname, n_id,
|
||||||
"(fashion) saved changes.")
|
"(fashion) saved changes.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--yl_speak_up.speak_to[pname].textures = textures
|
|
||||||
end
|
|
||||||
|
|
||||||
yl_speak_up.show_fs(player, "fashion")
|
yl_speak_up.show_fs(player, "fashion")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -350,3 +358,17 @@ yl_speak_up.update_nametag = function(self)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- inspired/derived from the wieldview mod in 3darmor
|
||||||
|
yl_speak_up.get_wield_texture = function(item)
|
||||||
|
if(not(item) or not(minetest.registered_items[ item ])) then
|
||||||
|
return "3d_armor_trans.png"
|
||||||
|
end
|
||||||
|
local def = minetest.registered_items[ item ]
|
||||||
|
if(def.inventory_image ~= "") then
|
||||||
|
return def.inventory_image
|
||||||
|
elseif(def.tiles and type(def.tiles[1]) == "string" and def.tiles[1] ~= "") then
|
||||||
|
return minetest.inventorycube(def.tiles[1])
|
||||||
|
end
|
||||||
|
return "3d_armor_trans.png"
|
||||||
|
end
|
||||||
|
@ -788,4 +788,6 @@ minetest.register_on_joinplayer(function(player, last_login)
|
|||||||
-- for setting up actions
|
-- for setting up actions
|
||||||
trade_inv:set_size("npc_gives", 1)
|
trade_inv:set_size("npc_gives", 1)
|
||||||
trade_inv:set_size("npc_wants", 1)
|
trade_inv:set_size("npc_wants", 1)
|
||||||
|
-- for setting wielded items (left and right)
|
||||||
|
trade_inv:set_size("wield", 2)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user