Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
minetest_game
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
minetest_game
Commits
8dc6b012
Commit
8dc6b012
authored
10 years ago
by
Sfan5
Committed by
BlockMen
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add /sethome & /home
parent
4602bd59
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mods/sethome/init.lua
+65
-0
65 additions, 0 deletions
mods/sethome/init.lua
with
65 additions
and
0 deletions
mods/sethome/init.lua
0 → 100644
+
65
−
0
View file @
8dc6b012
local
homes_file
=
minetest
.
get_worldpath
()
..
"/homes"
local
homepos
=
{}
local
function
loadhomes
()
local
input
=
io.open
(
homes_file
,
"r"
)
if
input
then
repeat
local
x
=
input
:
read
(
"*n"
)
if
x
==
nil
then
break
end
local
y
=
input
:
read
(
"*n"
)
local
z
=
input
:
read
(
"*n"
)
local
name
=
input
:
read
(
"*l"
)
homepos
[
name
:
sub
(
2
)]
=
{
x
=
x
,
y
=
y
,
z
=
z
}
until
input
:
read
(
0
)
==
nil
io.close
(
input
)
else
homepos
=
{}
end
end
loadhomes
()
minetest
.
register_privilege
(
"home"
,
"Can use /sethome and /home"
)
local
changed
=
false
minetest
.
register_chatcommand
(
"home"
,
{
description
=
"Teleport you to your home point"
,
privs
=
{
home
=
true
},
func
=
function
(
name
)
local
player
=
minetest
.
env
:
get_player_by_name
(
name
)
if
player
==
nil
then
-- just a check to prevent the server crashing
return
false
end
if
homepos
[
player
:
get_player_name
()]
then
player
:
setpos
(
homepos
[
player
:
get_player_name
()])
minetest
.
chat_send_player
(
name
,
"Teleported to home!"
)
else
minetest
.
chat_send_player
(
name
,
"Set a home using /sethome"
)
end
end
,
})
minetest
.
register_chatcommand
(
"sethome"
,
{
description
=
"Set your home point"
,
privs
=
{
home
=
true
},
func
=
function
(
name
)
local
player
=
minetest
.
env
:
get_player_by_name
(
name
)
local
pos
=
player
:
getpos
()
homepos
[
player
:
get_player_name
()]
=
pos
minetest
.
chat_send_player
(
name
,
"Home set!"
)
changed
=
true
if
changed
then
local
output
=
io.open
(
homes_file
,
"w"
)
for
i
,
v
in
pairs
(
homepos
)
do
output
:
write
(
v
.
x
..
" "
..
v
.
y
..
" "
..
v
.
z
..
" "
..
i
..
"
\n
"
)
end
io.close
(
output
)
changed
=
false
end
end
,
})
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment