From b60d5b03d066c51a3f1bb5a11b7e30e1c976664c Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sat, 12 Jun 2021 01:07:08 +0200 Subject: [PATCH] added effect state change of variable --- fs_edit_effects.lua | 22 +++++++++++++++++++++- quest_api.lua | 8 ++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/fs_edit_effects.lua b/fs_edit_effects.lua index 5cb3cab..1bd75ea 100644 --- a/fs_edit_effects.lua +++ b/fs_edit_effects.lua @@ -360,7 +360,27 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r) -- "an internal state (i.e. of a quest)", -- 2 elseif(r.r_type == "state") then - -- TODO: implement effect "state" + if(not(r.r_variable) or r.r_variable == "") then + return false + end + local pname = player:get_player_name() + local owner = yl_speak_up.npc_owner[ n_id ] + -- set the value of the variable + local new_value = nil + if( r.r_operator and r.r_operator == "set_to") then + new_value = r.r_var_cmp_value + elseif(r.r_operator and r.r_operator == "unset") then + new_value = nil + else + yl_speak_up.debug_msg(player, n_id, o_id, tostring(r.r_id).." ".. + "state: Unsupported type: "..tostring(r.r_value)..".") + return false + end + local ret = yl_speak_up.set_quest_variable_value(owner, pname, r.r_variable, new_value) + yl_speak_up.debug_msg(player, n_id, o_id, tostring(r.r_id).." ".. + "state: Success: "..tostring(ret).." for setting "..tostring(r.r_variable).." to ".. + tostring(new_value)..".") + return ret -- "a block somewhere" -- 3 elseif(r.r_type == "block") then -- is the position given correctly? diff --git a/quest_api.lua b/quest_api.lua index fca2717..4f5b4e1 100644 --- a/quest_api.lua +++ b/quest_api.lua @@ -3,6 +3,14 @@ yl_speak_up.player_vars = {} +-- set the value of a variable used by a player in an NPC +yl_speak_up.set_quest_variable_value = function(owner_name, current_player_name, variable_name, new_value) + -- TODO: actually implement + minetest.chat_send_player(current_player_name, "[Info] Trying to set variable ".. + tostring(variable_name).." to "..tostring(new_value)..".") + return false +end + -- get the value of a variable used by a player in an NPC yl_speak_up.get_quest_variable_value = function(owner_name, current_player_name, variable_name) -- TODO: actually implement