Page 3 of 4

PostPosted: Tue Dec 31, 2013 16:16
by AMMOnym
will be nice if u add skin chooser for npcs

PostPosted: Tue Dec 31, 2013 16:38
by aldobr
@stu you might be interested in my g-ode interpreter code for your builder npc:

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
reprap = {}

-- adds <material> to each node in a line from <from_position> to <to_position>
function reprap.drawline3d(from_position, to_position, material)
   --modified from https://github.com/ryanramage/bresenham3d/blob/master/index.js
   --lua port by jin_xi
   local temp
   local x0 = math.floor(from_position.x)
   local y0 = math.floor(from_position.y)
   local z0 = math.floor(from_position.z)
   local x1 = math.floor(to_position.x)
   local y1 = math.floor(to_position.y)
   local z1 = math.floor(to_position.z)
   --'steep' xy Line, make longest delta x plane
   local swap_xy = math.abs(y1 - y0) > math.abs(x1 - x0)
   if swap_xy then
      temp = x0; x0 = y0; y0 = temp --swap(x0, y0);
      temp = x1; x1 = y1; y1 = temp --swap(x1, y1);
   end
   local swap_xz = math.abs(z1 - z0) > math.abs(x1 - x0)
   if swap_xz then
      temp = x0; x0 = z0; z0 = temp --swap(x0, z0);
      temp = x1; x1 = z1; z1 = temp --swap(x1, z1);
   end
   --delta is Length in each plane
   local delta_x = math.abs(x1 - x0)
   local delta_y = math.abs(y1 - y0)
   local delta_z = math.abs(z1 - z0)
   --drift controls when to step in 'shallow' planes
   --starting value keeps Line centred
   local drift_xy = (delta_x / 2)
   local drift_xz = (delta_x / 2)
   --direction of line
   local step_x = 1
   if x0 > x1 then step_x = -1 end
   local step_y = 1
   if y0 > y1 then step_y = -1 end
   local step_z = 1
   if z0 > z1 then step_z = -1 end
   --starting point
   local y = y0
   local z = z0
   --step through longest delta (which we have swapped to x)
   local cx, cy, cz
   for x = x0, x1, step_x do
      --copy position
      cx = x; cy = y; cz = z
      --unswap (in reverse)
      if swap_xz then
                temp = cx; cx = cz; cz = temp --swap(cx, cz)
      end
      if swap_xy then
                temp = cx; cx = cy; cy = temp --swap(cx, cy)
      end
      print("drawing dot: "..cx..', '..cy..', '..cz)
      minetest.env:add_node({ x = cx, y = cy, z = cz }, { name=material, param2=2 })
      --update progress in other planes
      drift_xy = drift_xy - delta_y
      drift_xz = drift_xz - delta_z
      --step in y plane
      if drift_xy < 0 then
                y = y + step_y
                drift_xy = drift_xy + delta_x
      end
      --same in z
      if (drift_xz < 0) then
                z = z + step_z
                drift_xz = drift_xz + delta_x
      end
   end
end

-- process a gcode file <filename> placing <material> on each point touched by the machine
function reprap.process_gcode(filename, material, center)
    local path = minetest.get_modpath("reprap").."/"..filename
    local f = io.open(path)
    local line
    local cmd, param = "", ""
    local lastx, lasty, lastz
    local cmdx, cmdy, cmdz
    lastx = 0
    lasty = 0
    lastz = 0
    for line in f:lines() do
        if (line ~= "") and (line:sub(1,1) ~= ";") then
            if string.find(line, "G1 ") then
                cmdx = lastx
                cmdy = lasty
                cmdz = lastz
                for cmd, param in string.gmatch(line, "(%w)([0-9.-]+)") do
                    param = tonumber(param)
                    if cmd == "X" then
                        cmdx = param
                    elseif cmd == "Y" then
                        cmdz = param
                    elseif cmd == "Z" then
                        cmdy = param
                    end
                end
                reprap.drawline3d(
                        { x = center.x + lastx, y = center.y + lasty, z = center.z + lastz },
                        { x = center.x + cmdx, y = center.y + cmdy, z = center.z + cmdz },
                        material
                    )
                lastx = cmdx
                lasty = cmdy
                lastz = cmdz
            end
        end
    end
end

minetest.register_chatcommand("reprap", {
        params = "<gcodefilename>,<material>,<x>,<y>,<z>",
        description = "start printing a gcode file",
        privs = {},
        func = function(name, param)
            local paramlist
            print(param)
            paramlist = string.split(param, ",")
            print(paramlist[1])
            print(paramlist[2])
            print(paramlist[3])
            print(paramlist[4])
            print(paramlist[5])
            filename = paramlist[1]
            material = paramlist[2]
            drawx = tonumber(paramlist[3])
            drawy = tonumber(paramlist[4])
            drawz = tonumber(paramlist[5])
            reprap.process_gcode(filename, material, { x=drawx, y=drawy, z=drawz })
            -- reprap.process_gcode("column.gcode", "default:mese", { x=-65, y=0, z=77 })
        end
    }
)



it allows reading a gcode file, generated from cad models, like a virtul 3d printer (reprap)

PostPosted: Tue Dec 31, 2013 20:50
by stu
aldobr wrote:@stu you might be interested in my g-ode interpreter code for your builder npc:

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
reprap = {}

-- adds <material> to each node in a line from <from_position> to <to_position>
function reprap.drawline3d(from_position, to_position, material)
   --modified from https://github.com/ryanramage/bresenham3d/blob/master/index.js
   --lua port by jin_xi
   local temp
   local x0 = math.floor(from_position.x)
   local y0 = math.floor(from_position.y)
   local z0 = math.floor(from_position.z)
   local x1 = math.floor(to_position.x)
   local y1 = math.floor(to_position.y)
   local z1 = math.floor(to_position.z)
   --'steep' xy Line, make longest delta x plane
   local swap_xy = math.abs(y1 - y0) > math.abs(x1 - x0)
   if swap_xy then
      temp = x0; x0 = y0; y0 = temp --swap(x0, y0);
      temp = x1; x1 = y1; y1 = temp --swap(x1, y1);
   end
   local swap_xz = math.abs(z1 - z0) > math.abs(x1 - x0)
   if swap_xz then
      temp = x0; x0 = z0; z0 = temp --swap(x0, z0);
      temp = x1; x1 = z1; z1 = temp --swap(x1, z1);
   end
   --delta is Length in each plane
   local delta_x = math.abs(x1 - x0)
   local delta_y = math.abs(y1 - y0)
   local delta_z = math.abs(z1 - z0)
   --drift controls when to step in 'shallow' planes
   --starting value keeps Line centred
   local drift_xy = (delta_x / 2)
   local drift_xz = (delta_x / 2)
   --direction of line
   local step_x = 1
   if x0 > x1 then step_x = -1 end
   local step_y = 1
   if y0 > y1 then step_y = -1 end
   local step_z = 1
   if z0 > z1 then step_z = -1 end
   --starting point
   local y = y0
   local z = z0
   --step through longest delta (which we have swapped to x)
   local cx, cy, cz
   for x = x0, x1, step_x do
      --copy position
      cx = x; cy = y; cz = z
      --unswap (in reverse)
      if swap_xz then
                temp = cx; cx = cz; cz = temp --swap(cx, cz)
      end
      if swap_xy then
                temp = cx; cx = cy; cy = temp --swap(cx, cy)
      end
      print("drawing dot: "..cx..', '..cy..', '..cz)
      minetest.env:add_node({ x = cx, y = cy, z = cz }, { name=material, param2=2 })
      --update progress in other planes
      drift_xy = drift_xy - delta_y
      drift_xz = drift_xz - delta_z
      --step in y plane
      if drift_xy < 0 then
                y = y + step_y
                drift_xy = drift_xy + delta_x
      end
      --same in z
      if (drift_xz < 0) then
                z = z + step_z
                drift_xz = drift_xz + delta_x
      end
   end
end

-- process a gcode file <filename> placing <material> on each point touched by the machine
function reprap.process_gcode(filename, material, center)
    local path = minetest.get_modpath("reprap").."/"..filename
    local f = io.open(path)
    local line
    local cmd, param = "", ""
    local lastx, lasty, lastz
    local cmdx, cmdy, cmdz
    lastx = 0
    lasty = 0
    lastz = 0
    for line in f:lines() do
        if (line ~= "") and (line:sub(1,1) ~= ";") then
            if string.find(line, "G1 ") then
                cmdx = lastx
                cmdy = lasty
                cmdz = lastz
                for cmd, param in string.gmatch(line, "(%w)([0-9.-]+)") do
                    param = tonumber(param)
                    if cmd == "X" then
                        cmdx = param
                    elseif cmd == "Y" then
                        cmdz = param
                    elseif cmd == "Z" then
                        cmdy = param
                    end
                end
                reprap.drawline3d(
                        { x = center.x + lastx, y = center.y + lasty, z = center.z + lastz },
                        { x = center.x + cmdx, y = center.y + cmdy, z = center.z + cmdz },
                        material
                    )
                lastx = cmdx
                lasty = cmdy
                lastz = cmdz
            end
        end
    end
end

minetest.register_chatcommand("reprap", {
        params = "<gcodefilename>,<material>,<x>,<y>,<z>",
        description = "start printing a gcode file",
        privs = {},
        func = function(name, param)
            local paramlist
            print(param)
            paramlist = string.split(param, ",")
            print(paramlist[1])
            print(paramlist[2])
            print(paramlist[3])
            print(paramlist[4])
            print(paramlist[5])
            filename = paramlist[1]
            material = paramlist[2]
            drawx = tonumber(paramlist[3])
            drawy = tonumber(paramlist[4])
            drawz = tonumber(paramlist[5])
            reprap.process_gcode(filename, material, { x=drawx, y=drawy, z=drawz })
            -- reprap.process_gcode("column.gcode", "default:mese", { x=-65, y=0, z=77 })
        end
    }
)



it allows reading a gcode file, generated from cad models, like a virtul 3d printer (reprap)

This is a very interenting piece of code. I actually work in mechanical engineering so I'm no stranger to gcode and cad

I will maybe try this with the builder NPC at some stage or even use it for something else, thank you for sharing it.

PostPosted: Fri Jan 03, 2014 01:40
by jenova99sephiros
stu wrote:
LuxAtheris wrote:So hows the bug fixing?

There are no bugs I am currently aware of, at least none that are within my control (lua wise).
Work on this mod is pretty much on hold until entities are properly fixed in minetest.

jenova99sephiros wrote:Please battler mob!
Get the goods when you win them!

For this sort of thing you should look at Simple Mobs or Mob Framework.


I want to make the arena!

PostPosted: Fri Jan 03, 2014 01:58
by Josh
Look's cool, do they spawn on there own, or do you have to do it manually?
you could also make something like a butler npc that does random chores for you.

PostPosted: Fri Jan 17, 2014 09:35
by freejack
This works ok, I just had an issue and now have a guard spawner that duplicates itself. I placed the spawner right clicked it and named the guard. Out pops th guard but the spawner was still there. Now if I click on it to get rid of it or pick it up it duplicates itself. Any idea how to remove it? The spawner.

PostPosted: Sat Jan 18, 2014 04:27
by jenova99sephiros
I say things to spawn in automatic!
In addition, Spawner things random is generated in the detailed configurable automatic and Spawner want!

May not be achieved by taking you to ask this, but I would like to have when you're also Npc spawner to start in Mesecon signal!

PostPosted: Sun Jan 26, 2014 00:14
by Inocudom
CheerfulCherub wrote:Can anyone help me set up the 3d or class Characters, I download it to my mod folder and extracted and name the right name but I don't exactly know how to put the character in 3d and I tried the command for class but no luck either, I know it's not the mod it's me. Please any help in greatly appreciated. I am using 0.49minetest, love this game, making a big castle in singleplayer.

Cheerful Cherub

CheerfulCherub started a topic in the forums and posted this in it. Would anyone care to explain what needs to be done?

PostPosted: Tue Jan 28, 2014 20:07
by hoodedice
A player crashed my server using this mod. Here are the last lines before the crash:

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
14:45:28: ACTION[ServerThread]: kinkinkijkin digs base:grass at (-389,42,207)
14:45:36: ACTION[ServerThread]: CHAT: <hoodedice> And because we have >10 players, there might be rarely any lag
14:45:44: ACTION[ServerThread]: Zen places node npcf:guard_npc_spawner at (-459,22,-97)
14:45:44: ACTION[ServerThread]: facedir: 3
14:45:49: ACTION[ServerThread]: hoodedice leaves game. List of players: Zen kinkinkijkin
14:45:49: ERROR[main]: ServerError: .../../games/nodetopia/mods/minetest-npcf/npcf/npcf.lua:108: attempt to index local 'npc_name' (a nil value)
14:45:49: ERROR[main]: stack traceback:
14:45:49: ERROR[main]:     .../../games/nodetopia/mods/minetest-npcf/npcf/npcf.lua:108: in function 'get_valid_npc_name'
14:45:49: ERROR[main]:     .../../games/nodetopia/mods/minetest-npcf/npcf/npcf.lua:334: in function <.../../games/nodetopia/mods/minetest-npcf/npcf/npcf.lua:326>
AL lib: FreeContext: (0x2c86420) Deleting 3 Source(s)


Weird. I left the game befor the server died? LOL.

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Sat Aug 16, 2014 14:38
by Esteban
Stu I wonder that Is it possible to remove the name feature and checking? If so, could you please tell me what should I remove.

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Sat Aug 16, 2014 16:25
by stu
Esteban wrote:Stu I wonder that Is it possible to remove the name feature and checking? If so, could you please tell me what should I remove.


Unfortunately the naming system is pretty fundamental to how this mod works so
I don't see an easy way it can be removed. You might be better off with sapier's mobf npcs

To be honest, I have not really worked on this for some time, it was written at
a time when my understanding of the minetest entity system (and the Lua language itself)
were a little bit naive, at best.

I have just pushed a couple of changes which should fix that bug reported in January (sorry I missed that)
and removed the duplicate entity checking as it should not be needed anymore and didn't work that well anyway.

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Sat Aug 16, 2014 16:36
by Sokomine
Your npcf mod has been an inspiration and a great help when I wrote my mobf_trader mod. Especially regarding the naming system.

I'm currently facing the problem of wishing for personalized mobs (inhabitants of a village) that wander around and return to their homes at night. That may be quite difficult as it's pretty likely that only part of the village will be loaded and/or have active mobs.

[Edit] Plus the system the npcf mobs use might also work quite well for farm animals.

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Sat Aug 16, 2014 17:20
by Esteban
stu wrote:
Unfortunately the naming system is pretty fundamental to how this mod works so
I don't see an easy way it can be removed. You might be better off with sapier's mobf npcs

To be honest, I have not really worked on this for some time, it was written at
a time when my understanding of the minetest entity system (and the Lua language itself)
were a little bit naive, at best.

I have just pushed a couple of changes which should fix that bug reported in January (sorry I missed that)
and removed the duplicate entity checking as it should not be needed anymore and didn't work that well anyway.


Thanks for your reply!

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Sat Sep 06, 2014 00:40
by SAMIAMNOT
Looks great, cant wait to get it, got a few questions:
1) Is this thing still in development? (Not that it matters unless it's deleted online)
2) Can you please make female deco NPCs? And make it so that if a male NPC touches a Female NPC a child NPC.
3) Do NPCs spawn by themselves? I had trouble getting stuff to spawn with Animals Modpack.

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Wed Sep 10, 2014 23:30
by SAMIAMNOT
Good Work. Nice mod.
My brother said a trader was going to give him like 20 peices of wood for like 5 obsidian. ;) Hey, there are unfair traders today! (Just not in the US. Here they call it being overpriced.)
*EDIT* Also my lil bro claims that if you place an NPC it may crash Minetest.

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Thu Sep 11, 2014 20:10
by balthazariv
How do I remove them ?
I hit them but they resistent.

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Fri Sep 12, 2014 12:12
by Esteban
balthazariv wrote:How do I remove them ?
I hit them but they resistent.


/npc remove npcsname

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Fri Sep 12, 2014 23:13
by balthazariv
Esteban wrote:/npc remove npcsname


Okay, but if you had an option "destruct" in menu of each character, it would be easier for players who don't like command lines (like me ;-) )

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Sat Sep 20, 2014 23:05
by SAMIAMNOT
Hey, I got two issues,
#1 Only Guards and Deco NPCs move
#2 I can't kill any of the NPCs.

How do you fix this? I made a hotel complete with a cafeteria but I can't go in cause this NPC is blocking the way. Cant kill him either.

EDIT 1: Never mind. Esteban fixed it. But still, how do you make them move?
EDIT 2: /npc is not a valid command according to Minetest.

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Sat Sep 20, 2014 23:13
by Esteban
SAMIAMNOT wrote:Hey, I got two issues,
#1 Only Guards and Deco NPCs move
#2 I can't kill any of the NPCs.

How do you fix this? I made a hotel complete with a cafeteria but I can't go in cause this NPC is blocking the way. Cant kill him either.

EDIT 1: Never mind. Esteban fixed it. But still, how do you make them move?


Issue #1

Info npcs and trader npcs do not move. The builder moves as he builds the basic_hut.we.
Its not a bug or problem, they were coded that way.

Issue #2

Npcs cannot be killed, they are removed by using a command:
/npcf remove npcsname
EDIT: /npcf delete npcsname
They are meant to be placed by admins and not removable by other users.

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Sat Sep 20, 2014 23:21
by SAMIAMNOT
I issued the command twice and nothing happened.

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Sat Sep 20, 2014 23:26
by Esteban
SAMIAMNOT wrote:I issued the command twice and nothing happened.


Sorry, Its:
/npcf delete npcsname

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Sat Sep 20, 2014 23:32
by SAMIAMNOT
Thanks! It worked! Goodbye Ken! ;)

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Sun Sep 21, 2014 00:41
by Sokomine
SAMIAMNOT wrote:Thanks! It worked! Goodbye Ken! ;)

Poor Ken :-)

Esteban wrote:Info npcs and trader npcs do not move. The builder moves as he builds the basic_hut.we.
Its not a bug or problem, they were coded that way.

That's right. NPC standing in the way and/or becoming victim to clearallobjects where reasons for me to add an option to pick them up in my traders mod. Beeing able to place a mob elsewhere is sometimes important.

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Mon Oct 13, 2014 22:33
by SAMIAMNOT
How do blacklists and whitelists work?

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Mon Oct 13, 2014 22:52
by Esteban
SAMIAMNOT wrote:How do blacklists and whitelists work?


Blacklist is the mobs to be attacked.
Ex. Oerkki monster, type in the box "mobs:oerkki".

Whitelist is the name of players not to be attacked if you check "Attack players"
Ex. Just write the name of the player.

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Fri Nov 14, 2014 02:44
by kidmondo
my only question is what do i save it as?

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Fri Nov 14, 2014 12:01
by Esteban
kidmondo wrote:my only question is what do i save it as?


The name of the mod? Is a modpack, so make sure the mod with the npcs is called "npcf" and the one with fonts as "textcolors". If you have issues check the posts above, usually they help.

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Sun Nov 30, 2014 12:43
by Ikishida
Hey man,can I Please use this for my Sword Art Online/Gun Gale Online Mod I wanna make a comeback mod

Re: [Modpack] NPC Framework [minetest-npcf] [WIP]

PostPosted: Mon Dec 01, 2014 01:01
by Esteban
Ikishida wrote:Hey man,can I Please use this for my Sword Art Online/Gun Gale Online Mod I wanna make a comeback mod


Welcome back! is good to see you back working on mods!