Compare commits
5 Commits
567b95fd6c
...
22865372bf
Author | SHA1 | Date |
---|---|---|
Alexsandro Percy | 22865372bf | |
Alexsandro Percy | 834bd5109b | |
Alexsandro Percy | 2d4e1db097 | |
Alexsandro Percy | ca70e6ae5c | |
Alexsandro Percy | 4c985f126f |
177
init.lua
|
@ -26,11 +26,11 @@ else
|
|||
S = function ( s ) return s end
|
||||
end
|
||||
|
||||
local hud_default_x=0.4
|
||||
local hud_default_y=0.01
|
||||
local hud_default_x=0.5
|
||||
local hud_default_y=0.8
|
||||
local hud_default_color="FFFF00"
|
||||
local compass_default_type="c"
|
||||
local compass_valid_types={"a","b","c"}
|
||||
local compass_valid_types={"a","b","c", "d"}
|
||||
local activewidth=8 --until I can find some way to get it from minetest
|
||||
local max_shared=10 --how many shared bookmarks a user with shared_bookmarks priv can make.
|
||||
local show_shared_on_singleplayer=false --show shared and admin checkboxes on singleplayer
|
||||
|
@ -362,7 +362,7 @@ function compassgps.bookmark_loop(mode,playername,findidx)
|
|||
--minetest.chat_send_player(playername, vbkmrkname..": "..compassgps.pos_to_string(v))
|
||||
minetest.chat_send_player(playername, compassgps.bookmark_name_pos_dist(v,playername,playerpos))
|
||||
end
|
||||
end --if vtype
|
||||
end --if vtype
|
||||
|
||||
--print("bookmark_loop mode="..mode.." bkmrkidx="..bkmrkidx.." vbkmkrname="..vbkmrkname.." point_to="..point_to[playername].bkmrkname.." vplayer="..vplayer.." point_to="..point_to[playername].player)
|
||||
--set testlist_clicked to the currently selected item in the list
|
||||
|
@ -454,22 +454,38 @@ minetest.register_on_player_receive_fields(function(player,formname,fields)
|
|||
--this leaves open the possibility of someone typing in the hudx or hudy
|
||||
--field and hitting enter after typing in the bookmark field. Not likely
|
||||
if (fields["new_bookmark"] and fields["bookmark"]) --hit the bookmark button
|
||||
or ( (fields["bookmark"]) and (fields["bookmark"]~="") --bookmark field not blank
|
||||
and (not fields["remove_bookmark"]) and (not fields["find_bookmark"])
|
||||
and (not fields["bookmark_list"]) and (not fields["sort_type"])
|
||||
and (not fields["distance_type"]) and (not fields["settings"])
|
||||
and (not fields["teleport"]) and (not fields["show_private"])
|
||||
and (not fields["show_shared"]) and (not fields["show_admin"])
|
||||
or ( (fields["bookmark"]) and (fields["bookmark"]~="") --bookmark field not blank
|
||||
and (not fields["remove_bookmark"]) and (not fields["find_bookmark"])
|
||||
and (not fields["bookmark_list"]) and (not fields["sort_type"])
|
||||
and (not fields["distance_type"]) and (not fields["settings"])
|
||||
and (not fields["teleport"]) and (not fields["show_private"])
|
||||
and (not fields["show_shared"]) and (not fields["show_admin"])
|
||||
)
|
||||
then
|
||||
local type="P"
|
||||
if fields["new_shared_bookmark"] then
|
||||
type="S"
|
||||
elseif fields["new_admin_bookmark"] then
|
||||
type="A"
|
||||
end --shared or admin
|
||||
compassgps.set_bookmark(playername, fields["bookmark"],type)
|
||||
minetest.show_formspec(playername, compassgps.get_compassgps_formspec(playername))
|
||||
local type="P"
|
||||
if fields["new_shared_bookmark"] then
|
||||
type="S"
|
||||
elseif fields["new_admin_bookmark"] then
|
||||
type="A"
|
||||
end --shared or admin
|
||||
|
||||
--lets limmit to 5 for normal users
|
||||
if type=="P" and not minetest.check_player_privs(player, {protection_bypass=true}) then
|
||||
local c=0
|
||||
for k,v in pairs(bookmarks) do
|
||||
if v.player and v.player==playername and v.type and v.type=="P" then
|
||||
c=c+1
|
||||
end --if
|
||||
end --for
|
||||
local limit = 5
|
||||
if c >= limit then
|
||||
minetest.chat_send_player(playername,S("You have reached the limit of " .. tostring(limit) .." bookmarks. Delete some records to be able to add a new one"))
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
compassgps.set_bookmark(playername, fields["bookmark"],type)
|
||||
minetest.show_formspec(playername, compassgps.get_compassgps_formspec(playername))
|
||||
elseif fields["remove_bookmark"] and textlist_clicked[playername] then
|
||||
local bkmrkidx=textlist_clicked[playername]
|
||||
if textlist_bkmrks[playername][bkmrkidx].player ~= playername then
|
||||
|
@ -563,6 +579,8 @@ minetest.register_on_player_receive_fields(function(player,formname,fields)
|
|||
compass_type[playername]="b"
|
||||
elseif fields["compass_type_c"] then
|
||||
compass_type[playername]="c"
|
||||
elseif fields["compass_type_d"] then
|
||||
compass_type[playername]="d"
|
||||
end --if fields["hud_pos"]
|
||||
elseif (playername ~= "" and formname == "compassgps:confirm_remove") then
|
||||
if fields["confirm_remove_yes"] then
|
||||
|
@ -640,7 +658,26 @@ function compassgps.clean_string(str)
|
|||
return str
|
||||
end --clean_string
|
||||
|
||||
local function locate( table, value )
|
||||
for i = 1, #table do
|
||||
if table[i] == value then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function check_is_inside_forbiden_area(pos)
|
||||
local table = {"fbd"}
|
||||
if areas then
|
||||
local areasAtPos = areas:getAreasAtPos(pos)
|
||||
for id, area in pairs(areasAtPos) do
|
||||
--minetest.chat_send_all(dump(area.name))
|
||||
if locate( table, area.name ) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function compassgps.set_bookmark(playername, bkmrkname, type, predefinedpos)
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
|
@ -649,6 +686,10 @@ function compassgps.set_bookmark(playername, bkmrkname, type, predefinedpos)
|
|||
end
|
||||
|
||||
local pos = player:getpos()
|
||||
|
||||
local is_forbiden = check_is_inside_forbiden_area(pos)
|
||||
if minetest.check_player_privs(player, {protection_bypass=true}) then is_forbiden = false end
|
||||
|
||||
if predefinedpos ~= nil then
|
||||
pos = predefinedpos
|
||||
end
|
||||
|
@ -662,6 +703,7 @@ function compassgps.set_bookmark(playername, bkmrkname, type, predefinedpos)
|
|||
return
|
||||
end
|
||||
if bkmrkname == "default" or bkmrkname == "bed" or bkmrkname == "sethome"
|
||||
or is_forbiden == true
|
||||
or string.sub(bkmrkname,1,8) == "*shared*"
|
||||
or string.sub(bkmrkname,1,7)=="*admin*" then
|
||||
minetest.chat_send_player(playername, S("A bookmark with the name '%s' can't be created."):format(bkmrkname))
|
||||
|
@ -824,7 +866,7 @@ function compassgps.teleport_bookmark(playername, bkmrkidx)
|
|||
compassgps.bookmark_name_string(textlist_bkmrks[playername][bkmrkidx])))
|
||||
minetest.chat_send_player(playername, S("Teleporting to %s"):format(
|
||||
compassgps.bookmark_name_string(textlist_bkmrks[playername][bkmrkidx])))
|
||||
player:setpos(textlist_bkmrks[playername][bkmrkidx])
|
||||
player:set_pos(textlist_bkmrks[playername][bkmrkidx])
|
||||
end --teleport_bookmark
|
||||
|
||||
|
||||
|
@ -1013,52 +1055,63 @@ minetest.register_globalstep(function(dtime)
|
|||
local stackidx=0
|
||||
--first check to see if the user has a compass, because if they don't
|
||||
--there is no reason to waste time calculating bookmarks or spawnpoints.
|
||||
local wielded_item = player:get_wielded_item():get_name()
|
||||
if string.sub(wielded_item, 0, 11) == "compassgps:" and string.sub(wielded_item, 0, 18) ~= "compassgps:cgpsmap" then
|
||||
--if the player is wielding a compass, change the wielded image
|
||||
wielded=true
|
||||
stackidx=player:get_wield_index()
|
||||
gotacompass=true
|
||||
else
|
||||
--check to see if compass is in active inventory
|
||||
if player:get_inventory() then
|
||||
--is there a way to only check the activewidth items instead of entire list?
|
||||
--problem being that arrays are not sorted in lua
|
||||
for i,stack in ipairs(player:get_inventory():get_list("main")) do
|
||||
if i<=activewidth and string.sub(stack:get_name(), 0, 11) == "compassgps:" and string.sub(stack:get_name(),0,18) ~= "compassgps:cgpsmap" then
|
||||
activeinv=stack --store the stack so we can update it later with new image
|
||||
stackidx=i --store the index so we can add image at correct location
|
||||
gotacompass=true
|
||||
break
|
||||
end --if i<=activewidth
|
||||
end --for loop
|
||||
end -- get_inventory
|
||||
local wielded_item = player:get_wielded_item():get_name()
|
||||
if string.sub(wielded_item, 0, 11) == "compassgps:" and string.sub(wielded_item, 0, 18) ~= "compassgps:cgpsmap" then
|
||||
--if the player is wielding a compass, change the wielded image
|
||||
wielded=true
|
||||
stackidx=player:get_wield_index()
|
||||
gotacompass=true
|
||||
else
|
||||
--check to see if compass is in active inventory
|
||||
if player:get_inventory() then
|
||||
--is there a way to only check the activewidth items instead of entire list?
|
||||
--problem being that arrays are not sorted in lua
|
||||
for i,stack in ipairs(player:get_inventory():get_list("main")) do
|
||||
if i<=activewidth and string.sub(stack:get_name(), 0, 11) == "compassgps:" and string.sub(stack:get_name(),0,18) ~= "compassgps:cgpsmap" then
|
||||
activeinv=stack --store the stack so we can update it later with new image
|
||||
stackidx=i --store the index so we can add image at correct location
|
||||
gotacompass=true
|
||||
break
|
||||
end --if i<=activewidth
|
||||
end --for loop
|
||||
end -- get_inventory
|
||||
end --if wielded else
|
||||
|
||||
|
||||
--dont mess with the rest of this if they don't have a compass
|
||||
if gotacompass then
|
||||
--if they don't have a bookmark set, use the default
|
||||
point_to[playername]=point_to[playername] or compassgps.get_default_bookmark(playername,1)
|
||||
target=point_to[playername] --just to take up less space
|
||||
pos = player:getpos()
|
||||
dir = player:get_look_horizontal()
|
||||
local angle_north = math.deg(math.atan2(target.x - pos.x, target.z - pos.z))
|
||||
if angle_north < 0 then angle_north = angle_north + 360 end
|
||||
local angle_dir = 90 - math.deg(dir)
|
||||
local angle_relative = (angle_north - angle_dir) % 360
|
||||
local compass_image = math.floor((angle_relative/30) + 0.5)%12
|
||||
--if they don't have a bookmark set, use the default
|
||||
point_to[playername]=point_to[playername] or compassgps.get_default_bookmark(playername,1)
|
||||
target=point_to[playername] --just to take up less space
|
||||
pos = player:getpos()
|
||||
dir = player:get_look_horizontal()
|
||||
|
||||
local angle_north = math.deg(math.atan2(target.x - pos.x, target.z - pos.z))
|
||||
if angle_north < 0 then angle_north = angle_north + 360 end
|
||||
local angle_dir = -math.deg(dir)
|
||||
|
||||
local divisions = 12
|
||||
local angle_interval = 30
|
||||
local ctype = compass_type[playername]
|
||||
if ctype == "d" then -- for use of more frames
|
||||
angle_interval = 11.25
|
||||
divisions = 32
|
||||
end
|
||||
|
||||
local angle_relative = (angle_north - angle_dir) % 360
|
||||
local compass_image = math.floor((angle_relative/angle_interval) + 0.5)%divisions
|
||||
--minetest.chat_send_all(compass_image)
|
||||
|
||||
|
||||
--update compass image to point at target
|
||||
if wielded then
|
||||
player:set_wielded_item("compassgps:"..
|
||||
compassgps.compass_type_name(playername,compass_image))
|
||||
elseif activeinv then
|
||||
--player:get_inventory():remove_item("main", activeinv:get_name())
|
||||
player:get_inventory():set_stack("main",stackidx,"compassgps:"..
|
||||
compassgps.compass_type_name(playername,compass_image))
|
||||
end --if wielded elsif activin
|
||||
--update compass image to point at target
|
||||
if wielded then
|
||||
player:set_wielded_item("compassgps:"..
|
||||
compassgps.compass_type_name(playername,compass_image))
|
||||
elseif activeinv then
|
||||
--player:get_inventory():remove_item("main", activeinv:get_name())
|
||||
player:get_inventory():set_stack("main",stackidx,"compassgps:"..
|
||||
compassgps.compass_type_name(playername,compass_image))
|
||||
end --if wielded elsif activin
|
||||
|
||||
|
||||
--update the hud with playerpos -> target pos : distance to target
|
||||
|
@ -1086,7 +1139,7 @@ minetest.register_globalstep(function(dtime)
|
|||
|
||||
local compasstype=compass_default_type
|
||||
if compass_type[playername] and
|
||||
(compass_type[playername]=="a" or compass_type[playername]=="b" or compass_type[playername]=="c") then
|
||||
(compass_type[playername]=="a" or compass_type[playername]=="b" or compass_type[playername]=="c" or compass_type[playername]=="d") then
|
||||
compasstype=compass_type[playername]
|
||||
else
|
||||
compass_type[playername]=compass_default_type
|
||||
|
@ -1175,6 +1228,7 @@ end--spairs
|
|||
|
||||
function compassgps.get_compassgps_formspec(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then return end
|
||||
local playerpos = player:getpos()
|
||||
--print("get_compassgps_formspec spawn="..compassgps.pos_to_string(store_spawn[name]))
|
||||
--local list = "default "..compassgps.pos_to_string(compassgps.get_default_pos_and_name(name))
|
||||
|
@ -1273,7 +1327,8 @@ function compassgps.get_settings_formspec(name)
|
|||
"label[1,1.5;"..S("Compass Type:").."]"..
|
||||
"image_button[3,1.5;1,1;compass_0.png;compass_type_a;]"..
|
||||
"image_button[4,1.5;1,1;compass_b0.png;compass_type_b;]"..
|
||||
"image_button[5,1.5;1,1;compass_c0.png;compass_type_c;]"
|
||||
"image_button[5,1.5;1,1;compass_c0.png;compass_type_c;]" ..
|
||||
"image_button[6,1.5;1,1;compass_d0.png;compass_type_d;]"
|
||||
|
||||
end --get_compassgps_formspec
|
||||
|
||||
|
@ -1284,7 +1339,7 @@ end --get_compassgps_formspec
|
|||
|
||||
local i
|
||||
--for i,img in ipairs(images) do
|
||||
for i=1,12 do
|
||||
for i=1,32 do
|
||||
for c,ctype in pairs(compass_valid_types) do
|
||||
local inv = 1
|
||||
if i == 1 and ctype=="a" then
|
||||
|
|
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 225 B |
After Width: | Height: | Size: 225 B |
After Width: | Height: | Size: 225 B |
After Width: | Height: | Size: 227 B |
After Width: | Height: | Size: 227 B |
After Width: | Height: | Size: 229 B |
After Width: | Height: | Size: 229 B |
After Width: | Height: | Size: 227 B |
After Width: | Height: | Size: 227 B |
After Width: | Height: | Size: 228 B |
After Width: | Height: | Size: 227 B |
After Width: | Height: | Size: 227 B |
After Width: | Height: | Size: 227 B |
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 228 B |
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 228 B |
After Width: | Height: | Size: 227 B |
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 226 B |
After Width: | Height: | Size: 226 B |