Add README.txt
[minetest_returnmirror.git] / init.lua
blob7b15e05b57f165e619ad1668cef434acc43d590b
1 returnmirror = {}
2 returnmirror.cost_teleport = 100
3 returnmirror.cost_set = 20
5 if tonumber(minetest.setting_get("returnmirror_cost_teleport")) ~= nil then
6 returnmirror.cost_teleport = tonumber(minetest.setting_get("returnmirror_cost_teleport"))
7 end
8 if tonumber(minetest.setting_get("returnmirror_cost_set")) ~= nil then
9 returnmirror.cost_set = tonumber(minetest.setting_get("returnmirror_cost_set"))
10 end
12 if minetest.get_modpath("mana") ~= nil then
13 returnmirror.mana = true
14 else
15 returnmirror.mana = false
16 end
18 returnmirror.mana_check = function(player, cost)
19 local allowed
20 if returnmirror.mana then
21 if mana.subtract(player:get_player_name(), cost) then
22 allowed = true
23 else
24 allowed = false
25 end
26 else
27 allowed = true
28 end
29 return allowed
30 end
32 minetest.register_tool("returnmirror:returnmirror", {
33 description = "Mirror of Returning",
34 stack_max = 1,
35 inventory_image = "returnmirror_returnmirror.png",
36 wield_image = "returnmirror_returnmirror.png",
37 tool_capabilities = {},
38 on_use = function(itemstack, user, pointed_thing)
39 local dest_string = itemstack:get_metadata()
40 local dest = minetest.string_to_pos(dest_string)
41 if dest ~= nil then
42 if returnmirror.mana_check(user, returnmirror.cost_teleport) then
43 local src = user:getpos()
44 minetest.sound_play( {name="returnmirror_teleport", gain=1}, {pos=src, max_hear_distance=30})
45 minetest.add_particlespawner({
46 amount = 50,
47 time = 0.1,
48 minpos = {x=src.x-0.4, y=src.y+0.25, z=src.z-0.4},
49 maxpos = {x=src.x+0.4, y=src.y+0.75, z=src.z+0.4},
50 minvel = {x=-0.2, y=-0.2, z=-0.2},
51 maxvel = {x=0.2, y=0.2, z=0.2},
52 minexptime=3,
53 maxexptime=4.5,
54 minsize=1,
55 maxsize=1.25,
56 texture = "returnmirror_particle_departure.png",
58 user:setpos(dest)
59 minetest.sound_play( {name="returnmirror_teleport", gain=1}, {pos=dest, max_hear_distance=30})
60 minetest.add_particlespawner({
61 amount = 100,
62 time = 0.1,
63 minpos = {x=dest.x-0.4, y=dest.y+0.25, z=dest.z-0.4},
64 maxpos = {x=dest.x+0.4, y=dest.y+0.75, z=dest.z+0.4},
65 minvel = {x=-0.4, y=-0.3, z=-0.4},
66 maxvel = {x=0.4, y=0.3, z=0.4},
67 minexptime=6,
68 maxexptime=12,
69 minsize=1,
70 maxsize=1.25,
71 texture = "returnmirror_particle_arrival.png",
73 end
74 end
75 end,
76 on_place = function(itemstack, placer, pointed_thing)
77 if returnmirror.mana_check(placer, returnmirror.cost_set) then
78 local pos = placer:getpos()
79 itemstack:set_metadata(minetest.pos_to_string(pos))
80 minetest.sound_play( {name="returnmirror_set", gain=1}, {pos=pos, max_hear_distance=12})
81 return itemstack
82 end
83 end