properties starting with "server" can only be changed manually by players with the npc_master priv

This commit is contained in:
Sokomine 2022-08-07 23:18:35 +02:00
parent 5da08359cb
commit b7d0f88790
5 changed files with 20 additions and 6 deletions

View File

@ -350,6 +350,9 @@ and
custom_functions_you_can_override.lua custom_functions_you_can_override.lua
You can also react to or limit normal property changes this way. You can also react to or limit normal property changes this way.
Properties starting with "server" can only be changed by players who have
the npc_master priv.
Example for a property: mood of the NPC (raises when treated well, gets Example for a property: mood of the NPC (raises when treated well, gets
lowered when treated badly). lowered when treated badly).

View File

@ -518,7 +518,7 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r)
local var_val = property_data.properties[r.r_value] local var_val = property_data.properties[r.r_value]
-- set the value of the variable -- set the value of the variable
local new_value = yl_speak_up.execute_effect_get_new_value(r, var_val, nil) local new_value = yl_speak_up.execute_effect_get_new_value(r, var_val, nil)
local res = yl_speak_up.set_npc_property(pname, r.r_value, new_value) local res = yl_speak_up.set_npc_property(pname, r.r_value, new_value, "effect")
if(res ~= "OK") then if(res ~= "OK") then
yl_speak_up.debug_msg(player, n_id, o_id, tostring(r.r_id).." ".. yl_speak_up.debug_msg(player, n_id, o_id, tostring(r.r_id).." "..
"property: "..tostring(res)) "property: "..tostring(res))

View File

@ -1653,6 +1653,8 @@ yl_speak_up.get_fs_edit_option_p_and_e_property = function(
"hypertext[1.2,7.0;16.0,2.5;some_text;<normal>".. "hypertext[1.2,7.0;16.0,2.5;some_text;<normal>"..
"<b>Note:</b> Properties are useful for NPC that have a generic ".. "<b>Note:</b> Properties are useful for NPC that have a generic "..
"behaviour and may vary their behaviour slightly.\n".. "behaviour and may vary their behaviour slightly.\n"..
"Properties starting with \"server\" can only be set or changed by "..
"players with the \"npc_master\" privilege."..
"</normal>]" "</normal>]"
end end

View File

@ -42,7 +42,7 @@ yl_speak_up.get_npc_properties = function(pname)
end end
yl_speak_up.set_npc_property = function(pname, property_name, property_value) yl_speak_up.set_npc_property = function(pname, property_name, property_value, reason)
if(not(pname) or not(property_name) or property_name == "") then if(not(pname) or not(property_name) or property_name == "") then
return "No player name or property name given. Cannot load property data." return "No player name or property name given. Cannot load property data."
end end
@ -59,7 +59,16 @@ yl_speak_up.set_npc_property = function(pname, property_name, property_value)
end end
-- properties of type self. are not set directly -- properties of type self. are not set directly
if(string.sub(property_name, 1, 5) == "self.") then if(string.sub(property_name, 1, 5) == "self.") then
return "This properties of the type \"self.\" cannot be modified." return "Properties of the type \"self.\" cannot be modified."
end
-- properites starting with "server" can only be changed or added manually by
-- players with the npc_master priv
if(string.sub(property_name, 1, 6) == "server") then
if(not(reason) or reason ~= "manually" or not(pname)
or not(minetest.check_player_privs(pname, {npc_master=true}))) then
return "Properties starting with \"server\" can only be changed by players "..
"who have the \"npc_master\" priv."
end
end end
-- store it -- store it
property_data.entity.yl_speak_up.properties[property_name] = property_value property_data.entity.yl_speak_up.properties[property_name] = property_value
@ -82,11 +91,11 @@ yl_speak_up.input_properties = function(player, formname, fields)
local selected_row = nil local selected_row = nil
if(fields and fields.store_new_val and fields.store_new_val ~= "" and fields.prop_val) then if(fields and fields.store_new_val and fields.store_new_val ~= "" and fields.prop_val) then
yl_speak_up.set_npc_property(pname, fields.prop_name, fields.prop_val) yl_speak_up.set_npc_property(pname, fields.prop_name, fields.prop_val, "manually")
elseif(fields and fields.delete_prop and fields.delete_prop ~= "") then elseif(fields and fields.delete_prop and fields.delete_prop ~= "") then
-- delete the old property -- delete the old property
yl_speak_up.set_npc_property(pname, fields.prop_name, nil) yl_speak_up.set_npc_property(pname, fields.prop_name, nil, "manually")
elseif(fields and fields.table_of_properties) then elseif(fields and fields.table_of_properties) then
local selected = minetest.explode_table_event(fields.table_of_properties) local selected = minetest.explode_table_event(fields.table_of_properties)

View File

@ -39,7 +39,7 @@ yl_speak_up.input_talk = function(player, formname, fields)
end end
if(new_move_order ~= "") then if(new_move_order ~= "") then
local dialog = yl_speak_up.speak_to[pname].dialog local dialog = yl_speak_up.speak_to[pname].dialog
yl_speak_up.set_npc_property(pname, "self.order", new_move_order) yl_speak_up.set_npc_property(pname, "self.order", new_move_order, "move_order")
minetest.chat_send_player(pname, minetest.chat_send_player(pname,
tostring(dialog.n_npc or "NPC").." tells you: ".. tostring(dialog.n_npc or "NPC").." tells you: "..
"Ok. I will "..tostring(new_move_order)..".") "Ok. I will "..tostring(new_move_order)..".")