Post your modding questions here

sofar
Developer
 
Posts: 2124
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Post your modding questions here

by sofar » Tue Feb 14, 2017 04:02

GreenDimond wrote:I seem to be having trouble with registering 2 'on_punch' to the same node.


You can't. Combine the code into one function.
 

User avatar
GreenDimond
Member
 
Posts: 1299
Joined: Wed Oct 28, 2015 01:26
Location: SCP-3008
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 04:06

sofar wrote:
GreenDimond wrote:I seem to be having trouble with registering 2 'on_punch' to the same node.


You can't. Combine the code into one function.

I have realized this, but now I am having trouble with that aswell. I will post here if I cant fix.
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenXenith#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.
 

User avatar
GreenDimond
Member
 
Posts: 1299
Joined: Wed Oct 28, 2015 01:26
Location: SCP-3008
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 04:45

Still working on this, but apparently I still cant seem to be able to lua.
Code: Select all
   get_item = function ()
--        function(pos, node, player, pointed_thing)
        local inv = player:get_inventory()
        inv:add_item("main", "modname:nodedame")
    end,
    replace_model = function ()
--        function(pos, node, puncher, pointed_thing)
        minetest.set_node(pos, {name = "modname:othernodename", param2 = node.param2})
    end,
    do_punch = function do_punch()
      get_item()
      replace_model()
   end,
    on_punch = do_punch

commenting the function(pos, blablabla) out allows the mod to run. Otherwise it wants '<name>' at the first function(pos, node, player, blablabla). No idea what to do.
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenXenith#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.
 

User avatar
GreenDimond
Member
 
Posts: 1299
Joined: Wed Oct 28, 2015 01:26
Location: SCP-3008
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 05:07

This code lets the game start and actually does something when I punch the node. My game crashes.
Code: Select all
   get_item = function (player)
--      function(pos, node, player, pointed_thing)
      local inv = player:get_inventory()
      inv:add_item("main", "modname:nodename")
   end,
   replace_model = function (pos, node)
--      function(pos, node, puncher, pointed_thing)
      minetest.set_node(pos, {name = "modname:othernodename", param2 = node.param2})
   end,

   on_punch = function (pos, node, player, pointed_thing)
      node.get_item(player)
      node.replace_model(pos, node)
   end
})

I think I am about 90% of the way there, but am now moving as fast as a brick. So wat do now?
error code:
Code: Select all
2017-02-13 21:02:12: ERROR[Main]: ServerError: Lua: Runtime error from mod 'modname' in callback node_on_punch(): /home/alex/.minetest/mods/modname/nodes.lua:68: attempt to call field 'get_item' (a nil value)
2017-02-13 21:02:12: ERROR[Main]: stack traceback:
2017-02-13 21:02:12: ERROR[Main]:    /home/alex/.minetest/mods/modname/nodes.lua:68: in function </home/alex/.minetest/mods/modname/nodes.lua:67>

In case you are wondering, I use "modname" and "nodename" and stuff to keep the mod a secret :P
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenXenith#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.
 

User avatar
D00Med
Member
 
Posts: 943
Joined: Sat Feb 07, 2015 22:49
Location: Australia...somewhere
GitHub: D00Med

Re: Post your modding questions here

by D00Med » Tue Feb 14, 2017 09:49

I have a maths related question.
I can make an entity rotate so that it matches the player's yaw. Now I'm trying to make the entity 'catch-up' to the player's yaw. There's a problem with this though. When the player's yaw crosses 0/2pi the difference between the player's yaw and the entity's yaw makes the entity spin around in the opposite direction(the long way around).
At the moment the rotation of the entity is divided into four steps. The higher the number of steps it takes to catch up, the more noticeable the problem is.

Code: Select all
   
local target_yaw = yaw+math.pi+math.pi/2
local entity_yaw = entity.object:getyaw()
if target_yaw <= 6.2 and target_yaw >= 0.2 then --this is the only method I have to stop the problem
   entity.object:setyaw(entity_yaw+(target_yaw-entity_yaw)/4)
   else
   entity.object:setyaw(target_yaw)
end

^ yaw is the player's yaw

How can I do this so that the shortest difference is used?

@GreenDimond:
Have you tried just using get_item and replace_model rather than node.get_item and node.replace_model?
 

User avatar
orwell
Member
 
Posts: 811
Joined: Wed Jun 24, 2015 18:45
Location: Raxacoricofallapatorius
GitHub: orwell96
IRC: orwell96_mt
In-game: orwell

Re: Post your modding questions here

by orwell » Tue Feb 14, 2017 13:45

Code: Select all
-- before the node definition, make these as local functions
local function get_item(player)
      local inv = player:get_inventory()
      inv:add_item("main", "modname:nodename")
end
local function replace_model(pos, node)
--      function(pos, node, puncher, pointed_thing)
      minetest.set_node(pos, {name = "modname:othernodename", param2 = node.param2})
end
minetest.register_node("name",{
-- ...
   on_punch = function (pos, node, player, pointed_thing)
      get_item(player)
      replace_model(pos, node)
   end
-- ...
})

get_item and replace_model are functions local to the lua file. Because the node is defined in this scope, you can call the functions from there.
Also, 'node' is not ' node definition'.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
orwell
Member
 
Posts: 811
Joined: Wed Jun 24, 2015 18:45
Location: Raxacoricofallapatorius
GitHub: orwell96
IRC: orwell96_mt
In-game: orwell

Re: Post your modding questions here

by orwell » Tue Feb 14, 2017 13:48

D00Med wrote:I have a maths related question.
I can make an entity rotate so that it matches the player's yaw. Now I'm trying to make the entity 'catch-up' to the player's yaw. There's a problem with this though. When the player's yaw crosses 0/2pi the difference between the player's yaw and the entity's yaw makes the entity spin around in the opposite direction(the long way around).
At the moment the rotation of the entity is divided into four steps. The higher the number of steps it takes to catch up, the more noticeable the problem is.

Code: Select all
   
local target_yaw = yaw+math.pi+math.pi/2
local entity_yaw = entity.object:getyaw()
if target_yaw <= 6.2 and target_yaw >= 0.2 then --this is the only method I have to stop the problem
   entity.object:setyaw(entity_yaw+(target_yaw-entity_yaw)/4)
   else
   entity.object:setyaw(target_yaw)
end

^ yaw is the player's yaw

How can I do this so that the shortest difference is used?

@GreenDimond:
Have you tried just using get_item and replace_model rather than node.get_item and node.replace_model?

I have a function advtrains.minAngleDiffRad in advtrains/helpers.lua. maybe this is helpful.
Returns how far to rotate from first angle in which direction to reach second angle
Link is in signature
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
DS-minetest
Member
 
Posts: 1129
Joined: Thu Jun 19, 2014 19:49
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.
GitHub: Desour
IRC: DS-minetest
In-game: DS

Re: Post your modding questions here

by DS-minetest » Tue Feb 14, 2017 15:15

@GreenDimond: Try it like this:
Code: Select all
   get_item = function(pos, node, player)
      local inv = player:get_inventory()
      inv:add_item("main", "modname:nodename")
   end,
   replace_model = function(pos, node)
      minetest.set_node(pos, {name = "modname:othernodename", param2 = node.param2})
   end,

   on_punch = function(pos, node, player, pointed_thing)
      node.get_item(player)
      node.replace_model(pos, node)
   end
})

Perhaps it will work.
Btw where is this code? Is it in minetest.reister_node ?
Note that I've recently renamed myself on github and co. to "Desour". (I'm bad at naming things.)
Feel free to call me DS.
 

User avatar
GreenDimond
Member
 
Posts: 1299
Joined: Wed Oct 28, 2015 01:26
Location: SCP-3008
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 16:26

@D00Med: Yes, I believe I have tried that.

@DS-minetest: I tried your answer before orwells (just cuz it was a copy/past). I get this:
Code: Select all
2017-02-14 08:16:04: ERROR[Main]: ServerError: Lua: Runtime error from mod 'modname' in callback node_on_punch(): /home/alex/.minetest/mods/modname/nodes.lua:66: attempt to call field 'get_item' (a nil value)
2017-02-14 08:16:04: ERROR[Main]: stack traceback:
2017-02-14 08:16:04: ERROR[Main]:    /home/alex/.minetest/mods/modname/nodes.lua:66: in function </home/alex/.minetest/mods/modname/nodes.lua:65>

For reference, the first line of your code is line 57. Yes, this code is inside a register_node.

@orwell: :D :D :D It worked! So what I get from that, is whenever I want to combine 2 functions for one node, I must define the functions outside the register_node. Is this correct?
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenXenith#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.
 

User avatar
orwell
Member
 
Posts: 811
Joined: Wed Jun 24, 2015 18:45
Location: Raxacoricofallapatorius
GitHub: orwell96
IRC: orwell96_mt
In-game: orwell

Re: Post your modding questions here

by orwell » Tue Feb 14, 2017 16:57

Everything inside {} is a table definition. Statements like key=value, declare a new table entry.
So, if you define replace_model inside the {}, they become a member of the definition table. You can't access values of a table from functions defined in that table unless you can reference the whole table object, which in your case would be the node definition (which is stored in minetest.registered_nodes).
In contrast, you can always call functions that are identified in the global or local namespace.
Answer to question: basically yes, but depends on the use case
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
GreenDimond
Member
 
Posts: 1299
Joined: Wed Oct 28, 2015 01:26
Location: SCP-3008
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 17:03

Ok :D
New question:
I am defining a tool that replaces a model, but when it does, the model has a fixed rotation. I want it to be the same rotation as the node the player is punching.
Code:
Code: Select all
   on_use = function(itemstack, user, pointed_thing)

      if pointed_thing.type ~= "node" then
         return
      end

      local pos = pointed_thing.under
      local pname = user:get_player_name()

      if minetest.is_protected(pos, pname) then
         minetest.record_protection_violation(pos, pname)
         return
      end

      local node = minetest.get_node(pos).name

      if node == "modename:node1" then

--         minetest.swap_node(pos, {name = "modename:node2"})
         minetest.set_node(pos, {name = "modename:node2", param2 = node.param2})

         return itemstack
      end

   end,

The commented out line was the original one, but I don't think I want to swap, so I used the set_node.
This code currently makes it so no matter which direction the original node is facing, the new node faces in a fixed direction (which I don't want). How do I make it the same orientation as the node the player replaced?
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenXenith#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.
 

User avatar
orwell
Member
 
Posts: 811
Joined: Wed Jun 24, 2015 18:45
Location: Raxacoricofallapatorius
GitHub: orwell96
IRC: orwell96_mt
In-game: orwell

Re: Post your modding questions here

by orwell » Tue Feb 14, 2017 18:28

I guess you get an error "attempt to index a string"
Your local var "node" is misleading, since it's a node name and not a node table representation.

local node=minetest.get_node(pos)
If node.name=="whatever" then
mt.set_node(pos, {name="whatever", param2=node.param2})

Param2 is the value that stores the rotation of the node, you need to keep it when you set the new node.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
GreenDimond
Member
 
Posts: 1299
Joined: Wed Oct 28, 2015 01:26
Location: SCP-3008
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 18:30

Is that not the code I currently have?
We could talk about this in IRC if you like (#minetest).
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenXenith#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.
 

User avatar
orwell
Member
 
Posts: 811
Joined: Wed Jun 24, 2015 18:45
Location: Raxacoricofallapatorius
GitHub: orwell96
IRC: orwell96_mt
In-game: orwell

Re: Post your modding questions here

by orwell » Tue Feb 14, 2017 18:47

GreenDimond wrote:Is that not the code I currently have?
We could talk about this in IRC if you like (#minetest).

No not exactly. The .name went elsewhere. IRC not today.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
GreenDimond
Member
 
Posts: 1299
Joined: Wed Oct 28, 2015 01:26
Location: SCP-3008
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 18:49

orwell wrote:
GreenDimond wrote:Is that not the code I currently have?
We could talk about this in IRC if you like (#minetest).

No not exactly. The .name went elsewhere. IRC not today.

I see...trying this.
EDIT: It works! Thanks!
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenXenith#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.
 

User avatar
GreenDimond
Member
 
Posts: 1299
Joined: Wed Oct 28, 2015 01:26
Location: SCP-3008
GitHub: GreenXenith
IRC: GreenDimond
In-game: GreenDimond

Re: Post your modding questions here

by GreenDimond » Tue Feb 14, 2017 19:28

Functions hate me :(
I am trying to get a simple function to work, and it doesn't.
Code: Select all
   function() replace_donemodel(pos, node)
      minetest.set_node(pos, {name = "modname:nodename", param2 = node.param2})
   end,
   on_place = {
      minetest.after(2.0, replace_donemodel)}

This is inside a register_node.
I want the model to be replaced 2 seconds after it is placed (or set).
I have tried registering the function outside the register node aswell, but nothing works. What do?
EDIT: Fixed.
Y▹uTube | Mods | Patre●n | Twitter | Minetest Discord | GreenXenith#3232

Hey, you. You're finally awake.
You were trying to view their profile, right? Found the rest of their signature, same as us, and that guest over there.
 

sofar
Developer
 
Posts: 2124
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Post your modding questions here

by sofar » Tue Feb 14, 2017 21:01

GreenDimond wrote:This code lets the game start and actually does something when I punch the node. My game crashes.
Code: Select all
   get_item = function (player)
--      function(pos, node, player, pointed_thing)
      local inv = player:get_inventory()
      inv:add_item("main", "modname:nodename")
   end,
   replace_model = function (pos, node)
--      function(pos, node, puncher, pointed_thing)
      minetest.set_node(pos, {name = "modname:othernodename", param2 = node.param2})
   end,

   on_punch = function (pos, node, player, pointed_thing)
      node.get_item(player)
      node.replace_model(pos, node)
   end
})

I think I am about 90% of the way there, but am now moving as fast as a brick. So wat do now?
error code:
Code: Select all
2017-02-13 21:02:12: ERROR[Main]: ServerError: Lua: Runtime error from mod 'modname' in callback node_on_punch(): /home/alex/.minetest/mods/modname/nodes.lua:68: attempt to call field 'get_item' (a nil value)
2017-02-13 21:02:12: ERROR[Main]: stack traceback:
2017-02-13 21:02:12: ERROR[Main]:    /home/alex/.minetest/mods/modname/nodes.lua:68: in function </home/alex/.minetest/mods/modname/nodes.lua:67>

In case you are wondering, I use "modname" and "nodename" and stuff to keep the mod a secret :P



get_item() is declared as a member of the node definition. `node` is not a `node definition`.

you probably want to do something like this instead:

local function my_mod_get_item(params...) ...
end

(entirely OUTSIDE the minetest.registered_node() call)

and then call *that* function from the on punch handler directly:

on_punch = my_mod_get_item,
 

sofar
Developer
 
Posts: 2124
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: Post your modding questions here

by sofar » Tue Feb 14, 2017 21:01

GreenDimond wrote:Functions hate me :(
I am trying to get a simple function to work, and it doesn't.
Code: Select all
   function() replace_donemodel(pos, node)
      minetest.set_node(pos, {name = "modname:nodename", param2 = node.param2})
   end,
   on_place = {
      minetest.after(2.0, replace_donemodel)}

This is inside a register_node.
I want the model to be replaced 2 seconds after it is placed (or set).
I have tried registering the function outside the register node aswell, but nothing works. What do?
EDIT: Fixed.


tell us the fix - this way everyone learns from the mistake!
 

User avatar
rubenwardy
Moderator
 
Posts: 6012
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Tue Feb 14, 2017 21:10

GreenDimond wrote:Functions hate me :(
I am trying to get a simple function to work, and it doesn't.
Code: Select all
   function() replace_donemodel(pos, node)
      minetest.set_node(pos, {name = "modname:nodename", param2 = node.param2})
   end,
   on_place = {
      minetest.after(2.0, replace_donemodel)}

This is inside a register_node.
I want the model to be replaced 2 seconds after it is placed (or set).
I have tried registering the function outside the register node aswell, but nothing works. What do?
EDIT: Fixed.


This was the fix:

Code: Select all
-- in definition of node A

on_punch = function(pos, node, puncher, pointed_thing)
    minetest.set_node(pos, { name = "nodeBName", param2 = node.param2 })
    minetest.after(2, minetest.set_node, pos, { name = "nodeCName", param2 = node.param2 })
end,


Turns out they wanted a node to go from A -> B when punched, then to C a few seconds later.

Here is a corrected version of their original code (Although it's not the right fix)

Code: Select all
local function replace_donemodel(pos, node)
    minetest.set_node(pos, {name = "waffles:wafflemaker_open_done", param2 = node.param2})
end

minetest.register_node("node:name", {
     after_place_node = function(pos, placer, itemstack, pointed_thing)
        local node = minetest.get_node(pos)
        minetest.after(2.0, replace_donemodel, pos, node)
    end
})
 

User avatar
D00Med
Member
 
Posts: 943
Joined: Sat Feb 07, 2015 22:49
Location: Australia...somewhere
GitHub: D00Med

Re: Post your modding questions here

by D00Med » Tue Feb 14, 2017 21:12

orwell wrote:I have a function advtrains.minAngleDiffRad in advtrains/helpers.lua. maybe this is helpful.
Returns how far to rotate from first angle in which direction to reach second angle
Link is in signature

Thanks, this improves it a lot. The problem still occurs a little, but it's not as common
 

Nyarg
Member
 
Posts: 276
Joined: Sun May 15, 2016 04:32

Re: Post your modding questions here

by Nyarg » Thu Feb 16, 2017 04:45

A little question.
I need something like get_camera_pos() but nothing found.
Is there a simple way to get it ?
I am a noob. still yet. Not so noob ) [vml] WIP and a little proof for fun PlantedTorch )))
MT Strike 78a36b468554d101e0be3b0d1f587a555f396452 Great! Somebody have found it )
"My english isn't well" I know. I'm sorry )
 

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

Re: Post your modding questions here

by kaeza » Thu Feb 16, 2017 04:57

Nyarg wrote:A little question.
I need something like get_camera_pos() but nothing found.
Is there a simple way to get it ?

There's no access to camera, but you can get the player's position and add the eye offset:

Code: Select all
local pos = player:getpos()
pos.y = pos.y + 1.625


I don't recall if `player:get_eye_offset()` returns anything meaningful by default (i.e. if you don't explicitly set it in your code).

Getting third person camera position is possible by doing some maths with looking direction, but since there's no way to detect if a player is in third person view mode (AFAIK) it's kinda useless.
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
 

User avatar
googol
Member
 
Posts: 80
Joined: Mon Dec 09, 2013 09:23

Re: Post your modding questions here

by googol » Fri Feb 17, 2017 07:46

Hi experts.
How i can get (pos) of the particles in time.
Is the some function for example?
minetest.get particle(id)
return:
pos - position of particle
meta - meta of particle
------------
P.S. If this is not. Please write the post in issues GitHub.
It is very necessary.
Thank.
I am groot!
 

Byakuren
Member
 
Posts: 816
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: Post your modding questions here

by Byakuren » Fri Feb 17, 2017 19:16

googol wrote:Hi experts.
How i can get (pos) of the particles in time.
Is the some function for example?
minetest.get particle(id)
return:
pos - position of particle
meta - meta of particle
------------
P.S. If this is not. Please write the post in issues GitHub.
It is very necessary.
Thank.


The server does not keep track of particles (or their positions), and if you look at the specification of add_particle, you will notice that it does not return an id. If you want something you can keep track of the position of, I would use an entity.

What is your use case for getting the position of a particle? Maybe there is a better way that is already possible.
Every time a mod API is left undocumented, a koala dies.
 

User avatar
googol
Member
 
Posts: 80
Joined: Mon Dec 09, 2013 09:23

Re: Post your modding questions here

by googol » Sat Feb 18, 2017 21:42

Thank Byakuren.
I tried the "entity", and think you're right.
I am groot!
 

PreviousNext

Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 0 guests