copied player move code over to fs_edit_effects.lua

This commit is contained in:
Sokomine 2021-06-10 23:34:34 +02:00
parent b684ec3307
commit 7cfad9586a

View File

@ -169,12 +169,14 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r)
-- TODO: how to handle target dialog?
return true
elseif(r.r_type == "function") then
-- this can only be set and edited with the staff
return yl_speak_up.eval_and_execute_function(player, r, "r_")
-- this can only be set and edited with the staff
elseif(r.r_type == "give_item") then
if(not(v.r_value)) then
if(not(r.r_value)) then
return false
end
local item = ItemStack(v.r_value)
local item = ItemStack(r.r_value)
if(not(minetest.registered_items[item:get_name()])) then
yl_speak_up.debug_msg(player, n_id, o_id, tostring(r_id).." "..
"give_item: "..tostring(item:get_name()).." unknown.")
@ -187,11 +189,12 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r)
return false
end
return true
-- this can only be set and edited with the staff
elseif(r.r_type == "take_item") then
if(not(v.r_value)) then
if(not(r.r_value)) then
return false
end
local item = ItemStack(v.r_value)
local item = ItemStack(r.r_value)
if(not(minetest.registered_items[item:get_name()])) then
yl_speak_up.debug_msg(player, n_id, o_id, tostring(r_id).." "..
"take_item: "..tostring(item:get_name()).." unknown.")
@ -204,8 +207,75 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r)
return false
end
return true
-- this can only be set and edited with the staff
elseif(r.r_type == "move") then
-- TODO: copy/adjust effect "move"
-- copeid/moved here from AliasAlreadyTakens code in functions.lua
local target_pos = nil
local target_pos_valid = false
--pos like (100,20,400)
if minetest.string_to_pos(r.r_value) then
target_pos = minetest.string_to_pos(r.r_value)
target_pos_valid = true
end
--pos like 100,20,400
local maybe = string.split(r.r_value, ",")
if not target_pos_valid and maybe and tonumber(maybe[1])
and tonumber(maybe[2]) and tonumber(maybe[3]) and maybe[4] == nil and
tonumber(maybe[1]) <= 32000 and tonumber(maybe[1]) >= -32000 and
tonumber(maybe[2]) <= 32000 and tonumber(maybe[2]) >= -32000 and
tonumber(maybe[3]) <= 32000 and tonumber(maybe[3]) >= -32000 then
target_pos = {x=maybe[1],y=maybe[2],z=maybe[3]}
target_pos_valid = true
end
--pos like {x=100,y=20,z=400}
if not target_pos_valid and string.sub(r.r_value,1,1) == "{"
and string.sub(r.r_value,-1,-1) == "}" then
local might_be_pos = minetest.deserialize("return " .. r.r_value)
if tonumber(might_be_pos.x)
and tonumber(might_be_pos.x) <= 32000
and tonumber(might_be_pos.x) >= -32000
and tonumber(might_be_pos.y)
and tonumber(might_be_pos.y) <= 32000
and tonumber(might_be_pos.y) >= -32000
and tonumber(might_be_pos.z)
and tonumber(might_be_pos.z) <= 32000
and tonumber(might_be_pos.z) >= -32000 then
target_pos = might_be_pos
target_pos_valid = true
end
end
if target_pos_valid == true then
player:set_pos(target_pos)
if vector.distance(player:get_pos(),target_pos) >= 2 then
yl_speak_up.log_change(pname, n_id, tostring(r.r_id)..": "..
"Something went wrong! Player wasn't moved properly.")
end
end
-- Debug
if target_pos_valid == false then
local obj = yl_speak_up.speak_to[pname].obj
local n_id = yl_speak_up.speak_to[pname].n_id
local npc = get_number_from_id(n_id)
if obj:get_luaentity() and tonumber(npc) then
yl_speak_up.log_change(pname, n_id, tostring(r.r_id)..": "..
"NPC at "..minetest.pos_to_string(obj:get_pos(),0)..
" could not move player "..pname.." because the content of "..
tostring(r.r_id).." is wrong:"..dump(r.r_value))
else
yl_speak_up.log_change(pname, n_id, tostring(r.r_id)..": "..
"NPC with unknown ID or without proper object "..
" could not move player "..pname.." because the content of "..
tostring(r.r_id).." is wrong:"..dump(r.r_value))
end
return false
end
return true
-- "an internal state (i.e. of a quest)", -- 2
elseif(r.r_type == "state") then
-- TODO: implement effect "state"