Split mana, technic and infinite teletool into 3 tools

master
Wuzzy 2015-02-16 00:55:19 +01:00
parent 0e15ae99cd
commit a5ab1498e5
6 changed files with 68 additions and 42 deletions

102
init.lua
View File

@ -8,14 +8,6 @@ end
teletool = {}
teletool.settings = {}
--[[ Tool Mode:
- "technic": Use Technic mod, each shot costs energy, tool must be recharged
- "mana": Each shot depletes the player's mana reserves
- "infinite": There are no limits on using this tool.
- "auto" (default): Based on mod availabilty, it will try these modes in this order: "technic", "mana", "infinity"
]]
teletool.settings.toolmode = "auto"
function teletool.teleport(player, pointed_thing)
local pos = pointed_thing.above
local over1 = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
@ -53,25 +45,39 @@ function teletool.teleport(player, pointed_thing)
minetest.after(0.5, function(dest) minetest.sound_play( {name="teletool_teleport2", gain=1}, {pos=dest, max_hear_distance=12}) end, dest)
end
if(minetest.get_modpath("technic") ~= nil) then
technic.register_power_tool("teletool:teletool", 50000)
teletool.on_refill = technic.refill_RE_charge
else
teletool.on_refill = nil
end
minetest.register_tool("teletool:teletool", {
description = S("point teleporter"),
minetest.register_tool("teletool:teletool_infinite", {
description = S("infinite point teleporter"),
range = 20.0,
tool_capabilities = {},
wield_image = "teletool_teletool.png",
inventory_image = "teletool_teletool.png",
wield_image = "teletool_teletool_infinite.png",
inventory_image = "teletool_teletool_infinite.png",
on_use = function(itemstack, user, pointed_thing)
local failure = false
if(pointed_thing.type == "node") then
local has_technic = minetest.get_modpath("technic") ~= nil
local has_mana = minetest.get_modpath("mana") ~= nil
if(has_technic and (teletool.settings.toolmode == "auto" or teletool.settings.toolmode=="technic")) then
teletool.teleport(user, pointed_thing)
else
failure = true
end
if failure then
minetest.sound_play( {name="teletool_fail", gain=0.5}, {pos=user:getpos(), max_hear_distance=4})
end
return itemstack
end,
})
if(minetest.get_modpath("technic")) then
technic.register_power_tool("teletool:teletool_technic", 50000)
minetest.register_tool("teletool:teletool_technic", {
description = S("electronic point teleporter"),
range = 20.0,
tool_capabilities = {},
wield_image = "teletool_teletool_technic.png",
inventory_image = "teletool_teletool_technic.png",
on_use = function(itemstack, user, pointed_thing)
local failure = false
if(pointed_thing.type == "node") then
local meta = minetest.deserialize(itemstack:get_metadata())
if not meta or not meta.charge then return end
if meta.charge >= 1000 then
@ -82,35 +88,50 @@ minetest.register_tool("teletool:teletool", {
else
failure = true
end
elseif(has_mana and (teletool.settings.toolmode == "auto" or teletool.settings.toolmode=="mana")) then
else
failure = true
end
if failure then
minetest.sound_play( {name="teletool_fail", gain=0.5}, {pos=user:getpos(), max_hear_distance=4})
end
return itemstack
end,
-- Technic data
wear_represents = "technic_RE_charge",
on_refill = technic.refill_RE_charge
})
end
if(minetest.get_modpath("mana") ~= nil) then
minetest.register_tool("teletool:teletool_mana", {
description = S("magical point teleporter"),
range = 20.0,
tool_capabilities = {},
wield_image = "teletool_teletool_mana.png",
inventory_image = "teletool_teletool_mana.png",
on_use = function(itemstack, user, pointed_thing)
local failure = false
if(pointed_thing.type == "node") then
if(mana.subtract(user:get_player_name(), 20)) then
teletool.teleport(user, pointed_thing)
else
failure = true
end
elseif(teletool.settings.toolmode == "auto" or teletool.settings.toolmode=="infinite") then
teletool.teleport(user, pointed_thing)
else
minetest.log("error", "[teletool] Incorrect tool mode set!")
failure = true
end
else
failure = true
end
if failure then
minetest.sound_play( {name="teletool_fail", gain=0.5}, {pos=user:getpos(), max_hear_distance=4})
end
return itemstack
end,
-- Technic data
wear_represents = "technic_RE_charge",
on_refill = teletool.on_refill,
})
if failure then
minetest.sound_play( {name="teletool_fail", gain=0.5}, {pos=user:getpos(), max_hear_distance=4})
end
return itemstack
end,
})
end
if(minetest.get_modpath("default") ~= nil and minetest.get_modpath("technic") ~= nil) then
minetest.register_craft({
output = "teletool:teletool",
output = "teletool:teletool_technic",
recipe = {
{"", "default:mese_crystal", ""},
{"technic:stainless_steel_ingot", "technic:red_energy_crystal", "technic:stainless_steel_ingot"},
@ -119,3 +140,4 @@ if(minetest.get_modpath("default") ~= nil and minetest.get_modpath("technic") ~=
})
end
minetest.register_alias("teletool:teletool", "teletool:teletool_infinite")

View File

@ -1 +1,3 @@
point teleporter = Zeigeteleporter
electronic point teleporter = elektronischer Zeigeteleporter
magic point teleporter = magischer Zeigeteleporter
infinite point teleporter = unendlicher Zeigeteleporter

View File

@ -1 +1,3 @@
point teleporter
infinite point teleporter
electronic point teleporter
magical point teleporter

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 B

View File

Before

Width:  |  Height:  |  Size: 395 B

After

Width:  |  Height:  |  Size: 395 B