mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-11-19 13:38:00 +01:00
added custom effect copy_prop_from_n_id
This commit is contained in:
parent
dcc7125659
commit
5cfa446d00
@ -638,6 +638,68 @@ yl_speak_up.custom_functions_r_[ "var0_eq_var1_op_var2" ] = {
|
||||
}
|
||||
|
||||
|
||||
yl_speak_up.custom_functions_r_[ "copy_prop_from_n_id" ] = {
|
||||
description = "Set a <property0> to the value of <property1> of NPC <n_id>.",
|
||||
param1_text = "Property to set:",
|
||||
param1_desc = "Which property of *this* NPC do you want to set?",
|
||||
param2_text = "Copy property named:",
|
||||
param2_desc = "Which property do you want to copy from the *other* NPC?"..
|
||||
"\nSupports $PROP property_name$ and $VAR var_name$ replacements."..
|
||||
"\nNote: Property name cannot start with \'server\' or \'self.\'.",
|
||||
param3_text = "Copy from NPC ID (n_id):",
|
||||
param3_desc = "Which NPC holds the property you want to copy?"..
|
||||
"\nNote: Both NPC need to have the same owner.",
|
||||
code = function(player, n_id, r)
|
||||
if(not(r) or not(r.r_param1) or r.r_param1 == ""
|
||||
or not(r.r_param2) or r.r_param2 == ""
|
||||
or not(r.r_param3) or r.r_param3 == "") then
|
||||
return false
|
||||
end
|
||||
local pname = player:get_player_name()
|
||||
local owner = yl_speak_up.npc_owner[ n_id ]
|
||||
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
local to_prop = r.r_param1
|
||||
local from_prop = r.r_param2
|
||||
local from_n_id = r.r_param3
|
||||
from_n_id = tonumber(string.sub(from_n_id, 3) or "")
|
||||
-- replacements are *allowed* for from_prop - this makes it easier to let
|
||||
-- generic NPC request specific data for them by including their name/ID
|
||||
-- in the property name:
|
||||
from_prop = yl_speak_up.replace_vars_in_text(from_prop, dialog, pname)
|
||||
if( string.sub(to_prop, 1, 5) == "self."
|
||||
or string.sub(from_prop, 1, 5) == "self."
|
||||
or string.sub(to_prop, 1, 6) == "server"
|
||||
or string.sub(from_prop, 1, 6) == "server") then
|
||||
return false
|
||||
end
|
||||
if(not(yl_speak_up.npc_list)
|
||||
or not(yl_speak_up.npc_list[from_n_id])
|
||||
or not(yl_speak_up.npc_list[from_n_id].properties)
|
||||
or not(yl_speak_up.npc_list[from_n_id].properties[from_prop])) then
|
||||
yl_speak_up.debug_msg(player, n_id, o_id, tostring(r.r_id).." "..
|
||||
"ERROR: property or source NPC not found.")
|
||||
return false
|
||||
end
|
||||
local new_value = yl_speak_up.npc_list[from_n_id].properties[from_prop]
|
||||
-- the owner needs to be able to edit the npc from which to copy
|
||||
if(owner ~= yl_speak_up.npc_list[from_n_id].owner) then
|
||||
yl_speak_up.debug_msg(player, n_id, o_id, tostring(r.r_id).." "..
|
||||
"ERROR: NPC owners do not match.")
|
||||
return false
|
||||
end
|
||||
-- actually set the property
|
||||
yl_speak_up.set_npc_property(pname, to_prop, new_value, "manually")
|
||||
yl_speak_up.debug_msg(player, n_id, o_id, tostring(r.r_id).." "..
|
||||
"state: Success: Setting property "..
|
||||
tostring(to_prop).." to ".. tostring(new_value)..
|
||||
" (copied from NPC "..tostring(from_n_id)..
|
||||
" and property "..tostring(from_prop)..").")
|
||||
return ret
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
yl_speak_up.custom_functions_r_[ "play_sound" ] = {
|
||||
description = "Plays a sound.",
|
||||
param1_text = "Name of the sound(file):",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user