From 4011f698898e7d108d357a6e77a90e6c6362b774 Mon Sep 17 00:00:00 2001 From: Farooq Karimi Zadeh Date: Sat, 18 May 2024 02:21:34 +0330 Subject: [PATCH] Give score for bringing tools/weapons to the team chest (#1173) --- mods/ctf/ctf_teams/team_chest.lua | 79 ++++++++++++++++++++++++++++--- mods/pvp/dropondie/init.lua | 11 ++++- 2 files changed, 82 insertions(+), 8 deletions(-) diff --git a/mods/ctf/ctf_teams/team_chest.lua b/mods/ctf/ctf_teams/team_chest.lua index 1b08885ae0..49aba0450f 100644 --- a/mods/ctf/ctf_teams/team_chest.lua +++ b/mods/ctf/ctf_teams/team_chest.lua @@ -5,6 +5,59 @@ local blacklist = { "default:pick_stone", } +--[[ +local item_value = { + ["grenades:poison"] = 5, + ["grenades:frag"] = 6, + ["grenades:smoke"] = 2, + ["ctf_ranged:pistol_loaded"] = 2, + ["ctf_ranged:pistol"] = 1, + ["ctf_ranged:rifle"] = 4, + ["ctf_ranged:rifle_loaded"] = 5, + ["ctf_ranged:smg"] = 4, + ["ctf_ranged:smg_loaded"] = 5, + ["ctf_ranged:sniper_magnum"] = 8, + ["ctf_ranged:sniper_magnum_loaded"] = 10, + ["ctf_ranged:ammo"] = 4, + ["default:diamond"] = 2.5, + ["default:mese_crystal"] = 2, + ["default:mese"] = 18, + ["default:steel_ingot"] = 1, + ["default:iron_lump"] = 1, + ["default:sword_diamond"] = 16, + ["default:sword_steel"] = 7, + ["default:sword_mese"] = 13, + ["default:pick_steel"] = 3, + ["default:pick_mese"] = 6, + ["default:pick_diamond"] = 7, + ["default:axe_steel"] = 3, + ["default:axe_mese"] = 6, + ["default:axe_diamond"] = 7, + ["default:shovel_steel"] = 2, + ["default:shovel_mese"] = 3, + ["default:shovel_diamond"] = 4, + ["default:stick"] = 0.5, + ["default:wood"] = 1, + ["default:cobble"] = 1, + ["ctf_map:reinforced_cobble"] = 3, + ["ctf_map:damage_cobble"] = 3, + ["ctf_map:unwalkable_cobble"] = 1, + ["ctf_map:unwalkable_stone"] = 1, + ["ctf_map:unwalkable_dirt"] = 1, + ["default:steelblock"] = 2.5, + ["default:bronzeblock"] = 2.5, + ["default:obsidian_block"] = 3.5, + ["ctf_map:spike"] = 2.5, + ["default:apple"] = 1.5, + ["ctf_healing:medkit"] = 6, + ["ctf_healing:bandage"] = 6, +} +--]] + + + + + local function get_chest_access(name) local current_mode = ctf_modebase:get_current_mode() if not current_mode then return false, false end @@ -246,13 +299,27 @@ for _, team in ipairs(ctf_teams.teamlist) do end end - function def.on_metadata_inventory_put(pos, listname, index, stack, player) - minetest.log("action", string.format("%s puts %s to team chest at %s", - player:get_player_name(), - stack:to_string(), - minetest.pos_to_string(pos) - )) + + function def.on_metadata_inventory_put(pos, listname, index, stack, player) + minetest.log("action", string.format("%s puts %s to team chest at %s", + player:get_player_name(), + stack:to_string(), + minetest.pos_to_string(pos) + )) + local meta = stack:get_meta() + local dropped_by = meta:get_string("dropped_by") + local pname = player:get_player_name() + if dropped_by ~= pname and dropped_by ~= "" then + local cur_mode = ctf_modebase:get_current_mode() + if pname and cur_mode then + --local score = (item_value[stack:get_name()] or 0) * stack:get_count() + cur_mode.recent_rankings.add(pname, { score = 1 }, false) + end end + meta:set_string("dropped_by", "") + local inv = minetest.get_inventory({ type="node", pos=pos }) + inv:set_stack(listname, index, stack) + end function def.on_metadata_inventory_take(pos, listname, index, stack, player) minetest.log("action", string.format("%s takes %s from team chest at %s", diff --git a/mods/pvp/dropondie/init.lua b/mods/pvp/dropondie/init.lua index c9135e44a8..ef2acd2a08 100644 --- a/mods/pvp/dropondie/init.lua +++ b/mods/pvp/dropondie/init.lua @@ -1,7 +1,14 @@ dropondie = {} -local function drop_list(pos, inv, list) +local function drop_list(pos, inv, list, player) for _, item in ipairs(inv:get_list(list)) do + if minetest.registered_items[item:get_name()].stack_max == 1 then + local pname = player:get_player_name() + if pname ~= "" then + local meta = item:get_meta() + meta:set_string("dropped_by", pname) + end + end local obj = minetest.add_item(pos, item) if obj then @@ -21,7 +28,7 @@ function dropondie.drop_all(player) local pos = player:get_pos() pos.y = math.floor(pos.y + 0.5) - drop_list(pos, player:get_inventory(), "main") + drop_list(pos, player:get_inventory(), "main", player) end if ctf_core.settings.server_mode ~= "mapedit" then