-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathheavy.lua
209 lines (189 loc) · 6.43 KB
/
heavy.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
local function check(obj, pos)
local node = minetest.get_node(pos)
if node.name ~= "air" and node.name ~= "artillery:barbed_wire" then
if node.name == "artillery:concrete" then
obj.object:remove()
tnt.boom(pos, {radius = 2, damage_radius = 2})
elseif node.name == "artillery:concrete_cracked_1" or
node.name == "artillery:concrete_cracked_2" or
node.name == "artillery:concrete_cracked_3" then
obj.object:remove()
tnt.boom(pos, {radius = 2, damage_radius = 3})
else
obj.object:remove()
tnt.boom(pos, {radius = 3, damage_radius = 5})
end
end
end
local time_since_spawned = 0
local bomb_entity = {
physical = true,
timer = 0,
visual = "cube",
visual_size = {x=0.2, y=0.2,},
textures = {'default_stone.png', 'default_stone.png', 'default_stone.png', 'default_stone.png', 'default_stone.png', 'default_stone.png'},
collisionbox = {4, 4, 4, 4, 4, 4},
on_step = function(self, dtime)
local pos = self.object:get_pos()
check(self, pos)
end
}
local grenade_entity = {
physical = true,
timer = 0,
visual = "mesh",
mesh = "gwenade.obj",
visual_size = {x=1.5, y=1.5, z=1.5},
textures = {'default_stone.png'},
collisionbox = {10, 10, 10, 10, 10, 10},
on_step = function(self, dtime)
local pos = self.object:get_pos()
local node = minetest.get_node(pos)
time_since_spawned = time_since_spawned + dtime
if time_since_spawned > 4.5 or node.name ~= "air" then
time_since_spawned = 0
tnt.boom({x=pos.x, y=pos.y+1.2, z=pos.z}, {radius = 1, damage_radius = 6})
self.object:remove()
end
end
}
minetest.register_entity("artillery:bomb", bomb_entity)
minetest.register_entity("artillery:grenadey", grenade_entity)
function fire_bomb(name, radius, pos, distance, direction)
local dir = minetest.facedir_to_dir(direction)
local obj = minetest.add_entity({x=pos.x+dir.x, y=pos.y+1, z=pos.z+dir.z}, name) -- Adds bomb one node above starting node
obj:set_velocity({x=dir.x*(distance/2), y=20, z=dir.z*(distance/2)}) -- Starting velocity
obj:set_acceleration({x=dir.x*(distance/2), y=-30, z=dir.z*(distance/2)}) -- Acceleration after the bomb starts moving. Negative numbers slow it down
end
function throw_grenade(name, pos, direction)
local dir = direction
local obj = minetest.add_entity({x=pos.x+dir.x, y=pos.y+1.3, z=pos.z+dir.z}, name)
obj:set_velocity({x=dir.x*5, y=5, z=dir.z*5}) -- Starting velocity
obj:set_acceleration({x=dir.x, y=-10, z=dir.z}) -- Acceleration after the bomb starts moving
end
minetest.register_craftitem("artillery:shell", {
description = "Explosive Shell",
image = "shell.png",
})
minetest.register_node("artillery:mortar", {
description = "Mortar launcher",
drawtype = "mesh",
tiles = {"default_stone.png"},
groups = {oddly_breakable_by_hand = 3, attached_node = 1, force_floor = 1},
mesh = "mortar.obj",
paramtype2 = "facedir",
force_floor,
selection_box = {
type = "fixed",
fixed = {0.6, -0.3, 0.6, -0.6, -0.5, -0.6},
},
collision_box = {
type = "fixed",
fixed = {0.6, -0.3, 0.6, -0.6, -0.5, -0.6},
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("distance", 15)
meta:set_int("cooldown", 0)
meta:set_string("formspec",
"size[3,2.2]" ..
"bgcolor[#080808BB;true]" ..
"background[5,5;1,1;gui_formbg.png;true]" ..
"label[0,-0.3;Mortar Configuration]" ..
"field[0.5,1;2.5,1;distance; Power(distance);"..meta:get_int("distance").."]" ..
"button_exit[0,1.5;3,1;save;Save Configuration]")
end,
on_receive_fields = function(pos, formname, fields, player)
local meta = minetest.get_meta(pos)
if fields.save and fields.distance ~= "" then
--Prevent user from putting in disallowed characters or values
local function limity(input, limit)
local inputy = tonumber(input)
if inputy == nil then
return(5)
end
if inputy > limit then
return(limit)
elseif inputy < 5 then
return(5)
else
return(inputy)
end
end
meta:set_int("distance", limity(fields.distance, 40))
meta:set_string("formspec",
"size[3,2.2]" ..
"bgcolor[#080808BB;true]" ..
"background[5,5;1,1;gui_formbg.png;true]" ..
"label[0,-0.3;Mortar Configuration]" ..
"field[0.5,1;2.5,1;distance; Power(distance);"..meta:get_int("distance").."]" ..
"button_exit[0,1.5;3,1;save;Save Configuration]")
end
end,
on_punch = function(pos, node, puncher, pointed_thing)
local nodey = minetest.get_node(pos)
local inv = puncher:get_inventory()
local itemstack = puncher:get_wielded_item()
local meta = minetest.get_meta(pos)
if meta:get_int("cooldown") == 0 then
if itemstack:get_name() ~= "artillery:shell" then
return itemstack
end
if not minetest.setting_getbool("creative_mode") then
inv:remove_item("main", "artillery:shell")
end
fire_bomb("artillery:bomb", 5, pos, meta:get_int("distance"), nodey.param2)
meta:set_int("cooldown", 1)
meta:set_string("infotext", "Mortar Launcher is cooling down")
minetest.after(2.5, function()
meta:set_int("cooldown", 0)
meta:set_string("infotext", "")
end)
end
end,
})
--Grenade
minetest.register_node("artillery:grenade", {
drawtype = "mesh",
mesh = "gwenade.obj",
description = "Grenade (Right-Click to pull pin, Left-Click to throw",
tiles = "default_stone.png^default_diamond.png",--"grenade.png",
stack_max = 1,
range = 0,
on_secondary_use = function(itemstack, user, pointed_thing)
local player = user:get_player_name()
local meta = itemstack:get_meta()
local inv = user:get_inventory()
if player ~= nil and meta:get_int("active") == 0 then
meta:set_int("active", 1)
minetest.after(5, function()
if inv:contains_item("main", "artillery:grenade") then
tnt.boom(user:get_pos(), {radius = 1, damage_radius = 4})
if not minetest.setting_getbool("creative_mode") then
inv:remove_item("main", "artillery:grenade")
end
end
end)
return itemstack
end
end,
on_use = function(itemstack, placer, pointed_thing)
local player = placer:get_player_name()
local meta = itemstack:get_meta()
local inv = placer:get_inventory()
if player ~= nil and meta:get_int("active") == 1 then
throw_grenade("artillery:grenadey", placer:get_pos(), placer:get_look_dir())
if not minetest.settings:get_bool("creative_mode") then
inv:remove_item("main", "artillery:grenade")
end
end
end,
})
minetest.register_craft({
output = "artillery:grenade",
recipe = {
{"", "default:steel_ingot", ""},
{"default:steel_ingot", "tnt:tnt", "default:steel_ingot"},
{"", "default:steel_ingot", ""}
},
})