![Image](http://i.imgur.com/iTuGkzw.gif)
local function generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume, ore_per_chunk, height_min, height_max)
if maxp.y < height_min or minp.y > height_max then
return
end
local y_min = math.max(minp.y, height_min)
local y_max = math.min(maxp.y, height_max)
local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
local pr = PseudoRandom(seed)
local num_chunks = math.floor(chunks_per_volume * volume)
local chunk_size = 3
if ore_per_chunk <= 4 then
chunk_size = 2
end
local inverse_chance = math.floor(chunk_size*chunk_size*chunk_size / ore_per_chunk)
--print("generate_ore num_chunks: "..dump(num_chunks))
for i=1,num_chunks do
local y0 = pr:next(y_min, y_max-chunk_size+1)
if y0 >= height_min and y0 <= height_max then
local x0 = pr:next(minp.x, maxp.x-chunk_size+1)
local z0 = pr:next(minp.z, maxp.z-chunk_size+1)
local p0 = {x=x0, y=y0, z=z0}
for x1=0,chunk_size-1 do
for y1=0,chunk_size-1 do
for z1=0,chunk_size-1 do
if pr:next(1,inverse_chance) == 1 then
local x2 = x0+x1
local y2 = y0+y1
local z2 = z0+z1
local p2 = {x=x2, y=y2, z=z2}
if minetest.env:get_node(p2).name == wherein then
minetest.env:set_node(p2, {name=name})
end
end
end
end
end
end
end
end
minetest.register_on_generated(function(minp, maxp, seed)
generate_ore("pokenodeschems:fake_air", "default:dirt_with_grass", minp, maxp, seed+21, 1/30/30/30, 1, -31000, 100)
end)
pokenodesschems = {}
local pokenodesschems_list = {
{ "Pokemon Center", "pkmncenter"},
{ "Pokemon Market", "pkmnmarket"},
{ "Pokemon Stadium", "pkmnstadium"},
}
for i in ipairs(pokenodesschems_list) do
local builddesc = pokenodesschems_list[i][1]
local build = pokenodesschems_list[i][2]
minetest.register_node("pokenodesschems:fake_air", {
description = fake_air,
tiles = {"fake_air.png"},
is_ground_content = true,
groups = {not_in_creative_inventory =1},
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above then
local file = io.open(minetest.get_modpath("pokenodesschems").."/schems/"..build..".we")
local value = file:read("*a")
file:close()
local p = pointed_thing.above
p.x = p.x - 5
p.z = p.z - 2
local count = worldedit.deserialize(pointed_thing.above, value)
itemstack:take_item()
end
return itemstack
end,
})
end
minetest.register_abm({
nodenames = {"pokenodesschems:pkmncenter"},
interval = 1,
chance = 1,
action = function(pos)
if pos then
local file = io.open(minetest.get_modpath("pokenodesschems").."/schems/pkmncenter.we")
local value = file:read("*a")
file:close()
local p = pos
p.x = p.x - 5
p.z = p.z - 2
local count = worldedit.deserialize(pos, value)
end
end,
})
minetest.register_abm({
nodenames = {"pokenodesschems:pkmnmarket"},
interval = 5,
chance = 1,
action = function(pos)
if pos then
local file = io.open(minetest.get_modpath("pokenodesschems").."/schems/pkmnmarket.we")
local value = file:read("*a")
file:close()
local p = pos
p.x = p.x - 5
p.z = p.z - 2
local count = worldedit.deserialize(pos, value)
end
end,
})
minetest.register_abm({
nodenames = {"pokenodesschems:pkmnstadium"},
interval = 1,
chance = 1,
action = function(pos)
if pos then
local file = io.open(minetest.get_modpath("pokenodesschems").."/schems/pkmnstadium.we")
local value = file:read("*a")
file:close()
local p = pos
p.x = p.x - 5
p.z = p.z - 2
local count = worldedit.deserialize(pos, value)
end
end,
})
15:40:21: ERROR[main]: ServerError: ...op\minetest-0.4.10\bin\..\mods\PKMNS\poke
schems\init.lua:42: attempt to concatenate global 'build' (a nil value)
15:40:21: ERROR[main]: stack traceback:
15:40:21: ERROR[main]: ...op\minetest-0.4.10\bin\..\mods\PKMNS\pokeschems\init.
lua:42: in function <...op\minetest-0.4.10\bin\..\mods\PKMNS\pokeschems\init.lua
:41>
15:40:21: ERROR[main]: ...Desktop\minetest-0.4.10\bin\..\builtin\game\register.
lua:348: in function <...Desktop\minetest-0.4.10\bin\..\builtin\game\register.lu
a:336>
local function generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume, ore_per_chunk, height_min, height_max)
if maxp.y < height_min or minp.y > height_max then
return
end
local y_min = math.max(minp.y, height_min)
local y_max = math.min(maxp.y, height_max)
local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
local pr = PseudoRandom(seed)
local num_chunks = math.floor(chunks_per_volume * volume)
local chunk_size = 3
if ore_per_chunk <= 4 then
chunk_size = 2
end
local inverse_chance = math.floor(chunk_size*chunk_size*chunk_size / ore_per_chunk)
--print("generate_ore num_chunks: "..dump(num_chunks))
for i=1,num_chunks do
local y0 = pr:next(y_min, y_max-chunk_size+1)
if y0 >= height_min and y0 <= height_max then
local x0 = pr:next(minp.x, maxp.x-chunk_size+1)
local z0 = pr:next(minp.z, maxp.z-chunk_size+1)
local p0 = {x=x0, y=y0, z=z0}
for x1=0,chunk_size-1 do
for y1=0,chunk_size-1 do
for z1=0,chunk_size-1 do
if pr:next(1,inverse_chance) == 1 then
local x2 = x0+x1
local y2 = y0+y1
local z2 = z0+z1
local p2 = {x=x2, y=y2, z=z2}
if minetest.env:get_node(p2).name == wherein then
minetest.env:set_node(p2, {name=name})
end
end
end
end
end
end
end
end
minetest.register_on_generated(function(minp, maxp, seed)
generate_ore("pokeschems:"..build, "default:dirt_with_grass", minp, maxp, seed+21, 1/30/30/30, 1, -31000, 100)
end)
pokeschems = {}
local pokeschems_list = {
{ "Pokemon Center", "pkmncenter"},
{ "Pokemon Market", "pkmnmarket"},
{ "Pokemon Stadium", "pkmnstadium"},
}
for i in ipairs(pokeschems_list) do
local builddesc = pokeschems_list[i][1]
local build = pokeschems_list[i][2]
minetest.register_node("pokeschems:"..build, {
description = builddesc,
tiles = {"fake_air.png"},
is_ground_content = true,
groups = {not_in_creative_inventory =0},
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above then
local file = io.open(minetest.get_modpath("pokeschems").."/schems/"..build..".we")
local value = file:read("*a")
file:close()
local p = pointed_thing.above
p.x = p.x - 5
p.z = p.z - 2
local count = worldedit.deserialize(pointed_thing.above, value)
itemstack:take_item()
end
return itemstack
end,
})
end
minetest.register_abm({
nodenames = {"pokeschems:pkmncenter"},
interval = 1,
chance = 1,
action = function(pos)
if pos then
local file = io.open(minetest.get_modpath("pokeschems").."/schems/pkmncenter.we")
local value = file:read("*a")
file:close()
local p = pos
p.x = p.x - 5
p.z = p.z - 2
local count = worldedit.deserialize(pos, value)
end
end,
})
minetest.register_abm({
nodenames = {"pokeschems:pkmnmarket"},
interval = 1,
chance = 1,
action = function(pos)
if pos then
local file = io.open(minetest.get_modpath("pokeschems").."/schems/pkmnmarket.we")
local value = file:read("*a")
file:close()
local p = pos
p.x = p.x - 5
p.z = p.z - 2
local count = worldedit.deserialize(pos, value)
end
end,
})
minetest.register_abm({
nodenames = {"pokeschems:pkmnstadium"},
interval = 1,
chance = 1,
action = function(pos)
if pos then
local file = io.open(minetest.get_modpath("pokeschems").."/schems/pkmnstadium.we")
local value = file:read("*a")
file:close()
local p = pos
p.x = p.x - 5
p.z = p.z - 2
local count = worldedit.deserialize(pos, value)
end
end,
})
q9c9p, post: 1636, member: 260 wrote:Hello,
this is my first post in this community, being a linux user I like a lot the idea of an open source and free software game but lets cut to the chase.
Where should one look to create a multiple world mod with scaling, like multiverse for bukkit, to create for example the 9 rings of hell each that scale 1:3 from the precedent world?
Can i call from lua the main mapgen function?
Thank you for your time.
q9c9p
local functions = {}
local function myFunction()
--does stuff
end
functions.myfunction = myfunction
return functions
local functions = require("functions")
functions.myfunction()
-- module.lua
local m = { }
-- This is local, since it's stored into `m` (which is a local itself).
function m.do_something(foo, bar)
return foo + bar
end
return m
-- init.lua
package.path = package.path .. ";" .. minetest.get_modpath("yourmodname").."/?.lua"
local mymodule = require("module")
local x = mymodule.do_something(1, 2)
kaeza wrote:Try this:Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
-- module.lua
local m = { }
-- This is local, since it's stored into `m` (which is a local itself).
function m.do_something(foo, bar)
return foo + bar
end
return mYour phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
-- init.lua
package.path = package.path .. ";" .. minetest.get_modpath("yourmodname").."/?.lua"
local mymodule = require("module")
local x = mymodule.do_something(1, 2)
Strikingwolf wrote:I was wondering how I could require code in another mod and modulize it. For example I know how you would make regular code modular
...
So how could I do this with a core mod or something of the sort?
-- This mod is named "parent"
parent = {}
parent.foo = function() ... end
-- This mod is named "child" and depends on "parent".
-- There is a line naming "parent" (without quotes) in this mod's depends.txt file.
-- Call parent's function:
parent.foo()
local MOD_NAME = minetest.get_current_modname()
local MOD_PATH = minetest.get_modpath(MOD_NAME)
local myModule = dofile(MOD_PATH .. "/myModule.lua")
minetest.register_node("battles:arenablock", {
description = "Arenablock",
tiles = {"arenablock.png"},
groups = {cracky=1, oddly_breakable_by_hand=1},
can_dig = function(pos, player)
local can_access = minetest.check_player_privs(player:get_player_name(), {arenabuilder=true})
return can_access
end,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local can_access = minetest.check_player_privs(placer:get_player_name(), {arenabuilder=true})
if can_access == true then
return
else
minetest.set_node(pos, {name="air"})
end
end,
})
GunshipPenguin wrote:I know that I could modify the TNT code so it doesn't destroy the arenablock, but I would prefer modifying my mod's code to make the arenablock immune to TNT explosions.
Sokomine wrote:GunshipPenguin wrote:I know that I could modify the TNT code so it doesn't destroy the arenablock, but I would prefer modifying my mod's code to make the arenablock immune to TNT explosions.
Take a look at how default:cloud is defined. It ought to be sufficient to give your block none of the groups that are relevant for digging. You might also want to ask about that in the TNT mod thread. It ought to remove no blocks that can't be digged. Of course you can't easily dig such blocks, priv nonwithstanding. A special tool might help you there. If you handle the digging about can_dig, players will be able to dig the block and slip through before the server sends the information that it can't be digged.
4aiman wrote:GunshipPenguin, THANK YOU VERY MUCH!!! Honestly. You've just gave me an awesome idea! :)
Regards!
GunshipPenguin wrote:Hello everybody,
And it works fine, the problem arises when you use my arenablock node with the TNT mod that is included in minetest_game as the TNT destroys the arenablock when it explodes. Looking at the code for the TNT mod, I see that it uses minetest.remove_node when it explodes to remove the nodes around it and simulate an explosion. My question is this: Is it possible to make arenablock not be destroyed by TNT explosions? I know that I could modify the TNT code so it doesn't destroy the arenablock, but I would prefer modifying my mod's code to make the arenablock immune to TNT explosions.
jin_xi wrote:minetest.registered_nodes is a table of all registered nodes
benedict424 wrote:Question: How do I make an ore that spawns in the world?
Reason: I'm working on a mod that makes veriaty in pre-existing ores.
lag01 wrote:benedict424 wrote:Question: How do I make an ore that spawns in the world?
Reason: I'm working on a mod that makes veriaty in pre-existing ores.
I myself don't know how to do this, but maybe you can check how they do it in moreores mod
philipbenr wrote:Look at magpen.lua in default. It uses minetest.register_ore function. That one works really well.
benedict424 wrote:Question: How do I make an ore that spawns in the world?
benedict424 wrote:How do I get a node, or and ore, to drop multiple things?
RHR wrote:Is there any way to create light-emitting entities?
Users browsing this forum: No registered users and 9 guests