Add cost for setting mirror point

This commit is contained in:
Wuzzy 2015-02-14 00:25:55 +01:00
parent dc5d58ceb9
commit 9aa76bead8
1 changed files with 23 additions and 16 deletions

View File

@ -1,5 +1,6 @@
returnmirror = {}
returnmirror.cost = 100
returnmirror.cost_teleport = 100
returnmirror.cost_set = 20
if minetest.get_modpath("mana") ~= nil then
returnmirror.mana = true
@ -7,6 +8,20 @@ else
returnmirror.mana = false
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", {
description = "Mirror of Returning",
stack_max = 1,
@ -17,17 +32,7 @@ minetest.register_tool("returnmirror:returnmirror", {
local dest_string = itemstack:get_metadata()
local dest = minetest.string_to_pos(dest_string)
if dest ~= nil then
local allowed
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
if returnmirror.mana_check(user, returnmirror.cost_teleport) then
local src = user:getpos()
minetest.sound_play( {name="returnmirror_teleport", gain=1}, {pos=src, max_hear_distance=30})
minetest.add_particlespawner({
@ -62,9 +67,11 @@ minetest.register_tool("returnmirror:returnmirror", {
end
end,
on_place = function(itemstack, placer, pointed_thing)
local pos = placer:getpos()
itemstack:set_metadata(minetest.pos_to_string(pos))
minetest.sound_play( {name="returnmirror_set", gain=1}, {pos=pos, max_hear_distance=12})
return itemstack
if returnmirror.mana_check(placer, returnmirror.cost_set) then
local pos = placer:getpos()
itemstack:set_metadata(minetest.pos_to_string(pos))
minetest.sound_play( {name="returnmirror_set", gain=1}, {pos=pos, max_hear_distance=12})
return itemstack
end
end
})