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
5d74e552
Commit
5d74e552
authored
9 years ago
by
TenPlus1
Browse files
Options
Downloads
Patches
Plain Diff
Code tidy and particle effect added
parent
4ed639de
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
init.lua
+81
-48
81 additions, 48 deletions
init.lua
textures/particle.png
+0
-0
0 additions, 0 deletions
textures/particle.png
with
81 additions
and
48 deletions
init.lua
+
81
−
48
View file @
5d74e552
--= Teleport Potion mod 0.
3
by TenPlus1
--= Teleport Potion mod 0.
4
by TenPlus1
--= Create potion/pad, right-click to enter coords and walk into the blue light,
--= Portal closes after 10 seconds, pad remains... SFX are license Free...
-- 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... SFX are license Free...
teleport
=
{}
--
T
eleport
P
ortal recipe
--
t
eleport
p
ortal recipe
minetest
.
register_craft
({
output
=
'teleport_potion:potion'
,
type
=
"shapeless"
,
recipe
=
{
'vessels:glass_bottle'
,
'default:diamondblock'
}
})
--
T
eleport
P
ad recipe
--
t
eleport
p
ad recipe
minetest
.
register_craft
({
output
=
'teleport_potion:pad'
,
recipe
=
{
...
...
@@ -23,10 +24,10 @@ minetest.register_craft({
}
})
--
D
efault coords
teleport
.
default
=
{
x
=
0
,
y
=
0
,
z
=
0
}
--
d
efault coords
(from static spawnpoint or default values at end)
teleport
.
default
=
(
minetest
.
setting_get_pos
(
"static_spawnpoint"
)
or
{
x
=
0
,
y
=
2
,
z
=
0
}
)
--
P
ortal
--
teleport p
ortal
minetest
.
register_node
(
"teleport_potion:portal"
,
{
drawtype
=
"plantlike"
,
tiles
=
{
...
...
@@ -46,14 +47,14 @@ minetest.register_node("teleport_potion:portal", {
buildable_to
=
true
,
waving
=
1
,
sunlight_propagates
=
true
,
damage_per_second
=
1
,
--
W
alking into portal also hurts player
damage_per_second
=
1
,
--
w
alking into portal also hurts player
--
S
tart timer when portal appears
--
s
tart timer when portal appears
on_construct
=
function
(
pos
)
minetest
.
get_node_timer
(
pos
):
start
(
10
)
end
,
--
R
emove portal after 10 seconds
--
r
emove portal after 10 seconds
on_timer
=
function
(
pos
)
minetest
.
sound_play
(
"portal_close"
,
{
pos
=
pos
,
...
...
@@ -64,7 +65,7 @@ minetest.register_node("teleport_potion:portal", {
end
,
})
--
P
otion
--
teleport p
otion
minetest
.
register_node
(
"teleport_potion:potion"
,
{
tile_images
=
{
"pad.png"
},
drawtype
=
"signlike"
,
...
...
@@ -75,7 +76,6 @@ minetest.register_node("teleport_potion:potion", {
description
=
"Teleport Potion (place and right-click to enchant location)"
,
inventory_image
=
"potion.png"
,
wield_image
=
"potion.png"
,
metadata_name
=
"sign"
,
groups
=
{
snappy
=
3
,
dig_immediate
=
3
},
selection_box
=
{
type
=
"wallmounted"
},
...
...
@@ -83,41 +83,44 @@ minetest.register_node("teleport_potion:potion", {
local
meta
=
minetest
.
get_meta
(
pos
)
--
T
ext entry formspec
--
t
ext 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
)
-- Load with default coords
meta
:
set_float
(
"enabled"
,
-
1
)
-- 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
,
--
R
ight-click to enter new coords
--
r
ight-click to enter new coords
on_right_click
=
function
(
pos
,
placer
)
local
meta
=
minetest
.
get_meta
(
pos
)
end
,
--
Once entered,
check coords
and tele
port, otherwise return potion
-- check
if
coords
ok then open
port
al
, otherwise 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
coords
then
if
coords
then
minetest
.
add_node
(
pos
,
{
name
=
"teleport_potion:portal"
})
local
newmeta
=
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
)
-- portal open effect and sound
effect
(
pos
)
minetest
.
sound_play
(
"portal_open"
,
{
pos
=
pos
,
gain
=
1
.
0
,
...
...
@@ -132,7 +135,7 @@ minetest.register_node("teleport_potion:potion", {
end
,
})
--
P
ad
--
teleport p
ad
minetest
.
register_node
(
"teleport_potion:pad"
,
{
tile_images
=
{
"padd.png"
},
drawtype
=
'nodebox'
,
...
...
@@ -143,9 +146,8 @@ minetest.register_node("teleport_potion:pad", {
description
=
"Teleport Pad (place and right-click to enchant location)"
,
inventory_image
=
"padd.png"
,
wield_image
=
"padd.png"
,
metadata_name
=
"sign"
,
light_source
=
5
,
groups
=
{
snappy
=
3
,
dig_immediate
=
3
},
groups
=
{
snappy
=
3
},
node_box
=
{
type
=
"wallmounted"
,
wall_top
=
{
-
0
.
5
,
0
.
4375
,
-
0
.
5
,
0
.
5
,
0
.
5
,
0
.
5
},
...
...
@@ -158,24 +160,23 @@ minetest.register_node("teleport_potion:pad", {
local
meta
=
minetest
.
get_meta
(
pos
)
--
T
ext entry formspec
--
t
ext 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
)
-- Load with default coords
meta
:
set_float
(
"enabled"
,
-
1
)
-- 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
,
--
R
ight-click to enter new coords
--
r
ight-click to enter new coords
on_right_click
=
function
(
pos
,
placer
)
local
meta
=
minetest
.
get_meta
(
pos
)
end
,
--
O
nce entered, check coords
and teleport, otherwise
return potion
--
o
nce entered, check coords
, if ok then
return potion
on_receive_fields
=
function
(
pos
,
formname
,
fields
,
sender
)
local
coords
=
teleport
.
coordinates
(
fields
.
text
)
...
...
@@ -187,7 +188,7 @@ minetest.register_node("teleport_potion:pad", {
return
end
if
coords
then
if
coords
then
local
newmeta
=
minetest
.
get_meta
(
pos
)
...
...
@@ -209,60 +210,92 @@ minetest.register_node("teleport_potion:pad", {
end
,
})
-- Check coords
teleport
.
coordinates
=
function
(
str
)
if
not
str
or
str
==
""
then
return
nil
end
--
G
et coords from string
--
g
et coords from string
local
x
,
y
,
z
=
string.match
(
str
,
"^(-?%d+),(-?%d+),(-?%d+)"
)
--
C
heck coords
--
c
heck 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
--
C
onvert string coords to numbers
x
=
x
+
0
.
0
y
=
y
+
0
.
0
z
=
z
+
0
.
0
--
c
onvert string coords to numbers
x
=
tonumber
(
x
)
y
=
tonumber
(
y
)
z
=
tonumber
(
z
)
--
A
re coords in map range ?
--
a
re 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
--
R
eturn ok coords
--
r
eturn ok coords
return
{
x
=
x
,
y
=
y
,
z
=
z
}
end
-- Has player walked inside portal
-- particle effects
function
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
-- check pad and teleport objects on top
minetest
.
register_abm
({
nodenames
=
{
"teleport_potion:portal"
,
"teleport_potion:pad"
},
interval
=
1
.
0
,
interval
=
1
,
chance
=
1
,
action
=
function
(
pos
,
node
,
active_object_count
,
active_object_count_wider
)
-- check objects inside pad/portal
local
objs
=
minetest
.
get_objects_inside_radius
(
pos
,
1
)
local
meta
,
target_coords
if
#
objs
==
0
then
return
end
-- get coords from pad/portal
local
meta
=
minetest
.
get_meta
(
pos
)
local
target_coords
=
{
x
=
meta
:
get_float
(
"x"
),
y
=
meta
:
get_float
(
"y"
),
z
=
meta
:
get_float
(
"z"
)
}
for
k
,
player
in
pairs
(
objs
)
do
if
player
:
get_player_name
()
then
meta
=
minetest
.
get_meta
(
pos
)
target_coords
=
{
x
=
meta
:
get_float
(
"x"
),
y
=
meta
:
get_float
(
"y"
),
z
=
meta
:
get_float
(
"z"
)
}
if
player
:
get_player_name
()
then
-- play sound on portal end
minetest
.
sound_play
(
"portal_close"
,
{
pos
=
pos
,
gain
=
1
.
0
,
max_hear_distance
=
5
})
-- move player/object
player
:
moveto
(
target_coords
,
false
)
-- paricle effects on arrival
effect
(
target_coords
)
-- play sound on destination end
minetest
.
sound_play
(
"portal_close"
,
{
pos
=
target_coords
,
gain
=
1
.
0
,
...
...
@@ -270,5 +303,5 @@ minetest.register_abm({
})
end
end
end
end
})
\ No newline at end of file
This diff is collapsed.
Click to expand it.
textures/particle.png
0 → 100644
+
0
−
0
View file @
5d74e552
173 B
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