Skip to content

Commit

Permalink
Give score for bringing tools/weapons to the team chest (#1173)
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqkz authored May 17, 2024
1 parent e286269 commit 4011f69
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 8 deletions.
79 changes: 73 additions & 6 deletions mods/ctf/ctf_teams/team_chest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 9 additions & 2 deletions mods/pvp/dropondie/init.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4011f69

Please sign in to comment.