Initial work for playing with less weapons (yet useless at the moment, it requires weapons_lib first)

This commit is contained in:
marco_a 2024-03-16 23:27:31 +01:00
parent 2b1a3e7434
commit b1a309bafd
3 changed files with 31 additions and 11 deletions
block_league/src

@ -40,8 +40,8 @@ function get_formspec(p_name)
or "image[2,1.7;1.5,1.5;" .. weap.wield_image .. "]"
elem_name = weap.description
body = get_weapon_details(weap)
button = "" -- TODO v
--[[if block_league.has_weapon_equipped(p_name, elem_technical) then
button = "" --[[ TODO v
if block_league.has_weapon_equipped(p_name, elem_technical) then
button = "image_button[1.45,7.9;2.2,0.8;bl_gui_profile_button_unequip.png;unequip;" .. S("UNEQUIP") .. "]"
else
button = "image_button[1.45,7.9;2.2,0.8;bl_gui_profile_button_equip.png;equip;" .. S("EQUIP") .. "]"
@ -89,9 +89,9 @@ function get_formspec(p_name)
"image[1.1,0;1.05,1.05;bl_gui_profile_button_weap.png]",
"image[2.2,0;1.05,1.05;bl_gui_profile_button_weap.png]",
"image[3.3,0;1.05,1.05;bl_gui_profile_button_skill.png]",
"image_button[0.1,0.11;0.85,0.85;" .. minetest.registered_nodes[p_weaps[1]].inventory_image .. ";weap;1]",
"image_button[1.2,0.11;0.85,0.85;" .. minetest.registered_nodes[p_weaps[2]].inventory_image .. ";weap;2]",
"image_button[2.3,0.11;0.85,0.85;" .. minetest.registered_nodes[p_weaps[3]].inventory_image .. ";weap;3]",
"image_button[0.1,0.11;0.85,0.85;" .. (p_weaps[1] and minetest.registered_nodes[p_weaps[1]].inventory_image or "blank.png") .. ";weap;1]",
"image_button[1.2,0.11;0.85,0.85;" .. (p_weaps[2] and minetest.registered_nodes[p_weaps[2]].inventory_image or "blank.png") .. ";weap;2]",
"image_button[2.3,0.11;0.85,0.85;" .. (p_weaps[3] and minetest.registered_nodes[p_weaps[3]].inventory_image or "blank.png") .. ";weap;3]",
"image_button[3.4,0.11;0.85,0.85;" .. skill_def.icon .. ";skill;]",
"tooltip[skill;" .. skill_def.name .. "]",
"container[0.05,1.55]",
@ -221,13 +221,22 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.quit then return end
local p_name = player:get_player_name()
local p_meta = player:get_meta()
local elem_technical = "block_league:" .. p_meta:get_string("bl_profile_elem_active")
if fields.close then
minetest.close_formspec(p_name, "block_league:profile")
return end
if fields.weap then
player:get_meta():set_string("bl_profile_elem_active", string.sub(block_league.get_player_weapons(p_name)[tonumber(fields.weap)], 14, -1))
local weap = block_league.get_player_weapons(p_name)[tonumber(fields.weap)]
if not weap then
p_meta:set_string("bl_profile_elem_active", "")
else
p_meta:set_string("bl_profile_elem_active", string.sub(weap, 14, -1))
end
elseif fields.skill then
player:get_meta():set_string("bl_profile_elem_active", string.sub(block_league.get_player_skill(p_name), 14, -1))
elseif fields.wslot then
@ -235,7 +244,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
elseif fields.sslot then
player:get_meta():set_string("bl_profile_elem_active", fields.sslot)
elseif fields.equip then
local elem_technical = "block_league:" .. player:get_meta():get_string("bl_profile_elem_active")
local weap = minetest.registered_items[elem_technical]
if weap then
@ -246,7 +254,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
elseif fields.unequip then
minetest.chat_send_player(p_name, "TODO")
block_league.unequip(p_name, elem_technical)
end
minetest.show_formspec(p_name, "block_league:profile", get_formspec(p_name))

@ -116,10 +116,12 @@ function equip(arena, p_name)
local weapons = block_league.get_player_weapons(p_name)
local propulsor = arena.mode == 1 and "block_league:propulsor" or "block_league:propulsor_dm"
for _, weapon_name in pairs(weapons) do
inv:add_item("main", ItemStack(weapon_name))
for i = 1, 3 do
if weapons[i] then
inv:set_stack("main", i, ItemStack(weapons[i]))
end
end
inv:add_item("main", ItemStack(propulsor))
inv:set_stack("main", 4, ItemStack(propulsor))
local skill = block_league.get_player_skill(p_name)

@ -8,6 +8,16 @@ end
function block_league.unequip(p_name, w_name)
for i, ww_name in pairs(equip[p_name].weapons) do
if w_name == ww_name then
equip[p_name].weapons[i] = nil
end
end
end
function block_league.get_player_weapons(p_name)
return equip[p_name].weapons
end