Fix set_nav if player is not owner, commented code

entity
Benrob0329 2017-07-27 03:00:53 -04:00
parent 36db191c18
commit 9421c24ee3
3 changed files with 17 additions and 1 deletions

View File

@ -2,6 +2,7 @@ local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
local worldpath = minetest.get_worldpath()
-- Hacky node swap function since minetest.swap_node doesnt call any callbacks
function tardis.swap_node (pos, name)
local meta = minetest.get_meta (pos)
local meta_old = meta:to_table()
@ -13,6 +14,7 @@ function tardis.swap_node (pos, name)
end
-- Spawn a TARDIS and set the controls/doors meta with relative coordinates
function tardis:spawn_interior (pos, owner)
local place_pos = {
x = tardis.count * 12 ,
@ -38,11 +40,13 @@ function tardis:spawn_interior (pos, owner)
minetest.place_schematic (place_pos, modpath .. "/schematics/tardis_interior.mts")
-- Add TARDIS to index
tardis.tardises [owner] = {}
tardis.tardises [owner]["exterior"] = pos
tardis.tardises [owner]["interior"] = interior_doors_pos
tardis.tardises [owner]["in_vortex"] = false
--Set meta
local demat_meta = minetest.get_meta (demat_lever_pos)
demat_meta:set_string ("owner", owner)
@ -59,6 +63,8 @@ function tardis:spawn_interior (pos, owner)
file:close()
end
-- Set navigation, uses a formspec
function tardis.set_nav (player, owner)
local player_name = player:get_player_name()
if player_name ~= owner then minetest.chat_send_player(player_name, "You don't own that TARDIS!"); return end

View File

@ -1,3 +1,4 @@
-- Define global table and TARDIS index
tardis = {}
tardis.count = 0
tardis.tardises = {}
@ -11,18 +12,21 @@ dofile (modpath .. "/demat.lua")
dofile (modpath .. "/functions.lua")
dofile (modpath .. "/nodes.lua")
-- Open TARDIS index from file
local file = io.open (worldpath .. "/tardis.tardises", "r")
-- If file exists, write into current index
if file then
tardis.tardises = minetest.deserialize (file:read("*all"))
file:close()
end
-- Register chatcommand to set navigation, return a help message if user doe not own a TARDIS
minetest.register_chatcommand ("set_nav", {
description = "Sets the navigation coordinates for your TARDIS.",
func = function (name, param)
if (tardis.tardises [name] == nil) then
name.chat_send_player (name, "Must be owner!")
minetest.chat_send_player (name, "Must be owner!")
else
local owner = name
local player = minetest.get_player_by_name (name)
@ -32,6 +36,7 @@ minetest.register_chatcommand ("set_nav", {
end
})
-- Save index on shutdown
minetest.register_on_shutdown( function()
local file = io.open (worldpath .. "/tardis.tardises", "w+")
file:write(minetest.serialize (tardis.tardises) )

View File

@ -7,6 +7,7 @@ minetest.register_node ("tardis:tardis", {
paramtype = "light" ,
is_ground_content = true ,
-- Setup Meta, clone meta if not placed by a player
on_place = function (itemstack, placer, pointed_thing)
local pos = pointed_thing.above
local player = placer:get_player_name()
@ -28,6 +29,7 @@ minetest.register_node ("tardis:tardis", {
end ,
-- Teleport Player
on_rightclick = function (pos, node, player, itemstack, pointed_thing)
local meta = minetest.get_meta (pos)
local owner = meta:get_string ("owner")
@ -39,6 +41,7 @@ minetest.register_node ("tardis:tardis", {
})
-- Initialize materialization, fail if nav is not set, then swap node to off pos
minetest.register_node ("tardis:demat_lever_on", {
tiles = {"tardis_demat.png"} ,
drawtype = "mesh" ,
@ -66,6 +69,7 @@ minetest.register_node ("tardis:demat_lever_on", {
})
-- Initialize dematerialization, then set lever to on pos
minetest.register_node ("tardis:demat_lever_off", {
groups = {crumbly = 1} ,
tiles = {"tardis_demat.png"} ,
@ -111,6 +115,7 @@ minetest.register_node ("tardis:navigator", {
})
-- Teleports player to exterior is in_vortex is set to false
minetest.register_node ("tardis:interior_doors", {
tiles = {"tardis_exterior.png"} ,
use_texture_alpha = true ,