diff --git a/mods/compassgps/README.md b/mods/compassgps/README.md new file mode 100644 index 00000000..7b2bc3ad --- /dev/null +++ b/mods/compassgps/README.md @@ -0,0 +1,158 @@ +This mod creates a customizable compass with user settable bookmarks and shared and admin bookmarks in multiplayer. + +**Compass GPS version 2.6** + +Echo created a compass mod back in 2012: [https://forum.minetest.net/viewtopic.php?id=3785](https://forum.minetest.net/viewtopic.php?id=3785)

+PilzAdams made a modification of it, which I can not find the source to, I don't know how much of PilzAdams changes made it into the later versions of Echo's mod.

+Then in 2013 TeTpaAka made a fork of the compass mod that he called compass+ [https://forum.minetest.net/viewtopic.php?id=8117](https://forum.minetest.net/viewtopic.php?id=8117)

+This fork added the ability to "bookmark" specific places, and a gui so you could choose what point the compass should point to. + +This is my fork of TeTpaAka's fork of Echo's mod. :) + +The compass mod as it was is REALLY cool I love the way Echo managed to make the compass in your inventory actually change it's image to point in the direction of it's target + +![alt text](http://i59.tinypic.com/a15ls0.png "image") + +And TeTpaAka's gui, file io, and coding for multiplayer games was simply amazing. But as I was learning from their awesome code, I saw some changes I'd like to make using these new ideas, as well as some things I learned while looking at other mods. So, with complete and total respect for the original awesome mods, and hopefully in the same spirit as theirs, I present my own fork of the fork. CompassGPS + +The crafting recipe for a compass is unchanged:

+``` + , steel , +steel, mese fragment, steel + , steel , +``` +![alt text](http://i59.tinypic.com/14ad2qw.png "image") + +Compass GPS introduces several other changes though. First of all, this mod adds a heads up display that indicates your current position, and the name of the bookmark the compass is pointing at, that bookmarks pos, as well as the distance to that bookmark. + +![alt text](http://i60.tinypic.com/facwea.png "image") + +The hud updates constantly as long as the compass is in one of your active inventory slots, so you can always know where you are in relation to the target node, and how far away it is. + +There is a GUI that pops up whenever you wield the compass and left click. I never played with a GUI in minetest before, so this was a new experience for me, I learned a lot and made quite a few changes: + +![alt text](http://i61.tinypic.com/29zzgy1.png "image") + +To create a new bookmark, type the name into the "bookmark:" field and click "Create Bookmark" (or just hit enter). To remove a bookmark, select it from the list and click "Remove Bookmark." A confirmation dialog will appear and the bookmark will only be removed if you click "YES". + +The bookmark list has been expanded from a dropdown into a textlist to improve visibility. Select any bookmark in the list by clicking on it, and then click "Find Selected Bookmark" to make the compass (and hud) point at that location. "default" is always at the top of the list and will point to (0,0,0) or your bed from PilzAdams bed-mod, or home location as defined in the sethome-mod. (Setting default to your bed or sethome is old code, I modified it to make it work with my new version, but I cant take credit for the idea or basic structure.) The rest of the list are bookmarked locations that you have set and named + +Just click in the "Sort by" box to change whether the bookmarks are sorted by name, or by distance from your current location. ("default" will still always be the first item in the list no matter which way you sort it) + +Click in the "Dist" box to change whether the distance is calculated in 3d (including your distance in the vertical direction) or in 2d (x and z coords only, ignore vertical distance) + +Down at the lower right of the screen, I'm certain you noticed the "Teleport to bookmark" button. *That button appears if, and ONLY IF the player has teleport privileges.* If they do, then they can select any bookmark out of the list, click on teleport, and be instantly transported to the location of that bookmark. Since the user already had teleport privileges, this just saved them some typing, it's not adding any new abilities. + +If you click the "Settings" button in the upper right hand corner it brings up a screen where you can customize the appearance of your compass gps: + +![alt text](http://i59.tinypic.com/aahqa8.png "image")

+(The two awesome new compass images are by Bas080 and Spootonium) + +I figured the position of the hud text was likely to be something that people would want to customize, so here in the settings gui are the x and y coords for the hud text. Just enter the new coords where you want the hud text to appear and click "Change Hud"

+The cords must be between 0 and 1 and represent a percentage of the screen, so x=0 would put the text at the far left of the screen, and y=0.98 would put the text almost at the bottom of the screen. The default is x=0.4 and y=0.01, and that is displayed right over the input boxes so the user can easily set them back to the default if they are having trouble placing the hud. If you change either the x or y coord to a number that is out of range (less than 0 or greater than 1) then the hud will not be displayed. That makes it easy to turn the hud off if you wish.

+You can also change the color of the hud text by changing the value in the "Color" field here. Again, click "Change Hud" to make the update appear. + +AND, there are three buttons here that allow you to select from 3 different styles of compass images. The basic compass image by Echo. A nice wooden compass image by Bas080. And a high resolution compass image by spootonium. + +In Multiplayer, there are now shared and admin bookmarks!

+![alt text](http://i61.tinypic.com/a5b7li.png "image")

+If a player has the new "shared_bookmarks" privilege, then they will get the "Create Shared Bookmark" button and be able to create bookmarks that all players on the server can see and use. Shared bookmarks are preceded by *shared* and the name of the player that created them. There is a variable near the top of the init.lua called max_shared. This controls the maximum number of shared bookmarks that an individual player can create. It is set to 10 by default, but the server admin can change it to whatever they want. A player can delete their own shared bookmarks, but they can not delete anyone else's (unless they are an admin, then they can delete anyone's shared bookmarks) + +If a player has the "privs" privilege, then they will get the "Create Admin Bookmark" button. Admin bookmarks are intended to allow the admins to mark important places in their world that they want everyone to be able to find. There are no limits on how many admin bookmarks can be created. Only Admins can delete admin bookmarks. + +In a multiplayer game, all players get the "Show: Private, Shared, Admin" checkboxes. You can use these checkboxes to toggle which type of bookmarks show in your list. If you uncheck all three the system will automatically recheck "Private" for you. + +The bookmark list is saved any time a user changes it. All of your other settings, the currently selected bookmark, sort order, distance function, and hud position and color, and compass type, are saved whenever a user leaves the game, and on game shutdown. So if you move the hud down to the lower right hand corner of the screen, and then quit, the hud will still be in the place you put it when you restart the game later. + +The Chat Commands from the orignal compass mod still work, but only on private bookmarks. Chat commands available are:

+list_bookmarks

+set_bookmark

+find_bookmark

+remove_bookmark + +I also fixed a few bugs while I was working on this. There was a problem in the mod that caused compass to jump around in inventory if there were empty slots above it, that is fixed now. And there was also a problem with the bookmark list not being saved after you removed a bookmark if you didn't add a new bookmark afterwards. Now the bookmark list is saved whenever you change it, either adding or removing. + +I tried to follow Echo and TeTpaAka's examples of how to properly code for multiplayer games, and all of the new settings should work just fine in a multiplayer game. + +----** MAPS! **---- + +Thanks to a great idea and initial code from TeTpaAka CompassGPS now includes MAPS!

+Maps allow you to store a bookmark that you can then give to another player and they can use the map to put that bookmark into their own list. They also enhance role playing/story possibilities since you can hide maps for players to find that will give them bookmarks they need to find their next goal. + +Craft a blank map by putting 5 papers in an X pattern:

+``` +paper, ,paper + ,paper, +paper, ,paper +``` +![alt text](http://i57.tinypic.com/20z5wmr.png "image") + +To place a bookmark into a map, just right click while wielding the map, select any bookmark from your list, and click the "write to cgpsmap" button. You can also put your current position into the map (without having to first create a bookmark in your compassGPS) + +The map icon now changes to have a red X on it, so you can tell it is a marked map. This map can be given to another player. To transfer the bookmark to their own compassgps, they right click while wielding the marked map and a formspec like this pops up:

+![alt text](http://i61.tinypic.com/jakj9v.png "image")

+You can change the name of the bookmark to whatever you wish, click the "copy bookmark to your compassgps" button and the new bookmark is now available in your compassgps list. + +To turn a marked map back into a blank map, just put it into the crafting grid. + +Thanks to some nice code by Miner59 you can now mount a map on a wall! If you can dig on the position where the map is placed, you can take the map, otherwise you can add the bookmark saved in the map in your compassgps. This will make it possible on a multiplayer server to mount maps that everyone can use. + +--------------------- + +The code is kinda a mess, because I was learning a lot of new things while working on it. I hope to do a clean up on it sometime in the near future, but I wanted to release it now so some people could start testing it. Please do not hesitate to offer critiques, criticism, or coding advice. I'm new to lua and minetest and could use the help. + +And above all, if you run into a bug, please let me know! + +**Credits:**

+Original mod is by Echo and TeTpaAka, and probably PilzAdam. Cactuz_pl clockmod showed me how to write the hud to the screen. My son offered a lot of advice and suggested several changes. I got an example of how to sort lists in lua from Michal Kottman on StackOverflow. Big thanks to Bas080 and spootonium for providing some very nice alternate images for the compass gps mod! Also thanks to Topywo for the shared bookmarks idea, and to my son for several ideas, corrections, and testing help.

+Map idea, image, and initial code by TeTpaAka. Store current position in map code contributed by Miner95

+intllib support by TeTpaAka

+Wall mounted maps by Miner59 + +**License:**

+Original code by Echo, PilzAdam, and TeTpaAka is WTFPL. My changes are CC0 (No rights reserved)

+textures: original compass textures: CC BY-SA by Echo

+ compass b textures: CC BY-SA by Bas080 (slight modifications by Kilarin)

+ compass c textures: CC BY-SA by Andre Goble mailto:spootonium@gmail.com

+ (slight modifications by Kilarin)

+ map texture: CC BY-SA by TeTpaAka (slight modifications by Kilarin for blank map) + +**Dependencies:**

+default is the only requirement.

+PilzAdams Beds mod and the sethome-mod are supported if you have them. + +**Incompatibilities:**

+This mod will clash with both the original compass and compass+ mods. They should not be installed and enabled at the same time as compassgps. HOWEVER, compassgps is 100% compatible with the bookmarks file from the compass+ mod. So if you were using compass+ and switch to compassgps you will NOT lose your previous bookmarks. + +**github source:**

+[https://github.com/Kilarin/compassgps](https://github.com/Kilarin/compassgps) + +**Download:**

+[https://github.com/Kilarin/compassgps/archive/master.zip](https://github.com/Kilarin/compassgps/archive/master.zip) + +**To install:**

+Simply unzip the file into your mods folder, then rename the resulting folder from compassgps-master to compassgps

+OR, simply install it directly from minetest using the online mod repository. + +**Mod Database:**

+If you use this mod, please consider reviewing it on the MineTest Mod Database.

+[https://forum.minetest.net/mmdb/mod/compassgps/](https://forum.minetest.net/mmdb/mod/compassgps/) + +**Changelog:**

+2.6 bug fix from myoung008, type causing crashes when entering bad color.

+2.5 bug fix from TeTpaAka fix bug when static_spawnpoint is invalid

+2.4 wall mounted maps by Miner59

+2.3 intllib support by TeTpaTka so CompassGPS will work with different languages now!

+2.2 current position option in bookmark list when writing to map (Miner95 contribution)

+2.1 cgpsmap_marked notincreative and defaults to default on /giveme

+2.0 maps so you can exchange bookmarks between players (TeTpaAka initial contribution)

+1.9 corrected undeclared global variables to avoid warnings.

+1.8 changed register_craft to compassgps:0 for unified inventory compatibility

+1.7 fixed bug causing crash on first load of formspec in multiplayer

+1.6 fixed compass point_to not saving

+1.5 shared/admin bookmarks. confirm dialog for remove.

+1.4 corrected teleport button priv

+1.3 multiple compass types

+1.2 rounding of position corrected

+1.1 switched core to minetest

+1.0 Initial release

diff --git a/mods/compassgps/README.txt b/mods/compassgps/README.txt new file mode 100644 index 00000000..781c9898 --- /dev/null +++ b/mods/compassgps/README.txt @@ -0,0 +1,157 @@ +[b]Compass GPS version 2.6[/b] +This mod creates a customizable compass with user settable bookmarks and shared and admin bookmarks in multiplayer. + +Echo created a compass mod back in 2012: [url]https://forum.minetest.net/viewtopic.php?id=3785[/url] +PilzAdams made a modification of it, which I can not find the source to, I don't know how much of PilzAdams changes made it into the later versions of Echo's mod. +Then in 2013 TeTpaAka made a fork of the compass mod that he called compass+ [url]https://forum.minetest.net/viewtopic.php?id=8117[/url] +This fork added the ability to "bookmark" specific places, and a gui so you could choose what point the compass should point to. + +This is my fork of TeTpaAka's fork of Echo's mod. :) + +The compass mod as it was is REALLY cool I love the way Echo managed to make the compass in your inventory actually change it's image to point in the direction of it's target + +[img]http://i59.tinypic.com/a15ls0.png[/img] + +And TeTpaAka's gui, file io, and coding for multiplayer games was simply amazing. But as I was learning from their awesome code, I saw some changes I'd like to make using these new ideas, as well as some things I learned while looking at other mods. So, with complete and total respect for the original awesome mods, and hopefully in the same spirit as theirs, I present my own fork of the fork. CompassGPS + +The crafting recipe for a compass is unchanged: +[code] + , steel , +steel, mese fragment, steel + , steel , +[/code] +[img]http://i59.tinypic.com/14ad2qw.png[/img] + +Compass GPS introduces several other changes though. First of all, this mod adds a heads up display that indicates your current position, and the name of the bookmark the compass is pointing at, that bookmarks pos, as well as the distance to that bookmark. + +[img]http://i60.tinypic.com/facwea.png[/img] + +The hud updates constantly as long as the compass is in one of your active inventory slots, so you can always know where you are in relation to the target node, and how far away it is. + +There is a GUI that pops up whenever you wield the compass and left click. I never played with a GUI in minetest before, so this was a new experience for me, I learned a lot and made quite a few changes: + +[IMG]http://i61.tinypic.com/29zzgy1.png[/IMG] + +To create a new bookmark, type the name into the "bookmark:" field and click "Create Bookmark" (or just hit enter). To remove a bookmark, select it from the list and click "Remove Bookmark." A confirmation dialog will appear and the bookmark will only be removed if you click "YES". + +The bookmark list has been expanded from a dropdown into a textlist to improve visibility. Select any bookmark in the list by clicking on it, and then click "Find Selected Bookmark" to make the compass (and hud) point at that location. "default" is always at the top of the list and will point to (0,0,0) or your bed from PilzAdams bed-mod, or home location as defined in the sethome-mod. (Setting default to your bed or sethome is old code, I modified it to make it work with my new version, but I cant take credit for the idea or basic structure.) The rest of the list are bookmarked locations that you have set and named + +Just click in the "Sort by" box to change whether the bookmarks are sorted by name, or by distance from your current location. ("default" will still always be the first item in the list no matter which way you sort it) + +Click in the "Dist" box to change whether the distance is calculated in 3d (including your distance in the vertical direction) or in 2d (x and z coords only, ignore vertical distance) + +Down at the lower right of the screen, I'm certain you noticed the "Teleport to bookmark" button. [i]That button appears if, and ONLY IF the player has teleport privileges.[/i] If they do, then they can select any bookmark out of the list, click on teleport, and be instantly transported to the location of that bookmark. Since the user already had teleport privileges, this just saved them some typing, it's not adding any new abilities. + +If you click the "Settings" button in the upper right hand corner it brings up a screen where you can customize the appearance of your compass gps: + +[IMG]http://i59.tinypic.com/aahqa8.png[/IMG] +(The two awesome new compass images are by Bas080 and Spootonium) + +I figured the position of the hud text was likely to be something that people would want to customize, so here in the settings gui are the x and y coords for the hud text. Just enter the new coords where you want the hud text to appear and click "Change Hud" +The cords must be between 0 and 1 and represent a percentage of the screen, so x=0 would put the text at the far left of the screen, and y=0.98 would put the text almost at the bottom of the screen. The default is x=0.4 and y=0.01, and that is displayed right over the input boxes so the user can easily set them back to the default if they are having trouble placing the hud. If you change either the x or y coord to a number that is out of range (less than 0 or greater than 1) then the hud will not be displayed. That makes it easy to turn the hud off if you wish. +You can also change the color of the hud text by changing the value in the "Color" field here. Again, click "Change Hud" to make the update appear. + +AND, there are three buttons here that allow you to select from 3 different styles of compass images. The basic compass image by Echo. A nice wooden compass image by Bas080. And a high resolution compass image by spootonium. + +In Multiplayer, there are now shared and admin bookmarks! +[IMG]http://i61.tinypic.com/a5b7li.png[/IMG] +If a player has the new "shared_bookmarks" privilege, then they will get the "Create Shared Bookmark" button and be able to create bookmarks that all players on the server can see and use. Shared bookmarks are preceded by *shared* and the name of the player that created them. There is a variable near the top of the init.lua called max_shared. This controls the maximum number of shared bookmarks that an individual player can create. It is set to 10 by default, but the server admin can change it to whatever they want. A player can delete their own shared bookmarks, but they can not delete anyone else's (unless they are an admin, then they can delete anyone's shared bookmarks) + +If a player has the "privs" privilege, then they will get the "Create Admin Bookmark" button. Admin bookmarks are intended to allow the admins to mark important places in their world that they want everyone to be able to find. There are no limits on how many admin bookmarks can be created. Only Admins can delete admin bookmarks. + +In a multiplayer game, all players get the "Show: Private, Shared, Admin" checkboxes. You can use these checkboxes to toggle which type of bookmarks show in your list. If you uncheck all three the system will automatically recheck "Private" for you. + +The bookmark list is saved any time a user changes it. All of your other settings, the currently selected bookmark, sort order, distance function, and hud position and color, and compass type, are saved whenever a user leaves the game, and on game shutdown. So if you move the hud down to the lower right hand corner of the screen, and then quit, the hud will still be in the place you put it when you restart the game later. + +The Chat Commands from the orignal compass mod still work, but only on private bookmarks. Chat commands available are: +list_bookmarks +set_bookmark +find_bookmark +remove_bookmark + +I also fixed a few bugs while I was working on this. There was a problem in the mod that caused compass to jump around in inventory if there were empty slots above it, that is fixed now. And there was also a problem with the bookmark list not being saved after you removed a bookmark if you didn't add a new bookmark afterwards. Now the bookmark list is saved whenever you change it, either adding or removing. + +I tried to follow Echo and TeTpaAka's examples of how to properly code for multiplayer games, and all of the new settings should work just fine in a multiplayer game. + +----[b] MAPS! [/b]---- + +Thanks to a great idea and initial code from TeTpaAka CompassGPS now includes MAPS! +Maps allow you to store a bookmark that you can then give to another player and they can use the map to put that bookmark into their own list. They also enhance role playing/story possibilities since you can hide maps for players to find that will give them bookmarks they need to find their next goal. + +Craft a blank map by putting 5 papers in an X pattern: +[code] +paper, ,paper + ,paper, +paper, ,paper +[/code] +[img]http://i57.tinypic.com/20z5wmr.png[/img] + +To place a bookmark into a map, just right click while wielding the map, select any bookmark from your list, and click the "write to cgpsmap" button. You can also put your current position into the map (without having to first create a bookmark in your compassGPS) + +The map icon now changes to have a red X on it, so you can tell it is a marked map. This map can be given to another player. To transfer the bookmark to their own compassgps, they right click while wielding the marked map and a formspec like this pops up: +[img]http://i61.tinypic.com/jakj9v.png[/img] +You can change the name of the bookmark to whatever you wish, click the "copy bookmark to your compassgps" button and the new bookmark is now available in your compassgps list. + +To turn a marked map back into a blank map, just put it into the crafting grid. + +Thanks to some nice code by Miner59 you can now mount a map on a wall! If you can dig on the position where the map is placed, you can take the map, otherwise you can add the bookmark saved in the map in your compassgps. This will make it possible on a multiplayer server to mount maps that everyone can use. + +--------------------- + +The code is kinda a mess, because I was learning a lot of new things while working on it. I hope to do a clean up on it sometime in the near future, but I wanted to release it now so some people could start testing it. Please do not hesitate to offer critiques, criticism, or coding advice. I'm new to lua and minetest and could use the help. + +And above all, if you run into a bug, please let me know! + +[b]Credits:[/b] +Original mod is by Echo and TeTpaAka, and probably PilzAdam. Cactuz_pl clockmod showed me how to write the hud to the screen. My son offered a lot of advice and suggested several changes. I got an example of how to sort lists in lua from Michal Kottman on StackOverflow. Big thanks to Bas080 and spootonium for providing some very nice alternate images for the compass gps mod! Also thanks to Topywo for the shared bookmarks idea, and to my son for several ideas, corrections, and testing help. +Map idea, image, and initial code by TeTpaAka. Store current position in map code contributed by Miner95 +intllib support by TeTpaAka +Wall mounted maps by Miner59 + +[b]License:[/b] +Original code by Echo, PilzAdam, and TeTpaAka is WTFPL. My changes are CC0 (No rights reserved) +textures: original compass textures: CC BY-SA by Echo + compass b textures: CC BY-SA by Bas080 (slight modifications by Kilarin) + compass c textures: CC BY-SA by Andre Goble mailto:spootonium@gmail.com + (slight modifications by Kilarin) + map texture: CC BY-SA by TeTpaAka (slight modifications by Kilarin for blank map) + +[b]Dependencies:[/b] +default is the only requirement. +PilzAdams Beds mod and the sethome-mod are supported if you have them. + +[b]Incompatibilities:[/b] +This mod will clash with both the original compass and compass+ mods. They should not be installed and enabled at the same time as compassgps. HOWEVER, compassgps is 100% compatible with the bookmarks file from the compass+ mod. So if you were using compass+ and switch to compassgps you will NOT lose your previous bookmarks. + +[b]github source:[/b] +[url]https://github.com/Kilarin/compassgps[/url] + +[b]Download:[/b] +[url]https://github.com/Kilarin/compassgps/archive/master.zip[/url] + +[b]To install:[/b] +Simply unzip the file into your mods folder, then rename the resulting folder from compassgps-master to compassgps +OR, simply install it directly from minetest using the online mod repository. + +[b]Mod Database:[/b] +If you use this mod, please consider reviewing it on the MineTest Mod Database. +[url]https://forum.minetest.net/mmdb/mod/compassgps/[/url] + +[b]Changelog:[/b] +2.6 bug fix from myoung008, type causing crashes when entering bad color. +2.5 bug fix from TeTpaAka fix bug when static_spawnpoint is invalid +2.4 wall mounted maps by Miner59 +2.3 intllib support by TeTpaTka so CompassGPS will work with different languages now! +2.2 current position option in bookmark list when writing to map (Miner95 contribution) +2.1 cgpsmap_marked notincreative and defaults to default on /giveme +2.0 maps so you can exchange bookmarks between players (TeTpaAka initial contribution) +1.9 corrected undeclared global variables to avoid warnings. +1.8 changed register_craft to compassgps:0 for unified inventory compatibility +1.7 fixed bug causing crash on first load of formspec in multiplayer +1.6 fixed compass point_to not saving +1.5 shared/admin bookmarks. confirm dialog for remove. +1.4 corrected teleport button priv +1.3 multiple compass types +1.2 rounding of position corrected +1.1 switched core to minetest +1.0 Initial release diff --git a/mods/compassgps/cgpsmap.lua b/mods/compassgps/cgpsmap.lua new file mode 100644 index 00000000..cab62ed6 --- /dev/null +++ b/mods/compassgps/cgpsmap.lua @@ -0,0 +1,350 @@ +--original code for storing bookmarks outside of the compass by TeTpaAka +--modifications by Kilarin and Miner59 +--wall mounted maps by Miner59 + +--set growing_wall_maps to true and wall mounted maps will get bigger the further +--away the target is. +local growing_wall_maps=false + + +-- Boilerplate to support localized strings if intllib mod is installed. +local S +if (minetest.get_modpath("intllib")) then + dofile(minetest.get_modpath("intllib").."/intllib.lua") + S = intllib.Getter(minetest.get_current_modname()) +else + S = function ( s ) return s end +end + + +local selected_cgpsmap = {} +local textlist_bookmark = {} +local selected_bookmark = {} + +function write_to_cgpsmap(itemstack, user) + --print("write_to_cgpsmap") + selected_cgpsmap[user:get_player_name()] = itemstack + local list,bkmrkidx=compassgps.bookmark_loop("M", user:get_player_name()) + if list == "" then + return nil + end + textlist_bookmark[user:get_player_name()] = list + local formspec = "size[9,10;]".. + "button_exit[2,2;5,0.5;write;"..S("Write to cgpsmap").."]".. + "textlist[0,3.0;9,6;bookmark_list;"..list..";"..bkmrkidx.."]" + minetest.show_formspec(user:get_player_name(), "compassgps:write", formspec) + --print("write_to_cgpsmap end") +end + + +function read_from_cgpsmap(itemstack, user, meta) + --print("read_from_cgpsmap") + local formspec = "size[9,5]".. + "button_exit[2,3;5,0.5;read;"..S("copy bookmark to your compassgps").."]" + if itemstack~=nil then + formspec=formspec.. "button_exit[3.1,4;2.6,0.8;rename;"..S("rename bookmark").."]" + else + itemstack=ItemStack("compassgps:cgpsmap_marked 1") + if meta then + itemstack:set_metadata(minetest.serialize(meta)) + end + end + if not meta then --marked map from creative or /giveme has no meta! + meta={bkmrkname="default",x=0,y=0,z=0} + itemstack:set_metadata(minetest.serialize(meta)) + end + selected_cgpsmap[user:get_player_name()] = itemstack + + formspec=formspec.."label[2,0.5;"..S("bookmark pos:").." ("..meta["x"]..","..meta["y"]..","..meta["z"]..")]".. + "field[2,2;5,0.5;name;"..S("bookmark name:")..";"..meta["bkmrkname"].."]" + minetest.show_formspec(user:get_player_name(), "compassgps:read", formspec) + --print("read_from_cgpsmap end") +end + + + +minetest.register_craft({ + output = 'compassgps:cgpsmap', + recipe = { + {'default:paper', '', 'default:paper'}, + {'', 'default:paper', ''}, + {'default:paper', '', 'default:paper'} + } +}) + +minetest.register_craft({ + output = 'compassgps:cgpsmap', + recipe = { + {'compassgps:cgpsmap_marked'}, + } +}) + +minetest.register_craftitem("compassgps:cgpsmap", { + description = S("CompassGPS Map (blank)"), + inventory_image = "cgpsmap-blank.png", + --groups = {book = 1}, + stack_max = 1, + on_use = function(itemstack, user, pointed_thing) + write_to_cgpsmap(itemstack, user) + return + end +}) + +minetest.register_craftitem("compassgps:cgpsmap_marked", { + description = "CompassGPS Map (marked)", + inventory_image = "cgpsmap-marked.png", + groups = {not_in_creative_inventory = 1}, + stack_max = 1, + + on_use = function(itemstack, user, pointed_thing) + local meta = minetest.deserialize(itemstack:get_metadata()) + read_from_cgpsmap(itemstack, user, meta) + return nil + end, + + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.type=="node" and pointed_thing.above then + local pos=pointed_thing.above + local ppos=placer:getpos() + local facedir=minetest.dir_to_facedir(vector.direction(ppos,pointed_thing.under)) + local x=pos.x + local y=pos.y + local z=pos.z + if facedir~=nil and itemstack:get_name()=="compassgps:cgpsmap_marked" + and (not minetest.is_protected(pos,placer:get_player_name())) then + minetest.set_node(pos,{name="compassgps:cgpsmap_wall",param2=facedir}) + local mapdata = itemstack:get_metadata() + local meta=minetest.get_meta(pos) + meta:set_string("mapdata",mapdata) + if mapdata~=nil then + local data=minetest.deserialize(mapdata) + if data~=nil then + meta:set_string("infotext", data["bkmrkname"]) + x=data["x"] + y=data["y"] + z=data["z"] + end + end + if facedir==1 then + pos={x=pos.x+0.3,y=pos.y,z=pos.z} + elseif facedir==3 then + pos={x=pos.x-0.3,y=pos.y,z=pos.z} + elseif facedir==0 then + pos={x=pos.x,y=pos.y,z=pos.z+0.3} + elseif facedir==2 then + pos={x=pos.x,y=pos.y,z=pos.z-0.3} + end + local e = minetest.env:add_entity(pos,"compassgps:cgpsmap_item") + local yaw = math.pi*2 - facedir * math.pi/2 + e:setyaw(yaw) + local dist=math.abs(pos.x-x)+math.abs(pos.y-y)+math.abs(pos.z-z) + if growing_wall_maps == false then + e:set_properties({visual_size={x=0.85,y=0.85}}) + elseif dist>30000 then + e:set_properties({visual_size={x=3.45,y=3.45}}) + elseif dist>15000 then + e:set_properties({visual_size={x=2.95,y=2.95}}) + elseif dist>5000 then + e:set_properties({visual_size={x=2.45,y=2.45}}) + elseif dist>3000 then + e:set_properties({visual_size={x=1.45,y=1.45}}) + elseif dist>2000 then + e:set_properties({visual_size={x=1.2,y=1.2}}) + elseif dist>1000 then + e:set_properties({visual_size={x=1,y=1}}) + elseif dist>500 then + e:set_properties({visual_size={x=0.85,y=0.85}}) + end--else default (0.7) + + itemstack:take_item() + end + end + return itemstack + end, +}) + +minetest.register_node("compassgps:cgpsmap_wall",{ + description = "CompassGPS Map (wallmounted)", + drawtype = "nodebox", + node_box = { type = "fixed", fixed = {-0.5, -0.5, 7/16, 0.5, 0.5, 0.5} }, + selection_box = { type = "fixed", fixed = {-0.7, -0.7, 7/16, 0.7, 0.7, 0.7} }, + tiles = {"compassgps_blank.png"}, + inventory_image = "cgpsmap_marked.png", + wield_image = "cgpsmap_marked.png", + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + groups = { choppy=2,dig_immediate=2,not_in_creative_inventory=1,not_in_craft_guide=1 }, + legacy_wallmounted = true, + sounds = default.node_sound_defaults(), + on_punch = function(pos,node,puncher) + local meta = minetest.env:get_meta(pos) + local mapdata=meta:get_string("mapdata") + + if minetest.is_protected(pos,puncher:get_player_name()) then + --don't take map, instead open formspec to add coordinates in compassgps + if mapdata~=nil then + read_from_cgpsmap(nil, puncher, minetest.deserialize(mapdata)) + end + return + end + local inv = puncher:get_inventory() + + local objs = nil + objs = minetest.env:get_objects_inside_radius(pos, .5) + if objs then + for _, obj in ipairs(objs) do + if obj and obj:get_luaentity() and obj:get_luaentity().name == "compassgps:cgpsmap_item" then + obj:remove() + end + end + end + local itemstack=ItemStack("compassgps:cgpsmap_marked 1") + itemstack:set_metadata(mapdata) + if inv:room_for_item("main",itemstack) then + inv:add_item("main",itemstack) + else + minetest.env:add_item(pos, itemstack) + end + minetest.remove_node(pos) + end, +}) + +minetest.register_entity("compassgps:cgpsmap_item",{ + hp_max = 1, + visual="wielditem", + visual_size={x=0.7,y=0.7}, + collisionbox = {0,0,0,0,0,0}, + physical=false, + textures={"compassgps:cgpsmap_marked"}, +}) + +minetest.register_abm({ + nodenames = { "compassgps:cgpsmap_wall" }, + interval = 600, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + if #minetest.get_objects_inside_radius(pos, 0.5) > 0 then return end + local meta=minetest.get_meta(pos) + local x=pos.x + local y=pos.y + local z=pos.z + local mapdata=meta:get_string("mapdata",mapdata) + if mapdata~=nil then + local data=minetest.deserialize(mapdata) + if data~=nil then + x=data["x"] + y=data["y"] + z=data["z"] + end + end + local facedir=node.param2 + if facedir==1 then + pos={x=pos.x+0.3,y=pos.y,z=pos.z} + elseif facedir==3 then + pos={x=pos.x-0.3,y=pos.y,z=pos.z} + elseif facedir==0 then + pos={x=pos.x,y=pos.y,z=pos.z+0.3} + elseif facedir==2 then + pos={x=pos.x,y=pos.y,z=pos.z-0.3} + end + local e = minetest.env:add_entity(pos,"compassgps:cgpsmap_item") + local yaw = math.pi*2 - facedir * math.pi/2 + e:setyaw(yaw) + local dist=math.abs(pos.x-x)+math.abs(pos.y-y)+math.abs(pos.z-z) + if dist>30000 then + e:set_properties({visual_size={x=3.45,y=3.45}}) + elseif dist>15000 then + e:set_properties({visual_size={x=2.95,y=2.95}}) + elseif dist>5000 then + e:set_properties({visual_size={x=2.45,y=2.45}}) + elseif dist>3000 then + e:set_properties({visual_size={x=1.45,y=1.45}}) + elseif dist>2000 then + e:set_properties({visual_size={x=1.2,y=1.2}}) + elseif dist>1000 then + e:set_properties({visual_size={x=1,y=1}}) + elseif dist>500 then + e:set_properties({visual_size={x=0.85,y=0.85}}) + end--else default (0.7) + + end +}) + + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if (formname == "compassgps:write") then + if not player then + return + end + local playername = player:get_player_name(); + if (playername ~= "") then + if (selected_cgpsmap[playername] == nil) then + return + end + if fields["bookmark_list"] then + -- to get the currently selected + local id = minetest.explode_textlist_event(fields["bookmark_list"]) + selected_bookmark[playername] = id.index + end + if fields["write"] then + --print("***cgpsmap fields=write***") + if selected_bookmark[playername] == nil then + return nil + end + local bkmrk=textlist_bkmrks[playername][selected_bookmark[playername]] + local write = { ["bkmrkname"] = bkmrk.bkmrkname, + x = bkmrk.x, + y = bkmrk.y, + z = bkmrk.z} + --print("dump(write)="..dump(write)) + selected_cgpsmap[playername]:set_name("compassgps:cgpsmap_marked") + selected_cgpsmap[playername]:set_metadata(minetest.serialize(write)) + player:set_wielded_item(selected_cgpsmap[playername]) + end + end + end + if (formname == "compassgps:read") then + if not player then + return + end + if (fields["read"]) then + --print("***cgpsmap fields=read***") + local meta = minetest.deserialize(selected_cgpsmap[player:get_player_name()]:get_metadata()) + --print("dump(meta)="..dump(meta)) + local bkmrkname = fields["name"] + --print("bkmrkname from fields[name]="..bkmrkname) + local pos = { x = meta["x"] + 0, + y = meta["y"] + 0, + z = meta["z"] + 0 } + local playername = player:get_player_name() + --print(bkmrkname) + compassgps.set_bookmark(playername, bkmrkname, "P", pos) + end + end + + if (selected_cgpsmap == nil) then + return + end + local playername = player:get_player_name() + if (playername == nil) then + return + end + if (selected_cgpsmap[playername] == nil) then + return + end + if fields["rename"] then + local bkmrkname = fields["name"] + local meta = minetest.deserialize(selected_cgpsmap[player:get_player_name()]:get_metadata()) + if meta~=nil and bkmrkname~=nil then + local pos = { x = meta["x"] + 0, + y = meta["y"] + 0, + z = meta["z"] + 0 } + selected_cgpsmap[playername]:set_metadata(minetest.serialize({ ["bkmrkname"] = bkmrkname, + x = pos.x, + y = pos.y, + z = pos.z})) + player:set_wielded_item(selected_cgpsmap[playername]) --new name is saved in marked cpgsmap + end + end + end) diff --git a/mods/compassgps/depends.txt b/mods/compassgps/depends.txt new file mode 100644 index 00000000..9207dab8 --- /dev/null +++ b/mods/compassgps/depends.txt @@ -0,0 +1,2 @@ +default +intllib? diff --git a/mods/compassgps/init.lua b/mods/compassgps/init.lua new file mode 100644 index 00000000..09e2525b --- /dev/null +++ b/mods/compassgps/init.lua @@ -0,0 +1,1298 @@ +--compassgps 2.1 + +--This fork was written by Kilarin (Donald Hines) +--Original code by Echo, PilzAdam, and TeTpaAka is WTFPL. +--My changes are CC0 (No rights reserved) +--textures: original compass textures: CC BY-SA by Echo +-- compass b textures: CC BY-SA by Bas080 (slight modifications by Kilarin) +-- compass c textures: CC BY-SA by Andre Goble mailto:spootonium@gmail.com +-- (slight modifications by Kilarin) + +--fixed bug that caused compass to jump around in inventory +--fixed bug causing removed bookmarks not to be saved +--expanded bookmark list from dropdown to textlist +--added pos and distance to display list +--added hud showing current pos -> target pos : distance + +-- Boilerplate to support localized strings if intllib mod is installed. +local S +if (minetest.get_modpath("intllib")) then + S = intllib.Getter() +else + S = function ( s ) return s end +end + +local hud_default_x=0.4 +local hud_default_y=0.01 +local hud_default_color="FFFF00" +local compass_default_type="a" +local compass_valid_types={"a","b","c"} +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 +--the ONLY reason to change this variable to true is for testing. shared and admin bookmarks +--make no sense in a single player game. + +minetest.register_privilege("shared_bookmarks", + S("Can create shared bookmarks for use by anyone with a compassgps")) +--minetest.register_privilege("shared_bookmarks", { +-- description = "Can create shared bookmarks for use by anyone with a compassgps", +-- give_to_singleplayer = false,}) + +compassgps = { } +local player_hud = { }; +local bookmarks = { } +local point_to = {} +local sort_function = {} +local distance_function ={} +local hud_pos = {} +local hud_color = {} +local compass_type = {} +local view_type_P = {} +local view_type_S = {} +local view_type_A = {} +local textlist_clicked = {} +textlist_bkmrks = {} +local singleplayer = false +local target = {} +local pos = {} +local dir = 90 +local default_bookmark = {} +local backwardscompatsave = "NO" + + +print(S("compassgps reading bookmarks")) +local file = io.open(minetest.get_worldpath().."/bookmarks", "r") +if file then + bookmarks = minetest.deserialize(file:read("*all")) + file:close() +end + +--local remove + + +--the sort functions and distance functions have to be defined ABOVE the +--"main" block or will be nil + +function compassgps.sort_by_distance(table,a,b,player) + --print("sort_by_distance a="..compassgps.pos_to_string(table[a]).." b="..pos_to_string(table[b])) + local playerpos = player:getpos() + local name=player:get_player_name() + --return compassgps.distance3d(playerpos,table[a]) < compassgps.distance3d(playerpos,table[b]) + if distance_function[name] then + return distance_function[name](playerpos,table[a]) < + distance_function[name](playerpos,table[b]) + else + return false --this should NEVER happen + end +end --sort_by_distance + +function compassgps.sort_by_name(table,a,b,player) + local atype="P" --default to P + if table[a].type then atype=table[a].type end + local btype="P" + if table[b].type then btype=table[b].type end + if atype == btype then + local aplayer="" + if table[a].player then aplayer=table[a].player end + local bplayer="" + if table[b].player then bplayer=table[b].player end + if aplayer == bplayer then + return a < b --compare on bookmark name + else + return aplayer < bplayer --compare on player name + end --compare player name + else + return atype < btype --compare on bookmark type + end -- compare type +end --sort_by_name + + +function compassgps.distance2d(pos1in,pos2in) +local pos1=compassgps.round_digits_vector(pos1in,0) +local pos2=compassgps.round_digits_vector(pos2in,0) +return math.sqrt((pos2.x-pos1.x)^2+(pos2.z-pos1.z)^2) +end --distance2d + + +--calculate distance between two points +function compassgps.distance3d(pos1in,pos2in) +--round to nearest node +--print(" pos1in="..compassgps.pos_to_string(pos1in).." pos2in="..compassgps.pos_to_string(pos2in)) +local pos1=compassgps.round_digits_vector(pos1in,0) +local pos2=compassgps.round_digits_vector(pos2in,0) +return math.sqrt((pos2.x-pos1.x)^2+(pos2.z-pos1.z)^2+(pos2.y-pos1.y)^2) +end --distance3d + + + +-- ********************************************************** +print(S("compassgps reading settings")) +if minetest.is_singleplayer() and show_shared_on_singleplayer==false then + singleplayer=true +else + singleplayer=false +end + +local settings = { } +local file = io.open(minetest.get_worldpath().."/compassgps_settings", "r") +if file then + settings = minetest.deserialize(file:read("*all")) + file:close() +end +--now transfer these to the correct variables +for name,stng in pairs(settings) do + --if settings[name].point_name then + -- point_name[name]=settings[name].point_name + --end + if settings[name].point_to and settings[name].point_to.bkmrkname then + point_to[name]=settings[name].point_to + else + point_to[name]=nil + end + if settings[name].sort_function then + if settings[name].sort_function == "name" then + sort_function[name]=compassgps.sort_by_name + else + sort_function[name]=compassgps.sort_by_distance + end + end + if settings[name].distance_function then + if settings[name].distance_function == "2d" then + distance_function[name]=compassgps.distance2d + else + distance_function[name]=compassgps.distance3d + end + end + if settings[name].hud_pos then + hud_pos[name]=settings[name].hud_pos + end + if settings[name].hud_color then + hud_color[name]=settings[name].hud_color + end + if settings[name].compass_type then + compass_type[name]=settings[name].compass_type + end + --saved as strings so its easier to check for nil + if settings[name].view_type_P then + view_type_P[name]=settings[name].view_type_P + else + view_type_P[name]="true" + end --view_type_P + if settings[name].view_type_S then + view_type_S[name]=settings[name].view_type_S + else + view_type_S[name]="false" + end --view_type_S + if settings[name].view_type_A then + view_type_A[name]=settings[name].view_type_A + else + view_type_A[name]="false" + end --view_type_A + + if singleplayer then + view_type_P[name]="true" + view_type_A[name]="false" + view_type_S[name]="false" + end--override view types + +end --for + + +function compassgps.bookmark_to_string(bkmrk) + if not bkmrk then return "{nil}" end + local str="{" + if bkmrk.player then str=str..bkmrk.player + else str=str.."player=nil" end + str=str.." : " + if bkmrk.bkmrkname then str=str..bkmrk.bkmrkname + else str=str.."bkmrkname=nil" end + str=str.." : "..compassgps.pos_to_string(bkmrk).." : " + if bkmrk.type then str=str..bkmrk.type + else str=str.."type=nil" end + str=str.."}" + return str + end -- bookmark_to_string + + +function compassgps.bookmark_name_string(bkmrk) + --print("bookmark_name_string: "..compassgps.bookmark_to_string(bkmrk)) + if bkmrk.type=="A" then + return "*admin*:"..bkmrk.player.."> "..bkmrk.bkmrkname + elseif bkmrk.type=="S" then + return "*shared*:"..bkmrk.player.."> "..bkmrk.bkmrkname + else + return bkmrk.bkmrkname + end +end --bookmark_name_string + + +function compassgps.bookmark_name_pos_dist(bkmrk,playername,playerpos) + if distance_function[playername] == nil then + return "" + end + return compassgps.bookmark_name_string(bkmrk).." : "..compassgps.pos_to_string(bkmrk).. + " : "..compassgps.round_digits(distance_function[playername](playerpos,bkmrk),2) +end --gookmark_name_pos_dist + + +function compassgps.count_shared(playername) + local c=0 + for k,v in pairs(bookmarks) do + if v.player and v.player==playername and v.type and v.type=="S" then + c=c+1 + end --if + end --for + return c +end--count_shared + + + +--********************************************************* +--mode "L" create list for displaying bookmarks in gui +--mode "C" display private bookmarks only in chat +--mode "M" similar to "L" but with current position (for maps) +function compassgps.bookmark_loop(mode,playername,findidx) + --print("bookmark_loop top") + local player = minetest.get_player_by_name(playername) + local playerpos = player:getpos() + local list="" + local bkmrkidx=1 + local i=1 + if mode=="L" or mode=="M" then + local spawnbkmrk=compassgps.get_default_bookmark(playername,1) + textlist_bkmrks[playername]={} + if mode=="M" then + local cpos=compassgps.round_pos(playerpos) + list = S("current position : ")..compassgps.pos_to_string({x=cpos.x,y=cpos.y,z=cpos.z,player=playername,type="P",bkmrkname=playername.."'s map"})..",".. + compassgps.bookmark_name_pos_dist(spawnbkmrk,playername,playerpos) + textlist_bkmrks[playername][1]={x=cpos.x,y=cpos.y,z=cpos.z,player=playername,type="P",bkmrkname=S("%s's map"):format(playername)} + textlist_bkmrks[playername][2]=spawnbkmrk + i=2 + mode="L" + else + list = compassgps.bookmark_name_pos_dist(spawnbkmrk,playername,playerpos) + textlist_bkmrks[playername][1]=spawnbkmrk + end --initialize list + + --add all spawn position from beds mod, sethome mod and the default spawn point + spawnbkmrk=compassgps.get_default_bookmark(playername,2) + if spawnbkmrk~=nil then + i=i+1 + list = list..","..compassgps.bookmark_name_pos_dist(spawnbkmrk,playername,playerpos) + textlist_bkmrks[playername][i]=spawnbkmrk + end + spawnbkmrk=compassgps.get_default_bookmark(playername,3) + if spawnbkmrk~=nil then + i=i+1 + list = list..","..compassgps.bookmark_name_pos_dist(spawnbkmrk,playername,playerpos) + textlist_bkmrks[playername][i]=spawnbkmrk + end + textlist_clicked[playername]=1 + end + + --bkmrkidx will be used to highlight the currently selected item in the list + backwardscompatsave="NO" + + for k,v in spairs(bookmarks,sort_function[playername],player) do + --backwards compatibility + --since version 1.5, all bookmarks will have a player and type, but + --bookmarks from the old compass mods and previous versions of this + --mod will not. Because the original mod did not put a seperator between + --the playername and the bookmark name, the only way to seperate them + --is when you have the player name. this if says that if v.player is + --not defined and the begining of the bookmark matches the playername + --then set v.player and v.type and set a flag to save the bookmarks + --print("bookmark_loop unmod "..compassgps.bookmark_to_string(v)) + if not v.player then --if playername is not set, fix it + local pos1, pos2 = string.find(k, playername, 0) + if pos1==1 and pos2 then --add playername and type to bookmark + v.player=playername + v.type="P" + v.bkmrkname=string.sub(k,string.len(v.player)+1) + backwardscompatsave="YES" + end --if pos1==1 + end --if not v.player backwards compatibility + + --even though we set v.player above, that was for bookmarks that match + --this playername, so there could still be other players bookmarks that + --do not have v.player defined, thats why we have to check it again. + local vplayernm="" + if v.player then vplayernm=v.player end + local vtype="P" + if v.type then vtype=v.type end + local vbkmrkname=k + if v.bkmrkname then vbkmrkname=v.bkmrkname end + --now vplayernm,vtype,vbkmrkname are guaranteed to be defined + + --admin and shared bookmarks + if (mode=="L") and + ( (vtype=="A" and view_type_A[playername]=="true") or + (vtype=="S" and view_type_S[playername]=="true") ) then + i=i+1 + list = list..","..compassgps.bookmark_name_pos_dist(v,playername,playerpos) + textlist_bkmrks[playername][i]=v + --print("bookmark_loop AS "..i.." "..compassgps.bookmark_to_string(textlist_bkmrks[playername][i])) + --private bookmarks + elseif vtype=="P" and vplayernm==playername and view_type_P[playername]=="true" then + i=i+1 + if mode=="L" then + list = list..","..compassgps.bookmark_name_pos_dist(v,playername,playerpos) + --list = list..","..vbkmrkname.." : "..compassgps.pos_to_string(v).. + -- " : "..compassgps.round_digits(distance_function[playername](playerpos,v),2) + textlist_bkmrks[playername][i]=v + --print("bookmark_loop P "..i.." "..compassgps.bookmark_to_string(textlist_bkmrks[playername][i])) + elseif mode=="C" then + --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 + + --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 + if point_to[playername]~=nil then -- don't crash when point_to[playername] is nil + if mode=="L" and bkmrkidx==1 and vbkmrkname==point_to[playername].bkmrkname + and vplayernm==point_to[playername].player then + bkmrkidx=i + textlist_clicked[playername]=i + --point_to is the bookmark this player's compass is already pointing to + --when we open the list, if we found a bookmark that matches that item, we want + --to highlight it (by setting bkmrkidx to the index to highlight) and we want + --to set textlist_clicked to match that item. We need textlist_clicked because + --textlist does not return the currently selected item when you click a button, + --so we must keep the currently selected item in memory + --elseif mode=="I" and i==findidx then + -- return bkmrkname --found the item we were looking for, we are done. + end --if mode=L + end --for spairs + end --point_to[playername]~=nil + + if backwardscompatsave=="YES" then compassgps.write_bookmarks() end + + if mode=="L" then + return list,bkmrkidx + --elseif mode=="I" then + -- return "default" --didn't find it, so return default. + end --if mode=="L" + +end --bookmark_loop + + + + + + +function compassgps.get_confirm_formspec(playername,bkmrkidx) + --print("get_confirm_remove_formspec") + local player = minetest.get_player_by_name(playername) + if not compassgps.verify_bookmark_parms("remove_bookmark",player,playername,bkmrkidx) + then return end + local bkmrk=textlist_bkmrks[playername][bkmrkidx] + + return "compassgps:confirm_remove", "size[8,2;]".. + "label[0,0.2;"..S("Remove bookmark: ")..compassgps.bookmark_name_string(bkmrk).." ?]".. + "button[0,0.7;4,1;confirm_remove_yes;"..S("Yes").."]".. + "button[4,0.7;4,1;confirm_remove_no;"..S("No").."]" +end + + +function compassgps.check_view_type_all_blank(playername) + --view_type values are not all set when you first bring up the form + --so we check to ensure that view_type_A and S are default false for sp and true for mp + --and that if all values are false we set view_type_P to true + local defaultvalue="true" + if singleplayer then + defaultvalue="false" + end + if (not view_type_A[playername]) then + view_type_A[playername]=defaultvalue + end + if (not view_type_S[playername]) then + view_type_S[playername]=defaultvalue + end + if (not view_type_P[playername]) + or (view_type_P[playername]=="false" and view_type_S[playername]=="false" + and view_type_A[playername]=="false") then + view_type_P[playername]="true" + end +end --check_view_type_all_blank + + + +minetest.register_on_player_receive_fields(function(player,formname,fields) + if (not player) then + return false; + end + + local playername = player:get_player_name(); + if (playername ~= "" and formname == "compassgps:bookmarks") then + --"bookmark" field is set EVERY time. I would like to detect someone hitting + --enter in that field, but the problem is, if someone types something into + --the bookmark field, and then clicks on a bookmark in the textlist, + --I would get back bookmark as set. So, the only way to detect that + --enter has been hit in the bookmark field is to check bookmark, and ensure + --every other field is NOT set. + --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"]) + ) + 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)) + elseif fields["remove_bookmark"] and textlist_clicked[playername] then + local bkmrkidx=textlist_clicked[playername] + if textlist_bkmrks[playername][bkmrkidx].player ~= playername then + --only admins can delete someone elses shared bookmark + --check to see if the player has "privs" privliges + local player_privs + player_privs = minetest.get_player_privs(playername) + if not player_privs["privs"] then + minetest.chat_send_player(playername,S("you can not remove someone elses bookmark:").. + compassgps.bookmark_name_string(textlist_bkmrks[playername][bkmrkidx])) + return + end --if not player_privs + end -- if player~=playername + + -- you can't remove default bookmarks (bed, home, spawnpoint) + if textlist_bkmrks[playername][bkmrkidx].bkmrkname==nil or textlist_bkmrks[playername][bkmrkidx].player==nil then + return + end + if bookmarks[textlist_bkmrks[playername][bkmrkidx].player..textlist_bkmrks[playername][bkmrkidx].bkmrkname]==nil then + return + end + + --if they got here, they have authority to del the bookmark, show confirm dialog + minetest.show_formspec(playername, compassgps.get_confirm_formspec(playername, bkmrkidx)) + elseif fields["find_bookmark"] and textlist_clicked[playername] then + --print("compassgps.fields find_bookmark triggered, playername="..playername.." textlist_clicked="..textlist_clicked[playername]) + compassgps.find_bookmark(playername,textlist_clicked[playername]) + elseif fields["bookmark_list"] then + local idx=tonumber(string.sub(fields["bookmark_list"],5)) + --textlist_clicked[playername]=compassgps.bookmark_from_idx(playername,idx) + --textlist_clicked[playername]=compassgps.bookmark_loop("I",playername,idx) + textlist_clicked[playername]=idx + --print("bookmark_list triggered textlist idx="..idx.." tlc="..textlist_clicked[playername]) + elseif fields["sort_type"] then + local idx=tonumber(string.sub(fields["sort_type"],5)) + if idx==1 then + sort_function[playername]=compassgps.sort_by_name + else + sort_function[playername]=compassgps.sort_by_distance + end --if name else distance + minetest.show_formspec(playername, compassgps.get_compassgps_formspec(playername)) + elseif fields["distance_type"] then + local idx=tonumber(string.sub(fields["distance_type"],5)) + if idx==1 then + distance_function[playername]=compassgps.distance3d + else + distance_function[playername]=compassgps.distance2d + end --if 2d else 3d + minetest.show_formspec(playername, compassgps.get_compassgps_formspec(playername)) + elseif fields["show_private"] then + view_type_P[playername]=tostring(fields["show_private"]) + compassgps.check_view_type_all_blank(playername) + minetest.show_formspec(playername, compassgps.get_compassgps_formspec(playername)) + elseif fields["show_shared"] then + view_type_S[playername]=tostring(fields["show_shared"]) + compassgps.check_view_type_all_blank(playername) + minetest.show_formspec(playername, compassgps.get_compassgps_formspec(playername)) + elseif fields["show_admin"] then + view_type_A[playername]=tostring(fields["show_admin"]) + compassgps.check_view_type_all_blank(playername) + minetest.show_formspec(playername, compassgps.get_compassgps_formspec(playername)) + elseif fields["teleport"] then + -- Teleport player. + compassgps.teleport_bookmark(playername, textlist_clicked[playername]) + elseif fields["settings"] then + --bring up settings screen + minetest.show_formspec(playername, compassgps.get_settings_formspec(playername)) + end --compassgps formspec + elseif (playername ~= "" and formname == "compassgps:settings") then + if fields["hud_pos"] then --and fields["hudx"] and fields["hudy"] then + --minetest.chat_send_all("hud_pos triggered") + if tonumber(fields["hudx"]) and tonumber(fields["hudy"]) then + hud_pos[playername].x=fields["hudx"] + hud_pos[playername].y=fields["hudy"] + if tonumber(hud_pos[playername].x)<0 or tonumber(hud_pos[playername].x)>1 + or tonumber(hud_pos[playername].y)<0 or tonumber(hud_pos[playername].y)>1 then + minetest.chat_send_player(playername,S("compassgps: hud coords out of range, hud will not be displayed. Change to between 0 and 1 to restore")) + --compassgps.write_settings() --no need to save until you quit + end + else --not numbers + minetest.chat_send_player(playername,S("compassgps: hud coords are not numeric. Change to between 0 and 1")) + end --if x,y valid + if tonumber(fields["hudcolor"],16) then + hud_color[playername]=fields["hudcolor"] + else + minetest.chat_send_player(playername,S("compassgps: hud color not valid hex number")) + end --if color valid + elseif fields["compass_type_a"] then + compass_type[playername]="a" + elseif fields["compass_type_b"] then + compass_type[playername]="b" + elseif fields["compass_type_c"] then + compass_type[playername]="c" + end --if fields["hud_pos"] + elseif (playername ~= "" and formname == "compassgps:confirm_remove") then + if fields["confirm_remove_yes"] then + compassgps.remove_bookmark(playername, textlist_clicked[playername]) + minetest.show_formspec(playername, compassgps.get_compassgps_formspec(playername)) + elseif fields["confirm_remove_no"] then + minetest.show_formspec(playername, compassgps.get_compassgps_formspec(playername)) + end -- if fields["confirm_remove_yes"] + end -- form if +end) + + +--saves the bookmark list in minetest/words//bookmarks +function compassgps.write_bookmarks() + local file = io.open(minetest.get_worldpath().."/bookmarks", "w") + if file then + file:write(minetest.serialize(bookmarks)) + file:close() + end +end --write_bookmarks + + +--saves the settings in minetest/words//compassgps_settings +function compassgps.write_settings() + --loop through players and set settings + --(less error prone than trying to keep settings in sync all the time + print(S("compassgps writing settings")) + local players = minetest.get_connected_players() + for i,player in ipairs(players) do + local name = player:get_player_name(); + local sort_short="name" + --if you save the actual sort_function or distance_function, it saves the + --whole function in the serialized file! not what I wanted, and doesn't work right. + if sort_function[name] and sort_function[name]==compassgps.sort_by_distance then + sort_short="distance" + end + local dist_short="2d" + if distance_function[name] and distance_function[name]==compassgps.distance3d then + dist_short="3d" + end + settings[name]={point_to=point_to[name], + hud_pos=hud_pos[name], + sort_function=sort_short, + distance_function=dist_short, + hud_color=hud_color[name], + compass_type=compass_type[name], + view_type_P=view_type_P[name], + view_type_S=view_type_S[name], + view_type_A=view_type_A[name]} + end + --now write to file + local file = io.open(minetest.get_worldpath().."/compassgps_settings", "w") + if file then + file:write(minetest.serialize(settings)) + file:close() + end +end --write_settings + + +minetest.register_on_leaveplayer(function(player) + compassgps.write_settings() + end) + +minetest.register_on_shutdown(compassgps.write_settings) + + +function compassgps.clean_string(str) + --remove dangerous characters that will mess up the list of bookmarks + --the file can handle these fine, but the LIST for the textlist + --will interpret these as seperators + str=string.gsub(str,",",".") + str=string.gsub(str,";",".") + str=string.gsub(str,"%[","(") + str=string.gsub(str,"%]",")") + return str +end --clean_string + + + +function compassgps.set_bookmark(playername, bkmrkname, type, predefinedpos) + local player = minetest.get_player_by_name(playername) + if not player then + return + end + + local pos = player:getpos() + if predefinedpos ~= nil then + pos = predefinedpos + end + --we are marking a NODE, no need to keep all those fractions + pos=compassgps.round_pos(pos) + + bkmrkname=compassgps.clean_string(bkmrkname) + + if bkmrkname == "" then + minetest.chat_send_player(playername, S("Give the bookmark a name.")) + return + end + if bkmrkname == "default" or bkmrkname == "bed" or bkmrkname == "sethome" + 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)) + return + end + if bookmarks[playername..bkmrkname] then + minetest.chat_send_player(playername, S("You already have a bookmark with that name.")) + return + end + + pos.type=type or "P" --Private Shared Admin + + if pos.type=="S" and compassgps.count_shared(playername) >= max_shared then + minetest.chat_send_player(playername, S("The maximum number of shared bookmarks any user can create is %d."):format(max_shared)) + return + end + + pos.bkmrkname=bkmrkname + pos.player=playername + + bookmarks[playername..bkmrkname] = pos + + compassgps.write_bookmarks() + minetest.chat_send_player(playername, S("Bookmark '%s' added at %s type=%s"):format(bkmrkname, compassgps.pos_to_string(pos), pos.type)) +end + + +minetest.register_chatcommand("set_bookmark", { + params = "", + description = S("set_bookmark: Sets a location bookmark for the player"), + func = function (playername, bkmrkname) + compassgps.set_bookmark(playername, bkmrkname, "P") + end, +}) + + + +--returns a pos that is rounded special case. round 0 digits for X and Z, +--round 1 digit for Y +function compassgps.round_pos(pos) + pos.x=compassgps.round_digits(pos.x,0) + pos.y=compassgps.round_digits(pos.y,1) + pos.z=compassgps.round_digits(pos.z,0) + return pos +end --round_pos + + + +function compassgps.round_digits(num,digits) + if num >= 0 then return math.floor(num*(10^digits)+0.5)/(10^digits) + else return math.ceil(num*(10^digits)-0.5)/(10^digits) + end +end --round_digits + +function compassgps.round_digits_vector(vec,digits) + return {x=compassgps.round_digits(vec.x,digits),y=compassgps.round_digits(vec.y,digits), + z=compassgps.round_digits(vec.z,digits)} +end --round_digits_vector + + +--because built in pos_to_string doesn't handle nil, and commas mess up textlist +--this rounds same rules as for setting bookmark or teleporting +--that way what you see in the hud matches where you teleport or bookmark +function compassgps.pos_to_string(pos) + if pos==nil then return "(nil)" + else + pos=compassgps.round_pos(pos) + return "("..pos.x.." "..pos.y.." "..pos.z..")" + end --pos==nill +end --pos_to_string + + + +minetest.register_chatcommand("list_bookmarks", { + params = "", + description = S("list_bookmarks: Lists all bookmarks of a player"), + func = function(name, param) + compassgps.bookmark_loop("C",name) + end, +}) + + +function compassgps.verify_bookmark_parms(from_function,player,playername,bkmrkidx) + --just being paranoid, probably none of these checks are necessary + if not player then + print(S("compassgps.%s player not found"):format(from_function)) + if not playername then print(S(" playername=nil")) + else print(S(" playername=%s"):format(playername)) + end --if not playername + return false + end --if not player + if not tonumber(bkmrkidx) then + print(S("compassgps.%s invalid bkrmkidx"):format(from_funtion)) + if not bkmrkidx then print(S(" bkmrkidx=nil")) + else print(" bkmrkidx="..bkmrkidx) + end --if not bkmrkidx + return false + end --if not tonumber(bkmrkidx) + if not textlist_bkmrks[playername][bkmrkidx] then + print(S("compassgps.%s invalid bookmark playername=%s bkmrkid=%s"):format(from_function, playername, bkmrkidx)) + minetest.chat_send_player(playername,S("compassgps:%s invalid bookmark"):format(from_function)) + return false + end --if not textlist_bkmrks + return true --if you got here it is all good +end --verify_bookmark_parms + + + +function compassgps.remove_bookmark(playername, bkmrkidx) + local player = minetest.get_player_by_name(playername) + if not compassgps.verify_bookmark_parms("remove_bookmark",player,playername,bkmrkidx) + then return end + + + + print(S("remove bookmark playername=%s bkmrkidx=%s"):format(playername, bkmrkidx)) + minetest.chat_send_player(playername, S("removed %s"):format( + compassgps.bookmark_name_string(textlist_bkmrks[playername][bkmrkidx]))) + bookmarks[textlist_bkmrks[playername][bkmrkidx].player.. + textlist_bkmrks[playername][bkmrkidx].bkmrkname] = nil + compassgps.write_bookmarks() +end --remove_bookmarks + + + +function compassgps.remove_bookmark_byname(playername, bkmrkname) + local player = minetest.get_player_by_name(playername) + if not player then + return + end + if bkmrkname == "" then + minetest.chat_send_player(name, S("No bookmark was specified.")) + return + end + if not bookmarks[playername..bkmrkname] then + minetest.chat_send_player(playername, S("You have no bookmark with this name.")) + return + end + bookmarks[playername..bkmrkname] = nil + compassgps.write_bookmarks() + minetest.chat_send_player(playername, S("The bookmark "..bkmrkname.." has been successfully removed.")) +end + + + +minetest.register_chatcommand("remove_bookmark", { + params = "", + description = S("Removes the bookmark specified by "), + func = function(name, bkmrkname) + compassgps.remove_bookmark_byname(name,bkmrkname) + end, +}) + + +function compassgps.teleport_bookmark(playername, bkmrkidx) + local player = minetest.get_player_by_name(playername) + if not compassgps.verify_bookmark_parms("teleport_bookmark",player,playername,bkmrkidx) + then return end + print(S("compassgps teleporting player %s to %s"):format(playername, + 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]) +end --teleport_bookmark + + + +function compassgps.find_bookmark_byname(playername, bkmrkname) + local player = minetest.get_player_by_name(playername) + if not player then + return + end + if not bkmrkname or bkmrkname == "" then + minetest.chat_send_player(playername, S("No bookmark was specified.")) + return + end + if bkmrkname == "default" then + minetest.chat_send_player(playername, S("Pointing at default location.")) + point_to[playername] = compassgps.get_default_bookmark(playername,1) + return + end + if not bookmarks[playername..bkmrkname] then + minetest.chat_send_player(playername, S("You have no bookmark with this name.")) + return + end + point_to[playername] = bookmarks[playername..bkmrkname] + minetest.chat_send_player(playername, S("Pointing at %s."):format(bkmrkname)) +end + + + +function compassgps.find_bookmark(playername, bkmrkidx) + local player = minetest.get_player_by_name(playername) + if not compassgps.verify_bookmark_parms("find_bookmark",player,playername,bkmrkidx) + then return end + point_to[playername] = textlist_bkmrks[playername][bkmrkidx] + minetest.chat_send_player(playername, S("Pointing at %s."):format(point_to[playername].bkmrkname)) +end + + +minetest.register_chatcommand("find_bookmark", { + params = "", + description = S("Lets the compassgps point to the bookmark"), + func = function(playername, bkmrkname) + compassgps.find_bookmark_byname(playername,bkmrkname) + end, +}) + + + + + +-- compassgps mod + + + + +-- default to static spawnpoint +local static_spawnpoint = minetest.setting_get_pos("static_spawnpoint") +-- default to 0/0/0 if spawnpoint is not present or invalid +local default_spawn = static_spawnpoint or {x=0, y=0, z=0} + +local last_time_spawns_read = "default" +local beds_spawns = {} +local sethome_spawns = {} +function read_spawns() + -- read BlockMen beds-mod positions (added to default minetest game) + local beds_file = io.open(minetest.get_worldpath().."/beds_spawns", "r") + if beds_file then + while true do + local x = beds_file:read("*n") + if x == nil then + break + end + local y = beds_file:read("*n") + local z = beds_file:read("*n") + local name = beds_file:read("*l") + beds_spawns[name:sub(2)] = {x = x, y = y, z = z} + end + io.close(beds_file) + else + -- read PilzAdams beds-mod positions + beds_file = io.open(minetest.get_worldpath().."/beds_player_spawns", "r") + if beds_file then + beds_spawns = minetest.deserialize(beds_file:read("*all")) + beds_file:close() + end + end + + -- read sethome-mod positions + if minetest.get_modpath('sethome') then + local sethome_file = io.open(minetest.get_modpath('sethome')..'/homes', "r") + if sethome_file then + while true do + local x = sethome_file:read("*n") + if x == nil then + break + end + local y = sethome_file:read("*n") + local z = sethome_file:read("*n") + local name = sethome_file:read("*l") + sethome_spawns[name:sub(2)] = {x = x, y = y, z = z} + end + io.close(sethome_file) + end + end +end + + +function compassgps.compass_type_name(playername,imagenum,ctypein) + local ctype="a" + if ctypein then + ctype=ctypein + end + if playername~="" and compass_type[playername] then + ctype=compass_type[playername] + end + if ctype=="a" then + ctype="" + end + --print("compass type name return "..ctype..imagenum) + return ctype..imagenum +end + + +function compassgps.get_default_bookmark(name,num) + -- try to get position from beds-mod spawn + local pos = beds_spawns[name] + local posname="bed" + if pos~=nil and num==1 then + default_bookmark={x=pos.x,y=pos.y,z=pos.z,player=name,type="P",bkmrkname=posname} + return default_bookmark + elseif pos~=nil then + num=num-1 + end + -- fallback to sethome position + pos = sethome_spawns[name] + posname="home" + if pos~=nil and num==1 then + default_bookmark={x=pos.x,y=pos.y,z=pos.z,player=name,type="P",bkmrkname=posname} + return default_bookmark + elseif pos~=nil then + num=num-1 + end + if num>1 then + return + end + + -- fallback to default + pos = default_spawn; + posname="spawn" + default_bookmark={x=pos.x,y=pos.y,z=pos.z,player=name,type="P",bkmrkname=posname} + return default_bookmark +end --get_default_bookmark + +function compassgps.get_default_pos_and_name(name) + -- try to get position from PilzAdams bed-mod spawn + local pos = beds_spawns[name] + local posname="bed" + -- fallback to sethome position + if pos == nil then + pos = sethome_spawns[name] + posname="sethome" + end + -- fallback to default + if pos == nil then + pos = default_spawn; + posname="default" + end +default_bookmark={x=pos.x,y=pos.y,z=pos.z,player=name,type="P"} +return pos,posname +end --get_compassgps_target_pos + + + + +minetest.register_globalstep(function(dtime) + if last_time_spawns_read ~= os.date("%M") then + last_time_spawns_read = os.date("%M") + read_spawns() + end + local players = minetest.get_connected_players() + for i,player in ipairs(players) do + local playername = player:get_player_name(); + + local gotacompass=false + local wielded=false + local activeinv=nil + 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 + 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_yaw() + 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 + + + --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 + distance_function[playername]=distance_function[playername] or compassgps.distance3d + --if distance_function[playername]==nil then + -- distance_function[playername]=compassgps.distance3d + --end + + + local hudx=tonumber(hud_default_x) + local hudy=tonumber(hud_default_y) + if hud_pos[playername] then + hudx=tonumber(hud_pos[playername].x) + hudy=tonumber(hud_pos[playername].y) + else + hud_pos[playername]={x=hud_default_x, y=hud_default_y} + end + + local hudcolor=tonumber(hud_default_color, 16) + if hud_color[playername] then + hudcolor=tonumber(hud_color[playername], 16) + else + hud_color[playername]=hud_default_color + end + + 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 + compasstype=compass_type[playername] + else + compass_type[playername]=compass_default_type + end + + local h=nil + if hudx>=0 and hudx<=1 and hudy>=0 and hudy<=1 then + h = player:hud_add({ + hud_elem_type = "text"; + position = {x=hudx, y=hudy}; + text = compassgps.pos_to_string(pos).." -> ".. + compassgps.bookmark_name_pos_dist(target,playername,pos); + --text = compassgps.pos_to_string(pos).." -> "..target.bkmrkname.. + -- " "..compassgps.pos_to_string(target).." : ".. + -- compassgps.round_digits(distance_function[playername](pos,target),2); + number = hudcolor; + scale = 20; + }); + end --if x and y in range + if (player_hud[playername]) then + --remove the previous element + player:hud_remove(player_hud[playername]); + end + player_hud[playername] = h; --store this element for removal next time + --this elseif is triggered if gotacompass=false + elseif (player_hud[playername]) then --remove the hud if player no longer has compass + player:hud_remove(player_hud[playername]); + player_hud[playername]=nil + end --if gotacompass + end --for i,player in ipairs(players) +end) -- register_globalstep + + + + + + + + + +function compassgps.sort_by_coords(table,a,b) + if table[a].x==table[b].x then + if table[a].z==table[b].z then + return table[a].y = Entfernt den Wegpunkt der mit angegeben ist. +Settings = Einstellungen +Shared = Geteilt +Show: = Zeige: +Sort by: = Sortiere nach: +Teleporting to %s = Teleportiere zu %s +The bookmark = Der Wegpunkt +The maximum number of shared bookmarks any user can create is %d. = Jeder Nutzer kann nur %d geteilte Wegpunkte erstellen. +Yes = Ja +You already have a bookmark with that name. = Sie haben bereits einen Wegpunkt mit diesem Namen. +You have no bookmark with this name. = Sie haben keinen Wegpunkt mit diesem Namen. +bookmark = Wegpunkt +compassgps reading bookmarks = compassgps liest die Wegpunkte. +compassgps reading settings = compassgps liest die Einstellungen. +compassgps = Kompass +compassgps teleporting player %s to %s = compassgps teleportiert Spieler %s nach %s. +compassgps writing settings = compassgps schreibt die Einstellungen. +compassgps.%s invalid bkrmkidx = compassgps.%s ungültige bkmrkidx. +compassgps.%s invalid bookmark playername\=%s bkmrkid\=%s = compassgps.%s ungültiger Wegpunkt Spielername\=%s bkmrkidx\=%s. +compassgps.%s player not found = compassgps.%s Spieler nicht gefunden. +compassgps: hud color not valid hex number = compassgps: HUD Farbe ist keine zulässige Hexadezimalzahl. +compassgps: hud coords are not numeric. Change to between 0 and 1 = compassgps: HUD Koordinaten sind keine Zahlen. Ändern sie diese zu Werten zwischen 0 und 1. +compassgps: hud coords out of range, hud will not be displayed. Change to between 0 and 1 to restore = compassgps: HUD Koordinaten sind außerhalb des zulässigen Bereichs. Ändern sie diese zu Werten zwischen 0 und 1 um das HUD wiederherzustellen. +compassgps:%s invalid bookmark = compassgps.%s ungültiger Wegpunkt +create admin = Erstelle Administratorwegpunkt +create bookmark = Erstelle Wegpunkt +create shared = Erstelle geteilten Wegpunkt +current position : = Momentane Position : +distance = Entfernung +find selected bookmark = Finde den ausgewählten Wegpunkt +list_bookmarks: Lists all bookmarks of a player = list_bookmarks: Zeigt alle Wegpunkte eines Spielers. +name = Name +remove bookmark = Entferne den Wegpunkt +remove bookmark playername\=%s bkmrkidx\=%s = Entferne den Wegpunkt Spielername\=%s bkmrkidx\=%s +removed %s = %s entfernt. +set_bookmark: Sets a location bookmark for the player = set_bookmark: Setzt einen Wegpunkt für den Spieler. +teleport to bookmark = Teleportiere zu dem Wegpunkt. +you can not remove someone elses bookmark: = Sie können den Wegpunkt eines anderen Spielers nicht entfernen: +CompassGPS Map (blank) = CompassGPS Karte (leer) +CompassGPS Map (marked) = CompassGPS Karte (markiert) +Write to cgpsmap = Schreibe auf die Karte +copy bookmark to your compassgps = Kopiere den Wegpunkt in ihren Kompass. +bookmark name: = Name des Wegpunkts: +bookmark pos: = Position des Wegpunkts: diff --git a/mods/compassgps/locale/template.txt b/mods/compassgps/locale/template.txt new file mode 100644 index 00000000..20af3180 --- /dev/null +++ b/mods/compassgps/locale/template.txt @@ -0,0 +1,63 @@ + bkmrkidx\=nil = + playername\=%s = + playername\=nil = +%s's map = +A bookmark with the name '%s' can't be created. = +Admin = +Bookmark '%s' added at %s type\=%s = +Change hud: = +Color: = +Dist: = +Compass Type: = +Give the bookmark a name. = +Lets the compassgps point to the bookmark = +No = +No bookmark was specified. = +Pointing at %s. = +Pointing at default location. = +Private = +Remove bookmark: = +Removes the bookmark specified by = +Settings = +Shared = +Show: = +Sort by: = +Teleporting to %s = +The bookmark = +The maximum number of shared bookmarks any user can create is %d. = +Yes = +You already have a bookmark with that name. = +You have no bookmark with this name. = +bookmark = +compassgps reading bookmarks = +compassgps reading settings = +compassgps = +compassgps teleporting player %s to %s = +compassgps writing settings = +compassgps.%s invalid bkrmkidx = +compassgps.%s invalid bookmark playername\=%s bkmrkid\=%s = +compassgps.%s player not found = +compassgps: hud color not valid hex number = +compassgps: hud coords are not numeric. Change to between 0 and 1 = +compassgps: hud coords out of range, hud will not be displayed. Change to between 0 and 1 to restore = +compassgps:%s invalid bookmark = +create admin = +create bookmark = +create shared = +current position : = +distance = +find selected bookmark = +list_bookmarks: Lists all bookmarks of a player = +name = +remove bookmark = +remove bookmark playername\=%s bkmrkidx\=%s = +removed %s = +set_bookmark: Sets a location bookmark for the player = +teleport to bookmark = +you can not remove someone elses bookmark: = +CompassGPS Map (blank) = +CompassGPS Map (marked) = +Write to cgpsmap = +copy bookmark to your compassgps = +bookmark name: = +bookmark pos: = diff --git a/mods/compassgps/textures/cgpsmap-blank.png b/mods/compassgps/textures/cgpsmap-blank.png new file mode 100644 index 00000000..f3289f34 Binary files /dev/null and b/mods/compassgps/textures/cgpsmap-blank.png differ diff --git a/mods/compassgps/textures/cgpsmap-marked.png b/mods/compassgps/textures/cgpsmap-marked.png new file mode 100644 index 00000000..a4bfd7c7 Binary files /dev/null and b/mods/compassgps/textures/cgpsmap-marked.png differ diff --git a/mods/compassgps/textures/compass_0.png b/mods/compassgps/textures/compass_0.png new file mode 100644 index 00000000..bb33a804 Binary files /dev/null and b/mods/compassgps/textures/compass_0.png differ diff --git a/mods/compassgps/textures/compass_1.png b/mods/compassgps/textures/compass_1.png new file mode 100644 index 00000000..f7646828 Binary files /dev/null and b/mods/compassgps/textures/compass_1.png differ diff --git a/mods/compassgps/textures/compass_10.png b/mods/compassgps/textures/compass_10.png new file mode 100644 index 00000000..7b44a288 Binary files /dev/null and b/mods/compassgps/textures/compass_10.png differ diff --git a/mods/compassgps/textures/compass_11.png b/mods/compassgps/textures/compass_11.png new file mode 100644 index 00000000..2cf7fc03 Binary files /dev/null and b/mods/compassgps/textures/compass_11.png differ diff --git a/mods/compassgps/textures/compass_2.png b/mods/compassgps/textures/compass_2.png new file mode 100644 index 00000000..a4712f0d Binary files /dev/null and b/mods/compassgps/textures/compass_2.png differ diff --git a/mods/compassgps/textures/compass_3.png b/mods/compassgps/textures/compass_3.png new file mode 100644 index 00000000..3b07e41f Binary files /dev/null and b/mods/compassgps/textures/compass_3.png differ diff --git a/mods/compassgps/textures/compass_4.png b/mods/compassgps/textures/compass_4.png new file mode 100644 index 00000000..511497af Binary files /dev/null and b/mods/compassgps/textures/compass_4.png differ diff --git a/mods/compassgps/textures/compass_5.png b/mods/compassgps/textures/compass_5.png new file mode 100644 index 00000000..8ea4db90 Binary files /dev/null and b/mods/compassgps/textures/compass_5.png differ diff --git a/mods/compassgps/textures/compass_6.png b/mods/compassgps/textures/compass_6.png new file mode 100644 index 00000000..85b09ffe Binary files /dev/null and b/mods/compassgps/textures/compass_6.png differ diff --git a/mods/compassgps/textures/compass_7.png b/mods/compassgps/textures/compass_7.png new file mode 100644 index 00000000..64797814 Binary files /dev/null and b/mods/compassgps/textures/compass_7.png differ diff --git a/mods/compassgps/textures/compass_8.png b/mods/compassgps/textures/compass_8.png new file mode 100644 index 00000000..6b5a7115 Binary files /dev/null and b/mods/compassgps/textures/compass_8.png differ diff --git a/mods/compassgps/textures/compass_9.png b/mods/compassgps/textures/compass_9.png new file mode 100644 index 00000000..5243b798 Binary files /dev/null and b/mods/compassgps/textures/compass_9.png differ diff --git a/mods/compassgps/textures/compass_b0.png b/mods/compassgps/textures/compass_b0.png new file mode 100644 index 00000000..890da15b Binary files /dev/null and b/mods/compassgps/textures/compass_b0.png differ diff --git a/mods/compassgps/textures/compass_b1.png b/mods/compassgps/textures/compass_b1.png new file mode 100644 index 00000000..357a241c Binary files /dev/null and b/mods/compassgps/textures/compass_b1.png differ diff --git a/mods/compassgps/textures/compass_b10.png b/mods/compassgps/textures/compass_b10.png new file mode 100644 index 00000000..817a6227 Binary files /dev/null and b/mods/compassgps/textures/compass_b10.png differ diff --git a/mods/compassgps/textures/compass_b11.png b/mods/compassgps/textures/compass_b11.png new file mode 100644 index 00000000..b990fc2a Binary files /dev/null and b/mods/compassgps/textures/compass_b11.png differ diff --git a/mods/compassgps/textures/compass_b2.png b/mods/compassgps/textures/compass_b2.png new file mode 100644 index 00000000..36b33135 Binary files /dev/null and b/mods/compassgps/textures/compass_b2.png differ diff --git a/mods/compassgps/textures/compass_b3.png b/mods/compassgps/textures/compass_b3.png new file mode 100644 index 00000000..16f547bb Binary files /dev/null and b/mods/compassgps/textures/compass_b3.png differ diff --git a/mods/compassgps/textures/compass_b4.png b/mods/compassgps/textures/compass_b4.png new file mode 100644 index 00000000..812b7846 Binary files /dev/null and b/mods/compassgps/textures/compass_b4.png differ diff --git a/mods/compassgps/textures/compass_b5.png b/mods/compassgps/textures/compass_b5.png new file mode 100644 index 00000000..5d46b1ba Binary files /dev/null and b/mods/compassgps/textures/compass_b5.png differ diff --git a/mods/compassgps/textures/compass_b6.png b/mods/compassgps/textures/compass_b6.png new file mode 100644 index 00000000..41027182 Binary files /dev/null and b/mods/compassgps/textures/compass_b6.png differ diff --git a/mods/compassgps/textures/compass_b7.png b/mods/compassgps/textures/compass_b7.png new file mode 100644 index 00000000..73627a38 Binary files /dev/null and b/mods/compassgps/textures/compass_b7.png differ diff --git a/mods/compassgps/textures/compass_b8.png b/mods/compassgps/textures/compass_b8.png new file mode 100644 index 00000000..27dc7664 Binary files /dev/null and b/mods/compassgps/textures/compass_b8.png differ diff --git a/mods/compassgps/textures/compass_b9.png b/mods/compassgps/textures/compass_b9.png new file mode 100644 index 00000000..970e53f9 Binary files /dev/null and b/mods/compassgps/textures/compass_b9.png differ diff --git a/mods/compassgps/textures/compass_c0.png b/mods/compassgps/textures/compass_c0.png new file mode 100644 index 00000000..e4ec72fe Binary files /dev/null and b/mods/compassgps/textures/compass_c0.png differ diff --git a/mods/compassgps/textures/compass_c1.png b/mods/compassgps/textures/compass_c1.png new file mode 100644 index 00000000..74e2c58c Binary files /dev/null and b/mods/compassgps/textures/compass_c1.png differ diff --git a/mods/compassgps/textures/compass_c10.png b/mods/compassgps/textures/compass_c10.png new file mode 100644 index 00000000..c4b3e13f Binary files /dev/null and b/mods/compassgps/textures/compass_c10.png differ diff --git a/mods/compassgps/textures/compass_c11.png b/mods/compassgps/textures/compass_c11.png new file mode 100644 index 00000000..5468eadf Binary files /dev/null and b/mods/compassgps/textures/compass_c11.png differ diff --git a/mods/compassgps/textures/compass_c2.png b/mods/compassgps/textures/compass_c2.png new file mode 100644 index 00000000..431b687a Binary files /dev/null and b/mods/compassgps/textures/compass_c2.png differ diff --git a/mods/compassgps/textures/compass_c3.png b/mods/compassgps/textures/compass_c3.png new file mode 100644 index 00000000..8ea342f7 Binary files /dev/null and b/mods/compassgps/textures/compass_c3.png differ diff --git a/mods/compassgps/textures/compass_c4.png b/mods/compassgps/textures/compass_c4.png new file mode 100644 index 00000000..d38a4b19 Binary files /dev/null and b/mods/compassgps/textures/compass_c4.png differ diff --git a/mods/compassgps/textures/compass_c5.png b/mods/compassgps/textures/compass_c5.png new file mode 100644 index 00000000..aff3ccb2 Binary files /dev/null and b/mods/compassgps/textures/compass_c5.png differ diff --git a/mods/compassgps/textures/compass_c6.png b/mods/compassgps/textures/compass_c6.png new file mode 100644 index 00000000..cffa6c68 Binary files /dev/null and b/mods/compassgps/textures/compass_c6.png differ diff --git a/mods/compassgps/textures/compass_c7.png b/mods/compassgps/textures/compass_c7.png new file mode 100644 index 00000000..962bcb81 Binary files /dev/null and b/mods/compassgps/textures/compass_c7.png differ diff --git a/mods/compassgps/textures/compass_c8.png b/mods/compassgps/textures/compass_c8.png new file mode 100644 index 00000000..4f986042 Binary files /dev/null and b/mods/compassgps/textures/compass_c8.png differ diff --git a/mods/compassgps/textures/compass_c9.png b/mods/compassgps/textures/compass_c9.png new file mode 100644 index 00000000..6fbf03cc Binary files /dev/null and b/mods/compassgps/textures/compass_c9.png differ diff --git a/mods/compassgps/textures/compassgps_blank.png b/mods/compassgps/textures/compassgps_blank.png new file mode 100755 index 00000000..1b1e662c Binary files /dev/null and b/mods/compassgps/textures/compassgps_blank.png differ diff --git a/mods/worldedge/init.lua b/mods/worldedge/init.lua index 5e672dd7..7a7bf9bd 100644 --- a/mods/worldedge/init.lua +++ b/mods/worldedge/init.lua @@ -62,10 +62,10 @@ minetest.register_globalstep(function(dtime) if pos.z >= edge then newpos = {x = pos.x, y = 10, z = -newedge} - newpos.y = get_surface_pos(newpos).y + newpos.y = get_surface_pos(newpos).y+1 -- /MFF (Mg|19/05//15) elseif pos.z <= -edge then newpos = {x = pos.x, y = 10, z = newedge} - newpos.y = get_surface_pos(newpos).y + newpos.y = get_surface_pos(newpos).y+1 -- /MFF (Mg|19/05/15) end -- Teleport the player