Remove node from play?

User avatar
RabbiBob
Member
 
Posts: 335
Joined: Sat Jan 28, 2012 22:40

Remove node from play?

by RabbiBob » Sat Mar 24, 2012 11:14

Working on a new node type and I want the node to disappear over time based an interaction of usage with a player.

This is an object that is placed on the ground and has an area of influence that gives an effect (I have this working). While it is providing the effect, I would like to remove the node from play.

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_node("somenode", {
    description = "somenode",
    tile_images = {"somenode.png"},
    inventory_image = "somenode.png",
    paramtype2 = "facedir",
    groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3},
})



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_abm(
    {nodenames = {"somenode"},
    interval = 1.0,
    chance = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
        local objs = minetest.env:get_objects_inside_radius(pos, 5)
        for k, obj in pairs(objs) do
            obj:set_somefunctionthat is providing an effect on the player
         -->obj:add_wear(1)
        end
    end,
})


The above add_wear crashes the server and gives the below. I may not be calling it correctly either.

init.lua:32: attempt to call method 'add_wear' (a nil value)

My questions are:

  • Can I add_wear on a node from a function?
  • Does the node have to be a tool for add_wear to work? <- I believe yes from documentation
  • Is there a better way (within the above function) to do this?
Last edited by RabbiBob on Sat Mar 24, 2012 11:18, edited 1 time in total.
 

User avatar
bgsmithjr
Member
 
Posts: 436
Joined: Thu Mar 08, 2012 23:21

by bgsmithjr » Sat Mar 24, 2012 12:38

objs is a table you cannot set wear to a table. You have to find the entry in the table that you need. Like objs[index].name:set_wear(1), You get the general idea.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 42 guests

cron