added: check for air in y 2 positions, add teleport queue 5 sec., check for moving while in teleport queue

master
Juraj Vajda 2018-01-23 01:49:47 -05:00
parent b0b3fb85f2
commit d7208d4928
2 changed files with 107 additions and 28 deletions

127
api.lua
View File

@ -1,3 +1,34 @@
--[[
Telemosaic [telemosaic]
=======================
A mod which provides player-placed teleport pads
Copyright (C) 2015 Ben Deutsch <ben@bendeutsch.de>
Copyright (C) 2018 rewritten by SaKeL <juraj.vajda@gmail.com>
License
-------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
]]
local enable_particles = minetest.settings:get_bool("enable_particles")
-- @module telemosaic
telemosaic = {}
@ -9,13 +40,14 @@ telemosaic.extender_ranges = {
}
-- @field strengths
telemosaic.strengths = { "one", "two", "three" }
telemosaic.teleport_queue = {}
--- Add particle effect on deprature
-- @param {table} pos - deprature position
function telemosaic.effect_departure(pos)
if not enable_particles then return end
minetest.add_particlespawner({
return minetest.add_particlespawner({
amount = 100,
time = 5,
minpos = {x=pos.x, y=pos.y+0.3, z=pos.z},
@ -62,6 +94,71 @@ function telemosaic.effect_arrival(pos)
})
end
function telemosaic.get_table_length(tbl)
local length = 0
for k, v in pairs(tbl) do
length = length + 1
end
return length
end
function telemosaic.add_to_queue(player, pos2)
local ppos = player:getpos()
local dep_effect = telemosaic.effect_departure(player:get_pos())
telemosaic.teleport_queue[player:get_player_name()] = {
qtime = minetest.get_us_time() + (5 * 1000000),
ppos = ppos,
player = player,
pos2 = pos2,
sound = minetest.sound_play("warps_woosh", { pos = ppos, max_hear_distance = 8, gain = 1 }),
dep_effect = dep_effect
}
minetest.chat_send_player(player:get_player_name(), "Don't move for 5 seconds!")
if telemosaic.get_table_length(telemosaic.teleport_queue) == 1 then
minetest.after(1, telemosaic.from_queue)
end
-- attempt to emerge the target area before the player gets there
local vpos = vector.new(pos2)
minetest.get_voxel_manip():read_from_map(vpos, vpos)
if not minetest.get_node_or_nil(pos2) then
minetest.emerge_area(vector.subtract(vpos, 8), vector.add(vpos, 8))
end
end
function telemosaic.from_queue()
if telemosaic.get_table_length(telemosaic.teleport_queue) == 0 then
return
end
local time = minetest.get_us_time()
for k, v in pairs(telemosaic.teleport_queue) do
if v.player:getpos() then
if vector.equals(v.player:getpos(), v.ppos) then
if time > v.qtime then
local pos2 = {x = v.pos2.x, y = v.pos2.y + 1, z = v.pos2.z}
v.player:setpos(pos2)
telemosaic.effect_arrival(pos2)
telemosaic.teleport_queue[v.player:get_player_name()] = nil
end
else
minetest.sound_stop(v.sound)
minetest.delete_particlespawner(v.dep_effect)
minetest.chat_send_player(v.player:get_player_name(),
"You have to stand still for 5 seconds!")
telemosaic.teleport_queue[v.player:get_player_name()] = nil
end
end
end
if telemosaic.get_table_length(telemosaic.teleport_queue) == 0 then
return
end
minetest.after(1, telemosaic.from_queue)
end
--- Generate formspec dynamically
-- @param {table} pos - position of the node
-- @param {table} table - custom parameters passed in the table
@ -81,7 +178,6 @@ function telemosaic.get_formspec(pos, table)
local textlist = ""
for ipos, ival in pairs(arrivals_tbl) do
print("ival: ", dump(ival))
textlist = textlist..minetest.formspec_escape(ipos)..": "..ival..","
end
@ -134,10 +230,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
meta2:set_string("arrivals_tbl", minetest.serialize(arrivals_tbl2))
end
-- @TODO
-- check for air in y 2 positions
-- add teleport queue 5 sec.
-- check for moving while in teleport queue
if fields.teleport then
local range = meta:get_int("range")
@ -150,27 +242,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
end
pos2 = {x = pos2.x, y = pos2.y + 1, z = pos2.z}
-- attempt to emerge the target area before the player gets there
local vpos = vector.new(pos2)
minetest.get_voxel_manip():read_from_map(vpos, vpos)
if not minetest.get_node_or_nil(pos2) then
print("emerge area")
minetest.emerge_area(vector.subtract(vpos, 80), vector.add(vpos, 80))
end
minetest.sound_play("telemosaic_woosh", {
pos = pos,
max_hear_distance = 8,
gain = 1
})
telemosaic.effect_departure(player:get_pos())
minetest.after(5, function()
player:setpos(pos2)
telemosaic.effect_arrival(pos2)
end)
telemosaic.add_to_queue(player, pos2)
else
minetest.chat_send_player(player:get_player_name(), "Not enough power, destination is too far. Beacon needs "..math.floor(vector.distance(pos, pos2)) - range.." more power.")
end
@ -325,7 +397,6 @@ function telemosaic.beacon_after_place(pos, placer, itemstack, pointed_thing)
local bname = "beacon at: "..minetest.formspec_escape(minetest.pos_to_string(pos))
local description = minetest.registered_nodes[nodename]["description"]
print("playername: ", playername)
meta:set_int("range", range)
meta:set_string("bname", bname)
meta:set_string("owner", playername)

View File

@ -3,6 +3,8 @@ for num, strength in ipairs(telemosaic.strengths) do
minetest.register_node("telemosaic:extender_"..strength, {
description = "Telemosaic extender, tier "..num..", extends beacon range by: "..telemosaic.extender_ranges["telemosaic:extender_"..strength].." blocks",
tiles = { "telemosaic_extender_"..strength..".png" },
paramtype = "light",
light_source = 2 + num,
is_ground_content = false,
groups = { cracky = 2, ["telemosaic_extender_"..strength] = 1 },
sounds = default.node_sound_stone_defaults(),
@ -22,6 +24,8 @@ minetest.register_node("telemosaic:beacon_off", {
"telemosaic_beacon_side.png",
"telemosaic_beacon_side.png",
},
paramtype = "light",
light_source = 4,
is_ground_content = false,
groups = { cracky = 2 },
sounds = default.node_sound_stone_defaults(),
@ -41,6 +45,8 @@ minetest.register_node("telemosaic:beacon", {
"telemosaic_beacon_side.png",
"telemosaic_beacon_side.png",
},
paramtype = "light",
light_source = 5,
is_ground_content = false,
groups = { cracky = 2, not_in_creative_inventory = 1 },
drop = "telemosaic:beacon_off",
@ -60,6 +66,8 @@ minetest.register_node("telemosaic:beacon_err", {
"telemosaic_beacon_side.png",
"telemosaic_beacon_side.png",
},
paramtype = "light",
light_source = 3,
is_ground_content = false,
groups = { cracky = 2, not_in_creative_inventory = 1 },
drop = "telemosaic:beacon_off",