i was looking for a turret script and i found *Customizable Turrets 1.01* script which is very useful and i really liked it
Script is working fine but it has a bug that when a player build a turret in a round, it doesn't destroy in the end of round while the projectiles keep throw on enemies of the builder where it was built in previous round but image of custom turret remove!
Kindly i request someone to please fix it
I need it for my server
Here is the script. I hope someone will fix it
*Customizable Turrets 1.01* Script
Script has written
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
mm1 = { 	config = { 		destroyonexit = true; -- Destroy turrets on player exit? If not then it will just change owner id of turret to 0. 		gfx_base = "gfx/mafia_man/mm1/turret_base.png"; -- The thingy under turret 		 		turret = { 			["rocket"] = { 				name = "Rocket Cannon"; 				projid = 48; -- Projectile id 				health = 200; -- Turret health 				price = 1000; 				gfx = "gfx/mafia_man/mm1/turret_rocket.png"; 				 				shootself = false; -- If true then it shoots owner team players or only owner if deathmatch. If false it will only shoot enemies 				 				range = 240; -- range of turret in pixels (checking for players) 				flydist = 240; -- (0-X pixels) if it's -1 then distance from turret to player at aim time 				 				shoot_delay = 2000; -- In milliseconds 				aim_delay = 100; -- In milliseconds 				 				explode = true; -- explode if destroyed? 				exp_size = 100; -- explosion size 				exp_damage = 25; -- explosion damage 				 				f_if = nil; --[[ special condition usage example: 				f_if = function(id) 					-- This will turret will only shoot if player health is lower than his max health 					if player(id, "health") < player(id, "maxhealth") then 						return true 					else 						return false 					end 				end; ]] 			}; 			["Lazer turret"] = { 				name = "Lazer turret"; 				projid = 45; -- Projectile id 				health = 200; -- Turret health 				price = 1000; 				gfx = "gfx/mafia_man/mm1/turret_rocket.png"; 				 				shootself = false; -- If true then it shoots owner team players or only owner if deathmatch. If false it will only shoot enemies 				 				range = 240; -- range of turret in pixels (checking for players) 				flydist = 240; -- (0-X pixels) if it's -1 then distance from turret to player at aim time 				 				shoot_delay = 2000; -- In milliseconds 				aim_delay = 100; -- In milliseconds 				 				explode = true; -- explode if destroyed? 				exp_size = 100; -- explosion size 				exp_damage = 25; -- explosion damage 				 				f_if = nil; --[[ special condition usage example: 				f_if = function(id) 					-- This will turret will only shoot if player health is lower than his max health 					if player(id, "health") < player(id, "maxhealth") then 						return true 					else 						return false 					end 				end; ]] 			}; 			["bandage"] = { 				name = "Bandage Dispenser"; 				projid = 65; -- Projectile id 				health = 100; -- Turret health 				price = 5000; 				gfx = "gfx/mafia_man/mm1/turret_dispenser.png"; 				 				shootself = true; -- If true then it shoots owner team players or only owner if deathmatch. If false it will only shoot enemies 				 				range = 250; -- range of turret in pixels (checking for players) 				flydist = -1; -- (0-X pixels) if it's -1 then distance from turret to player at aim time 				 				shoot_delay = 2500; -- In milliseconds 				aim_delay = 100; -- In milliseconds 				 				explode = true; -- explode if destroyed? 				exp_size = 100; -- explosion size 				exp_damage = 25; -- explosion damage 				 				f_if = function(id) 					-- This turret will only shoot if player health is lower than his max health 					if player(id, "health") < player(id, "maxhealth") then 						return true 					else 						return false 					end 				end; 			}; 		}; 	}; 	turret_id = 1; 	turrets = {}; 	images = {}; 	player = {}; } addhook("serveraction", "mm1.onServeraction") function mm1.onServeraction(id, key) 	if key == 1 then 		mm1.TurretMenu(id) 	end end function dist2p(x1, y1, x2, y2) 	return math.sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2) end function dir2p(x1, y1, x2, y2) 	return math.deg(-math.atan2(x2 - x1, y2 - y1)) end function shootlinedir(x, y, rot, pixels) 	local steps = math.floor(pixels / 16) - 1 	if steps <= 1 then return true end 	 	rot = math.rad(rot) 	local tx, ty 	 	local i 	for i = 1, steps do 		x = x + math.sin(rot) * 16 		y = y + -math.cos(rot) * 16 		 		tx = math.floor(x / 32) 		ty = math.floor(y / 32) 		 		if tile(tx, ty, "wall") then 			return false 		end 	end 	 	return true end function mm1.CreateTurret(pid, tx, ty, type) 	local t = mm1.config.turret[type] 	mm1.turrets[mm1.turret_id] = {} 	local m = mm1.turrets[mm1.turret_id] 	m.tid = mm1.turret_id 	m.pid = pid 	m.type = type 	m.tx = tx 	m.ty = ty 	m.x = tx * 32 + 16 	m.y = ty * 32 + 16	 	m.hp = t.health 	m.rot = 0 	m.flydist = 0 	 	if pid > 0 then 		table.insert(mm1.player[pid].turrets, mm1.turret_id) 	end 	 	m.base = image(mm1.config.gfx_base, m.x, m.y, 0) 	m.img = image(t.gfx, m.x, m.y, 1) 	 	mm1.images[m.base] = m 	 	imagehitzone(m.base, 103, -16, -16, 32, 32) 	 	mm1.turret_id = mm1.turret_id + 1 	 	tween_rotateconstantly(m.img, 7) 	timer(t.shoot_delay, "mm1.UpdateTurret", m.tid) end function mm1.UpdateTurret(tid) 	tid = tonumber(tid) 	 	if not mm1.turrets[tid] then return end 	 	local m = mm1.turrets[tid] 	local t = mm1.config.turret[m.type] 	 	local _, i, x, y 	local shoot = false 	for _, i in pairs(player(0, "tableliving")) do 		shoot = false 		 		local gm = game("sv_gamemode") 		local t1 = player(m.pid, "team") 		local t2 = player(i, "team") 		 		if t.shootself then 			-- If deathmatch 			if gm == 1 then 				 				-- If it's owner of turret 				if i == m.pid then 					shoot = true 				end 			 			-- If not deathmatch 			else 			 				-- If same team 				if t1 == t2 then 					shoot = true 				end 			end 		else 			-- If deathmatch 			if gm == 1 then 				if i > m.pid or i < m.pid then 					shoot = true 				end 			 			-- If not deathmatch 			else 				if t1 > t2 or t1 < t2 then 					shoot = true 				end 			end 		end 		 		-- Custom condition 		if shoot then 			if t.f_if then 				if not t.f_if(i, m, t) then 					shoot = false 				end 			end 		end 		 		if shoot then 			x = player(i, "x") 			y = player(i, "y") 			 			m.flydist = dist2p(x, y, m.x, m.y) 			if m.flydist < t.range then 				m.rot = dir2p(x, y, m.x, m.y) 				 				if shootlinedir(m.x, m.y, m.rot, m.flydist) then 					if t.flydist >= 0 then 						m.flydist = t.flydist 					end 					 					tween_rotate(m.img, t.aim_delay, m.rot) 					imagepos(m.img, m.x, m.y, m.rot) 					timer(t.aim_delay, "mm1.AttackPlayer", m.tid) 					return 				end 			end 		end 	end 	 	m.flydist = 0 	timer(t.shoot_delay, "mm1.UpdateTurret", m.tid) end function mm1.AttackPlayer(tid) 	tid = tonumber(tid) 	 	if not mm1.turrets[tid] then return end 	 	local m = mm1.turrets[tid] 	local t = mm1.config.turret[m.type] 	 	parse("spawnprojectile ".. m.pid .." ".. t.projid .." ".. m.x .." ".. m.y .." ".. m.flydist .." ".. m.rot) 	 	tween_rotateconstantly(m.img, 7) 	timer(t.shoot_delay, "mm1.UpdateTurret", m.tid) end function mm1.TurretMenu(id) 	local str = "Build turret," 	local _, i 	 	for _, i in pairs(mm1.config.turret) do 		str = str .. i.name .. "|" .. i.price .. "$," 	end 	 	menu(id, str) end function mm1.DestroyTurret(m) 	local t = mm1.config.turret[m.type] 	freeimage(m.img) 	freeimage(m.base) 	 	if t.explode then 		parse("explosion " .. m.x .. " " .. m.y .. " " .. t.exp_size .." ".. t.exp_damage .." ".. m.pid) 	end 	 	mm1.turrets[m.tid] = nil end addhook("hitzone", "mm1.onHitzone") function mm1.onHitzone(iid, pid, oid, wpn, ix, iy) 	if mm1.images[iid] then 		local m = mm1.images[iid] 		m.hp = m.hp - itemtype(wpn, "dmg") 		if m.hp < 0 then 			mm1.DestroyTurret(m) 		end 	end end addhook("join", "mm1.onJoin") function mm1.onJoin(id) 	if player(id, "bot") then return end 	mm1.player[id] = {} 	mm1.player[id].turrets = {} 	mm1.player[id].first = true end addhook("leave", "mm1.onLeave") function mm1.onLeave(id) 	if player(id, "bot") then return end 	local _, i 	for _, i in pairs(mm1.player[id].turrets) do 		if mm1.turrets[i] then 			if mm1.config.destroyonexit then 				mm1.DestroyTurret(mm1.turrets[i]) 			else 				mm1.turrets[i].pid = 0 			end 		end 	end end addhook("menu", "mm1.onMenu") function mm1.onMenu(id, title, button) 	if title == "Build turret" then 		local _, i, tid 		tid = 1 		for _, i in pairs(mm1.config.turret) do 			if tid == button then 				mm1.player[id].turret = _ 				msg2(id, "©000255000Build anything with ©255255255wrench©000255000 to build ©255255255" .. i.name) 				break 			end 			tid = tid + 1 		end 	end end addhook("buildattempt", "mm1.onBuildattempt") function mm1.onBuildattempt(id, b, tx, ty) if b == 8 then if mm1.player[id].turret then 		local money = player(id, "money") 		local t = mm1.config.turret[mm1.player[id].turret] 		if money >= t.price then 			parse("setmoney ".. id .." ".. (money - t.price)) 			mm1.CreateTurret(id, tx, ty, mm1.player[id].turret) 			if mm1.player[id].first then 				msg2(id, "©255255255To build another turret you have to select it again from menu.") 				mm1.player[id].first = nil 			end 			mm1.player[id].turret = nil 		else 			mm1.player[id].turret = nil 			msg2(id, "©255000000You don't have enough money!@C") 			msg2(id, "©155000000(You have to select turret again)@C") 		end 		return 1 	end end end
edited 2×, last 31.12.19 04:55:19 pm