forked from veNext/magic_mod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_attack.lua
112 lines (106 loc) · 3.02 KB
/
basic_attack.lua
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
magic_ball = {
{"magic_mod:magic_ball", "magic_mod:magic_ball_entity"},
}
shoot_magic_ball = function(itemstack, player)
for _,magic_balls in ipairs(magic_ball) do
local playerpos = player:getpos()
local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, magic_balls[2])
local dir = player:get_look_dir()
obj:setvelocity({x=dir.x*19, y=dir.y*19, z=dir.z*19})
obj:setacceleration({x=dir.x, y=dir.y, z=dir.z})
obj:setyaw(player:get_look_yaw()+math.pi)
if obj:get_luaentity().player == "" then
obj:get_luaentity().player = player
end
obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name()
return true
end
return false
end
local magic_ball_blue={
physical = false,
timer=0,
visual = "sprite",
visual_size = {x=0.5, y=0.5},
textures = {"magic_ball.png"},
lastpos={},
collisionbox = {-0.1,-0.1,-0.1,0.1,0.1,0.1},
}
magic_ball_blue.on_step = function(self, dtime)
self.timer=self.timer+dtime
local pos = self.object:getpos()
local node = minetest.get_node(pos)
minetest.add_particlespawner({
amount = 1,
time = 0.10,
minpos = {x=pos.x, y=pos.y, z=pos.z},
maxpos = {x=pos.x, y=pos.y, z=pos.z},
minexptime = 0.1,
maxexptime = 0.2,
minsize = 0.50,
maxsize = 0.50, collisiondetection = false,
vertical = false,
texture = "electric_dot.png",
playername = "singleplayer"
})
if self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "magic_mod:magic_ball_entity" and obj:get_luaentity().name ~= "__builtin:item" then
local damage = 1
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
minetest.add_particlespawner({
amount = 50,
time = 0.10,
minpos = {x=pos.x - 1, y=pos.y - 1, z=pos.z - 1},
maxpos = {x=pos.x + 1, y=pos.y + 1, z=pos.z + 1},
minexptime = 0.1,
maxexptime = 0.2,
minsize = 0.50,
maxsize = 0.50, collisiondetection = false,
vertical = false,
texture = "electric_dot.png",
playername = "singleplayer"
})
self.object:remove()
end
else
local damage = 1
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
self.object:remove()
end
end
end
if self.lastpos.x~=nil then
if node.name ~= "air" then
if node.name ~= "default:water_source" then
if node.name ~= "default:water_flowing" then
minetest.add_particlespawner({
amount = 50,
time = 0.10,
minpos = {x=pos.x - 1, y=pos.y - 1, z=pos.z - 1},
maxpos = {x=pos.x + 1, y=pos.y + 1, z=pos.z + 1},
minexptime = 0.1,
maxexptime = 0.2,
minsize = 0.50,
maxsize = 0.50, collisiondetection = false,
vertical = false,
texture = "electric_dot.png",
playername = "singleplayer"
})
self.object:remove()
end
end
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end
minetest.register_entity("magic_mod:magic_ball_entity", magic_ball_blue)
--next