add automatic option
This commit is contained in:
parent
5426e42611
commit
d797adb812
@ -6,4 +6,6 @@ Have you ever died and been frustrated with being unable to find your way back t
|
||||
|
||||
But hurry! The server administrator may have limited the duration that the compass will function for.
|
||||
|
||||
Crafting recipe: four bones and a mese fragment.
|
||||
Crafting recipe: four bones and a mese fragment.
|
||||
|
||||
Alternately, there is a configuration setting (false by default) that automatically gives a player a death compass whenever they die. This automatic compass will disappear back to wherever it came from once its grim task is complete.
|
59
init.lua
59
init.lua
@ -5,6 +5,7 @@ local S = minetest.get_translator("death_compass")
|
||||
|
||||
-- how many seconds does the death compass work for? 0 for indefinite
|
||||
local duration = tonumber(minetest.settings:get("death_compass_duration")) or 0
|
||||
local automatic = minetest.settings:get_bool("death_compass_automatic", false)
|
||||
|
||||
local range_to_inactivate = 5
|
||||
|
||||
@ -43,8 +44,15 @@ end
|
||||
-- get right image number for players compass
|
||||
local function get_compass_stack(player, stack)
|
||||
local target = get_destination(player, stack)
|
||||
local inactive_return
|
||||
if automatic then
|
||||
inactive_return = ItemStack("")
|
||||
else
|
||||
inactive_return = ItemStack("death_compass:inactive")
|
||||
end
|
||||
|
||||
if not target then
|
||||
return ItemStack("death_compass:inactive")
|
||||
return inactive_return
|
||||
end
|
||||
local pos = player:get_pos()
|
||||
local dist = vector.distance(pos, target)
|
||||
@ -53,7 +61,7 @@ local function get_compass_stack(player, stack)
|
||||
if dist < range_to_inactivate then
|
||||
stop_ticking(player_name)
|
||||
minetest.sound_play("death_compass_bone_crunch", {to_player=player_name, gain = 1.0})
|
||||
return ItemStack("death_compass:inactive")
|
||||
return inactive_return
|
||||
end
|
||||
|
||||
local dir = player:get_look_horizontal()
|
||||
@ -74,7 +82,7 @@ local function get_compass_stack(player, stack)
|
||||
if remaining < 0 then
|
||||
stop_ticking(player_name)
|
||||
minetest.sound_play("death_compass_bone_crunch", {to_player=player_name, gain = 1.0})
|
||||
return ItemStack("death_compass:inactive")
|
||||
return inactive_return
|
||||
end
|
||||
start_ticking(player_name)
|
||||
meta_fields.description = S("@1m to @2's corpse, @3s remaining",
|
||||
@ -124,22 +132,25 @@ for i = 0, 15 do
|
||||
groups = groups,
|
||||
})
|
||||
end
|
||||
minetest.register_tool("death_compass:inactive", {
|
||||
description = S("Inactive Death Compass"),
|
||||
inventory_image = "death_compass_inactive.png",
|
||||
wield_image = "death_compass_inactive.png",
|
||||
stack_max = 1,
|
||||
groups = {death_compass = 1},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'death_compass:inactive',
|
||||
recipe = {
|
||||
{'', 'bones:bones', ''},
|
||||
{'bones:bones', 'default:mese_crystal_fragment', 'bones:bones'},
|
||||
{'', 'bones:bones', ''}
|
||||
}
|
||||
})
|
||||
if not automatic then
|
||||
minetest.register_tool("death_compass:inactive", {
|
||||
description = S("Inactive Death Compass"),
|
||||
inventory_image = "death_compass_inactive.png",
|
||||
wield_image = "death_compass_inactive.png",
|
||||
stack_max = 1,
|
||||
groups = {death_compass = 1},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'death_compass:inactive',
|
||||
recipe = {
|
||||
{'', 'bones:bones', ''},
|
||||
{'bones:bones', 'default:mese_crystal_fragment', 'bones:bones'},
|
||||
{'', 'bones:bones', ''}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
local player_death_location = {}
|
||||
minetest.register_on_dieplayer(function(player, reason)
|
||||
@ -147,10 +158,14 @@ minetest.register_on_dieplayer(function(player, reason)
|
||||
local inv = minetest.get_inventory({type="player", name=player:get_player_name()})
|
||||
local list = inv:get_list("main")
|
||||
local count = 0
|
||||
for i, itemstack in pairs(list) do
|
||||
if minetest.get_item_group(itemstack:get_name(), "death_compass") > 0 then
|
||||
count = count + itemstack:get_count()
|
||||
list[i] = ItemStack("")
|
||||
if automatic then
|
||||
count = 1
|
||||
else
|
||||
for i, itemstack in pairs(list) do
|
||||
if minetest.get_item_group(itemstack:get_name(), "death_compass") > 0 then
|
||||
count = count + itemstack:get_count()
|
||||
list[i] = ItemStack("")
|
||||
end
|
||||
end
|
||||
end
|
||||
if count > 0 then
|
||||
|
@ -1,3 +1,7 @@
|
||||
# The number of seconds the death compass will remain active for.
|
||||
# Set this to 0 to let the death compass continue to be active indefinitely.
|
||||
death_compass_duration (Death compass duration) int 0
|
||||
|
||||
# When a player dies they'll be given a death compass automatically, and it will
|
||||
# disappear when its duration expires or the player reaches the death location
|
||||
death_compass_automatic (Death compass given to players automatically) bool false
|
Loading…
x
Reference in New Issue
Block a user