Page 41 of 125

Re: Post your modding questions here

PostPosted: Mon Jul 07, 2014 15:10
by Chinchow
There is probably a very simple answer to this, but how would one create a flat area of certain dimensions. For example: Say you have a hill, but you want something to generate there via a mod. However when you generate your structure there are nodes from the hill inside. Therefore a flat area needs to be set.

Re: Post your modding questions here

PostPosted: Mon Jul 07, 2014 17:41
by srifqi
prestidigitator wrote:Where did you start the server?

Singleplayer
prestidigitator wrote:Can you see any error output in the console there, or in the log file?

No. Just a normal output

chinchow wrote:There is probably a very simple answer to this, but how would one create a flat area
of certain dimensions. For example: Say you have a hill, but you want something to
generate there via a mod. However when you generate your structure there are nodes
from the hill inside. Therefore a flat area needs to be set.

That's why i want it works in singlenode mapgen

Re: Post your modding questions here

PostPosted: Mon Jul 07, 2014 19:03
by Krock
Chinchow wrote:flat area

viewtopic.php?p=145653#p145653

Re: Post your modding questions here

PostPosted: Mon Jul 07, 2014 19:34
by Chinchow
Krock wrote:
Chinchow wrote:flat area

viewtopic.php?p=145653#p145653

I apologize it seems I did not specify. I want a normal world with hills and the like, and I want a contained area to be flattened.

Re: Post your modding questions here

PostPosted: Mon Jul 07, 2014 19:54
by Krock
Chinchow wrote:
Krock wrote:
Chinchow wrote:flat area

viewtopic.php?p=145653#p145653

I apologize it seems I did not specify. I want a normal world with hills and the like, and I want a contained area to be flattened.


Contains streets, hills, flatlands. viewtopic.php?f=9&t=9296

Re: Post your modding questions here

PostPosted: Mon Jul 07, 2014 19:54
by LionsDen
Check out paramat's terrain flattener mod.

viewtopic.php?f=11&t=7701

This may be a lot more like you want.

Re: Post your modding questions here

PostPosted: Thu Jul 10, 2014 22:52
by philipbenr
dev.minetest.net wrote:> drop — alternatively drop = { max_items = ..., items = { ... } }


How to use the multiple drop function? I am trying to get a node to drop more than one thing when it is dug.

Re: Post your modding questions here

PostPosted: Fri Jul 11, 2014 08:59
by Krock
philipbenr wrote:
dev.minetest.net wrote:> drop — alternatively drop = { max_items = ..., items = { ... } }


How to use the multiple drop function? I am trying to get a node to drop more than one thing when it is dug.


Something similar to
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
drop = {
   max_items = 2,
   items = {
      {items = {"mod:item"}, rarity = 10 },
      {items = {"mod:item"}, rarity = 2 },
   }
},

Chance to get the item is 1 / rarity

Re: Post your modding questions here

PostPosted: Fri Jul 11, 2014 16:22
by philipbenr
Ohhhh. Thanks Krock! ;)

Edit1: So, one is will drop and 10 really rare.

Edit2: More info (forgot to post this ;) I'm making a sub-game, and I want the birch tree (separate mod in the game) to drop a birch tree unit always and paper unit sometimes.

Re: Post your modding questions here

PostPosted: Sat Jul 12, 2014 11:16
by philipbenr
Question #2:
Is there a way to make sure that texture packs are not enabled in game.conf (when making a game...) I want to have the textures be default and stay that way (There is a good reason too). Or at least disabled at first entry.

Edit:
And for question #3:
What is the simplest way to define a tree and have it spawn in the world? I want to have a simple birch tree, close to the default elm or whatever. Anyhow, I saw that there is the L system, but I was hoping there would be a better way to do it now in 0.4.10

Re: Post your modding questions here

PostPosted: Sat Jul 12, 2014 13:01
by Casimir
#2 I don't think so. You can not prevent the clients from doing what they want.
#3 Look at minetest_game's default/trees.lua and functions.lua

Re: Post your modding questions here

PostPosted: Sat Jul 12, 2014 14:45
by philipbenr
#2: That's what I was afraid of... Oh well. Cant be helped. Also, when I look in minetest.conf, I see the line:
"mainmenu_last_selected_TP = 1" and the line "texture_path = ____" So I was wondering if those made any difference.
#3: I already looked in trees.lua so I suppose it would be in functions.lua...

Re: Post your modding questions here

PostPosted: Sat Jul 12, 2014 15:47
by kaeza
As said by Casimir, you can't force the client to do what you want, but you can recommend people to use the default textures. If it looks bad with other texture packs, it's the user's fault, not yours.

Re: Post your modding questions here

PostPosted: Sat Jul 12, 2014 16:22
by philipbenr
@kaeza: question, but do you know of you can change the facedir of a node on a spawning tree?

I want to have ivy growing on trees that is climbable. It would look horrible with random ladderlike nodes facing only one direction...

Re: Post your modding questions here

PostPosted: Sat Jul 12, 2014 16:31
by RHR
#2: Just rename all textures in the texture folder and in the source code e.g. default_stone.png --> philipbenr_stone.png

Re: Post your modding questions here

PostPosted: Sat Jul 12, 2014 17:48
by philipbenr
RHR wrote:#2: Just rename all textures in the texture folder and in the source code e.g. default_stone.png --> philipbenr_stone.png


Very very original thinking. XD Might even use. (probably a no; either that or release the textures as a separate TP.)

Re: Post your modding questions here

PostPosted: Sun Jul 13, 2014 04:37
by paramat
I've been meaning to ask a question for perhaps a year, i'm in the habit of adding 'modname = {}' to a mod's init.lua file, but i still don't know why this is done, which is why i title that with the comment 'Stuff' in my code. What is the purpose and (when) is it essential?

Re: Post your modding questions here

PostPosted: Sun Jul 13, 2014 05:20
by yaman
Topic - How do you get the player's position, or better, the position of the block they are standing on?
Reason - I am making a gold touch mod: it makes blocks the player walks on into gold blocks
More Info - I really want to get into coding mods and I want to succeed in making this one so I can get my self esteem up.

Re: Post your modding questions here

PostPosted: Sun Jul 13, 2014 07:43
by Krock
yaman wrote:Topic - How do you get the player's position, or better, the position of the block they are standing on?
Reason - I am making a gold touch mod: it makes blocks the player walks on into gold blocks
More Info - I really want to get into coding mods and I want to succeed in making this one so I can get my self esteem up.

minetest.get_node(vector.round(player:getpos())

Re: Post your modding questions here

PostPosted: Sun Jul 13, 2014 13:24
by Casimir
@paramat
(Please anyone correct me if I'm wrong on this.)
Normally you don't need this. Only it you want that definitions made by your mod can be used by other mods too.
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
yourmod = {} -- global variable
local modname = "yourmod" -- local variable
local function first_func(pos, player)
   -- this is a local function
end

function yourmod.second_func(pos, player)
      -- this is a global function
end

From within your mod you can call both functions by there name. From an other mod you can only call yourmod.second_func because it is part of the table "yourmod" which is a global variable.

edit: see webdesigners post

Re: Post your modding questions here

PostPosted: Sun Jul 13, 2014 13:56
by webdesigner97
Casimir wrote:@paramat
(Please anyone correct me if I'm wrong on this.)
Normally you don't need this. Only it you want that definitions made by your mod can be used by other mods too.
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
yourmod = {} -- global variable
local modname = "yourmod" -- local variable
function first_func(pos, player)
   -- this is a local function
end

function yourmod.second_func(pos, player)
      -- this is a global function
end

From within your mod you can call both functions by there name. From an other mod you can only call yourmod.second_func because it is part of the table "yourmod" which is a global variable.

first_func() is also global, make it local by putting "local" before "function". In theory, you don't need to put your mod's functions in a table, but to make sure that they are unique and don't get overriden accidently by other mods, many modders do put their function in tables.

Re: Post your modding questions here

PostPosted: Mon Jul 14, 2014 05:14
by yaman
2 Questions

Topic - How do you replace a single node if I have its position stored in a variable?
Reason - Creating goldtouch mod

Topic - How could i make a chat command make a loop to do a function over and over
Reason - to make the ground under you keep turning into gold


*Edit* - Solved

Re: Post your modding questions here

PostPosted: Mon Jul 14, 2014 09:34
by srifqi
How to create my own map gen?
I see there's many mapgen mod that use singlenode mapgen.
Minetest Dev Wiki wrote:singlenode:Intended to be used by mods that perform total mapgen takeovers.

Re: Gracefully replace node upon digging?

PostPosted: Tue Jul 15, 2014 17:24
by drkwv
prestidigitator wrote:you might need to us on_dig() instead.

I have copied on_dig from builtin/item.lua and set it for my needs, but lag is still there (pushed this code to github). I have found out that even with an empty function passed to on_dig, minetest client is removing node then setting it back instead of simply doing nothing. Is there anything else I can do to get rid of the lag?

Re: Post your modding questions here

PostPosted: Tue Jul 15, 2014 22:48
by prestidigitator
paramat wrote:I've been meaning to ask a question for perhaps a year, i'm in the habit of adding 'modname = {}' to a mod's init.lua file, but i still don't know why this is done, which is why i title that with the comment 'Stuff' in my code. What is the purpose and (when) is it essential?

As others have said, a table with the name of your mod creates a convenient namespace to place your API. Any functions or variables you want to be "publicly" accessible (part of an outside API usable by other mods and during debugging) should go there. This is the de facto standard for mod APIs.

EVERY top-level variable or function you use in your mod which does NOT go in that table should be local! Otherwise it pollutes the global namespace, which is a Bad Thing. Note that in Lua the syntax:

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
function mytable.myfunc(...) ... end

is guaranteed by the language to be exactly equivalent to:

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
mytable.myfunc = function(...) ... end

so if you do not create "mytable" in the first place you'll get an error because you are trying to set a value in a non-existent table (the global variable "mytable" effectively has the value nil). See Lua Function Definitions.

Re: Post your modding questions here

PostPosted: Tue Jul 15, 2014 23:07
by prestidigitator
yaman wrote:Topic - How do you get the player's position, or better, the position of the block they are standing on?
Reason - I am making a gold touch mod: it makes blocks the player walks on into gold blocks
More Info - I really want to get into coding mods and I want to succeed in making this one so I can get my self esteem up.

If you have a player object (like from a parameter to a registered callback function), you can get the player's position by calling the getpos() method on it:

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
local pos = player:getpos();
...

If you only have the player's name, you can try to get the player object using minetest.get_player_by_name():

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
local player = minetest.get_player_by_name(player_name);
if not player then error("player "..player_name.." not found"); end
local pos = player:getpos()
...

The player's position will generally be about one unit higher (the y direction is up) than the block he or she is standing on, if standing rather than jumping or flying or falling or swimming or whatever. So given the above two examples, you might be interested in the position "{x=pos.x, y=pos.y-1, z=pos.z}".

Re: Gracefully replace node upon digging?

PostPosted: Wed Jul 16, 2014 00:13
by LionsDen
drkwv wrote:
prestidigitator wrote:you might need to us on_dig() instead.

I have copied on_dig from builtin/item.lua and set it for my needs, but lag is still there (pushed this code to github). I have found out that even with an empty function passed to on_dig, minetest client is removing node then setting it back instead of simply doing nothing. Is there anything else I can do to get rid of the lag?


If you simply want the node to never be able to be dug then add diggable = false, to the node definition. If you want it to be dug and then replaced, I'm not sure how to optimize that because I only play single player and haven't tried to do anything for servers.

Re: Post your modding questions here

PostPosted: Wed Jul 16, 2014 09:40
by paramat
Thanks everyone.
srifqi wrote:How to create my own map gen?

See this thread https://forum.minetest.net/viewtopic.php?f=18&t=6396
I also have a few simplified lua mapgens meant to help people learn the methods, the most useful one is here https://forum.minetest.net/viewtopic.php?f=11&t=8628

Re: Post your modding questions here

PostPosted: Thu Jul 17, 2014 08:30
by srifqi
paramat wrote:See this thread https://forum.minetest.net/viewtopic.php?f=18&t=6396
I also have a few simplified lua mapgens meant to help people learn the methods, the most useful one is here https://forum.minetest.net/viewtopic.php?f=11&t=8628


Thanks, paramat!

Re: Post your modding questions here

PostPosted: Sat Jul 19, 2014 21:35
by Mitroman
Hi. I wanted to have the Itemstack of the wielded item of the player. But here is the problem:
There is a function (player:get_wielded_item() ) that should return the Itemstack, but it returns userdata and I have no idea how to change / use it into an itemstack. Thanks :).