Added `picked_up.<itemstring>
This commit is contained in:
parent
ea9c3d440e
commit
d714f9a8a5
19
API/API.lua
19
API/API.lua
@ -59,3 +59,22 @@ end)
|
|||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
better_commands.sidebars[player:get_player_name()] = {}
|
better_commands.sidebars[player:get_player_name()] = {}
|
||||||
end)
|
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
|
-- Make sure players always die when /killed, also track hp
|
||||||
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
minetest.register_on_player_hpchange(function(player, hp_change, reason)
|
||||||
if reason.better_commands == "kill" then
|
if reason.better_commands == "kill" then
|
||||||
return -player:get_properties().hp_max, true
|
return hp_change, true
|
||||||
end
|
end
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
for _, def in pairs(better_commands.scoreboard.objectives) do
|
for _, def in pairs(better_commands.scoreboard.objectives) do
|
||||||
|
@ -596,12 +596,13 @@ end
|
|||||||
|
|
||||||
---Handles item aliases
|
---Handles item aliases
|
||||||
---@param itemstring string
|
---@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)
|
function better_commands.handle_alias(itemstring)
|
||||||
local stack = ItemStack(itemstring)
|
local stack = ItemStack(itemstring)
|
||||||
if (stack:is_known() and stack:get_name() ~= "unknown" and stack:get_name() ~= "") then
|
if (stack:is_known() and stack:get_name() ~= "unknown" and stack:get_name() ~= "") then
|
||||||
return stack:get_name()
|
return stack:get_name()
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
---I wish #table would work for non-arrays...
|
---I wish #table would work for non-arrays...
|
||||||
|
@ -8,3 +8,7 @@ Initial release. Missing *lots* of commands, several `execute` subcommands, lots
|
|||||||
* Added TODO.md
|
* Added TODO.md
|
||||||
* Redid settings slightly (so it's easy to add more)
|
* 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(
|
better_commands.deal_damage(
|
||||||
---@diagnostic disable-next-line: param-type-mismatch
|
---@diagnostic disable-next-line: param-type-mismatch
|
||||||
target,
|
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",
|
type = "set_hp",
|
||||||
bypasses_totem = true,
|
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`
|
- [ ] `air`
|
||||||
- [ ] `armor` (MCLA/VL/3D Armor)
|
- [ ] `armor` (MCLA/VL/3D Armor)
|
||||||
- [x] `trigger`
|
- [x] `trigger`
|
||||||
- [ ] `picked_up.<itemstring>`
|
- [x] `picked_up.<itemstring>`
|
||||||
- [ ] `mined.<itemstring>`
|
- [ ] `mined.<itemstring>`
|
||||||
- [ ] `crafted.<itemstring>`
|
- [ ] `crafted.<itemstring>`
|
||||||
- [ ] `total_world_time`
|
- [ ] `total_world_time`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user