forked from ThorfinnS/fun_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguns.lua
332 lines (289 loc) · 8.26 KB
/
guns.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
-- Fun_tools guns.lua
-- Copyright Duane Robertson ([email protected]), 2019
-- Distributed under the LGPLv2.1 (https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html)
local mod = fun_tools
local mod_name = 'fun_tools'
function mod.puff(p)
local radius = 1
local velocity = 1.9*math.log(radius + 1)
local q = 20*math.log(radius + 1)
minetest.add_particlespawner({
amount = q,
time = 0.3,
minpos = vector.subtract(p, radius),
maxpos = vector.add(p, radius),
minvel = {x = -velocity, y = -velocity, z = -velocity},
maxvel = {x = velocity, y = velocity, z = velocity},
minacc = vector.new(),
maxacc = vector.new(),
minexptime = 0.5,
maxexptime = 1,
minsize = 9,
maxsize = 10,
texture = 'tnt_smoke.png',
})
radius = 1
velocity = 1.9*math.log(radius + 1)
q = 20*math.log(radius + 1)
minetest.add_particlespawner({
amount = q,
time = 0.3,
minpos = vector.subtract(p, radius),
maxpos = vector.add(p, radius),
minvel = {x = -velocity, y = -velocity, z = -velocity},
maxvel = {x = velocity, y = velocity, z = velocity},
minacc = vector.new(),
maxacc = vector.new(),
minexptime = 0.5,
maxexptime = 1,
minsize = 9,
maxsize = 10,
texture = 'tnt_smoke.png',
})
end
function mod.ranged_attack(itemstack, user, range)
local shot
local dir = user:get_look_dir()
local playerpos = user:get_pos()
local p = table.copy(playerpos)
p.y = p.y + 1.5
local eps = {}
for id, ent in pairs(minetest.luaentities) do
if ent.object:get_luaentity() then
if ent and ent.object and ent.object.get_pos and (ent._is_a_mob or ent.health) then
local ep = ent.object:get_pos()
if ep and vector.distance(ep, p) < range then
eps[id] = ep
end
end
end
end
for _ = 1, range do
p = vector.add(p, dir)
for id in pairs(eps) do
if vector.distance(eps[id], p) < 1 then
local ent = minetest.luaentities[id]
if ent.object:get_luaentity() then
if ent and ent._printed_name then
local player_name = user:get_player_name()
if player_name then
minetest.chat_send_player(player_name, 'You hit the ' .. ent._printed_name)
end
end
ent.object:punch(user, nil, itemstack:get_tool_capabilities(), nil)
end
shot = true
break
end
end
if shot then
mod.puff(p)
break
end
end
end
------------------------------------------------
-- Mattock
------------------------------------------------
minetest.register_tool(mod_name..':mattock', {
description = 'Mattock',
drawtype = 'plantlike',
paramtype = 'light',
tiles = {'fun_tools_mattock.png'},
inventory_image = 'fun_tools_mattock.png',
groups = {dig_immediate = 3},
sounds = default.node_sound_wood_defaults(),
tool_capabilities = {
full_punch_interval = 1.0,
max_drop_level=1,
groupcaps={
cracky = {times={[1]=4.00, [2]=1.60, [3]=0.80}, uses=80, maxlevel=2},
},
damage_groups = {fleshy=3},
},
on_use = function(itemstack, user, pointed_thing)
if not (user and pointed_thing) then
return
end
if pointed_thing.type == 'node' then
local n = minetest.get_node(pointed_thing.under)
if n.name == 'default:cobble' then
minetest.set_node(pointed_thing.under, {
name = 'default:gravel',
})
elseif n.name == 'default:stone' then
minetest.set_node(pointed_thing.under, {
name = 'default:cobble',
})
else
minetest.node_dig(pointed_thing.under, n, user)
end
elseif pointed_thing.type == 'object' then
pointed_thing.ref:punch(user, nil, itemstack:get_tool_capabilities(), nil)
end
--minetest.sound_play('', {
-- object = user,
-- gain = 0.1,
-- max_hear_distance = 30
--})
return itemstack
end,
})
minetest.register_craft({
output = mod_name..':mattock',
type = 'shapeless',
recipe = {'group:tree', 'group:stick',},
})
------------------------------------------------
-- Pebble Thrower
------------------------------------------------
minetest.register_tool(mod_name..':pebble_thrower_unloaded', {
description = 'Pebble Thrower (unloaded)',
drawtype = 'plantlike',
paramtype = 'light',
tiles = {'fun_tools_pebble_thrower.png'},
inventory_image = 'fun_tools_pebble_thrower.png',
groups = {dig_immediate = 3},
sounds = default.node_sound_metal_defaults(),
on_use = function(itemstack, user, pointed_thing)
if not (mod.fast_load and user and pointed_thing) then
return
end
if mod.use_inventory_items(user, { 'tnt:gunpowder', mod_name..':pebble' }) then
itemstack:clear()
itemstack:add_item(mod_name..':pebble_thrower_loaded')
return itemstack
end
end,
})
minetest.register_craftitem(mod_name..':pebble', {
description = 'Pebble',
inventory_image = 'fun_tools_pebble.png',
--groups = {dig_immediate = 3},
})
minetest.register_craft({
output = mod_name..':pebble 50',
type = 'shapeless',
recipe = {'default:gravel'},
})
minetest.register_craft({
output = mod_name..':pebble_thrower_loaded',
type = 'shapeless',
recipe = {'tnt:gunpowder', mod_name..':pebble', mod_name..':pebble_thrower_unloaded',},
})
minetest.register_craft({
output = mod_name..':pebble_thrower_unloaded',
recipe = {
{'', '', ''},
{'group:stone', 'mobs:leather', 'default:flint'},
{'', '', 'group:wood'},
},
})
minetest.register_tool(mod_name..':pebble_thrower_loaded', {
description = 'Pebble Thrower (loaded)',
drawtype = 'plantlike',
paramtype = 'light',
tiles = {'fun_tools_pebble_thrower.png'},
inventory_image = 'fun_tools_pebble_thrower.png',
groups = {dig_immediate = 3},
sounds = default.node_sound_stone_defaults(),
tool_capabilities = {
full_punch_interval = 1.0,
max_drop_level=1,
groupcaps={
cracky = {times={[1]=4.00, [2]=1.60, [3]=0.80}, uses=80, maxlevel=2},
},
damage_groups = {fleshy=5},
},
on_use = function(itemstack, user, pointed_thing)
if not (user and pointed_thing) then
return
end
minetest.sound_play('flintlock', {
object = user,
gain = 0.1,
max_hear_distance = 30
})
mod.ranged_attack(itemstack, user, 25)
itemstack:clear()
itemstack:add_item(mod_name..':pebble_thrower_unloaded')
return itemstack
end,
})
------------------------------------------------
-- Flintlock Pistol
------------------------------------------------
minetest.register_tool(mod_name..':flintlock_pistol_unloaded', {
description = 'Flintlock Pistol (unloaded)',
drawtype = 'plantlike',
paramtype = 'light',
tiles = {'fun_tools_flintlock_pistol.png'},
inventory_image = 'fun_tools_flintlock_pistol.png',
groups = {dig_immediate = 3},
sounds = default.node_sound_metal_defaults(),
on_use = function(itemstack, user, pointed_thing)
if not (mod.fast_load and user and pointed_thing) then
return
end
if mod.use_inventory_items(user, { 'tnt:gunpowder', mod_name..':gold_ball' }) then
itemstack:clear()
itemstack:add_item(mod_name..':flintlock_pistol_loaded')
return itemstack
end
end,
})
minetest.register_craftitem(mod_name..':gold_ball', {
description = 'Gold Ball',
inventory_image = 'fun_tools_gold_balls.png',
--groups = {dig_immediate = 3},
})
minetest.register_craft({
output = mod_name..':gold_ball 10',
type = 'cooking',
recipe = 'default:gold_ingot',
cooktime = 2,
})
minetest.register_craft({
output = mod_name..':flintlock_pistol_loaded',
type = 'shapeless',
recipe = {'tnt:gunpowder', mod_name..':gold_ball', mod_name..':flintlock_pistol_unloaded',},
})
minetest.register_craft({
output = mod_name..':flintlock_pistol_unloaded',
recipe = {
{'', '', ''},
{'default:steel_ingot', 'group:wood', 'default:flint'},
{'', '', mod.precision_tool},
},
})
minetest.register_tool(mod_name..':flintlock_pistol_loaded', {
description = 'Flintlock Pistol (loaded)',
drawtype = 'plantlike',
paramtype = 'light',
tiles = {'fun_tools_flintlock_pistol.png'},
inventory_image = 'fun_tools_flintlock_pistol.png',
groups = {dig_immediate = 3},
sounds = default.node_sound_metal_defaults(),
tool_capabilities = {
full_punch_interval = 1.0,
max_drop_level=1,
groupcaps={
cracky = {times={[1]=4.00, [2]=1.60, [3]=0.80}, uses=80, maxlevel=2},
},
damage_groups = {fleshy=15},
},
on_use = function(itemstack, user, pointed_thing)
if not (user and pointed_thing) then
return
end
minetest.sound_play('flintlock', {
object = user,
gain = 0.1,
max_hear_distance = 30
})
mod.ranged_attack(itemstack, user, 25)
itemstack:clear()
itemstack:add_item(mod_name..':flintlock_pistol_unloaded')
return itemstack
end,
})