Page 1 of 1

Help With npc roaming

PostPosted: Sat Sep 24, 2016 16:37
by The Glitch Rabbit
I'm using a mod: mobs_npc. It gives you the option for them to be "still", or "follow" when you right click them. But I'd like an option for them to also roam around. To give a town a feeling of life. I've managed to add in several skins I created, but can't figure the roaming out. Can anyone out there help with this? I'm not sure how to paste the npc text properly here... but here is what it is:


local S = mobs.intllib

-- Npc by TenPlus1

mobs.npc_drops = {
"none", "none", "none",
"none", "none", "none"
}

mobs:register_mob("mobs_npc:npc", {
type = "npc",
passive = false,
damage = 3,
attack_type = "dogfight",
attacks_monsters = true,
pathfinding = true,
hp_min = 10,
hp_max = 20,
armor = 100,
collisionbox = {-0.35,-1.0,-0.35, 0.35,0.8,0.35},
visual = "mesh",
mesh = "character.b3d",
drawtype = "front",
textures = {
{"mobs_npc.png"},
{"mobs_npc2.png"},
{"mobs_npc3.png"},
{"mobs_npc4.png"},
{"mobs_npc5.png"},
{"mobs_npc6.png"},
{"mobs_npc7.png"},
{"mobs_npc8.png"},
{"mobs_npc9.png"},
{"mobs_npc10.png"},
{"mobs_npc11.png"},
{"mobs_npc12.png"},
{"mobs_npc13.png"},
{"mobs_npc14.png"}, {"mobs_npc15.png"}, {"mobs_npc16.png"}, {"mobs_npc17.png"}, {"mobs_npc18.png"}, {"mobs_npc19.png"}, {"mobs_npc20.png"}, {"mobs_npc21.png"}, {"mobs_npc22.png"}, {"mobs_npc23.png"}, {"mobs_npc24.png"}, {"mobs_npc25.png"}, {"mobs_npc26.png"}, {"mobs_npc27.png"}, {"mobs_npc28.png"}, {"mobs_npc29.png"}, {"mobs_npc30.png"}, {"mobs_npc31.png"}, {"mobs_npc32.png"}, {"mobs_npc33.png"}, {"mobs_npc34.png"}, {"mobs_npc35.png"}, {"mobs_npc36.png"}, {"mobs_npc37.png"}, {"mobs_npc38.png"}, {"mobs_npc39.png"}, {"mobs_npc40.png"}, {"mobs_npc41.png"}, {"mobs_npc42.png"}, {"mobs_npc43.png"}, {"mobs_npc44.png"}, {"mobs_npc45.png"}, {"mobs_npc46.png"}, {"mobs_npc47.png"}, {"mobs_npc48.png"}, {"mobs_npc49.png"}, {"mobs_npc50.png"}, -- female by nuttmeg20
},
child_texture = {
{"mobs_npc_baby.png"}, -- derpy baby by AmirDerAssassine
},
makes_footstep_sound = true,
sounds = {},
walk_velocity = 2,
run_velocity = 3,
jump = false,
drops = {
{name = "none", chance = 1, min = 1, max = 3},
{name = "none", chance = 2, min = 1, max = 2},
{name = "none", chance = 5, min = 1, max = 1},
},
water_damage = 0,
lava_damage = 2,
light_damage = 0,
follow = {"farming:bread", "mobs:meat", "default:diamond"},
view_range = 15,
owner = "",
order = "follow",
fear_height = 3,
animation = {
speed_normal = 30,
speed_run = 30,
stand_start = 0,
stand_end = 79,
walk_start = 168,
walk_end = 187,
run_start = 168,
run_end = 187,
punch_start = 200,
punch_end = 219,
},
on_rightclick = function(self, clicker)

-- feed to heal npc
if mobs:feed_tame(self, clicker, 8, true, true) then
return
end

local item = clicker:get_wielded_item()
local name = clicker:get_player_name()

-- right clicking with gold lump drops random item from mobs.npc_drops
if item:get_name() == "default:gold_lump" then

if not minetest.setting_getbool("creative_mode") then
item:take_item()
clicker:set_wielded_item(item)
end

local pos = self.object:getpos()

pos.y = pos.y + 0.5

minetest.add_item(pos, {
name = mobs.npc_drops[math.random(1, #mobs.npc_drops)]
})

minetest.chat_send_player(name, S("NPC dropped you an item for gold!"))

return
end

-- capture npc with net or lasso
mobs:capture_mob(self, clicker, 0, 5, 80, false, nil)

-- by right-clicking owner can switch npc between follow and stand
if self.owner and self.owner == name then

if self.order == "follow" then
self.order = "stand"

minetest.chat_send_player(name, S("NPC stands still."))
else
self.order = "follow"

minetest.chat_send_player(name, S("NPC will follow you."))
end
end

end,
})

--mobs:register_spawn("mobs:npc", {"default:dirt_with_grass"}, 20, 0, 7000, 1, 31000)
--mobs:spawn_specific("mobs:npc", {"default:brick"}, {"air"}, 0, 15, 1, 1, 1, 0, 200, true)

mobs:register_egg("mobs_npc:npc", S("Npc"), "default_brick.png", 1)

-- compatibility
mobs:alias_mob("mobs:npc", "mobs_npc:npc")

Re: Help With npc roaming

PostPosted: Sat Sep 24, 2016 19:41
by TenPlus1
add another option for self.order = "" on register, then it'll just walk around :)

Re: Help With npc roaming

PostPosted: Sat Sep 24, 2016 20:56
by The Glitch Rabbit
TenPlus1, Do I put anything in the quotes ""

Re: Help With npc roaming

PostPosted: Fri Sep 30, 2016 21:14
by The Glitch Rabbit
I've tried making a new command for them to wonder around... it's not working for me.

Re: Help With npc roaming

PostPosted: Sat Oct 01, 2016 07:46
by TenPlus1
Try something like this:

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
-- by right-clicking owner can switch npc between follow and stand
if self.owner and self.owner == name then

    if self.order == "follow" then
        self.order = "stand"

         minetest.chat_send_player(name, S("NPC stands still."))
    elseif self.order == "stand" then
        self.order = ""
        self.following = nil

        minetest.chat_send_player(name, S("NPC will roam around."))
    elseif self.order == "" then
        self.order = "follow"

        minetest.chat_send_player(name, S("NPC will follow you."))
    end
end