forked from mtcontrib/minetest_returnmirror
Add cost for setting mirror point
This commit is contained in:
parent
dc5d58ceb9
commit
9aa76bead8
39
init.lua
39
init.lua
|
@ -1,5 +1,6 @@
|
||||||
returnmirror = {}
|
returnmirror = {}
|
||||||
returnmirror.cost = 100
|
returnmirror.cost_teleport = 100
|
||||||
|
returnmirror.cost_set = 20
|
||||||
|
|
||||||
if minetest.get_modpath("mana") ~= nil then
|
if minetest.get_modpath("mana") ~= nil then
|
||||||
returnmirror.mana = true
|
returnmirror.mana = true
|
||||||
|
@ -7,6 +8,20 @@ else
|
||||||
returnmirror.mana = false
|
returnmirror.mana = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
returnmirror.mana_check = function(player, cost)
|
||||||
|
local allowed
|
||||||
|
if returnmirror.mana then
|
||||||
|
if mana.subtract(player:get_player_name(), cost) then
|
||||||
|
allowed = true
|
||||||
|
else
|
||||||
|
allowed = false
|
||||||
|
end
|
||||||
|
else
|
||||||
|
allowed = true
|
||||||
|
end
|
||||||
|
return allowed
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_tool("returnmirror:returnmirror", {
|
minetest.register_tool("returnmirror:returnmirror", {
|
||||||
description = "Mirror of Returning",
|
description = "Mirror of Returning",
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
|
@ -17,17 +32,7 @@ minetest.register_tool("returnmirror:returnmirror", {
|
||||||
local dest_string = itemstack:get_metadata()
|
local dest_string = itemstack:get_metadata()
|
||||||
local dest = minetest.string_to_pos(dest_string)
|
local dest = minetest.string_to_pos(dest_string)
|
||||||
if dest ~= nil then
|
if dest ~= nil then
|
||||||
local allowed
|
if returnmirror.mana_check(user, returnmirror.cost_teleport) then
|
||||||
if returnmirror.mana then
|
|
||||||
if mana.subtract(user:get_player_name(), returnmirror.cost) then
|
|
||||||
allowed = true
|
|
||||||
else
|
|
||||||
allowed = false
|
|
||||||
end
|
|
||||||
else
|
|
||||||
allowed = true
|
|
||||||
end
|
|
||||||
if allowed then
|
|
||||||
local src = user:getpos()
|
local src = user:getpos()
|
||||||
minetest.sound_play( {name="returnmirror_teleport", gain=1}, {pos=src, max_hear_distance=30})
|
minetest.sound_play( {name="returnmirror_teleport", gain=1}, {pos=src, max_hear_distance=30})
|
||||||
minetest.add_particlespawner({
|
minetest.add_particlespawner({
|
||||||
|
@ -62,9 +67,11 @@ minetest.register_tool("returnmirror:returnmirror", {
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
local pos = placer:getpos()
|
if returnmirror.mana_check(placer, returnmirror.cost_set) then
|
||||||
itemstack:set_metadata(minetest.pos_to_string(pos))
|
local pos = placer:getpos()
|
||||||
minetest.sound_play( {name="returnmirror_set", gain=1}, {pos=pos, max_hear_distance=12})
|
itemstack:set_metadata(minetest.pos_to_string(pos))
|
||||||
return itemstack
|
minetest.sound_play( {name="returnmirror_set", gain=1}, {pos=pos, max_hear_distance=12})
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue