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