Update init.lua

Renamed "elevator" to "televator"
Removed error messages, replaced them with error sound for more immersion.
Increased range from 16 to 32 and changed crafting recipe to be 2x as expensive.
Added license to the top.
Simplified description text.
This commit is contained in:
NoctisLabs 2019-09-30 10:26:22 -07:00 committed by GitHub
parent 5b24e8439a
commit f57c28b78f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1,24 @@
-- televator/init.lua --[[
MIT License
Copyright (c) 2017 Elijah Duffy
Copyright (c) 2019 Noctis Labs
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--]]
-- an_televator/init.lua
local delay = {} local delay = {}
@ -16,9 +36,9 @@ end
--- Functions --- Functions
--- ---
-- [function] Get near elevators -- [function] Get near televators
local function get_near_elevators(pos, which) local function get_near_televators(pos, which)
for i = 1, 16 do for i = 1, 32 do
local cpos = vector.new(pos) local cpos = vector.new(pos)
if which == "above" then if which == "above" then
@ -28,17 +48,17 @@ local function get_near_elevators(pos, which)
end end
local name = minetest.get_node(cpos).name local name = minetest.get_node(cpos).name
if (which == "above" and name == "televator:elevator") if (which == "above" and name == "an_televator:televator")
or (which == "below" and i ~= 1 and name == "televator:elevator") then or (which == "below" and i ~= 1 and name == "an_televator:televator") then
cpos.y = cpos.y + 1 cpos.y = cpos.y + 1
return cpos return cpos
elseif name ~= "air" and name ~= "televator:elevator" then elseif name ~= "air" and name ~= "an_televator:televator" then
return return
end end
end end
end end
-- [function] Elevator safe -- [function] Televator safe
local function is_safe(pos) local function is_safe(pos)
for i = 0, 1 do for i = 0, 1 do
local tpos = vector.new(pos) local tpos = vector.new(pos)
@ -56,23 +76,22 @@ end
--- Registrations --- Registrations
--- ---
-- [register] Elevator node -- [register] Televator node
minetest.register_node("televator:elevator", { minetest.register_node("an_televator:televator", {
description = "Elevator\n".. description = "Televator\n"..
minetest.colorize("grey","Can be placed up to 16 nodes apart\n" minetest.colorize("grey","Place up to 32 nodes apart.\n"
.."Jump to go up, sneak to go down"), .."Jump goes up, sneak goes down."),
tiles = {"televator_elevator.png"}, tiles = {"televator_televator.png"},
groups = {cracky = 2, disable_jump = 1}, groups = {cracky = 2, disable_jump = 1},
after_place_node = function(pos) after_place_node = function(pos)
-- Set infotext minetest.get_meta(pos):set_string("infotext", "Televator")
minetest.get_meta(pos):set_string("infotext", "Elevator")
end, end,
}) })
-- [register] Recipe -- [register] Recipe
if itemset then if itemset then
minetest.register_craft({ minetest.register_craft({
output = "televator:elevator 2", output = "an_televator:televator",
recipe = { recipe = {
{itemset.steel, itemset.glass, itemset.steel}, {itemset.steel, itemset.glass, itemset.steel},
{itemset.steel, itemset.gold, itemset.steel}, {itemset.steel, itemset.gold, itemset.steel},
@ -94,7 +113,7 @@ minetest.register_globalstep(function(dtime)
end end
if not delay[name] or delay[name] > 0.5 then if not delay[name] or delay[name] > 0.5 then
if minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}).name == "televator:elevator" then if minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}).name == "an_televator:televator" then
local where local where
local controls = player:get_player_control() local controls = player:get_player_control()
if controls.jump then if controls.jump then
@ -103,20 +122,20 @@ minetest.register_globalstep(function(dtime)
where = "below" where = "below"
else return end else return end
local epos = get_near_elevators(pos, where) local epos = get_near_televators(pos, where)
if epos and is_safe(epos) then if epos and is_safe(epos) then
player:set_pos(epos) -- Update player position player:set_pos(epos) -- Update player position
-- Play sound
minetest.sound_play("televator_whoosh", { minetest.sound_play("televator_whoosh", {
gain = 0.75, gain = 0.75,
pos = epos, pos = epos,
max_hear_distance = 5, max_hear_distance = 5,
}) })
elseif epos then
minetest.chat_send_player(name, "Elevator blocked by obstruction")
else else
minetest.chat_send_player(name, "Could not find elevator") minetest.sound_play("televator_error", {
gain = 0.75,
pos = epos,
max_hear_distance = 5,
})
end end
delay[name] = 0 -- Restart delay delay[name] = 0 -- Restart delay