Merge pull request #1 from CiaranG/master

A few little fixes
This commit is contained in:
stujones11 2014-04-07 16:27:43 +01:00
commit 50eeef5eec
4 changed files with 44 additions and 7 deletions

1
npcf/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
npcf.conf

View File

@ -58,6 +58,15 @@ minetest.register_chatcommand("npcf", {
minetest.chat_send_player(name, "Invalid position "..args)
end
end
elseif cmd == "tell" then
if admin or name == index[npc_name] then
local luaentity = npcf:get_luaentity(npc_name)
if luaentity and luaentity.on_tell then
luaentity.on_tell(luaentity, name, args)
end
else
minetest.chat_send_player(name, "You don't have permission to tell "..npc_name.." things")
end
elseif cmd == "setskin" then
if admin or name == index[npc_name] then
if args == "random" then

View File

@ -276,6 +276,18 @@ function npcf:register_npc(name, def)
def.on_step(self, dtime)
end
end,
on_tell = function(self, sender, message)
if type(def.on_tell) == "function" and get_valid_entity(self) then
local player = minetest.get_player_by_name(sender)
local senderpos
if player then
senderpos = player:getpos()
else
senderpos = {0,0,0}
end
def.on_tell(self, sender, senderpos, message)
end
end,
get_staticdata = function(self)
local npc_data = {
name = self.name,
@ -317,7 +329,7 @@ function npcf:register_npc(name, def)
local player_name = puncher:get_player_name()
local admin = minetest.check_player_privs(player_name, {server=true})
if admin or player_name == owner then
minetest.dig_node(pos)
minetest.remove_node(pos)
if player_name == owner then
puncher:get_inventory():add_item("main", node)
end
@ -340,7 +352,7 @@ function npcf:register_npc(name, def)
minetest.chat_send_player(player_name, "Error: Invalid NPC Name!")
return
end
minetest.dig_node(pos)
minetest.remove_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, {

View File

@ -73,6 +73,20 @@ npcf:register_npc("npcf:deco_npc" ,{
npcf:set_animation(self, ANIMATION[self.metadata.anim_stop].state)
end,
on_activate = function(self, staticdata, dtime_s)
-- Deal with legacy errors where these fields sometimes had
-- invalid values...
if self.metadata.follow_players == true then
self.metadata.follow_players = "true"
elseif self.metadata.follow_players == false then
self.metadata.follow_players = "false"
end
if self.metadata.free_roaming == true then
self.metadata.free_roaming = "true"
elseif self.metadata.free_roaming == false then
self.metadata.free_roaming = "false"
end
if self.metadata.follow_players == "true" then
self.var.target = get_target_player(self)
end
@ -83,20 +97,21 @@ npcf:register_npc("npcf:deco_npc" ,{
if self.metadata.message then
message = minetest.formspec_escape(self.metadata.message)
end
local formspec = "label[0,0;"..message.."]"
local formspec
if player_name == self.owner then
local selected_id = ANIMATION[self.metadata.anim_stop].id or ""
self.metadata.free_roaming = false
self.metadata.follow_players = false
formspec = "size[8,4.0]"
.."field[0.5,1.0;7.5,0.5;message;Message;"..message.."]"
.."label[0.5,1.8;Stationary Animation\\:]"
.."dropdown[4.0,1.8;3.5;anim_stop;Stand,Sit,Lay,Mine;"..selected_id.."]"
.."checkbox[0.5,2.7;follow_players;Follow Players;false]"
.."checkbox[0.5,2.7;follow_players;Follow Players;"..self.metadata.follow_players.."]"
.."button_exit[7.0,3.5;1.0,0.5;;Ok]"
if NPCF_DECO_FREE_ROAMING == true then
formspec = formspec.."checkbox[3.5,2.7;free_roaming;Wander Map;false]"
formspec = formspec.."checkbox[3.5,2.7;free_roaming;Wander Map;"..self.metadata.free_roaming.."]"
end
else
formspec = "size[8,4]"
.."label[0,0;"..message.."]"
end
self.var.speed = 0
npcf:show_formspec(player_name, self.npc_name, formspec)