Post your modding questions here

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

by kaeza » Thu May 02, 2013 18:26

pandaro wrote:I tried to do something with minetest.register_on_joinplayer:

minetest.register_on_joinplayer(function(player)
print("hello")
minetest.env:place_node(player:getpos(),{name="default:stone"})

end)


is correctly printed "hello",but the node is not placed
What's wrong?

For some reason, there are some things you can't do from this callback (at least when playing singleplayer).
A quick workaround would be:
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
minetest.register_on_joinplayer(function(player)
  print("hello")
  minetest.after(0.1, function()
    minetest.env:place_node(player:getpos(),{name="default:stone"})
  end)
end)

Edit: I think it may be because the player has not "emerged" yet, but not sure. See what happens if you change print("hello") to print(dump(player:getpos()))
Last edited by kaeza on Thu May 02, 2013 18:28, edited 1 time in total.
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 | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
pandaro
Member
 
Posts: 266
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro

by pandaro » Thu May 02, 2013 19:17

kaeza thanks for your interest, I tried to call "player: GetPos ()" and the output is correct;
I tried, like you said, to call "place_node" after a bit of time but it still does not work.
Does anyone else have any ideas?
sorry for bad english
Linux debian 7 wheezy 64
kde
 

User avatar
BlockMen
Member
 
Posts: 768
Joined: Fri Mar 01, 2013 17:24
GitHub: BlockMen

by BlockMen » Thu May 02, 2013 20:00

pandaro wrote:kaeza thanks for your interest, I tried to call "player: GetPos ()" and the output is correct;
I tried, like you said, to call "place_node" after a bit of time but it still does not work.
Does anyone else have any ideas?


I dont know why, but it works if you use "set_node()" instead of "place_node()"

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
minetest.register_on_joinplayer(function(player)
  print("hello")
  minetest.after(0.1, function()
    minetest.env:set_node(player:getpos(),{name="default:stone"})
  end)
end)
 

1244
Member
 
Posts: 45
Joined: Fri Jul 13, 2012 16:40

by 1244 » Fri May 03, 2013 15:58

Can I transfer metadata between nodes? For example I have got node "a" which have metadata "x" and I have node "b" which have metadata "x". Can I transfer "x" from node "a" to node "b"?
 

Nore
Member
 
Posts: 468
Joined: Wed Nov 28, 2012 11:35
GitHub: Ekdohibs

by Nore » Fri May 03, 2013 16:05

Use that:

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 copy_meta(pos1,pos2)
    local meta1 = minetest.env:get_meta(pos1)
    local meta = meta:to_table()
    local meta2 = minetest.env:get_meta(pos2)
    meta2:from_table(meta)
end
 

User avatar
Excalibur Zero
Member
 
Posts: 142
Joined: Tue Apr 02, 2013 19:45
GitHub: ExcaliburZero

by Excalibur Zero » Sat May 04, 2013 13:08

Topic: How to create mob member at block?
Reason: I want to make a mod with a block that can be used to summon an enemy, and once it does so the block destroys its self.
More Info: I've tried to do it, but I couldn't figure it out.
 

User avatar
jojoa1997
Member
 
Posts: 2890
Joined: Thu Dec 13, 2012 05:11

by jojoa1997 » Sat May 04, 2013 13:48

How would I make a tool do two functions using on_place
Coding;
1X coding
3X debugging
12X tweaking to be just right
 

User avatar
Traxie21
Member
 
Posts: 753
Joined: Mon Dec 31, 2012 10:48

by Traxie21 » Sat May 04, 2013 13:54

jojoa1997 wrote:How would I make a tool do two functions using on_place

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
on_place = function(ARGS)
function1()

function2()
end

@ExcaliburZero: I know how, but I'm on a kindle and don't remember exactly.
Also, nice of you to read the first post and use correct formatting :3
 

User avatar
Casimir
Member
 
Posts: 1101
Joined: Fri Aug 03, 2012 16:59

by Casimir » Sat May 04, 2013 21:05

Casimir wrote:
12Me21 wrote:no I mean like only generating one mese block in the entire map

Look at the spawn of Minetest-Black.


That's what I came up with. The chanse to generate the node is very high, so it will be generated at the start of the world (that's what I want in this case).
There is the problem that the node can be removed by cavegen. I might have to use minetest.after, but that seems ugly to me.
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
minetest.register_on_generated(function(minp, maxp, seed)
    local file = io.open(minetest.get_worldpath().."/wcc.txt", "r")
    if file then
        return
    end
    if maxp.y >= 2 and minp.y <= 0 then
    local pr = PseudoRandom(seed+1)
        local x = pr:next(minp.x, maxp.x)
        local z = pr:next(minp.z, maxp.z)
        -- Find ground level (0...15)
        local ground_y = nil
        for y=30,0,-1 do
            if minetest.env:get_node({x=x,y=y,z=z}).name ~= "air"
            and minetest.env:get_node({x=x,y=y,z=z}).name ~= "default:leaves"
            and minetest.env:get_node({x=x,y=y,z=z}).name ~= "default:jungleleaves" then
                ground_y = y
                break
            end
        end
   
        if ground_y then
            local p = {x=x,y=ground_y+1,z=z}
            local nn = minetest.env:get_node(p).name
            local nn_ground = minetest.env:get_node({x=x,y=ground_y,z=z}).name
            -- Check if the node can be replaced
            if minetest.registered_nodes[nn] and
            minetest.registered_nodes[nn].buildable_to and
            minetest.registered_nodes[nn_ground].walkable and
            nn_ground ~= "ignore" then
                minetest.env:set_node(p,{name="wcc:wcc"})
                local file = io.open(minetest.get_worldpath().."/wcc.txt", "w")
                file:write(minetest.pos_to_string(p))
                file:close()
                print("[wcc] !")
            end
        end
    end
end)
Last edited by Casimir on Sat May 04, 2013 21:25, edited 1 time in total.
 

User avatar
Excalibur Zero
Member
 
Posts: 142
Joined: Tue Apr 02, 2013 19:45
GitHub: ExcaliburZero

by Excalibur Zero » Sun May 05, 2013 16:45

Excalibur Zero wrote:Topic: How to create mob member at block?
Reason: I want to make a mod with a block that can be used to summon an enemy, and once it does so the block destroys its self.
More Info: I've tried to do it, but I couldn't figure it out.

I figured out how to do something like I wanted, where it creates an item which creates an enemy where it would be placed. I found the code in PilzAdam's mob mod. I'll add it here so that others can find 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
minetest.register_craftitem("mobs:rat", {
    description = "Rat",
    inventory_image = "mobs_rat_inventory.png",
   
    on_place = function(itemstack, placer, pointed_thing)
        if pointed_thing.above then
            minetest.env:add_entity(pointed_thing.above, "mobs:rat")
            itemstack:take_item()
        end
        return itemstack
    end,
})
 

User avatar
12Me21
Member
 
Posts: 826
Joined: Tue Mar 05, 2013 00:36

by 12Me21 » Sun May 05, 2013 17:48

This seems like a stupid question with an obvious answer, but how do you make it so an abm will happen if a node is next to one type of node AND another type, like having an abm happen when a dirt block is next to a stone block AND a water source?
This is a signature virus. Add me to your signature so that I can multiply.
Don't ever save anything as a JPEG.
 

User avatar
ShadowNinja
Member
 
Posts: 194
Joined: Tue Jan 22, 2013 22:35
GitHub: ShadowNinja
IRC: ShadowNinja
In-game: ShadowNinja

by ShadowNinja » Mon May 06, 2013 15:58

12Me21 wrote:This seems like a stupid question with an obvious answer, but how do you make it so an abm will happen if a node is next to one type of node AND another type, like having an abm happen when a dirt block is next to a stone block AND a water source?


Use find_nodes_in_area() and check the result.
I play on my Minetest server and VanessaE's.
The best way to contact me is usually IRC (InchraNet, freenode).
 

User avatar
pandaro
Member
 
Posts: 266
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro

by pandaro » Wed May 08, 2013 20:07

some questions about armor_groups:
as always I have some difficulty ...
I try to fully understand the damage system.

I tried to give a armor_groups like this:

"player: set_armor_groups ({fleshy = 1})"

this does not return any errors, GOOD, but...
if I hit the player with any sword, the player receives no damage: for the sword of wood, stone, iron, diamond. NO damage.
Then try to return the player to a level of 0 armor:

"player: set_armor_groups ({fleshy = 0})"

trying to hit him with a sword sword of wood, stone, iron, diamond get NO damage.
So I try to figure out what the armor level through:

"print (dump (player: get_armor_groups ()))"

But Minetest crashes and returns:
attempt to call method 'get_armor_groups' (a nil value)

The main question is:
how to handle armor_groups?
secondary question:
you can create alternative groups of damage? for example: phisical damage or elemental damage?

Thanks to anyone who can answer me
sorry for bad english
Linux debian 7 wheezy 64
kde
 

deivan
Member
 
Posts: 452
Joined: Fri Feb 15, 2013 10:16

by deivan » Wed May 08, 2013 20:31

Is the percentage of the damage received no? Like 0 = 0% and 50 = 50%, correct?
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Wed May 08, 2013 21:10

deivan wrote:Is the percentage of the damage received no? Like 0 = 0% and 50 = 50%, correct?

Yep.
 

1244
Member
 
Posts: 45
Joined: Fri Jul 13, 2012 16:40

by 1244 » Thu May 09, 2013 16:46

In which way I can get itemstack which player hold in hand?
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Thu May 09, 2013 16:55

1244 wrote:In which way I can get itemstack which player hold in hand?

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
player:get_wielded_item()
 

User avatar
12Me21
Member
 
Posts: 826
Joined: Tue Mar 05, 2013 00:36

by 12Me21 » Thu May 09, 2013 21:19

How do you make it so if there is a certain item in a node's formspec, something will happen?
Example: if you put a music disk in a chest it will play a sound
This is a signature virus. Add me to your signature so that I can multiply.
Don't ever save anything as a JPEG.
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

by kaeza » Thu May 09, 2013 21:35

12Me21 wrote:How do you make it so if there is a certain item in a node's formspec, something will happen?
Example: if you put a music disk in a chest it will play a sound

One way would be to override the node's on_metadata_inventory_put callback.
See here.
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 | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
12Me21
Member
 
Posts: 826
Joined: Tue Mar 05, 2013 00:36

by 12Me21 » Thu May 09, 2013 21:52

kaeza wrote:
12Me21 wrote:How do you make it so if there is a certain item in a node's formspec, something will happen?
Example: if you put a music disk in a chest it will play a sound

One way would be to override the node's on_metadata_inventory_put callback.
See here.

So I would do
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
on_metadata_inventory_put = function(pos, listname, index, stack, player),
if stack == "music:disk" then
minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25})
end


(I've never done anything with formspecs, so this is probably completely wrong)
This is a signature virus. Add me to your signature so that I can multiply.
Don't ever save anything as a JPEG.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Thu May 09, 2013 22:01

12Me21 wrote:
kaeza wrote:
12Me21 wrote:How do you make it so if there is a certain item in a node's formspec, something will happen?
Example: if you put a music disk in a chest it will play a sound

One way would be to override the node's on_metadata_inventory_put callback.
See here.

So I would do
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
on_metadata_inventory_put = function(pos, listname, index, stack, player),
if stack == "music:disk" then
minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25})
end


(I've never done anything with formspecs, so this is probably completely wrong)

1.) There is a Lua syntax error
2.) Fix your indentation.
3.) This sound will be played locationless
4.) "stack" is a object of the type ItemStack (see lua-api.txt).
 

User avatar
12Me21
Member
 
Posts: 826
Joined: Tue Mar 05, 2013 00:36

by 12Me21 » Thu May 09, 2013 22:09

how about 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
    on_metadata_inventory_put = function(pos, node, listname, index, stack, player)
    if inv:contains_item("music:disk") then
        minetest.sound_play("music.ogg", {gain = 0.5, max_hear_distance = 25})
        end
   
    end,


EDIT: I tried it and it still won't work. It says:
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
18:09:37: ERROR[main]: ServerError: LuaError: error: ...netest-0.4.6\bin\..\mods\minetest\music\init.lua:37: attempt to index global 'inv' (a nil value)
18:09:37: ERROR[main]: stack traceback:
18:09:37: ERROR[main]: InventoryMenu: The selected inventory location "nodemeta:-449,3,467" doesn't exist
In trans_func.
Access violation at 5474754F write?=8 address=1416918351
18:09:37: ERROR[main]: Some exception: "Access violation"
In trans_func.
Access violation at 00EB1AF8 write?=8 address=15407864
18:09:37: ERROR[main]: ERROR: An unhandled exception occurred: Access violation
Last edited by 12Me21 on Thu May 09, 2013 22:22, edited 1 time in total.
This is a signature virus. Add me to your signature so that I can multiply.
Don't ever save anything as a JPEG.
 

User avatar
12Me21
Member
 
Posts: 826
Joined: Tue Mar 05, 2013 00:36

by 12Me21 » Thu May 09, 2013 22:24

PilzAdam wrote:
12Me21 wrote:
kaeza wrote:One way would be to override the node's on_metadata_inventory_put callback.
See here.

So I would do
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
on_metadata_inventory_put = function(pos, listname, index, stack, player),
if stack == "music:disk" then
minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25})
end


(I've never done anything with formspecs, so this is probably completely wrong)

1.) There is a Lua syntax error
2.) Fix your indentation.
3.) This sound will be played locationless
4.) "stack" is a object of the type ItemStack (see lua-api.txt).


1.) "I've never done anything with formspecs, so this is probably completely wrong"
2.) I'll fix that if the mod ever works
3.) I'll fix that if the mod ever works
4.) ok
Last edited by 12Me21 on Sat May 11, 2013 23:26, edited 1 time in total.
This is a signature virus. Add me to your signature so that I can multiply.
Don't ever save anything as a JPEG.
 

User avatar
12Me21
Member
 
Posts: 826
Joined: Tue Mar 05, 2013 00:36

by 12Me21 » Thu May 09, 2013 23:57

Someone please help!
This is a signature virus. Add me to your signature so that I can multiply.
Don't ever save anything as a JPEG.
 

deivan
Member
 
Posts: 452
Joined: Fri Feb 15, 2013 10:16

by deivan » Fri May 10, 2013 00:15

The moving (or running) light mode have a similar code, I think. Try read the code of this mode.
The mode who make you have light in the same place of you are if you have a torch in your hand.
 

User avatar
12Me21
Member
 
Posts: 826
Joined: Tue Mar 05, 2013 00:36

by 12Me21 » Fri May 10, 2013 00:45

Is it possible to make entities partially transparent?
This is a signature virus. Add me to your signature so that I can multiply.
Don't ever save anything as a JPEG.
 

User avatar
12Me22
Member
 
Posts: 38
Joined: Fri Apr 12, 2013 21:20

by 12Me22 » Fri May 10, 2013 01:14

My partner 12Me21 and I don't know a lot about this type of coding. Can you guide us with more details?
What syntax error, what is the proper indentation?

Thanks,

PilzAdam wrote:
12Me21 wrote:
kaeza wrote:One way would be to override the node's on_metadata_inventory_put callback.
See here.

So I would do
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
on_metadata_inventory_put = function(pos, listname, index, stack, player),
if stack == "music:disk" then
minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25})
end


(I've never done anything with formspecs, so this is probably completely wrong)

1.) There is a Lua syntax error
2.) Fix your indentation.
3.) This sound will be played locationless
4.) "stack" is a object of the type ItemStack (see lua-api.txt).
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Fri May 10, 2013 09:18

12Me22 wrote:My partner 12Me21 and I don't know a lot about this type of coding. Can you guide us with more details?
What syntax error, what is the proper indentation?

Thanks,

PilzAdam wrote:
12Me21 wrote:So I would do
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
on_metadata_inventory_put = function(pos, listname, index, stack, player),
if stack == "music:disk" then
minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25})
end


(I've never done anything with formspecs, so this is probably completely wrong)

1.) There is a Lua syntax error
2.) Fix your indentation.
3.) This sound will be played locationless
4.) "stack" is a object of the type ItemStack (see lua-api.txt).

For proper indentation read a tutorial about coding (the language doesnt matter).
There are several syntax errors, here is the fixed code.
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
on_metadata_inventory_put = function(pos, listname, index, stack, player)
    if stack == "music:disk" then
        minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25})
    end
end,

To play the sound at a position, just specify the pos field in the sound parameter table, like:
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
on_metadata_inventory_put = function(pos, listname, index, stack, player)
    if stack == "music:disk" then
        minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25, pos=pos})
    end
end,

Note that only mono channel sound files can be played at a position. Also only ogg files are supported.
To get the name of a ItemStack, use get_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
on_metadata_inventory_put = function(pos, listname, index, stack, player)
    if stack:get_name() == "music:disk" then
        minetest.sound_play("song.ogg", {gain = 0.5, max_hear_distance = 25, pos=pos})
    end
end,
 

User avatar
Dan Duncombe
Member
 
Posts: 904
Joined: Thu May 09, 2013 21:11

by Dan Duncombe » Mon May 13, 2013 19:05

I would strongly recommend using the free downloadable Notepad++ designed for coding, however if you don't want to do that you can use Window's Wordpad text editor, if you want to save a file as LUA in wordpad, you need to call it (name of file) .lua
ArcticStorm wrote:question: what program do you recommend to make a mod with?
reason: I wanna try to make mods. :)
more info: i'm using windows 7.
Last edited by Dan Duncombe on Mon May 13, 2013 19:06, edited 1 time in total.
Some Mods: Castles Prefab Camouflage
My Games: Nostalgia Realtest Revamped
Servers: See above games.
 

User avatar
Calinou
Member
 
Posts: 3124
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou

by Calinou » Mon May 13, 2013 19:37

Dan Duncombe wrote:I would strongly recommend using the free downloadable Notepad++ designed for coding


+1, it's a pretty good editor for Windows, it's also very fast to start.

Dan Duncombe wrote:however if you don't want to do that you can use Window's Wordpad text editor, if you want to save a file as LUA in wordpad, you need to call it (name of file)


Don't do that. No, really, you'll regret it. 8)
 

PreviousNext

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 74 guests

cron