-
Notifications
You must be signed in to change notification settings - Fork 2
/
visual_effects.lua
158 lines (156 loc) · 5.88 KB
/
visual_effects.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
Guns4d.effects={
bullet_holes = {}
}
--designed for use with the gun class
function Guns4d.effects.muzzle_flash(self)
local playername = self.player:get_player_name()
if self.particle_spawners.muzzle_smoke and self.particle_spawners.muzzle_smoke ~= -1 then
minetest.delete_particlespawner(self.particle_spawners.muzzle_smoke, self.player:get_player_name())
end
local dir, offset_pos = self.dir, self:get_pos(self.properties.flash_offset)
offset_pos=offset_pos+self.player:get_pos()
local min = vector.rotate(vector.new(-1, -1, -.15), {x=0,y=self.player_rotation.y,z=0})
local max = vector.rotate(vector.new(1, 1, .15), {x=0,y=self.player_rotation.y,z=0})
minetest.add_particlespawner({
exptime = .18,
time = .1,
amount = 15,
attached = self.entity,
pos = self.properties.flash_offset,
radius = .04,
glow = 3.5,
vel = {min=min, max=max, bias=0},
texpool = {
{ name = "smoke.png", alpha_tween = {.25, 0}, scale = 2, blend = "alpha",
animation = {
type = "vertical_frames", aspect_w = 16,
aspect_h = 16, length = .1,
},
},
{ name = "smoke.png", alpha_tween = {.25, 0}, scale = .8, blend = "alpha",
animation = {
type = "vertical_frames", aspect_w = 16,
aspect_h = 16, length = .1,
},
},
{ name = "smoke.png^[multiply:#dedede", alpha_tween = {.25, 0}, scale = 2,
blend = "alpha",
animation = {
type = "vertical_frames", aspect_h = 16,
aspect_w = 16, length = .1,
},
},
{ name = "smoke.png^[multiply:#b0b0b0", alpha_tween = {.2, 0}, scale = 2, blend = "alpha",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = .25,
},
}
}
})
--muzzle smoke
self.particle_spawners.muzzle_smoke = minetest.add_particlespawner({
exptime = .3,
time = 2,
amount = 50,
pos = self.properties.flash_offset,
glow = 2,
vel = {min=vector.new(-.1,.4,.2), max=vector.new(.1,.6,1), bias=0},
attached = self.entity,
texpool = {
{name = "smoke.png", alpha_tween = {.12, 0}, scale = 1.4, blend = "alpha",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = .35,
},
},
{name = "smoke.png^[multiply:#b0b0b0", alpha_tween = {.2, 0}, scale = 1.4, blend = "alpha",
animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = .35,},
}
}
})
end
--[[function Guns4d.effects.spawn_bullet_hole_particle(pos, size, texture)
--modern syntax isn't accepted by add particle to my knowledge, or it's not documented.
--so I have to use a particle spawner
minetest.add_particlespawner({
pos = pos,
amount = 1,
time=.1,
exptime = 10,
texture = {
name = 'bullet_hole.png',
alpha_tween = {1,0}
}
})
end
local bullet_holes = Guns4d.effects.bullet_holes
local hole_despawn_dist = 20
local time_since_last_check = 5
minetest.register_globalstep(function(dt)
if time_since_last_check >= 5 then
time_since_last_check = 0
for i, v in pairs(bullet_holes) do
local pos = v:get_pos()
if pos then
local nearby_players = false
for pname, player in pairs(minetest.get_connected_players()) do
if vector.distance(player:get_pos(), pos) < hole_despawn_dist then
nearby_players = true
end
end
if not nearby_players then
local props = v:get_properties()
Guns4d.effects.spawn_bullet_hole_particle(v:get_pos(), props.visual_size.x, props.textures[5])
bullet_holes[i]:remove()
table.remove(bullet_holes, i)
end
else
--if pos is nil, we know the bullet delete itself.
table.remove(bullet_holes, i)
end
end
else
time_since_last_check = time_since_last_check + dt
end
end)
minetest.register_entity("guns4d:bullet_hole", {
initial_properties = {
visual = "cube",
visual_size = {x=.15, y=.15, z=0},
pointable = false,
static_save = false,
use_texture_alpha = true,
textures = {"blank.png", "bullet_hole.png", "blank.png", "blank.png", "bullet_hole.png", "bullet_hole.png"}
},
on_step = function(self, dtime)
if not self.block_name then
table.insert(bullet_holes, 1, self.object)
self.block_name = minetest.get_node(self.block_pos).name
elseif (TICK%3==0) and (self.block_name ~= minetest.get_node(self.block_pos).name) then
self.object:remove()
return
end
if not self.timer then
local properties = self.object:get_properties()
self.timer = 31
properties.textures[5] = 'bullet_hole.png'
self.object:set_properties(properties)
else
self.timer = self.timer - dtime
end
if self.timer < 30 then
if self.timer < 0 then
self.object:remove()
return
end
local properties = self.object:get_properties()
properties.textures[5] = 'bullet_hole.png^[opacity:'..(math.floor((12.75*tostring(self.timer/30)))*20)
self.object:set_properties(properties)
end
end
})]]