Page 1 of 1

Modding tutorial

PostPosted: Wed Nov 30, 2011 02:57
by kahrl
With the advent (hah!) of the new Lua-based modding API, I think we should put some tutorials into the wiki. I'd like to hear your ideas about what they could be about. (Please don't suggest anything that would require significant changes on the C++ side, I expect such a tutorial to become out of date very quickly.)

Here's a start, but feel free to go in a completely different direction.
Note, I've often only thought about what concept the tutorial will be about, but still need to come up with a fun way to demonstrate it.

Mandatory
Every modder should read these.
  1. Getting started: This will give some basic information, show how a mod directory is set up, and define a new node type.
  2. Terminology: Gives an overview of the modding terminology, and some initial insights into the game engine.

Beginner
The beginner tutorials will explain one simple concept at a time, and don't go into much detail.
  1. Nodes: This will continue the "Getting started" tutorial and explore some of the simpler settings for nodes.
  2. Inventory: Explains itemstrings, and how to customize the give_initial_stuff mod.
  3. Crafting: This will show how to define new crafting recipes.
  4. Tools: This will show how to define new tools and their digging properties.
  5. Items: This tutorial demonstrates how to define a craftitem and explains the callbacks.
  6. Commands: This shows how to define a simple new server command. Not sure what this could be about. Maybe a /lightning command that damages all players? :O
  7. ...

Intermediate
These tutorials could explain more difficult concepts or expand on the info in the beginner tutorials.
  1. Engine details: Not directly a tutorial, but explains some of the engine details that don't fit into the "beginner" section, like active blocks and so on.
  2. ABMs: Shows a very simple ABM. Maybe one that converts cobble next to water to mossy cobble?
  3. Entities: This tutorial shows how Lua entities work. Again, what could it be about?
  4. Buckets: This will explain (in detail) how the existing bucket example works.
  5. Mapgen: How to run a callback each time a new mapblock has been generated, and do some fun stuff with it.
  6. Node parameters: Explains what nodes' param1 and param2 do. Maybe multiple parts, one for param1 = light value, one for param1 = facedir, another one for param2 things?
  7. Node metadata: Could show how to make a mob that vandalized all signs it finds. :D
  8. ...

Advanced
These will explain, um, advanced concepts or show how to combine several simpler steps to make a great mod (for science!)
TBD.

I'm quite sure I have forgotten something! Also, if anyone has an idea to get the tutorials into a logical order, that would be neat.

PostPosted: Wed Nov 30, 2011 15:59
by jachoo
IMO, this topic should be in 'development' section.

PostPosted: Thu Dec 01, 2011 13:43
by TBC_x
something about performance

PostPosted: Thu Dec 01, 2011 15:23
by hiro
just start simple, maybe illustrate how to add a new simple block with different properties, for example
nyan cat tail (stackable) and head (non-stackable).

then progress to something more complex, for example a pizza oven which is like a furnace but crafted
from brick blocks instead of stone, and gives better food.

i also like the idea of a safe, like a locking chest, but openable for anyone who knows the password or
combination.

direction blocks could be fun, blocks with an arrow on top that can only be passed in this direction. for this
a way to let the player set the direction would be needed. this could also be used to make more realistic logs.

dont know, but if possible leaf decay, water evaporation and lava cooling could be done via lua?

PostPosted: Thu Dec 01, 2011 18:14
by sfan5
Oh!I really missed something

PostPosted: Sat Dec 03, 2011 08:46
by kahrl
@TCB_x Thanks for the link. I agree, there should be at least some notes about performance in one of the early tutorials.

@hiro Nice ideas, thanks! (Although I'm not sure if the safe can be done any soon (requires an API for the GUIk), and the direction blocks are impossible to do in Lua because all player movement is still client-side.)

I'm not sure if I can start writing tutorials soon, too much other stuff to do :(. But this means the API will be less likely to change after the tutorials are written, right? ;)

PostPosted: Thu Dec 08, 2011 04:00
by NakedFury
Tutorials would be great to get started on modding. I know i would use them.

PostPosted: Thu Dec 08, 2011 09:58
by bcmpinc
Would the wiki be a good place to put these tutorials?

PostPosted: Thu Dec 08, 2011 16:21
by kddekadenz
I would like to know how to create a random number, e.g. from 1-10 in Lua and how to create new mobs ;)

PostPosted: Thu Dec 08, 2011 17:02
by MarkTraceur
kddekadenz wrote:I would like to know how to create a random number, e.g. from 1-10 in Lua and how to create new mobs ;)


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
-- at the beginning of your init.lua
math.randomseed(os.time())
-- wherever you need the random number
math.random(1,10)


New mobs are not yet available through the API, to my knowledge.

EDIT: You can see my leaf_decay mod for an example: https://gitorious.org/marktraceur-minetest-mods/leaf_decay/blobs/raw/master/init.lua (search for "random" in the file)

PostPosted: Sun Dec 11, 2011 16:22
by kddekadenz
Thank you for your help!
How can I combine a word with a random number with .png?
For example image_rndnumber.png? Is there any command for this, like 'concatword' ?

EDIT: Forget about this, I found a solution.

2nd EDIT:
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
tile_images = { 'kdd_painting' .. (math.random(1,3)) .. '.png' },


I always get the 3rd pic :/
Any idea how to fix this?

PostPosted: Sun Dec 11, 2011 18:06
by MarkTraceur
Put this at the beginning of your init.lua:

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
math.randomseed(os.time())


This "seeds" the random number generator with the current time, pseudo-ensuring a random result at each run.

PostPosted: Mon Jan 02, 2012 06:44
by jordan4ibanez
how would you make it randomly select an item say a painting? because i have tried everything and it will not allow me

PostPosted: Mon Jan 02, 2012 07:07
by Jeija
@Jordan:
Register all the painting nodes.
Then, in the on_placenode function for the painting node that you can craft, do something like this.
local i=math.random(5)
if i==1 then
minetest.env:add_node(pos, {name="painting:painting1"})
end
if i==2 then
minetest.env:add_node(pos, {name="painting:painting2"})
end
if i==3 then
minetest.env:add_node(pos, {name="painting:painting3"})
end
...

I'm not sure if this is the best solution, but it should be possible.

PostPosted: Mon Jan 02, 2012 07:18
by jordan4ibanez
its helping me get there! ..i was going to do a bunch of if then statements with that if == command