From f43dc80eb51a21519755d51a699da3b0f908f465 Mon Sep 17 00:00:00 2001 From: Austin Shenk Date: Mon, 1 Jul 2013 18:58:49 -0400 Subject: [PATCH] Remove wield image in item definition --- externalmodify.lua | 1 - init.lua | 30 ++++++++++++++++++++++++++++-- xp.lua | 18 +++++++++++++----- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/externalmodify.lua b/externalmodify.lua index b466296..3666a53 100644 --- a/externalmodify.lua +++ b/externalmodify.lua @@ -234,7 +234,6 @@ for name, def in pairs(minetest.registered_tools) do end newdef.description = def.description.." "..special.description newdef.inventory_image = def.inventory_image.."^specialties_"..special.name..".png" - newdef.wield_image = def.inventory_image.."^specialties_"..special.name..".png" if(name:find(":hoe") ~= nil) then newdef.on_use = function(itemstack, user, pointed_thing) if pointed_thing.type == "nothing" or pointed_thing.type == "object" or pointed_thing.above == nil then return itemstack end diff --git a/init.lua b/init.lua index 6ff0990..34f076e 100644 --- a/init.lua +++ b/init.lua @@ -18,7 +18,7 @@ local get_specialInfo = function(name, specialty) .."button[2,3;2,0.5;builder;Builder]" .."list[current_player;main;0,4;8,4;]" if(specialty ~= "") then - formspec = formspec.."label[4,0;XP: "..specialties.players[name][specialty].."]"..specialties.skills[specialty].menu + formspec = formspec.."label[4,0;XP: "..specialties.players[name].skills[specialty].."]"..specialties.skills[specialty].menu end return formspec end @@ -44,7 +44,33 @@ minetest.register_on_joinplayer(function(player) player:get_inventory():set_size("buildtrash", 1) name = player:get_player_name() specialties.players[name] = {} - specialties.players[name] = specialties.readXP(name) + specialties.players[name].skills = {} + specialties.players[name].skills = specialties.readXP(name) + specialties.players[name].menu = {} + minetest.after(0.5, function() + local Yoffset = 0.02 + local y = 0 + for skill,num in pairs(specialties.players[name].skills) do + specialties.players[name].menu[skill] = player:hud_add({ + hud_elem_type = "text", + position = {x=0, y=0.85+y}, + offset = {x=100, y=0}, + alignment = {x=1, y=0}, + number = 0xFFFFFF , + text = tostring(num), + }) + player:hud_add({ + hud_elem_type = "text", + position = {x=0, y=0.85+y}, + offset = {x=10, y=0}, + alignment = {x=1, y=0}, + scale = {x=100, y=50}, + number = 0xFFFFFF , + text = skill, + }) + y = y+Yoffset + end + end) end) local function show_formspec(name, specialty) minetest.show_formspec(name, "specialties:spec", get_specialInfo(name, specialty)) diff --git a/xp.lua b/xp.lua index a149910..da0b1c5 100644 --- a/xp.lua +++ b/xp.lua @@ -1,8 +1,8 @@ --File Manipulating specialties.writeXP = function(name) local file = io.open(minetest.get_worldpath().."/"..name.."_XP", "w") - for skill,_ in pairs(specialties.players[name]) do - file:write(skill.." "..tostring(specialties.players[name][skill]).."\n") + for skill,num in pairs(specialties.players[name].skills) do + file:write(skill.." "..tostring(num).."\n") end file:close() end @@ -29,9 +29,17 @@ end --Table Modification specialties.changeXP = function(name, specialty, amount) - local current = specialties.players[name][specialty] - if current+amount >= 0 then - specialties.players[name][specialty] = current+amount + local newAmount = specialties.players[name].skills[specialty]+amount + if newAmount >= 0 then + specialties.players[name].skills[specialty] = newAmount + local player = minetest.get_player_by_name(name) + local id = specialties.players[name].menu[specialty] + local hudItem = player:hud_get(id) + hudItem.text = tostring(newAmount) + hudItem.offset = {x=100, y=0} + hudItem.alignment = {x=1, y=0} + player:hud_remove(id) + specialties.players[name].menu[specialty] = player:hud_add(hudItem) return true else return false