Add facedir to NPC placement and update chatcommands

This commit is contained in:
stujones11 2013-10-08 20:17:06 +01:00
parent f4dfba13b4
commit 0a05f8c08d
2 changed files with 10 additions and 4 deletions

View File

@ -87,7 +87,6 @@ minetest.register_chatcommand("npcf", {
if cmd and npc_name then
if cmd == "delete" and admin then
npcf:clear(npc_name)
minetest.log("action", name.." deletes NPC "..npc_name)
local input = io.open(NPCF_DATADIR.."/"..npc_name..".npc", "r")
if input then
io.close(input)
@ -100,6 +99,7 @@ minetest.register_chatcommand("npcf", {
output:write(minetest.serialize(index))
io.close(output)
end
minetest.log("action", name.." deletes NPC "..npc_name)
end
elseif cmd == "clear" then
if admin or name == index[npc_name] then

View File

@ -64,7 +64,7 @@ local default_npc = {
},
animation_speed = 30,
decription = "Default NPC",
inventory_image = "npcf_info_inv.png",
inventory_image = "npcf_inv_top.png",
show_nametag = true,
nametag_color = "white",
metadata = {},
@ -296,7 +296,8 @@ function npcf:register_npc(name, def)
minetest.register_node(name.."_spawner", {
description = def.description,
inventory_image = minetest.inventorycube("npcf_inv_top.png", def.inventory_image, def.inventory_image),
tiles = {def.inventory_image, def.inventory_image, def.inventory_image},
tiles = {"npcf_inv_top.png", def.inventory_image, def.inventory_image},
paramtype2 = "facedir",
groups = groups,
sounds = default.node_sound_defaults(),
on_construct = function(pos)
@ -341,9 +342,11 @@ function npcf:register_npc(name, def)
end
minetest.dig_node(pos)
local npc_pos = {x=pos.x, y=pos.y + 0.5, z=pos.z}
local yaw = sender:get_look_yaw() + math.pi * 0.5
local luaentity = npcf:spawn(npc_pos, name, {
owner = player_name,
npc_name = fields.name,
origin = {pos=npc_pos, yaw=yaw}
})
if luaentity and type(def.on_registration) == "function" then
def.on_registration(luaentity, pos, sender)
@ -360,10 +363,13 @@ function npcf:spawn(pos, name, def)
if entity then
local luaentity = entity:get_luaentity()
if luaentity then
index[def.npc_name] = def.owner
luaentity.owner = def.owner
luaentity.npc_name = def.npc_name
luaentity.origin = def.origin or {pos=pos, yaw=0}
index[def.npc_name] = def.owner
if def.origin then
luaentity.object:setyaw(luaentity.origin.yaw)
end
if npcf:save(luaentity) then
local output = io.open(NPCF_DATADIR.."/index.txt", 'w')
if output then