fixed bug in tools when pointing at players; used a function instead of cut&paste
This commit is contained in:
parent
573753b80d
commit
4e16cc760a
141
tools.lua
141
tools.lua
@ -1,28 +1,44 @@
|
|||||||
minetest.register_tool("yl_speak_up:staff_of_i_said_so", {
|
|
||||||
description = "Staff of I-said-so",
|
|
||||||
inventory_image = "yl_speak_up_staff_of_i_said_so.png",
|
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
|
||||||
|
|
||||||
|
yl_speak_up.allow_staff_use = function(itemstack, user, pointed_thing)
|
||||||
local has_priv = minetest.check_player_privs(user, {npc_master=true})
|
local has_priv = minetest.check_player_privs(user, {npc_master=true})
|
||||||
local p_name = user:get_player_name()
|
local p_name = user:get_player_name()
|
||||||
|
|
||||||
if not has_priv then
|
if not has_priv then
|
||||||
minetest.chat_send_player(p_name,yl_speak_up.message_tool_taken_because_of_lacking_priv)
|
minetest.chat_send_player(p_name,yl_speak_up.message_tool_taken_because_of_lacking_priv)
|
||||||
minetest.log("action","[MOD] yl_speak_up: User "..p_name.." used an admin item: "..itemstack:get_name().." at pos "..minetest.pos_to_string(user:get_pos(),0))
|
minetest.log("action","[MOD] yl_speak_up: User "..p_name..
|
||||||
|
" used an admin item: "..itemstack:get_name()..
|
||||||
|
" at pos "..minetest.pos_to_string(user:get_pos(),0))
|
||||||
itemstack:take_item(1)
|
itemstack:take_item(1)
|
||||||
return itemstack
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if (pointed_thing.type ~= "object") then
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if (pointed_thing.type == "object") then
|
|
||||||
local obj = pointed_thing.ref
|
local obj = pointed_thing.ref
|
||||||
local luaentity = obj:get_luaentity()
|
local luaentity = obj:get_luaentity()
|
||||||
|
|
||||||
if luaentity ~= nil and luaentity.yl_speak_up == nil then return itemstack end -- Is the thing we clicked really one of our NPCs?
|
-- Is the thing we clicked really one of our NPCs?
|
||||||
|
if not(luaentity) or (luaentity and not(luaentity.yl_speak_up)) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
return obj
|
||||||
|
end
|
||||||
|
|
||||||
yl_speak_up.config(user, obj)
|
|
||||||
|
|
||||||
|
minetest.register_tool("yl_speak_up:staff_of_i_said_so", {
|
||||||
|
description = "Staff of I-said-so",
|
||||||
|
inventory_image = "yl_speak_up_staff_of_i_said_so.png",
|
||||||
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
|
||||||
|
local obj = yl_speak_up.allow_staff_use(itemstack, user, pointed_thing)
|
||||||
|
if(not(obj)) then
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
yl_speak_up.config(user, obj)
|
||||||
|
return itemstack
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -31,29 +47,23 @@ minetest.register_tool("yl_speak_up:staff_of_shut_up", {
|
|||||||
inventory_image = "yl_speak_up_staff_of_shut_up.png",
|
inventory_image = "yl_speak_up_staff_of_shut_up.png",
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
|
||||||
local has_priv = minetest.check_player_privs(user, {npc_master=true})
|
local obj = yl_speak_up.allow_staff_use(itemstack, user, pointed_thing)
|
||||||
|
if(not(obj)) then
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
local p_name = user:get_player_name()
|
local p_name = user:get_player_name()
|
||||||
|
|
||||||
if not has_priv then
|
|
||||||
minetest.chat_send_player(p_name,yl_speak_up.message_tool_taken_because_of_lacking_priv)
|
|
||||||
minetest.log("action","[MOD] yl_speak_up: User "..p_name.." used an admin item: "..itemstack:get_name().." at pos "..minetest.pos_to_string(user:get_pos(),0))
|
|
||||||
itemstack:take_item(1)
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
|
|
||||||
if (pointed_thing.type == "object") then
|
|
||||||
local obj = pointed_thing.ref
|
|
||||||
local luaentity = obj:get_luaentity()
|
local luaentity = obj:get_luaentity()
|
||||||
|
|
||||||
if luaentity ~= nil and luaentity.yl_speak_up == nil then return itemstack end -- Is the thing we clicked really one of our NPCs?
|
|
||||||
|
|
||||||
luaentity.yl_speak_up.talk = false
|
|
||||||
local npc = luaentity.yl_speak_up.id
|
local npc = luaentity.yl_speak_up.id
|
||||||
minetest.chat_send_player(p_name,"NPC with ID "..npc.." will shut up at pos "..minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
luaentity.yl_speak_up.talk = false
|
||||||
minetest.log("action","[MOD] yl_speak_up: NPC with ID n_"..npc.." will shut up at pos "..minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
|
||||||
|
minetest.chat_send_player(p_name,"NPC with ID "..npc.." will shut up at pos "..
|
||||||
|
minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
||||||
|
minetest.log("action","[MOD] yl_speak_up: NPC with ID n_"..npc..
|
||||||
|
" will shut up at pos "..minetest.pos_to_string(obj:get_pos(),0)..
|
||||||
|
" on command of "..p_name)
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
end
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_tool("yl_speak_up:staff_of_dawai_dawai", {
|
minetest.register_tool("yl_speak_up:staff_of_dawai_dawai", {
|
||||||
@ -61,29 +71,23 @@ minetest.register_tool("yl_speak_up:staff_of_dawai_dawai", {
|
|||||||
inventory_image = "yl_speak_up_staff_of_dawai_dawai.png",
|
inventory_image = "yl_speak_up_staff_of_dawai_dawai.png",
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
|
||||||
local has_priv = minetest.check_player_privs(user, {npc_master=true})
|
local obj = yl_speak_up.allow_staff_use(itemstack, user, pointed_thing)
|
||||||
|
if(not(obj)) then
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
local p_name = user:get_player_name()
|
local p_name = user:get_player_name()
|
||||||
|
|
||||||
if not has_priv then
|
|
||||||
minetest.chat_send_player(p_name,yl_speak_up.message_tool_taken_because_of_lacking_priv)
|
|
||||||
minetest.log("action","[MOD] yl_speak_up: User "..p_name.." used an admin item: "..itemstack:get_name().." at pos "..minetest.pos_to_string(user:get_pos(),0))
|
|
||||||
itemstack:take_item(1)
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
|
|
||||||
if (pointed_thing.type == "object") then
|
|
||||||
local obj = pointed_thing.ref
|
|
||||||
local luaentity = obj:get_luaentity()
|
local luaentity = obj:get_luaentity()
|
||||||
|
|
||||||
if luaentity ~= nil and luaentity.yl_speak_up == nil then return itemstack end -- Is the thing we clicked really one of our NPCs?
|
|
||||||
|
|
||||||
luaentity.yl_speak_up.talk = true
|
|
||||||
local npc = luaentity.yl_speak_up.id
|
local npc = luaentity.yl_speak_up.id
|
||||||
minetest.chat_send_player(p_name,"NPC with ID "..npc.." will resume speech at pos "..minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
luaentity.yl_speak_up.talk = true
|
||||||
minetest.log("action","[MOD] yl_speak_up: NPC with ID n_"..npc.." will resume speech at pos "..minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
|
||||||
|
minetest.chat_send_player(p_name,"NPC with ID "..npc.." will resume speech at pos "..
|
||||||
|
minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
||||||
|
minetest.log("action","[MOD] yl_speak_up: NPC with ID n_"..npc..
|
||||||
|
" will resume speech at pos "..minetest.pos_to_string(obj:get_pos(),0)..
|
||||||
|
" on command of "..p_name)
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
end
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_tool("yl_speak_up:staff_of_game_over", {
|
minetest.register_tool("yl_speak_up:staff_of_game_over", {
|
||||||
@ -91,29 +95,23 @@ minetest.register_tool("yl_speak_up:staff_of_game_over", {
|
|||||||
inventory_image = "yl_speak_up_staff_of_game_over.png",
|
inventory_image = "yl_speak_up_staff_of_game_over.png",
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
|
||||||
local has_priv = minetest.check_player_privs(user, {npc_master=true})
|
local obj = yl_speak_up.allow_staff_use(itemstack, user, pointed_thing)
|
||||||
local p_name = user:get_player_name()
|
if(not(obj)) then
|
||||||
|
|
||||||
if not has_priv then
|
|
||||||
minetest.chat_send_player(p_name,yl_speak_up.message_tool_taken_because_of_lacking_priv)
|
|
||||||
minetest.log("action","[MOD] yl_speak_up: User "..p_name.." used an admin item: "..itemstack:get_name().." at pos "..minetest.pos_to_string(user:get_pos(),0))
|
|
||||||
itemstack:take_item(1)
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
if (pointed_thing.type == "object") then
|
local p_name = user:get_player_name()
|
||||||
local obj = pointed_thing.ref
|
|
||||||
local luaentity = obj:get_luaentity()
|
local luaentity = obj:get_luaentity()
|
||||||
|
|
||||||
if luaentity ~= nil and luaentity.yl_speak_up == nil then return itemstack end -- Is the thing we clicked really one of our NPCs?
|
|
||||||
|
|
||||||
local npc = luaentity.yl_speak_up.id
|
local npc = luaentity.yl_speak_up.id
|
||||||
minetest.chat_send_player(p_name,"NPC with ID "..npc.." removed from position "..minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
|
||||||
minetest.log("action","[MOD] yl_speak_up: NPC with ID "..npc.." removed from position "..minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
minetest.chat_send_player(p_name,"NPC with ID "..npc.." removed from position "..
|
||||||
|
minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
||||||
|
minetest.log("action","[MOD] yl_speak_up: NPC with ID "..npc..
|
||||||
|
" removed from position "..minetest.pos_to_string(obj:get_pos(),0)..
|
||||||
|
" on command of "..p_name)
|
||||||
obj:remove()
|
obj:remove()
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
end
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_tool("yl_speak_up:staff_of_fashion", {
|
minetest.register_tool("yl_speak_up:staff_of_fashion", {
|
||||||
@ -121,27 +119,20 @@ minetest.register_tool("yl_speak_up:staff_of_fashion", {
|
|||||||
inventory_image = "yl_speak_up_staff_of_fashion.png",
|
inventory_image = "yl_speak_up_staff_of_fashion.png",
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
|
||||||
local has_priv = minetest.check_player_privs(user, {npc_master=true})
|
local obj = yl_speak_up.allow_staff_use(itemstack, user, pointed_thing)
|
||||||
local p_name = user:get_player_name()
|
if(not(obj)) then
|
||||||
|
|
||||||
if not has_priv then
|
|
||||||
minetest.chat_send_player(p_name,yl_speak_up.message_tool_taken_because_of_lacking_priv)
|
|
||||||
minetest.log("action","[MOD] yl_speak_up: User "..p_name.." used an admin item: "..itemstack:get_name().." at pos "..minetest.pos_to_string(user:get_pos(),0))
|
|
||||||
itemstack:take_item(1)
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
if (pointed_thing.type == "object") then
|
local p_name = user:get_player_name()
|
||||||
local obj = pointed_thing.ref
|
|
||||||
local luaentity = obj:get_luaentity()
|
local luaentity = obj:get_luaentity()
|
||||||
|
local npc = luaentity.yl_speak_up.id
|
||||||
if luaentity ~= nil and luaentity.yl_speak_up == nil then return itemstack end -- Is the thing we clicked really one of our NPCs?
|
|
||||||
|
|
||||||
yl_speak_up.fashion(user, obj)
|
yl_speak_up.fashion(user, obj)
|
||||||
local npc = luaentity.yl_speak_up.id
|
minetest.chat_send_player(p_name,"NPC with ID n_"..npc.." will redress at pos "..
|
||||||
minetest.chat_send_player(p_name,"NPC with ID n_"..npc.." will redress at pos "..minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
||||||
minetest.log("action","[MOD] yl_speak_up: NPC with ID n_"..npc.." will redress at pos "..minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
minetest.log("action","[MOD] yl_speak_up: NPC with ID n_"..npc.." will redress at pos "..
|
||||||
|
minetest.pos_to_string(obj:get_pos(),0).." on command of "..p_name)
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
end
|
|
||||||
})
|
})
|
Loading…
Reference in New Issue
Block a user