-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwands.lua
More file actions
96 lines (87 loc) · 3 KB
/
wands.lua
File metadata and controls
96 lines (87 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
local cooldown = {}
minetest.register_on_joinplayer(function(player)
cooldown[player:get_player_name()] = false
end)
minetest.register_on_leaveplayer(function(player)
cooldown[player:get_player_name()] = false
end)
local FIREBALL_ENTITY = {
hp_max = 1,
physical = false,
weight = 5,
collisionbox = {-0.25,-0.25,-0.25, 0.25,0.25,0.25},
visual = "cube",
visual_size = {x=0.5, y=0.5},
mesh = "model",
textures = {"fireball.png", "fireball.png", "fireball.png", "fireball.png", "fireball.png", "fireball.png"}, -- number of required textures depends on visual
colors = {}, -- number of required colors depends on visual
spritediv = {x=1, y=1},
initial_sprite_basepos = {x=0, y=0},
is_visible = true,
makes_footstep_sound = false,
automatic_rotate = 0,
}
minetest.register_entity("froager2:fireball", FIREBALL_ENTITY)
local spawn_fireball = function(player, cooldown_time)
if cooldown[player:get_player_name()] then
minetest.chat_send_player(player:get_player_name(), "Please wait for your "..tostring(cooldown_time).." second cooldown to end")
return
end
cooldown[player:get_player_name()] = true
minetest.after(cooldown_time, function()
cooldown[player:get_player_name()] = false
end)
local obj = minetest.add_entity(vector.add(player:get_pos(), {x = 0, y = 1.5, z = 0}), "froager2:fireball")
local yaw = player:get_look_horizontal()
local dir = player:get_look_dir()
if obj then
obj:set_velocity(vector.multiply(dir, 5))
obj:set_yaw(yaw)
end
end
local function fire_wand(level, cooldown_time)
minetest.register_craftitem("froager2:fire_wand_"..level, {
description = "Fire wand: Level "..level.." \nRight-Click: Spawn Fireball\nCooldown depends on wand level:\nL1: 5sec; L2: 3sec; L3: 1sec\n\nRARE",
inventory_image = "default_stick.png",
stack_max = 1,
on_place = function(itemstack, placer, pointed_thing)
spawn_fireball(placer, cooldown_time)
end,
on_secondary_use = function(itemstack, user, pointed_thing)
spawn_fireball(user, cooldown_time)
end
})
end
fire_wand("1", 5)
fire_wand("2", 3)
fire_wand("3", 1)
local on_collide = function(self, pos)
self.object:remove()
local minp = vector.add(pos, {x = -1, y = -1, z = -1})
local maxp = vector.add(pos, {x = 1, y = 1, z = 1})
for _,airpos in ipairs(minetest.find_nodes_in_area(minp, maxp, "air")) do
minetest.set_node(airpos, {name="fire:basic_flame"})
end
end
local fireballtimer = {}
FIREBALL_ENTITY.on_step = function(self, dtime)
if not fireballtimer[self] then
fireballtimer[self] = 0
end
fireballtimer[self] = fireballtimer[self]+dtime
if fireballtimer[self] >= 1 then
local objects = minetest.get_objects_inside_radius(self.object:get_pos(), 0.75)
for _,obj in ipairs(objects) do
if obj:is_player() then--damage to players
local hp = obj:get_hp()
obj:set_hp(hp-4)
self.object:remove()
end
end
end
--checks for collisions with nodes
local pos = self.object:get_pos()
local node = minetest.get_node(pos)
if node.name == "air" then return end
on_collide(self, pos)
end