Added `picked_up.<itemstring>
This commit is contained in:
parent
ea9c3d440e
commit
d714f9a8a5
19
API/API.lua
19
API/API.lua
@ -58,4 +58,23 @@ end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
better_commands.sidebars[player:get_player_name()] = {}
|
||||
end)
|
||||
|
||||
minetest.register_on_item_pickup(function(itemstack, player)
|
||||
for _, objective in pairs(better_commands.scoreboard.objectives) do
|
||||
local score = objective.scores[player:get_player_name()]
|
||||
if score then -- don't bother with other players' scores
|
||||
if objective.criterion:sub(1, 10) == "picked_up." then
|
||||
local criterion_item = objective.criterion:sub(11, -1)
|
||||
local handled = better_commands.handle_alias(criterion_item)
|
||||
if handled and handled == itemstack:get_name() then
|
||||
score.score = score.score + 1
|
||||
elseif criterion_item:sub(1, 6) == "group:" then
|
||||
if minetest.get_item_group(itemstack:get_name(), criterion_item:sub(7, -1)) ~= 0 then
|
||||
score.score = score.score + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
@ -86,7 +86,7 @@ end)
|
||||
-- Make sure players always die when /killed, also track hp
|
||||
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
||||
if reason.better_commands == "kill" then
|
||||
return -player:get_properties().hp_max, true
|
||||
return hp_change, true
|
||||
end
|
||||
local player_name = player:get_player_name()
|
||||
for _, def in pairs(better_commands.scoreboard.objectives) do
|
||||
|
@ -596,12 +596,13 @@ end
|
||||
|
||||
---Handles item aliases
|
||||
---@param itemstring string
|
||||
---@return string? itemstring corrected itemstring if valid, otherwise false
|
||||
---@return string|false itemstring corrected itemstring if valid, otherwise false
|
||||
function better_commands.handle_alias(itemstring)
|
||||
local stack = ItemStack(itemstring)
|
||||
if (stack:is_known() and stack:get_name() ~= "unknown" and stack:get_name() ~= "") then
|
||||
return stack:get_name()
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
---I wish #table would work for non-arrays...
|
||||
|
@ -7,4 +7,8 @@ Initial release. Missing *lots* of commands, several `execute` subcommands, lots
|
||||
* Removed a reference to ACOVG (hopefully the last)
|
||||
* Added TODO.md
|
||||
* Redid settings slightly (so it's easy to add more)
|
||||
* Removed debug logging when using the `/kill` command
|
||||
* Removed debug logging when using the `/kill` command
|
||||
|
||||
## v2.0
|
||||
* Added `picked_up.<itemstring>` scoreboard criterion (supports groups!)
|
||||
*
|
@ -22,7 +22,7 @@ better_commands.register_command("kill", {
|
||||
better_commands.deal_damage(
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
target,
|
||||
math.max(target:get_hp(), 1000000000000), -- 1 trillion damage to make sure they die :D
|
||||
-math.max(target:get_hp(), 1000000000000), -- 1 trillion damage to make sure they die :D
|
||||
{
|
||||
type = "set_hp",
|
||||
bypasses_totem = true,
|
||||
|
2
TODO.md
2
TODO.md
@ -10,7 +10,7 @@ A place for me to write out my future plans. Also, I can just copy/paste into a
|
||||
- [ ] `air`
|
||||
- [ ] `armor` (MCLA/VL/3D Armor)
|
||||
- [x] `trigger`
|
||||
- [ ] `picked_up.<itemstring>`
|
||||
- [x] `picked_up.<itemstring>`
|
||||
- [ ] `mined.<itemstring>`
|
||||
- [ ] `crafted.<itemstring>`
|
||||
- [ ] `total_world_time`
|
||||
|
Loading…
x
Reference in New Issue
Block a user