Check for distance
parent
74151870c6
commit
06b7546187
5
README
5
README
|
@ -1,2 +1,7 @@
|
|||
License of checkpoint_teleporter.png:
|
||||
CC-BY-SA 3.0 UNPORTED. Created by Dragonop
|
||||
|
||||
License of checkpoint_checkpoint.ogg:
|
||||
CC BY-NC 3.0. Created by Robinhood76
|
||||
Original filename: 334914__robinhood76__06304-message-ding-1.wav
|
||||
Source: www.freesound.org/people/Robinhood76/sounds/334914/
|
||||
|
|
50
init.lua
50
init.lua
|
@ -1,27 +1,39 @@
|
|||
local players = {}
|
||||
|
||||
local function vdistance(a, b)
|
||||
local x, y, z = a.x - b.x, a.y - b.y, a.z - b.z
|
||||
return x*x + y*y + z*z
|
||||
end
|
||||
|
||||
local function set_checkpoint(player, pos)
|
||||
local name = player:get_player_name()
|
||||
local ppos = player:getpos()
|
||||
|
||||
--print(tostring(vdistance(pos, ppos)))
|
||||
if vdistance(pos, ppos) <= 10 then
|
||||
players[name] = ppos
|
||||
minetest.sound_play({name="checkpoint_checkpoint", gain=0.75},
|
||||
{to_player=name})
|
||||
minetest.chat_send_player(name, "Checkpoint saved")
|
||||
else
|
||||
minetest.chat_send_player(name, "Out of range!")
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("checkpoint:checkpoint", {
|
||||
description = "Checkpoint",
|
||||
--[[
|
||||
tiles = {"default_dirt.png^checkpoint_teleporter.png",
|
||||
"default_wood.png^checkpoint_teleporter.png",
|
||||
"default_steel_block.png^checkpoint_teleporter.png",
|
||||
"default_gold_block.png^checkpoint_teleporter.png",
|
||||
"default_mese_block.png^checkpoint_teleporter.png",
|
||||
"default_diamond_block.png^checkpoint_teleporter.png"},
|
||||
--]]
|
||||
tiles = {"checkpoint_teleporter.png"},
|
||||
inventory_image = "checkpoint_teleporter.png",
|
||||
drawtype = "plantlike",
|
||||
sunlight_propagates = true,
|
||||
light_source = 8,
|
||||
paramtype = "light",
|
||||
--paramtype2 = "facedir",
|
||||
groups = {cracky=1, choppy=1, crumbly=1, snappy=1},
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
local name = clicker:get_player_name()
|
||||
players[name] = clicker:getpos()
|
||||
|
||||
minetest.chat_send_player(name, "Checkpoint saved")
|
||||
groups = {cracky = 1, choppy = 1, crumbly = 1, snappy = 1},
|
||||
on_rightclick = function(pos, _, clicker)
|
||||
set_checkpoint(clicker, pos)
|
||||
end,
|
||||
on_punch = function(pos, _, puncher)
|
||||
set_checkpoint(puncher, pos)
|
||||
end
|
||||
})
|
||||
|
||||
|
@ -40,6 +52,7 @@ minetest.register_craftitem("checkpoint:teleporter", {
|
|||
})
|
||||
|
||||
minetest.register_chatcommand("checkpoint", {
|
||||
description = "Restore saved checkpoint",
|
||||
func = function(name, param)
|
||||
local pos = players[name]
|
||||
if pos then
|
||||
|
@ -49,7 +62,10 @@ minetest.register_chatcommand("checkpoint", {
|
|||
minetest.chat_send_player(name, "No checkpoint saved")
|
||||
--return "No checkpoint saved"
|
||||
end
|
||||
|
||||
--print(dump(players))
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
players[name] = nil
|
||||
end)
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue