Post your modding questions here

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

Re: problem with entity attach or activate

by Nyarg » Sat Feb 04, 2017 22:02

DS-minetest wrote:It seems like if I don't fly far enough away the entities are deactivated but not activated again.

As I know server only keeps place and type destroyed entity.
Another current data (velocity, collision box, attach map etc) you must say to server via
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 eObj:get_staticdata()
   return minetest.serialize(self.p)   --- for self I keep all depend data in table
end


Then init again entity at
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 eObj:on_activate( staticdata)
   if staticdata == "" then   
      self.p = {}
      self.p.vel = {x=1,y=0,z=0}
   else
      self.p = minetest.deserialize(staticdata)
      self.object:setvelocity(self.p.vel)
   end
end


PS: on_activate = function(self, staticdata, dtime_s)
Wiki don't explain dtime_s in on_activate
Last edited by Nyarg on Sat Feb 04, 2017 22:56, edited 9 times in total.
I am a noob. still yet. Not so noob ) [vml] WIP
"My english isn't well" I know. I'm sorry )
 

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

Re: problem with entity attach or activate

by Nyarg » Sat Feb 04, 2017 22:02

TumeniNodes wrote:I am stuck now because still, nothing shows up.


Why twice identical ?
function angledglass.register_glass(subname, recipeitem, groups, images, desc_glass, sounds)

Next give me error "attempt to index global "default" "
default.node_sound_glass_defaults())

After all I run main code as init.lua and finaly see
+ Spoiler
Last edited by Nyarg on Sun Feb 05, 2017 01:27, edited 1 time in total.
I am a noob. still yet. Not so noob ) [vml] WIP
"My english isn't well" I know. I'm sorry )
 

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

Re: Post your modding questions here

by GreenDimond » Sun Feb 05, 2017 00:30

n00b question: How do I make a tool break after 3 uses?
Thanks!
I am Green. I tend to binge-post. "All of this over a 16x16 representation of a cartoon cat ?!?! what has this world come to..." -TenPlus1, 2017.
Diz mah mods! :D ↑ github.com/minetest/minetest_game/issues/1647#issuecomment-288134572 ↑
Sand Plus - Tac Nayn - Waffles - Coming Soon: Caverealms Plus
 

User avatar
TumeniNodes
Member
 
Posts: 1335
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes

Re: problem with entity attach or activate

by TumeniNodes » Sun Feb 05, 2017 03:08

Nyarg wrote:Why twice identical ?
function angledglass.register_glass(subname, recipeitem, groups, images, desc_glass, sounds)


Apparently because I didn't want it to work :P

Thank you very much Nyarg, much appreciated :D
A second pair of eyes is always the best solution

Now I have to look at the model and figure out why the 2 materials are not working as they should
Flick?... Flick who?
 

User avatar
krokoschlange
Member
 
Posts: 38
Joined: Sat Jul 02, 2016 08:33
GitHub: krokoschlange
In-game: krokoschlange

How to get bone rotation?

by krokoschlange » Sun Feb 05, 2017 17:17

I want to make a tank mod and I need the rotation of a bone to add a another vector to it.
Because if if I 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
self.object:get_bone_position("bone_name")
it returns two tables. How to get to the values of the second (rotation) table? What do I need instead of the x?:
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
self.object:get_bone_position("bone_name").x
 

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

Re: How to get bone rotation?

by Nyarg » Sun Feb 05, 2017 19:43

krokoschlange wrote:it returns two tables. How to get to the values of the second (rotation) table?


Where do you found get_bone_position() ?

Anyway as I think access will like (you may check it here https://www.lua.org/cgi-bin/demo)
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
t = {a = {11},b = {12}}
print(t.a[1])
print(t.b[1])

function fn()
   tt = {a = {21},b = {22},c = {x = 23,y = 24, z = 25}}
   ttt = {a = {31},b = {32},c = {x = 33,y = 34, z = 35}}
   return tt,ttt
end

print(fn().b[1])
print(fn().c.x)

v, w = fn()
print(w.c.x)
Last edited by Nyarg on Sun Feb 05, 2017 20:00, edited 3 times in total.
I am a noob. still yet. Not so noob ) [vml] WIP
"My english isn't well" I know. I'm sorry )
 

User avatar
krokoschlange
Member
 
Posts: 38
Joined: Sat Jul 02, 2016 08:33
GitHub: krokoschlange
In-game: krokoschlange

Re: Post your modding questions here

by krokoschlange » Sun Feb 05, 2017 19:54

Thanks I will try that. I found the function in the modding api.
 

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

Re: Post your modding questions here

by Nyarg » Sun Feb 05, 2017 20:24

krokoschlange wrote: I found the function in the modding api.
Oops it's right but wiki seems outdated now.

now I see get_bone_position() return separate table so look my previously post that I update now ) for separate table handling.
I am a noob. still yet. Not so noob ) [vml] WIP
"My english isn't well" I know. I'm sorry )
 

User avatar
krokoschlange
Member
 
Posts: 38
Joined: Sat Jul 02, 2016 08:33
GitHub: krokoschlange
In-game: krokoschlange

Re: Post your modding questions here

by krokoschlange » Sun Feb 05, 2017 21:54

Unfortunately I still don't get how to get a value from the second table like the 32
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: How to get bone rotation?

by orwell » Sun Feb 05, 2017 22:07

krokoschlange wrote:I want to make a tank mod and I need the rotation of a bone to add a another vector to it.
Because if if I 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
self.object:get_bone_position("bone_name")
it returns two tables. How to get to the values of the second (rotation) table? What do I need instead of the x?:
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
self.object:get_bone_position("bone_name").x

Save in a local variable first:
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 _, rot = self.object:get_bone_position("bone_name")
rot.x

Underscore as a placeholder variable that is discarded.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: Post your modding questions here

by orwell » Sun Feb 05, 2017 22:08

GreenDimond wrote:n00b question: How do I make a tool break after 3 uses?
Thanks!

uses=3 in tool capabilities!?
Or maybe it's 2 or 4, there was an issue with count being off by 1
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: problem with entity attach or activate

by orwell » Sun Feb 05, 2017 22:18

DS-minetest wrote:I've got a very big problem. I'm not sure if this is the right place to post this but I'm not sure enough to open an issue.

To test I made this mod:
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_entity(
   "eat:test1",
   {
      on_activate = function(self, staticdata, dtime_s)
         minetest.chat_send_all("<1> activated")
         minetest.chat_send_all("<1> "..dtime_s)
         if staticdata == nil then
            minetest.chat_send_all("<1> nil")
         elseif staticdata == "" then
            minetest.chat_send_all("<1> \"\"")
         else
            minetest.chat_send_all("<1> "..staticdata)
         end
         if not self.at then
            self.at = minetest.add_entity(self.object:getpos(), "eat:test2")
         end
         if self.at then
            self.at:set_attach(self.object, "", {x=0,y=1,z=1}, {x=0,y=0,z=0})
            minetest.chat_send_all("<1> attach")
         end
         self.object:setvelocity({x=1,y=0,z=0})
      end,

      get_staticdata = function(self)
         return "sta"
      end,
   }
)

minetest.register_entity(
   "eat:test2",
   {
      on_activate = function(self, staticdata, dtime_s)
         minetest.chat_send_all("<2> activated")
         minetest.chat_send_all("<2> "..dtime_s)
         if staticdata == nil then
            minetest.chat_send_all("<2> nil")
         elseif staticdata == "" then
            minetest.chat_send_all("<2> \"\"")
         else
            minetest.chat_send_all("<2> "..staticdata)
         end
         if staticdata ~= "" then
            if not self.object:get_attach() then
               minetest.chat_send_all("<2> remove")
               self.object:remove()
            end
         end
      end,

      get_staticdata = function(self)
         return "sta"
      end,
   }
)

entity-activation-test.zip

Entity2 should be always attached to entity1, even after de- and activation.
I spawned the entity and flew away and came again and watched what happens.
I'm pretty sure that something is wrong. I'm just not sure what exactly is wrong. The reason for this is that different things happen.
On join everything is ok.
Most of the times entity2 isn't attached for some reason.
It seems like if I don't fly far enough away the entities are deactivated but not activated again.
Try it out yourself and be confused like me.

Someone would need to rewrite all attachment code. There are many issues with it.
Some things you should know:
When objects get unloaded, attachments are lost. You need to reattach in the on_activate function.
Try this:
- Staff your second object (the attachee) with something unique, such as a concatenation of os.time()..os.clock()
(not that I am using this in advtrains....) and save that in staticdata
- In on_activate() of the first object (attacher) or inside step as long as not found, loop through minetest.luaentites and search for exactly that unique property. When found, attach that object.
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
attacher on_step()
....
if not self.has_attached then
  for aoid, luaentity in pairs(minetest.luaentities) do
    if luaentity.unique_id==id then
      local attachee=minetest.object_refs[aoid]
      self.object:set_attach(attachee, ....)
      self.has_attached=true
    end
  end
end

attachee on_activate(self,staticdata)
self.unique_id=staticdata
if self.unique_id=="" then
  self.unique_id=os.time()..os.clock()
end

attachee get_staticdata()
return self.unique_id
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
DS-minetest
Member
 
Posts: 707
Joined: Thu Jun 19, 2014 19:49
GitHub: DS-Minetest
In-game: DS

Re: Post your modding questions here

by DS-minetest » Mon Feb 06, 2017 13:41

@orwell: Thanks, marking the attachee could be an interesting idea. Nevertheless the attach is obscure.
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

User avatar
krokoschlange
Member
 
Posts: 38
Joined: Sat Jul 02, 2016 08:33
GitHub: krokoschlange
In-game: krokoschlange

Re: How to get bone rotation?

by krokoschlange » Mon Feb 06, 2017 16:19

orwell wrote:Save in a local variable first:
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 _, rot = self.object:get_bone_position("bone_name")
rot.x

Underscore as a placeholder variable that is discarded.

Thank you, it works great!
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Mon Feb 06, 2017 23:42

Hello guys.
I would like to develop a method to identify (in real time) the players that are close to a specific node.
I've put the code below:
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 players = {}
minetest.register_abm{
   nodenames = {"mymod:mynode"},
   interval = 1,
   action = function(pos)
      local all_objects = minetest.get_objects_inside_radius(pos, 25)
      players = {}
      for _,obj in ipairs(all_objects) do
         if obj:is_player() then
            table.insert(players, obj)
         end
      end
      print(#players .. " players found")
   end,
}

My concern is, if this is really efficient.
I imagine there may be dozens of active nodes on a server, and this can lead to high processing usage.
Is there any better way to accomplish this task?
Does Minetest have any more suitable method for this?
Do not I have to worry about processing?
 

Byakuren
Member
 
Posts: 441
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri

Re: Post your modding questions here

by Byakuren » Tue Feb 07, 2017 03:24

BrunoMine wrote:Hello guys.
I would like to develop a method to identify (in real time) the players that are close to a specific node.
I've put the code below:
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 players = {}
minetest.register_abm{
   nodenames = {"mymod:mynode"},
   interval = 1,
   action = function(pos)
      local all_objects = minetest.get_objects_inside_radius(pos, 25)
      players = {}
      for _,obj in ipairs(all_objects) do
         if obj:is_player() then
            table.insert(players, obj)
         end
      end
      print(#players .. " players found")
   end,
}

My concern is, if this is really efficient.
I imagine there may be dozens of active nodes on a server, and this can lead to high processing usage.
Is there any better way to accomplish this task?
Does Minetest have any more suitable method for this?
Do not I have to worry about processing?

Instead of searching around each node for a player, use minetest.get_connected_players() and search for the node around each player. If you have a lot of nodes this will be faster, but I don't know exactly how many nodes you need for it to be faster. Probably you should try benchmarking it.
Every time a mod API is left undocumented, a koala dies.
 

User avatar
DS-minetest
Member
 
Posts: 707
Joined: Thu Jun 19, 2014 19:49
GitHub: DS-Minetest
In-game: DS

Re: Post your modding questions here

by DS-minetest » Tue Feb 07, 2017 13:14

@BrunoMine: #players doesn't work with such tables. Count the players in the for thing.
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

ABJ
Member
 
Posts: 2344
Joined: Sun Jan 18, 2015 13:02
GitHub: ABJ-MV
In-game: ABJ

Re: Post your modding questions here

by ABJ » Tue Feb 07, 2017 14:26

How do I create something that runs as long as a block exists but disappears when it is dug? EG: smoke for fire.
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Tue Feb 07, 2017 15:05

I am not able to use the dsdsds method. minetest.rollback_get_node_actions.
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_dignode(function(pos, oldnode, digger)
   local rollback = minetest.rollback_get_node_actions(
      pos, -- pos
      10, -- range
      5, -- seconds
      5 -- limit
   ) or {}
   
   minetest.chat_send_all(table.maxn(rollback).." actions")
end)

Results:
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
0 actions
0 actions
0 actions
...

What is wrong?

EDIT:
I forgot to enable it in minetest.conf
SOLVED!
Last edited by BrunoMine on Tue Feb 07, 2017 16:29, edited 2 times in total.
 

User avatar
BrunoMine
Member
 
Posts: 902
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine

Re: Post your modding questions here

by BrunoMine » Tue Feb 07, 2017 15:12

ABJ wrote:How do I create something that runs as long as a block exists but disappears when it is dug? EG: smoke for fire.


Have you tried an ABM?
This allows you to execute a function repeatedly while a node is active.
 

User avatar
DS-minetest
Member
 
Posts: 707
Joined: Thu Jun 19, 2014 19:49
GitHub: DS-Minetest
In-game: DS

Re: Post your modding questions here

by DS-minetest » Tue Feb 07, 2017 16:22

BrunoMine wrote:
ABJ wrote:How do I create something that runs as long as a block exists but disappears when it is dug? EG: smoke for fire.


Have you tried an ABM?
This allows you to execute a function repeatedly while a node is active.

An abm wouldn't make much sense here.
on_construct: Add a particlespawner in a variable (bla = minetest.add_particlespawner(particlespawner definition)) and store this variable somewhere, like in metadata.
on_destruct: Get this variable and remove the particlespawner again.
api:
particlespawner
on_construct and destruct
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Re: Post your modding questions here

by burli » Tue Feb 07, 2017 16:59

The documentation says, that get_node_timer accepts fractional values. But this code doesn't work. I only get full seconds

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.get_node_timer(leaves_near[i]):start(math.random() * 10.0)


What's wrong? The documentation, the function or I?
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: Post your modding questions here

by orwell » Wed Feb 08, 2017 09:41

The documentation, I think. Mesecons pressure plates also only work at an 1s interval.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: Post your modding questions here

by orwell » Wed Feb 08, 2017 09:43

DS-minetest wrote:
BrunoMine wrote:
ABJ wrote:How do I create something that runs as long as a block exists but disappears when it is dug? EG: smoke for fire.


Have you tried an ABM?
This allows you to execute a function repeatedly while a node is active.

An abm wouldn't make much sense here.
on_construct: Add a particlespawner in a variable (bla = minetest.add_particlespawner(particlespawner definition)) and store this variable somewhere, like in metadata.
on_destruct: Get this variable and remove the particlespawner again.
api:
particlespawner
on_construct and destruct

Particle spawners get removed when the block is unloaded I think. Use LBM to spawn it again.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Post your modding questions here

by rubenwardy » Wed Feb 08, 2017 12:51

burli wrote:The documentation says, that get_node_timer accepts fractional values. But this code doesn't work. I only get full seconds

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.get_node_timer(leaves_near[i]):start(math.random() * 10.0)


What's wrong? The documentation, the function or I?



There's a setting which makes this run faster. By default it only runs once a second
 

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Re: Post your modding questions here

by burli » Wed Feb 08, 2017 13:30

Ah, ok. Thanks
 

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

Re: Post your modding questions here

by GreenDimond » Wed Feb 08, 2017 17:35

How do I make items spawn in a certain area?
Explain:
I have block A and block B.
bA and bB form opposite corners of a cubic area.
I want a certain item to spawn anywhere in that area at a certain rate (appear and fall to the floor).
How do I do this (needs to be according to bA and BB so the area can be however I want)?
I am Green. I tend to binge-post. "All of this over a 16x16 representation of a cartoon cat ?!?! what has this world come to..." -TenPlus1, 2017.
Diz mah mods! :D ↑ github.com/minetest/minetest_game/issues/1647#issuecomment-288134572 ↑
Sand Plus - Tac Nayn - Waffles - Coming Soon: Caverealms Plus
 

ABJ
Member
 
Posts: 2344
Joined: Sun Jan 18, 2015 13:02
GitHub: ABJ-MV
In-game: ABJ

Re: Post your modding questions here

by ABJ » Thu Feb 09, 2017 08:55

How do I make something that gets created with a block and deleted with it?
 

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

Re: Post your modding questions here

by GreenDimond » Fri Feb 10, 2017 01:54

Another question: Is it possible to use items as buttons in a custom chest?
Explain:
Have a chest with 2 items.
Click/select an item and it takes you to another "page" in the chest.
In that "page", have a "back" item so when pressed takes you back to main "page".
I am Green. I tend to binge-post. "All of this over a 16x16 representation of a cartoon cat ?!?! what has this world come to..." -TenPlus1, 2017.
Diz mah mods! :D ↑ github.com/minetest/minetest_game/issues/1647#issuecomment-288134572 ↑
Sand Plus - Tac Nayn - Waffles - Coming Soon: Caverealms Plus
 

User avatar
orwell
Member
 
Posts: 467
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
In-game: orwell

Re: Post your modding questions here

by orwell » Fri Feb 10, 2017 06:50

You can add image buttons that look like the item. (item_image_button[])
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...
 

PreviousNext

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron