Add files via upload

master
AiTechEye 2022-07-14 23:15:20 +02:00 committed by GitHub
parent 4a2c9de68d
commit 6fe406dc80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 614 additions and 0 deletions

44
info.txt Normal file
View File

@ -0,0 +1,44 @@
/ttmd 0 0 0 can be usefull while testing them maps
The nodeextractor mod is great to create maps, it keeps all nodes and its metadata, and is easy to edit as text if needed.
You can find the tools in the game, as "Creater" and "Placer" if you want to place the map by your self.
Methods:
maps.get_pos(pos) -- adds y=28500, easier to use set_pos()
maps.set_pos(object,pos) -- set positions, easier then set_pos()
Add map:
maps.maps.MyMap={
info = "My map",
image="default_stone.png", -- optional, map icon
pos={x=0,y=0,z=0}, -- required, used to calcilate if the map interacts with other maps
size={y=51,x=133,z=100}, -- required, same as above
locked=true, -- optional, locks the map
unable=true, -- optional, makes the map unable
hide_items = true, -- optional, hides the players items
singleplayer=true, -- optional, singleplayer only
bones_disabled=true, -- optional, disabled bones / drop items on death
bones_drop_only = true, -- optional, drop items on death, do not placing bone
special_disabled=true, -- optional, disabled special/abilities
store_disabled=true, -- optional, disabled the store
on_enter=function(player) -- required, when player enter
if default.storage:get_int("mymap") < 1 then -- in this case, only generating the map 1 time, could also use it as a version number, to replace the map with a newer version, smart huh?
default.storage:set_int("mymap",1)
nodeextractor.set(maps.get_pos({x=0,y=0,z=0}),minetest.get_modpath("maps").."/nodeextractor/".."maps_tutorial.exexn",true)
end
minetest.after(0.1, function(player)
maps.set_pos(player,{x=60,y=31,z=42})
end,player)
end,
on_respawn=function(player) -- required, player respawns
maps.set_pos(player,{x=0,y=0,z=0})
end,
on_exit=function(player) -- optional, player leaving
end,
on_die=function(player) -- optional, player die
end,
}

248
init.lua Normal file
View File

@ -0,0 +1,248 @@
maps = {
user={},
maps={
["tutorial"]={
info = "Tutorials",
image="default_craftguide.png",
pos={x=0,y=0,z=0},
size={y=51,x=133,z=100},
--locked=true,
--unable=true,
hide_items = true,
singleplayer=true,
bones_disabled=true,
--bones_drop_only = true,
special_disabled=true,
store_disabled=true,
on_enter=function(player)
if default.storage:get_int("Tutorials") < 2 then
default.storage:set_int("Tutorials",2)
nodeextractor.set(maps.get_pos({x=0,y=0,z=0}),minetest.get_modpath("maps").."/nodeextractor/".."maps_tutorial.exexn",true)
end
minetest.after(0.1, function(player)
maps.set_pos(player,{x=60,y=31,z=42})
end,player)
end,
on_exit=function(player)
end,
on_die=function(player)
end,
on_respawn=function(player)
maps.set_pos(player,{x=60,y=31,z=42})
end,
},
}
}
dofile(minetest.get_modpath("maps") .. "/items.lua")
minetest.register_chatcommand("ttmd", {
params = "<pos>",
description = "Teleport to maps dimension",
privs = {teleport=true},
func = function(name, param)
local p = minetest.get_player_by_name(name)
local p2 = param:gsub(","," "):split(" ")
if p and p2[3] then
local x,y,z = tonumber(p2[1]),tonumber(p2[2]),tonumber(p2[3])
if math.abs(y) > 2500 then
return false, "Not allowed to move outside the dimension"
elseif x and y and z then
maps.set_pos(p,vector.new(x,y,z))
return true
else
return false, "Not a valid position, eg: 0 1 0 or 0,1,0"
end
end
end
})
maps.get_pos=function(pos)
return vector.add(pos,{x=0,y=28500,z=0})
end
maps.set_pos=function(object,pos)
if math.abs(pos.y) < 2500 then
object:set_pos(maps.get_pos(pos))
else
minetest.log("warning","Maps: Not allowed to move outside the dimension")
end
end
player_style.register_button({
name="maps",
image="map_map.png",
type="image",
info="Maps",
action=function(user)
local name = user:get_player_name()
local inv = player_style.players[name].inv
if inv.adds["maps_exit"] then
minetest.chat_send_player(name,"You have to exit the current map first")
else
maps.show(user)
end
end
})
maps.show=function(player)
minetest.after(0.2, function(player)
local name = player:get_player_name()
local x,y = 0,0
local form = "size[8,8]listcolors[#77777777;#777777aa;#000000ff]"
for i,v in pairs(maps.maps) do
if not (v.singleplayer and minetest.is_singleplayer() == false) then
form = form
.. "image_button["..x..","..y..";1,1;"..(v.image or "map_map.png")..(v.locked and "^default_lock_icon.png" or "")..(v.unable and "^default_cross.png" or "")..";mapsbut_"..i..";]"
.. (v.info and "tooltip[mapsbut_"..i..";"..v.info..(v.singleplayer and "\n(Singleplayer only)" or "").."]" or "")
x = x + 1
if x >= 8 then
x = 0
y = y +1
end
end
end
return minetest.show_formspec(name, "maps",form)
end, player)
end
minetest.register_on_player_receive_fields(function(player, form, pressed)
if form == "maps" then
for i,v in pairs(pressed) do
if i:sub(1,8) == "mapsbut_" then
local b = i:gsub("mapsbut_","")
local map = maps.maps[b]
if not (maps.maps[b].unable or maps.maps[b].locked) then
local m = player:get_meta()
m:set_string("maps_current",b)
maps.set_exit_player(player)
if map.hide_items then
player_style.inventory_handle(player,{hide=true})
if m:get_string("maps_pos") == "" then
m:set_string("maps_pos",minetest.pos_to_string(player:get_pos()))
end
end
if map.bones_disabled then
m:set_int("bones_disabled",1)
elseif map.bones_drop_only then
m:set_int("bones_drop_only",1)
end
if map.killme_disabled then
m:set_int("killme_disabled",1)
end
if map.special_disabled then
m:set_int("special_disabled",1)
end
if map.store_disabled then
m:set_int("store_disabled",1)
end
player_style.inventory(player)
maps.maps[b].on_enter(player)
minetest.close_formspec(player:get_player_name(),"")
end
end
end
end
end)
minetest.register_on_mods_loaded(function()
for map,m in pairs(maps.maps) do
local p1 = m.pos
local p2 = vector.add(m.pos,m.size)
if not m.pos then
minetest.log("warning","Maps: "..map.." Is missing pos (position/vector)")
maps.maps[map].unable = true
end
if not m.size then
minetest.log("warning","Maps: "..map.." Is missing size (vector)")
maps.maps[map].unable = true
end
if not m.on_enter then
minetest.log("warning","Maps: "..map.." Is missing on_enter (function)")
maps.maps[map].unable = true
end
if not m.on_respawn then
minetest.log("warning","Maps: "..map.." Is missing on_respawn (function)")
maps.maps[map].unable = true
end
for i,v in pairs(maps.maps) do
local pos1,pos2 = protect.sort(v.pos,vector.add(v.pos,v.size))
if map ~= i and not maps.maps[map].unable
and (pos1.x <= p2.x and pos2.x >= p1.x)
and (pos1.y <= p2.y and pos2.y >= p1.y)
and (pos1.z <= p2.z and pos2.z >= p1.z) then
minetest.log("error","Maps: "..i.." interacts with "..map)
maps.maps[i].unable = true
end
end
end
end)
minetest.register_on_joinplayer(function(player)
if player:get_meta():get_int("maps_exit") == 1 then
maps.set_exit_player(player)
end
end)
maps.set_exit_player=function(player)
local name = player:get_player_name()
local inv = player_style.players[name].inv
local m = player:get_meta()
inv.adds["maps_exit"] = "image_button[7,1;1,1;map_map.png^default_cross.png;maps_exit;]tooltip[maps_exit;Exit map]"
m:set_int("maps_exit",1)
m:set_int("respawn_disallowed",1)
player:hud_set_flags({basic_debug=false})
inv.adds_func["maps_exit"] = function(player)
player:hud_set_flags({basic_debug=true})
local m = player:get_meta()
local name = player:get_player_name()
local inv = player_style.players[name].inv
local p = minetest.string_to_pos(m:get_string("maps_pos"))
local map = maps.maps[m:get_string("maps_current")]
if map and map.on_exit then
map.on_exit(player)
end
if p then
player:set_pos(p)
end
inv.adds["maps_exit"] = nil
inv.adds_func["maps_exit"] =nil
m:set_string("maps_pos","")
m:set_int("maps_exit",0)
m:set_int("respawn_disallowed",0)
m:set_string("maps_current","")
m:set_int("bones_disabled",0)
m:set_int("bones_drop_only",0)
m:set_int("killme_disabled",0)
m:set_int("special_disabled",0)
m:set_int("store_disabled",0)
player_style.inventory_handle(player,{show=true})
minetest.close_formspec(name,"")
end
end
minetest.register_on_respawnplayer(function(player)
local map = maps.maps[player:get_meta():get_string("maps_current")]
if map then
minetest.after(0, function(player,map)
map.on_respawn(player)
end,player,map)
end
end)
minetest.register_on_dieplayer(function(player)
local map = maps.maps[player:get_meta():get_string("maps_current")]
if map and map.on_die then
map.on_die(player)
end
end)

322
items.lua Normal file
View File

@ -0,0 +1,322 @@
minetest.register_node("maps:node_set", {
description = "Node setter",
tiles={"default_stone.png^[invert:rb"},
groups = {unbreakable=1,exatec_wire_connected=1,not_in_creative_inventory=1},
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
minetest.get_meta(pos):set_string("formspec","size[2,1]button_exit[0,0;2,1;setup;Setup]")
end,
on_receive_fields=function(pos, formname, pressed, sender)
if (pressed.save or pressed.setup) and minetest.check_player_privs(sender:get_player_name(), {server=true}) then
local m = minetest.get_meta(pos)
local node = minetest.registered_nodes[pressed.node]
local n = tonumber(pressed.pos2)
local pos1
local pos2
if pressed.save then
local name = sender:get_player_name()
local p = protect.user[name]
if p and p.pos1 and p.pos2 then
pressed.node = minetest.get_node(p.pos1).name
node = true
pos1 = p.pos1
pos2 = p.pos2
pressed.pos1 = p.pos1.x.." "..p.pos1.y.." "..p.pos1.z
pressed.pos2 = p.pos2.x.." "..p.pos2.y.." "..p.pos2.z
protect.clear(name)
elseif p and p.pos1 then
local nod = minetest.get_node(p.pos1)
n = nod.param2
pressed.node = nod.name
pos1 = p.pos1
node = true
pressed.pos1 = p.pos1.x.." "..p.pos1.y.." "..p.pos1.z
protect.clear(name)
else
pos1 = minetest.string_to_pos("("..pressed.pos1:gsub(" ",",")..")")
pos2 = minetest.string_to_pos("("..pressed.pos2:gsub(" ",",")..")")
end
end
if node then
m:set_string("node",pressed.node)
end
if pos1 and (pos1.y > 26000 and pos1.y < 31000) then
m:set_string("pos1l",minetest.pos_to_string(vector.subtract(pos1,pos)))
m:set_string("pos1",pressed.pos1:gsub(","," "))
end
if pos2 and (pos2.y > 26000 and pos2.y < 31000) then
m:set_string("pos2l",minetest.pos_to_string(vector.subtract(pos2,pos)))
m:set_string("pos2",pressed.pos2:gsub(","," "))
else
m:set_string("pos2","")
m:set_string("pos2l","")
m:set_int("n",n or 0)
end
m:set_string("formspec","size[1.5,3]"
.."button_exit[-0.2,-0.2;2,1;save;Save]"
.."field[0,1;2,1;node;;"..m:get_string("node").."]"
.."field[0,2;2,1;pos1;;"..m:get_string("pos1").."]"
.."field[0,3;2,1;pos2;;"..(m:get_string("pos2") ~= "" and m:get_string("pos2") or m:get_string("n")).."]"
.."tooltip[save;You can also Mark with /protect 1 or both /protect 1 /protect 2 to select the position/area.\nDo not protect, just mark it then press save]"
.."tooltip[node;A valid node, eg default:stone]"
.."tooltip[pos1;Position 1, (eg 1,0,-5)]"
.."tooltip[pos2;Position 2, (eg -1,10,5) or (eg 4) (param2/rotation number) if you only will place 1 block, can be empty]"
)
end
end,
exatec={
on_wire = function(pos)
local m = minetest.get_meta(pos)
local node = m:get_string("node")
local n = m:get_int("n")
local pos1 = minetest.string_to_pos(m:get_string("pos1l"))
local pos2 = minetest.string_to_pos(m:get_string("pos2l"))
if node ~= "" and pos1 then
pos1 = vector.add(pos1,pos)
if pos2 then
pos2 = vector.add(pos2,pos)
pos1,pos2 = protect.sort(pos1,pos2)
local p = {}
for x=pos1.x,pos2.x do
for z=pos1.z,pos2.z do
for y=pos1.y,pos2.y do
table.insert(p,vector.new(x,y,z))
end
end
end
minetest.bulk_set_node(p,{name=node})
else
minetest.set_node(pos1,{name=node,param2=n})
end
end
end
}
})
minetest.register_node("maps:playermove", {
description = "player moveer",
tiles={"default_stone.png^[invert:gr"},
groups = {unbreakable=1,exatec_wire_connected=1,not_in_creative_inventory=1},
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
minetest.get_meta(pos):set_string("formspec","size[2,1]button_exit[0,0;2,1;setup;Setup]")
end,
on_receive_fields=function(pos, formname, pressed, sender)
if pressed.save or pressed.setup then
local m = minetest.get_meta(pos)
local pos1
local dir = sender:get_look_dir()
if pressed.save then
local name = sender:get_player_name()
local p = protect.user[name]
if p and p.pos1 then
pos1 = p.pos1
pressed.pos1 = p.pos1.x.." "..p.pos1.y.." "..p.pos1.z
protect.clear(name)
else
pos1 = minetest.string_to_pos("("..pressed.pos1:gsub(" ",",")..")")
end
end
if pos1 then
m:set_string("pos1l",minetest.pos_to_string(vector.subtract(pos1,pos)))
m:set_string("pos1",pressed.pos1:gsub(","," "))
end
m:set_int("rad",tonumber(pressed.rad) or 0)
m:set_string("dir",(math.floor(sender:get_look_horizontal()*100)*0.01) .." ".. (math.floor(sender:get_look_vertical()*100)*0.01))
m:set_string("formspec","size[1.5,3]"
.."button_exit[-0.2,-0.2;2,1;save;Save]"
.."field[0,1;2,1;rad;;"..m:get_int("rad").."]"
.."field[0,2;2,1;pos1;;"..m:get_string("pos1").."]"
.."field[0,3;2,1;dir;;"..m:get_string("dir") .."]"
.."tooltip[save;Mark with /protect 1 to mark the position, then press save]"
.."tooltip[pos1;Position 1, (eg 1,0,-5)]"
.."tooltip[rad;Max radius to objects]"
)
end
end,
exatec={
on_wire = function(pos)
local m = minetest.get_meta(pos)
local node = m:get_string("node")
local n = m:get_int("rad")
local pos1 = minetest.string_to_pos(m:get_string("pos1l"))
local dir = m:get_string("dir"):split(" ")
if pos1 and #dir > 1 then
local h = tonumber(dir[1])
local v = tonumber(dir[2])
pos1 = vector.add(pos1,pos)
for _, ob in pairs(minetest.get_objects_inside_radius(pos,n)) do
local en = ob:get_luaentity()
if ob:is_player() then
ob:set_look_horizontal(h)
ob:set_look_vertical(v)
end
if not (en and en.decoration) then
ob:set_pos(pos1)
end
end
end
end
}
})
minetest.register_node("maps:clearinv", {
description = "player clearinv",
tiles={"default_stone.png^[invert:bg"},
groups = {unbreakable=1,exatec_wire_connected=1,not_in_creative_inventory=1},
sounds = default.node_sound_stone_defaults(),
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
if minetest.is_protected(pos, player:get_player_name())==false then
local meta = minetest.get_meta(pos)
local r = meta:get_int("r")
r = r < 20 and r or 0
meta:set_int("r",r+1)
meta:set_string("infotext","Radius (" .. (r+1) ..")")
end
end,
exatec={
on_wire = function(pos)
for _, ob in pairs(minetest.get_objects_inside_radius(pos,minetest.get_meta(pos):get_int("r"))) do
if ob:is_player() then
player_style.inventory_handle(ob,{clear=true})
end
end
end
}
})
minetest.register_node("maps:button", {
description = "Button",
tiles={"default_wood.png",},
drawtype = "nodebox",
node_box = {type = "fixed",fixed={{0.5, 0.5, 0.5, -0.5, -0.5, -0.5},{-0.2, 0.5, -0.2, 0.2, 0.7, 0.2}}},
paramtype = "light",
paramtype2 = "facedir",
on_place = minetest.rotate_node,
sounds = default.node_sound_wood_defaults(),
groups = {unbreakable=1,exatec_wire_connected=1,not_in_creative_inventory=1},
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
exatec.send(pos)
end,
})
minetest.register_node("maps:settime", {
description = "Set time",
tiles={"default_stone.png^[invert:r"},
groups = {unbreakable=1,exatec_wire_connected=1,not_in_creative_inventory=1},
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local m = minetest.get_meta(pos)
m:set_float("t",12.0)
m:set_string("infotext","Time (12)")
end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
if minetest.is_protected(pos, player:get_player_name())==false then
local m = minetest.get_meta(pos)
local t = m:get_float("t")
t = t+1 < 25 and t+1 or 0
m:set_float("t",t)
m:set_string("infotext","Time (" .. t ..")")
end
end,
exatec={
on_wire = function(pos)
minetest.set_timeofday(minetest.get_meta(pos):get_float("t")/24)
end
}
})
minetest.register_node("maps:protect", {
description = "protects area, removes area when reused",
tiles={"default_stone.png^[invert:gbr"},
groups = {unbreakable=1,exatec_wire_connected=1,not_in_creative_inventory=1},
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
minetest.get_meta(pos):set_string("formspec","size[2,1]button_exit[0,0;2,1;setup;Setup]")
end,
after_place_node=function(pos, placer, itemstack, pointed_thing)
local m = minetest.get_meta(pos)
m:set_string("owner",placer:get_player_name())
m:set_int("id",-1)
end,
on_receive_fields=function(pos, formname, pressed, sender)
if (pressed.save or pressed.setup or pressed.toggle) and minetest.check_player_privs(sender:get_player_name(), {server=true}) then
local m = minetest.get_meta(pos)
local pos1
local pos2
if pressed.save then
local name = sender:get_player_name()
local p = protect.user[name]
if p and p.pos1 and p.pos2 then
pressed.node = minetest.get_node(p.pos1).name
node = true
pos1 = p.pos1
pos2 = p.pos2
pressed.pos1 = p.pos1.x.." "..p.pos1.y.." "..p.pos1.z
pressed.pos2 = p.pos2.x.." "..p.pos2.y.." "..p.pos2.z
protect.clear(name)
end
elseif pressed.toggle then
minetest.registered_nodes["maps:protect"].exatec.on_wire(pos)
end
m:set_string("name",pressed.name)
if pos1 and (pos1.y > 26000 and pos1.y < 31000) then
m:set_string("pos1l",minetest.pos_to_string(vector.subtract(pos1,pos)))
m:set_string("pos1",pressed.pos1:gsub(","," "))
end
if pos2 and (pos2.y > 26000 and pos2.y < 31000) then
m:set_string("pos2l",minetest.pos_to_string(vector.subtract(pos2,pos)))
m:set_string("pos2",pressed.pos2:gsub(","," "))
end
m:set_string("formspec","size[1.5,4]"
.."button_exit[-0.2,-0.2;2,1;save;Save]"
.."field[0,1;2,1;name;;"..m:get_string("name").."]"
.."field[0,2;2,1;pos1;;"..m:get_string("pos1").."]"
.."field[0,3;2,1;pos2;;"..m:get_string("pos2").."]"
.."tooltip[save;Mark with both /protect 1 /protect 2 to select the position/area.\nDo not protect, just mark it then press save]"
.."tooltip[node;A valid node, eg default:stone]"
.."tooltip[pos1;Position 1]"
.."tooltip[pos2;Position 2]"
.."button_exit[-0.2,3.5;2,1;toggle;Toggle "..(m:get_int("id") == -1 and "on" or "off").."]"
)
end
end,
exatec={
on_wire = function(pos)
local m = minetest.get_meta(pos)
local id = m:get_int("id")
local owner = m:get_string("owner")
if id ~= -1 then
protect.remove_game_rule_area(id)
m:set_int("id",-1)
return
end
local pos1 = minetest.string_to_pos(m:get_string("pos1l"))
local pos2 = minetest.string_to_pos(m:get_string("pos2l"))
if pos1 and pos2 and owner ~= "" then
pos1,pos2 = protect.sort(vector.add(pos1,pos),vector.add(pos2,pos))
local pr,o = protect.test(pos1,pos2,owner)
if pr == false then
minetest.chat_send_player(owner,"The area is protected by "..o)
return
end
id = protect.add_game_rule_area(pos1,pos2,m:get_string("name"),owner,false)
if id then
m:set_int("id",id)
end
end
end
}
})