how to delete an entity?

User avatar
Mito551
Member
 
Posts: 1271
Joined: Sat Jun 16, 2012 15:03

how to delete an entity?

by Mito551 » Wed Feb 13, 2013 12:50

is there a function to delete an entity? to remove it, to kill it?
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
minetest.env:add_entity

but
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.env:remove_entity
 

User avatar
Mito551
Member
 
Posts: 1271
Joined: Sat Jun 16, 2012 15:03

by Mito551 » Wed Feb 13, 2013 16:59

Hybrid Dog wrote:
Mito551 wrote:is there a function to delete an entity?
Yes, it is.
self.object:remove()


oh well. so i need expanded help then.
i have this thing here:
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
--the flame entity
minetest.register_entity("torch:flame", {
    physical = true,
    visual_size = {x=0.3, y=0.3},
    collisionbox = {0,00,0,0,0,0},
    visual = "sprite",
    textures = {"flame.png"},
    on_step = function(self, dtime)
        self.timer = self.timer + dtime
        if self.timer > 2 then
            self.object:remove()
        end
    end,
    timer = 0,
})

-- register flame abm
minetest.register_abm({
    nodenames = {"torch:torch"},
    interval = 1,
    chance = 1,
    action = function(pos)
        if minetest.env:get_node(pos).param2 == 0 then
            minetest.env:add_entity({x=pos.x,y=pos.y-0.25,z=pos.z}, "torch:flame")
        end
        if minetest.env:get_node(pos).param2 == 1 then
            minetest.env:add_entity({x=pos.x,y=pos.y+0.3,z=pos.z}, "torch:flame")
        end
        if minetest.env:get_node(pos).param2 == 2 then
            minetest.env:add_entity({x=pos.x+0.43,y=pos.y+0.4,z=pos.z}, "torch:flame")
        end
        if minetest.env:get_node(pos).param2 == 3 then
            minetest.env:add_entity({x=pos.x-0.43,y=pos.y+0.4,z=pos.z}, "torch:flame")
        end
        if minetest.env:get_node(pos).param2 == 4 then
            minetest.env:add_entity({x=pos.x,y=pos.y+0.4,z=pos.z+0.43}, "torch:flame")
        end
        if minetest.env:get_node(pos).param2 == 5 then
            minetest.env:add_entity({x=pos.x,y=pos.y+0.4,z=pos.z-0.43}, "torch:flame")
        end
    end,
})


and i need to register another abm to remove it. how would i do that?
 

4aiman
Member
 
Posts: 1208
Joined: Mon Jul 30, 2012 05:47

by 4aiman » Wed Feb 13, 2013 20:46

I'm not sure what do you want to achieve, but to remove an entity of a particular node I did this in my "gauges mod":
Entity definition
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 furnace_bar = {
    physical = false,
    collisionbox = {x=0, y=0, z=0},
    visual = "sprite",
    textures = {"20.png"},
    visual_size = {x=14/16, y=1/20, z=1},
    wielder,
}


Entity creation func:
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 add_furnace_gauge(pos, newnode, placer, oldnode, itemstack)
    if newnode.name ~= "default:furnace" then
       if  newnode.name ~= "default:furnace_active" then
           return
       end
    end
    pos.y = pos.y+1
    local ent = minetest.env:add_entity(pos, "gauges:furnace_bar")
    pos.y = pos.y-1
    if ent~= nil then
       ent = ent:get_luaentity()
       ent.wielder = pos             
    end
end


And this how I delete an entity:
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 position = self.wielder
  if minetest.env:get_node(position).name == "air" then
     self.object:remove()
     return   
  end
 

User avatar
Mito551
Member
 
Posts: 1271
Joined: Sat Jun 16, 2012 15:03

by Mito551 » Wed Feb 13, 2013 20:59

i somewhat achieved what i wanted. check out my torch mod.
thank you anyway
Last edited by Mito551 on Wed Feb 13, 2013 21:26, edited 1 time in total.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 29 guests

cron