Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
teleport_potion
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
teleport_potion
Commits
4f88bf11
Commit
4f88bf11
authored
8 years ago
by
TenPlus1
Browse files
Options
Downloads
Patches
Plain Diff
Tweaked and tidies code, added map_generation_limit's
parent
632d0685
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+7
-6
7 additions, 6 deletions
README.md
init.lua
+106
-115
106 additions, 115 deletions
init.lua
with
113 additions
and
121 deletions
README.md
+
7
−
6
View file @
4f88bf11
...
...
@@ -7,9 +7,10 @@ https://forum.minetest.net/viewtopic.php?f=9&t=9234
Changes:
0.
5 - Added throwable potions
0.
4 - Code tidy and particle effects added
0.
3 - Added Teleport Pad
0.
2 - Bug fixes
0.
1 - Added SFX
0.
0 - Initial release
\ No newline at end of file
-
0.6 - Tweaked and tidied code, added map_generation_limit's
-
0.5 - Added throwable potions
-
0.4 - Code tidy and particle effects added
-
0.3 - Added Teleport Pad
-
0.2 - Bug fixes
-
0.1 - Added SFX
-
0.0 - Initial release
\ No newline at end of file
This diff is collapsed.
Click to expand it.
init.lua
+
106
−
115
View file @
4f88bf11
--= Teleport Potion mod 0.
5
by TenPlus1
--= Teleport Potion mod 0.
6
by TenPlus1
-- Create teleport potion or pad, place then right-click to enter coords
-- and step onto pad or walk into the blue portal light, portal closes after
-- 10 seconds, pad remains, potions are throwable... SFX are license Free...
teleport
=
{}
-- max teleport distance
local
dist
=
tonumber
(
minetest
.
setting_get
(
"map_generation_limit"
)
or
31000
)
-- teleport portal recipe
minetest
.
register_craft
({
output
=
'teleport_potion:potion'
,
recipe
=
{
{
""
,
"default:diamond"
,
""
},
{
"default:diamond"
,
"vessels:glass_bottle"
,
"default:diamond"
},
{
""
,
"default:diamond"
,
""
},
},
})
local
check_coordinates
=
function
(
str
)
-- teleport pad recipe
minetest
.
register_craft
({
output
=
'teleport_potion:pad'
,
recipe
=
{
{
"teleport_potion:potion"
,
'default:glass'
,
"teleport_potion:potion"
},
{
"default:glass"
,
"default:mese"
,
"default:glass"
},
{
"teleport_potion:potion"
,
"default:glass"
,
"teleport_potion:potion"
}
}
})
if
not
str
or
str
==
""
then
return
nil
end
-- get coords from string
local
x
,
y
,
z
=
string.match
(
str
,
"^(-?%d+),(-?%d+),(-?%d+)"
)
-- check coords
if
x
==
nil
or
string.len
(
x
)
>
6
or
y
==
nil
or
string.len
(
y
)
>
6
or
z
==
nil
or
string.len
(
z
)
>
6
then
return
nil
end
-- convert string coords to numbers
x
=
tonumber
(
x
)
y
=
tonumber
(
y
)
z
=
tonumber
(
z
)
-- default coords (from static spawnpoint or default values at end)
teleport
.
default
=
(
minetest
.
setting_get_pos
(
"static_spawnpoint"
)
or
{
x
=
0
,
y
=
2
,
z
=
0
})
-- are coords in map range ?
if
x
>
dist
or
x
<
-
dist
or
y
>
dist
or
y
<
-
dist
or
z
>
dist
or
z
<
-
dist
then
return
nil
end
-- return ok coords
return
{
x
=
x
,
y
=
y
,
z
=
z
}
end
-- particle effects
function
tp_effect
(
pos
)
minetest
.
add_particlespawner
({
amount
=
20
,
time
=
0
.
25
,
minpos
=
pos
,
maxpos
=
pos
,
minvel
=
{
x
=
-
2
,
y
=
-
2
,
z
=
-
2
},
maxvel
=
{
x
=
2
,
y
=
2
,
z
=
2
},
minacc
=
{
x
=
-
4
,
y
=
-
4
,
z
=
-
4
},
maxacc
=
{
x
=
4
,
y
=
4
,
z
=
4
},
minexptime
=
0
.
1
,
maxexptime
=
1
,
minsize
=
0
.
5
,
maxsize
=
1
,
texture
=
"particle.png"
,
})
end
-- teleport portal
minetest
.
register_node
(
"teleport_potion:portal"
,
{
...
...
@@ -50,7 +79,7 @@ minetest.register_node("teleport_potion:portal", {
buildable_to
=
true
,
waving
=
1
,
sunlight_propagates
=
true
,
damage_per_second
=
1
,
-- walking into portal
also
hurts player
damage_per_second
=
1
,
-- walking into portal hurts player
-- start timer when portal appears
on_construct
=
function
(
pos
)
...
...
@@ -81,7 +110,7 @@ minetest.register_node("teleport_potion:potion", {
description
=
"Teleport Potion (place and right-click to enchant location)"
,
inventory_image
=
"potion.png"
,
wield_image
=
"potion.png"
,
groups
=
{
snappy
=
3
,
dig_immediate
=
3
},
groups
=
{
dig_immediate
=
3
},
selection_box
=
{
type
=
"wallmounted"
},
on_construct
=
function
(
pos
)
...
...
@@ -89,14 +118,14 @@ minetest.register_node("teleport_potion:potion", {
local
meta
=
minetest
.
get_meta
(
pos
)
-- text entry formspec
meta
:
set_string
(
"formspec"
,
"field[text;;${text}]"
)
meta
:
set_string
(
"infotext"
,
"
Enter teleport coords (e.g 200,20,-200)
"
)
meta
:
set_string
(
"text"
,
teleport
.
default
.
x
..
","
..
teleport
.
default
.
y
..
","
..
teleport
.
default
.
z
)
meta
:
set_string
(
"formspec"
,
"field[text;
Enter teleport coords (e.g. 200,20,-200)
;${text}]"
)
meta
:
set_string
(
"infotext"
,
"
Right-click to enchant teleport location
"
)
meta
:
set_string
(
"text"
,
pos
.
x
..
","
..
pos
.
y
..
","
..
pos
.
z
)
-- set default coords
meta
:
set_
floa
t
(
"x"
,
teleport
.
default
.
x
)
meta
:
set_
floa
t
(
"y"
,
teleport
.
default
.
y
)
meta
:
set_
floa
t
(
"z"
,
teleport
.
default
.
z
)
meta
:
set_
in
t
(
"x"
,
pos
.
x
)
meta
:
set_
in
t
(
"y"
,
pos
.
y
)
meta
:
set_
in
t
(
"z"
,
pos
.
z
)
end
,
-- throw potion when used like tool
...
...
@@ -113,21 +142,19 @@ minetest.register_node("teleport_potion:potion", {
-- check if coords ok then open portal, otherwise return potion
on_receive_fields
=
function
(
pos
,
formname
,
fields
,
sender
)
local
coords
=
teleport
.
coordinates
(
fields
.
text
)
local
meta
=
minetest
.
get_meta
(
pos
)
local
coords
=
check_coordinates
(
fields
.
text
)
local
name
=
sender
:
get_player_name
()
if
coords
then
minetest
.
set_node
(
pos
,
{
name
=
"teleport_potion:portal"
})
local
new
meta
=
minetest
.
get_meta
(
pos
)
local
meta
=
minetest
.
get_meta
(
pos
)
-- set portal destination
newmeta
:
set_float
(
"x"
,
coords
.
x
)
newmeta
:
set_float
(
"y"
,
coords
.
y
)
newmeta
:
set_float
(
"z"
,
coords
.
z
)
newmeta
:
set_string
(
"text"
,
fields
.
text
)
meta
:
set_int
(
"x"
,
coords
.
x
)
meta
:
set_int
(
"y"
,
coords
.
y
)
meta
:
set_int
(
"z"
,
coords
.
z
)
-- portal open effect and sound
tp_effect
(
pos
)
...
...
@@ -146,6 +173,16 @@ minetest.register_node("teleport_potion:potion", {
end
,
})
-- teleport potion recipe
minetest
.
register_craft
({
output
=
'teleport_potion:potion'
,
recipe
=
{
{
""
,
"default:diamond"
,
""
},
{
"default:diamond"
,
"vessels:glass_bottle"
,
"default:diamond"
},
{
""
,
"default:diamond"
,
""
},
},
})
-- teleport pad
minetest
.
register_node
(
"teleport_potion:pad"
,
{
tiles
=
{
"padd.png"
},
...
...
@@ -173,28 +210,19 @@ minetest.register_node("teleport_potion:pad", {
local
meta
=
minetest
.
get_meta
(
pos
)
-- text entry formspec
meta
:
set_string
(
"formspec"
,
"field[text;;${text}]"
)
meta
:
set_string
(
"infotext"
,
"Enter teleport coords (e.g 200,20,-200)"
)
meta
:
set_string
(
"text"
,
teleport
.
default
.
x
..
","
..
teleport
.
default
.
y
..
","
..
teleport
.
default
.
z
)
meta
:
set_string
(
"formspec"
,
"field[text;Enter teleport coords (e.g. 200,20,-200);${text}]"
)
meta
:
set_string
(
"infotext"
,
"Right-click to enchant teleport location"
)
meta
:
set_string
(
"text"
,
pos
.
x
..
","
..
pos
.
y
..
","
..
pos
.
z
)
-- set default coords
meta
:
set_float
(
"x"
,
teleport
.
default
.
x
)
meta
:
set_float
(
"y"
,
teleport
.
default
.
y
)
meta
:
set_float
(
"z"
,
teleport
.
default
.
z
)
end
,
-- right-click to enter new coords
on_right_click
=
function
(
pos
,
placer
)
local
meta
=
minetest
.
get_meta
(
pos
)
meta
:
set_int
(
"x"
,
pos
.
x
)
meta
:
set_int
(
"y"
,
pos
.
y
)
meta
:
set_int
(
"z"
,
pos
.
z
)
end
,
-- once entered, check coords, if ok then return potion
on_receive_fields
=
function
(
pos
,
formname
,
fields
,
sender
)
local
coords
=
teleport
.
coordinates
(
fields
.
text
)
local
meta
=
minetest
.
get_meta
(
pos
)
local
name
=
sender
:
get_player_name
()
if
minetest
.
is_protected
(
pos
,
name
)
then
...
...
@@ -202,16 +230,20 @@ minetest.register_node("teleport_potion:pad", {
return
end
local
coords
=
check_coordinates
(
fields
.
text
)
if
coords
then
local
newmeta
=
minetest
.
get_meta
(
pos
)
local
meta
=
minetest
.
get_meta
(
pos
)
meta
:
set_int
(
"x"
,
coords
.
x
)
meta
:
set_int
(
"y"
,
coords
.
y
)
meta
:
set_int
(
"z"
,
coords
.
z
)
meta
:
set_string
(
"text"
,
fields
.
text
)
newmeta
:
set_float
(
"x"
,
coords
.
x
)
newmeta
:
set_float
(
"y"
,
coords
.
y
)
newmeta
:
set_float
(
"z"
,
coords
.
z
)
newmeta
:
set_string
(
"text"
,
fields
.
text
)
meta
:
set_string
(
"infotext"
,
"Pad Active ("
..
coords
.
x
..
","
..
coords
.
y
..
","
..
coords
.
z
..
")"
)
meta
:
set_string
(
"infotext"
,
"Pad Active ("
..
coords
.
x
..
","
..
coords
.
y
..
","
..
coords
.
z
..
")"
)
minetest
.
sound_play
(
"portal_open"
,
{
pos
=
pos
,
gain
=
1
.
0
,
...
...
@@ -224,61 +256,20 @@ minetest.register_node("teleport_potion:pad", {
end
,
})
teleport
.
coordinates
=
function
(
str
)
if
not
str
or
str
==
""
then
return
nil
end
-- get coords from string
local
x
,
y
,
z
=
string.match
(
str
,
"^(-?%d+),(-?%d+),(-?%d+)"
)
-- check coords
if
x
==
nil
or
string.len
(
x
)
>
6
or
y
==
nil
or
string.len
(
y
)
>
6
or
z
==
nil
or
string.len
(
z
)
>
6
then
return
nil
end
-- convert string coords to numbers
x
=
tonumber
(
x
)
y
=
tonumber
(
y
)
z
=
tonumber
(
z
)
-- are coords in map range ?
if
x
>
30900
or
x
<
-
30900
or
y
>
30900
or
y
<
-
30900
or
z
>
30900
or
z
<
-
30900
then
return
nil
end
-- return ok coords
return
{
x
=
x
,
y
=
y
,
z
=
z
}
end
-- particle effects
function
tp_effect
(
pos
)
minetest
.
add_particlespawner
({
amount
=
20
,
time
=
0
.
25
,
minpos
=
pos
,
maxpos
=
pos
,
minvel
=
{
x
=
-
2
,
y
=
-
2
,
z
=
-
2
},
maxvel
=
{
x
=
2
,
y
=
2
,
z
=
2
},
minacc
=
{
x
=
-
4
,
y
=
-
4
,
z
=
-
4
},
maxacc
=
{
x
=
4
,
y
=
4
,
z
=
4
},
minexptime
=
0
.
1
,
maxexptime
=
1
,
minsize
=
0
.
5
,
maxsize
=
1
,
texture
=
"particle.png"
,
})
end
-- teleport pad recipe
minetest
.
register_craft
({
output
=
'teleport_potion:pad'
,
recipe
=
{
{
"teleport_potion:potion"
,
'default:glass'
,
"teleport_potion:potion"
},
{
"default:glass"
,
"default:mese"
,
"default:glass"
},
{
"teleport_potion:potion"
,
"default:glass"
,
"teleport_potion:potion"
}
}
})
-- check p
ad and teleport object
s on top
-- check p
ortal & pad, teleport any entitie
s on top
minetest
.
register_abm
({
nodenames
=
{
"teleport_potion:portal"
,
"teleport_potion:pad"
},
interval
=
1
,
interval
=
2
,
chance
=
1
,
catch_up
=
false
,
...
...
@@ -294,14 +285,14 @@ minetest.register_abm({
-- get coords from pad/portal
local
meta
=
minetest
.
get_meta
(
pos
)
local
target_coords
=
{
x
=
meta
:
get_
floa
t
(
"x"
),
y
=
meta
:
get_
floa
t
(
"y"
),
z
=
meta
:
get_
floa
t
(
"z"
)
x
=
meta
:
get_
in
t
(
"x"
),
y
=
meta
:
get_
in
t
(
"y"
),
z
=
meta
:
get_
in
t
(
"z"
)
}
for
k
,
player
in
pairs
(
objs
)
do
if
player
:
get_player_name
()
then
if
player
then
-- play sound on portal end
minetest
.
sound_play
(
"portal_close"
,
{
...
...
@@ -327,7 +318,7 @@ minetest.register_abm({
end
})
-- Throwable potion
s
-- Throwable potion
local
potion_entity
=
{
physical
=
true
,
...
...
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