Post your modding questions here

Locked
User avatar
pandaro
Member
Posts: 327
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro
Location: behind

by pandaro » Post

Krock wrote:
pandaro wrote:I need to execute a function when I put an item in the first row of the inventory of the player. Inventory of reference should be current_player, main. So I should redefine the function on_put () for inventory, "current_player"

is this possible?
You might look into the "flashlight" node/tool of the technic mod:
https://github.com/minetest-technic/tec ... hlight.lua
I do not think that's what I try. I have to run a function when a player put an item in the first row of the inventory. I do not want to use a "globalstep" because it is computationally exaggerated.


Then I still try to change "on_put" of the inventory of the player.
I discovered that through minetest.get_inventory ("player", "name_of_the_player")I can get a reference.
At this point can i change "on_put" for this player? or even for all players?
sorry for bad english
Linux debian 7 wheezy 64
kde

MrElmux
Member
Posts: 17
Joined: Sun Dec 29, 2013 09:50
Location: North Western Germany

by MrElmux » Post

How do i register an inventory for an Entity (To access it via get_inventory)

yaman
Member
Posts: 56
Joined: Wed Sep 04, 2013 21:22

by yaman » Post

Is it possible to spawn an ore in the air because wherein = "default:air", doesn't seem to work
cdb_441578b89f39

User avatar
kaeza
Moderator
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza
Location: Montevideo, Uruguay
Contact:

by kaeza » Post

yaman wrote:Is it possible to spawn an ore in the air because wherein = "default:air", doesn't seem to work
The node name for air is "air", not "default:air". See if that works.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal

yaman
Member
Posts: 56
Joined: Wed Sep 04, 2013 21:22

by yaman » Post

kaeza wrote:
yaman wrote:Is it possible to spawn an ore in the air because wherein = "default:air", doesn't seem to work
The node name for air is "air", not "default:air". See if that works.
It worked, thanks. Another question: is it possible to spawn something that isn't random, like a house or somethin, and how?
cdb_441578b89f39

yaman
Member
Posts: 56
Joined: Wed Sep 04, 2013 21:22

by yaman » Post

How do you make something that can't be placed on the ground, like a lump? I need it to make something for my mod.
cdb_441578b89f39

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

by Krock » Post

yaman wrote:How do you make something that can't be placed on the ground, like a lump? I need it to make something for my mod.
minetest_game/craftitems.lua wrote:

Code: Select all

minetest.register_craftitem("default:coal_lump", {
    description = "Coal Lump",
    inventory_image = "default_coal_lump.png",
})
Those things are called items.
EDIT: mo-hahah I was first!
Last edited by Krock on Tue Dec 31, 2013 15:54, edited 1 time in total.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
Casimir
Member
Posts: 1207
Joined: Fri Aug 03, 2012 16:59
GitHub: CasimirKaPazi

by Casimir » Post

minetest.register_craftitem(name, item definition)
The item definition is almost the same. You can read more in the lua_api.txt
edit: Krock was faster
Last edited by Casimir on Tue Dec 31, 2013 15:30, edited 1 time in total.

yaman
Member
Posts: 56
Joined: Wed Sep 04, 2013 21:22

by yaman » Post

Krock wrote: inventory_image = "default_coal_lump.png",
Casimir wrote:minetest.register_craftitem(name, item definition)
The item definition is almost the same. You can read more in the lua_api.txt
edit: Krock was faster
Thanks, to both of you :D
cdb_441578b89f39

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

by Krock » Post

Topic: Converting virtual money into... virtual money
Reason: I try but I've no itea how to make something like a "exchange rate"
More info: Well, I've a mod which gives money as items, but there are also other currencies like "money", those use non-touchable-money.

I planned to make something like an change block for the money mod any my mod-with-item-currency but I've no idea how I should make the formula for the exchange rate.

This is advanced but I'd be very thankful about that help.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

by Krock » Post

Okay, an easier question now:

When I've a configuration file in the worldpath, how can I set a variable in it with LUA?
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
Pitriss
Member
Posts: 254
Joined: Mon Aug 05, 2013 17:09
GitHub: Pitriss
IRC: pitriss
In-game: pitriss
Location: Czech republic, Bohumin

by Pitriss » Post

Krock wrote:Okay, an easier question now:

When I've a configuration file in the worldpath, how can I set a variable in it with LUA?
Variable: https://github.com/minetest/minetest/bl ... .txt#L1869

Data structures are easier.. you just put them into table and serialize them by minetest.serialize and write them into file.
Last edited by Pitriss on Wed Jan 01, 2014 13:27, edited 1 time in total.
I reject your reality and substitute my own. (A. Savage, Mythbusters)
I'm not modding and/or playing minetest anymore. All my mods were released under WTFPL. You can fix/modify them yourself. Don't ask me for support. Thanks.

User avatar
fairiestoy
Member
Posts: 191
Joined: Sun Jun 09, 2013 19:25
Location: Germany

by fairiestoy » Post

Hybrid Dog wrote:
Krock wrote:Okay, an easier question now:

When I've a configuration file in the worldpath, how can I set a variable in it with LUA?
you could use os.execute for a compiled c program which can do this
API Docs wrote: Settings: An interface to read config files in the format of minetest.conf
- Can be created via Settings(filename)
methods:
- get(key) -> value
- get_bool(key) -> boolean
- set(key, value)
- remove(key) -> success
- get_names() -> {key1,...}
- write() -> success
^ write changes to file
- to_table() -> {[key1]=value1,...}
^^^^^^^ ??
Krockody wrote: Topic: Converting virtual money into... virtual money
Reason: I try but I've no itea how to make something like a "exchange rate"
More info: Well, I've a mod which gives money as items, but there are also other currencies like "money", those use non-touchable-money.

I planned to make something like an change block for the money mod any my mod-with-item-currency but I've no idea how I should make the formula for the exchange rate.

This is advanced but I'd be very thankful about that help.
Why not making it configurable? Choose an initial exchange rate but refer to your code in order to make it changeable by the admin ( which would fit your needs about the configuration file ). Maybe with a extra option to add changes within this rate by time or by conversion amount ( the landrush way ).

Edit:
Hell, Pitriss x) Same thoughts it seems
Last edited by fairiestoy on Wed Jan 01, 2014 13:33, edited 1 time in total.
Interesting about new things is, to figure out how it works ...

prestidigitator
Member
Posts: 647
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Post

pandaro wrote:I do not think that's what I try. I have to run a function when a player put an item in the first row of the inventory. I do not want to use a "globalstep" because it is computationally exaggerated.
What I do is use the global step or (probably better) repeated uses of minetest.after. With the global step, do something like this to avoid large amounts of redundant computation:

Code: Select all

local DURATION = 1.0;
local timer = 0.0;

minetest.register_globalstep(
   function(dtime)
      timer = timer + dtime;
      if timer < DURATION then return end
      timer = timer - DURATION;

      -- Your logic
   end);
With the other solution, it'll look something more like:

Code: Select all

local DURATION = 1.0;

local function myFunction()
   minetest.after(DURATION, myFunction);

   -- Your logic
end

-- Boostrap it
minetest.after(DURATION, myFunction);
pandaro wrote:Then I still try to change "on_put" of the inventory of the player.
I discovered that through minetest.get_inventory ("player", "name_of_the_player")I can get a reference.
At this point can i change "on_put" for this player? or even for all players?
Unfortunately you can't do this with a player's (normal) inventory; only a node and a detached inventory. I've proposed unifying the inventory callback API in the past, but I guess it's not on the priority list of any approved developer.
Last edited by prestidigitator on Wed Jan 01, 2014 22:55, edited 1 time in total.

User avatar
pandaro
Member
Posts: 327
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro
Location: behind

by pandaro » Post

many thanks prestidigitator will evaluate your suggestions
sorry for bad english
Linux debian 7 wheezy 64
kde

prestidigitator
Member
Posts: 647
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Post

MrElmux wrote:How do i register an inventory for an Entity (To access it via get_inventory)
Entities do not have inventory. You can essentially create one by keeping a table of ItemStack objects in the entity object itself. You could even create a "class" that gives such a virtual inventory the same API as a full standard inventory.

Another option would be to create a unique name for each entity instance and use it to create a detached inventory associated with the entity. In this case you'd want to be really careful about "memory leaks" though. I haven't played with using metatables on entities, but theoretically you could use this to install a Lua finalizer to take care of cleanup.

Either way you'd want to also manage entity static data carefully if persisting the inventory contents is important. The engine is only going to persist node and player inventory data for you, so if you want other kinds of inventory you are pretty much on your own.

wcwyes
Member
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Post

how would I add an extra function to a special pick axe? like if I mine something from pos then do function?

User avatar
philipbenr
Member
Posts: 1897
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: robinspi
Location: United States

by philipbenr » Post

When using after_place_node, can I determine the direction in which a certain node is placed? (ex, facedir)

Not like this:
Image




But like so:
Image

prestidigitator
Member
Posts: 647
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Post

philipbenr wrote:When using after_place_node, can I determine the direction in which a certain node is placed? (ex, facedir
I believe the node's 'param2' value determines the direction it faces, but it may depend on the node's drawtype and other considerations. I believe 'param2' is set automatically for nodes a player places directly from inventory (for some types of node?), but you will probably have to set it explicitly if adding the node from Lua code.

prestidigitator
Member
Posts: 647
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Post

wcwyes wrote:how would I add an extra function to a special pick axe? like if I mine something from pos then do function?
Oddly, there's not a lot of customization you can do for the behavior from the tool's end. You can either completely override what it does by adding an on_use() callback (same for tools as for nodes), or you're pretty much stuck with what it does using the default Minetest behavior. [EDIT: I stand corrected. See Nore's post below. Excellent!] You can set parameters for the latter to customize the damage it does, how quickly it digs various types of block, what materials it can affect, etc., but you can't just do arbitrary things. If you make your own on_use() method, you'll have to figure out every detail of what happens when you left-click with it; the default behavior for digging and damage and all of that does not take effect, instead being replaced with whatever your callback does.

From the receiving end—meaning a node or entity on which a tool is being used—you have a few more options. So if there's some special entity/mob/node (but not player) you want the tool to affect in a particular way, there are a number of options to play with. For example, there are the on_punch(), on_dig(), can_dig(), after_dig_node(), and on_rightclick() callbacks on nodes and the punch() and right_click() callbacks on entites. From most of these you either get the wielded item as a parameter or get a reference to the player doing the digging/clicking and can use the player API to test things like what tool they are wielding.

It may be possible to re-create enough of the default behavior of digging/hitting if you dig around in the built-in Lua code a bit to figure out what everything is doing, but you'll have to be pretty careful to do it in a way that will work nicely with other mods (because of the way they assume it is all going to work).
Last edited by prestidigitator on Fri Jan 03, 2014 19:55, edited 1 time in total.

Nore
Developer
Posts: 501
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

by Nore » Post

prestidigitator wrote:
wcwyes wrote:how would I add an extra function to a special pick axe? like if I mine something from pos then do function?
Oddly, there's not a lot of customization you can do for the behavior from the tool's end. You can either completely override what it does by adding an on_use() callback (same for tools as for nodes), or you're pretty much stuck with what it does using the default Minetest behavior.
Wrong: there is the after_use callback in the API now: https://github.com/minetest/minetest/bl ... .txt#L2106
Last edited by Nore on Thu Jan 02, 2014 14:56, edited 1 time in total.

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

by Krock » Post

Thanks for all helpers with that saving question.
I used the "io.open("file", "w")" function for now but other timer, it will be better using another way :)
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

wcwyes
Member
Posts: 145
Joined: Wed Jul 31, 2013 22:42

by wcwyes » Post

sweet thnx
Nore wrote:
prestidigitator wrote:
wcwyes wrote:how would I add an extra function to a special pick axe? like if I mine something from pos then do function?
Oddly, there's not a lot of customization you can do for the behavior from the tool's end. You can either completely override what it does by adding an on_use() callback (same for tools as for nodes), or you're pretty much stuck with what it does using the default Minetest behavior.
Wrong: there is the after_use callback in the API now:

Code: Select all

https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L2106

User avatar
philipbenr
Member
Posts: 1897
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: robinspi
Location: United States

by philipbenr » Post

prestidigitator wrote:
philipbenr wrote:When using after_place_node, can I determine the direction in which a certain node is placed? (ex, facedir
I believe the node's 'param2' value determines the direction it faces, but it may depend on the node's drawtype and other considerations. I believe 'param2' is set automatically for nodes a player places directly from inventory (for some types of node?), but you will probably have to set it explicitly if adding the node from Lua code.
That's not quite what I meant. I know how to do so, but I need to be able to set the facing position inside the callback after_place_node.

shaheerziya
Member
Posts: 51
Joined: Sat Dec 07, 2013 06:57
Location: Pakistan

by shaheerziya » Post

how to make a mod?

Locked

Who is online

Users browsing this forum: No registered users and 1 guest