English fix this script

2 replies
Goto Page
To the start Previous 1 Next To the start
07.09.12 02:25:26 am
Up
eduxd0707
BANNED
Offline Off
>>> LUA ERROR: sys/lua/cs2dtibia/monsters.lua:346: attempt to index field 'spawn' (a nil value) <<<

Code:
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
Monster = {name = 'Monster', health = 100, image = 'gfx/weiwen/circle.png', scalex = 1, scaley = 1, atk = 1, def = 1, spd = 5, x = 0, y = 0, ang = 0, imgang = 0, exp = 5, money = 50, type = 'monster', loot = {}}
MONSTERS = {}
local t = 0

CONFIG.MONSTERS = {
     {
          name = 'Bulbasaur', health = 100, image = 'gfx/weiwen/pokemon/9.bmp', scalex = 2, scaley = 2, r = 136, g = 224, b = 32, 
          atk = 1.9, def = 2.1, spd = 6, atkspd = 8, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 5, runat = 10, 
          exp = 15, money = 100, loot = {{chance = 5000, id = 102}, {chance = 50, id = 221}}, spawn1 = {0, 100}, spawn2 = {150, 150}, 
          spc = {1500, function(self) 
               radiusmsg("Bulbasaur casts heal!", self.x, self.y)
               parse("effect \"colorsmoke\" " .. self.x .. " " .. self.y .. " 5 5 255 255 255")
          end}, 
             }, 
             {
          name = 'Charmander', health = 100, image = 'gfx/weiwen/pokemon/200.bmp', scalex = 2, scaley = 2, 
          atk = 2.2, def = 1.8, spd = 6, atkspd = 8, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 5, runat = 10,  
          exp = 15, money = 100, loot = {{chance = 5000, id = 100}, {chance = 50, id = 222}}, spawn1 = {0, 100}, spawn2 = {150, 150}, 
          spc = {1000, function(self, target) 
               radiusmsg("Charmander uses ember!", self.x, self.y)
               parse('explosion ' .. self.x .. ' ' .. self.y .. ' 96 40')
               parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' 100 64 255 128 0')
               parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' 100 96 255 255 0')
          end},
             },              
             {
          name = 'Squirtle', health = 100, image = 'gfx/weiwen/pokemon/azul.bmp', scalex = 2, scaley = 2, 
          atk = 1.7, def = 2.3, spd = 6, atkspd = 8, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 5, runat = 10, 
          exp = 15, money = 100, loot = {{chance = 5000, id = 101}, {chance = 50, id = 223}}, spawn1 = {0, 100}, spawn2 = {150, 150}, 
          spc = {1000, function(self) 
               radiusmsg("Squirtle uses watergun!", self.x, self.y)
               parse('explosion ' .. self.x .. ' ' .. self.y .. ' 96 40')
               parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' 100 96 255 255 255')
               parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' 75 96 128 128 255')
          end},
             }, 
             {
          name = 'Caterpie', health = 100, image = 'gfx/weiwen/pokemon/16.bmp', scalex = 1.5, scaley = 1.5, r = 104, g = 152, b = 40, 
          atk = 1.1, def = 1.2, spd = 7, atkspd = 10, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 100, runat = 20, spawn1 = {0, 0}, spawn2 = {150, 150}, 
          exp = 10, money = 30, loot = {{chance = 8000, id = 1}}, 
                }, 
             {
          name = 'Weedle', health = 100, image = 'gfx/weiwen/pokemon/17.bmp', scalex = 1.5, scaley = 1.5, r = 104, g = 152, b = 40, 
          atk = 1.2, def = 1.1, spd = 7, atkspd = 10, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 100, runat = 20, spawn1 = {0, 0}, spawn2 = {150, 150}, 
          exp = 10, money = 30, loot = {{chance = 8000, id = 1}}, 
             }, 
             {
          name = 'Pidgey', health = 100, image = 'gfx/weiwen/pokemon/18.bmp', scalex = 2, scaley = 2, 
          atk = 1.2, def = 1.2, spd = 10, atkspd = 7, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 50, runat = 20, spawn1 = {0, 0}, spawn2 = {150, 150}, 
          exp = 20, money = 60, loot = {}, 
          spc = {500, function(self) 
               radiusmsg("Pidgey uses sand attack!", self.x, self.y)
               parse('flashposition ' .. self.x .. ' ' .. self.y .. ' 100')
           end},
             }, 
             {
          name = 'esquelet', health = 100, image = 'gfx/weiwen/pokemon/7.bmp', scalex = 1.5, scaley = 1.5, 
          atk = 1.0, def = 1.0, spd = 9, atkspd = 5, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 100, runat = 20, spawn1 = {0, 0}, spawn2 = {150, 150}, 
          exp = 10, money = 50, loot = {{chance = 8000, id = 4}}, 
             },
                {
                name = 'Bronze Vortex', health = 165, image = 'gfx/weiwen/pokemon/tierra.bmp', scalex = 2, scaley = 2, 
          atk = 2.0, def = 7.0, spd = 10, atkspd = 9, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 100, runat = 20, spawn1 = {0, 0}, spawn2 = {180, 77}, 
          exp = 410, money = 1000, loot = {{chance = 8000, id = 320}, {chance = 8000, id = 321}},
                },
                {
                name = 'Ice Monster', health = 200, image = 'gfx/weiwen/pokemon/13.bmp', scalex = 2, scaley = 2, 
          atk = 4.3, def = 11.2, spd = 10, atkspd = 11, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 100, runat = 20, spawn1 = {0, 0}, spawn2 = {177, 143}, 
          exp = 2020, money = 2200, loot = {{chance = 8000, id = 340}, {chance = 8000, id = 341}},
                },
                {
                name = 'Fire Dragon', health = 190, image = 'gfx/weiwen/pokemon/firedragon.bmp', scalex = 2, scaley = 2, 
          atk = 6.3, def = 19.2, spd = 20, atkspd = 11, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 100, runat = 20, spawn1 = {0, 0}, spawn2 = {177, 143}, 
          exp = 4020, money = 5000, loot = {{chance = 8000, id = 356}, {chance = 8000, id = 350}},
                },
                {
                name = 'Dragon', health = 200, image = 'gfx/weiwen/pokemon/3.bmp', scalex = 2, scaley = 2, 
          atk = 3.0, def = 9.0, spd = 12, atkspd = 9, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 100, runat = 20, spawn1 = {0, 0}, spawn2 = {171, 119}, 
          exp = 1020, money = 1200, loot = {{chance = 8000, id = 327}, {chance = 8000, id = 328}},
                },
                {
                name = 'Aqua', health = 200, image = 'gfx/weiwen/pokemon/3.bmp', scalex = 2, scaley = 2, 
          atk = 3.0, def = 9.0, spd = 12, atkspd = 9, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 100, runat = 20, spawn1 = {0, 0}, spawn2 = {171, 119}, 
          exp = 1020, money = 1200, loot = {{chance = 8000, id = 327}, {chance = 8000, id = 328}},
                },
             {
          name = 'Spearow', health = 100, image = 'gfx/weiwen/pokemon/6.bmp', scalex = 2, scaley = 2, 
          atk = 1.4, def = 1.0, spd = 10, atkspd = 7, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 50, runat = 20, spawn1 = {0, 0}, spawn2 = {150, 150}, 
          exp = 20, money =60, loot = {}, 
          spc = {2500, function(self, id, dist) 
               if not self.agility then
                    radiusmsg("Spearow uses agility!", self.x, self.y)
                    parse("effect \"colorsmoke\" " .. self.x .. " " .. self.y .. " 5 5 155 255 155")
                    radiussound("weapons/g_flash.wav", self.x, self.y)
                    self.spd = 10
                    self.agility = true
                    imagecolor(self.image, 155, 255, 155)
                    timer(5000, "CONFIG.MONSTERSKILLS.endAgility", self.id)
               elseif dist <= 32 then
                    self:hit(id, 10)
               end
          end},
             }, 
             {
          name = 'Ekans', health = 100, image = 'gfx/weiwen/pokemon/10.bmp', scalex = 2, scaley = 2, 
          atk = 1.8, def = 1.2, spd = 7, atkspd = 8, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 20, runat = 10, spawn1 = {0, 0}, spawn2 = {150, 150}, 
          exp = 10, money = 80, loot = {}, 
          spc = {500, function(self, id, dist) 
               if dist <= 96 then
                    radiusmsg("Ekans uses poison sting!", self.x, self.y)
                    self:hit(id, 20)
               end
          end},
             }, 
             {
          name = 'Bear', health = 100, image = 'gfx/weiwen/pokemon/15.bmp', scalex = 2, scaley = 2, 
          atk = 2.1, def = 2.1, spd = 7, atkspd = 7, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 5, runat = 10, spawn1 = {0, 100}, spawn2 = {150, 150}, 
          exp = 25, money = 120, loot = {{chance = 5000, id = 103}, {chance = 50, id = 220}}, 
          spc = {500, function(self) 
               radiusmsg("Pikachu uses thundershock!", self.x, self.y)
               parse('explosion ' .. self.x .. ' ' .. self.y .. ' 96 40')
               parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' 100 96 255 255 0')
               parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' 75 64 255 255 255')
          end},
             }, 
             {
          name = 'Sandshrew', health = 100, image = 'gfx/weiwen/pokemon/12.bmp', scalex = 2, scaley = 2, 
          atk = 1.7, def = 2.1, spd = 7, atkspd = 7, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 10, runat = 10, spawn1 = {165, 30}, spawn2 = {184, 48}, 
          exp = 18, money = 120, loot = {}, 
          spc = {1000, function(self) 
               radiusmsg("Sandshrew uses sand attack!", self.x, self.y)
               parse('flashposition ' .. self.x .. ' ' .. self.y .. ' 100')
          end},
             },
             {
          name = 'NidoranF', health = 100, image = 'gfx/weiwen/pokemon/100.bmp', scalex = 2, scaley = 2, 
          atk = 1.8, def = 1.2, spd = 7, atkspd = 8, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 20, runat = 10, spawn1 = {0, 0}, spawn2 = {150, 150}, 
          exp = 10, money = 80, loot = {}, 
          spc = {750, function(self, id, dist) 
               if dist <= 96 then
                    radiusmsg("NidoranF uses poison sting!", self.x, self.y)
                    self:hit(id, 20)
               end
          end},
              }, 
              {
          name = 'mumia', health = 100, image = 'gfx/weiwen/pokemon/10006.bmp', scalex = 2, scaley = 2, 
          atk = 1.8, def = 1.2, spd = 7, atkspd = 8, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 20, runat = 10, spawn1 = {0, 0}, spawn2 = {150, 150}, 
          exp = 10, money = 80, loot = {}, 
          spc = {750, function(self, id, dist) 
               if dist <= 96 then
                    radiusmsg("NidoranM uses horn attack!", self.x, self.y)
                    self:hit(id, 20)
               end
          end},
              }, 
              {
          name = 'Vulpix', health = 100, image = 'gfx/weiwen/pokemon/10005.bmp', scalex = 2, scaley = 2, 
          atk = 2.2, def = 1.8, spd = 7, atkspd = 8, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 10, runat = 0, spawn1 = {0, 100}, spawn2 = {150, 150}, 
          exp = 10, money = 100, loot = {{chance = 5000, id = 104}}, 
          spc = {500, function(self, id, dist) 
               radiusmsg("Vulpix uses flamethrower!", self.x, self.y)
               local x1, y1 = self.x, self.y
               local rot = math.atan2(player(id, 'y')-y1, player(id, 'x')-x1) + math.pi/2
               local x2, y2 = math.sin(rot), -math.cos(rot)
               local fire = image("gfx/sprites/spot.bmp", 0, 0, 1)
               imagepos(fire, x1+x2*64, y1+y2*64, math.deg(rot)+180)
               imagescale(fire, 1.5, 2)
               imagecolor(fire, 255, 64, 0)
               imageblend(fire, 1)
               timer(500, "freeimage", fire)
               parse('explosion ' .. x1+x2*100 .. ' ' .. y1+y2*100 .. ' 48 40')
               parse('explosion ' .. x1+x2*50 .. ' ' .. y1+y2*50 .. ' 32 40')
          end},
             }, 
             {
          name = 'Dog', health = 100000, image = 'gfx/weiwen/pokemon/14.bmp', scalex = 2, scaley = 2, 
          atk = 0, def = 999999, spd = 1, atkspd = 6, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 10, runat = 0, spawn1 = {0, 0}, spawn2 = {150, 150}, 
          exp = 25, money = 100, loot = {{chance = 1000, id = 230}},
             },
                {
                name = 'Exp', health = 500, image = 'gfx/weiwen/pokemon/exp.png', scalex = 2, scaley = 2, 
          atk = 0.0, def = 5.2, spd = 0.1, atkspd = 1, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 10, runat = 0, spawn1 = {0, 0}, spawn2 = {150, 150}, 
          exp = 5000000, money = 100, loot = {},
                },       
             {
          name = 'Mankey', health = 100, image = 'gfx/weiwen/pokemon/2000.bmp', scalex = 2, scaley = 2, 
          atk = 2.5, def = 1.8, spd = 10, atkspd = 6, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 10, runat = 0, range = 48, spawn1 = {0, 100}, spawn2 = {150, 150}, 
          exp = 25, money = 120, loot = {{chance = 1000, id = 300},{chance = 1000, id = 301},{chance = 1000, id = 302},{chance = 1000, id = 303},{chance = 1000, id = 304},{chance = 1000, id = 305},{chance = 1000, id = 306}}, 
          spc = {1000, function(self, id, dist) 
               if not self.rage then
                    radiusmsg("Mankey uses rage!", self.x, self.y)
                    parse("effect \"colorsmoke\" " .. self.x .. " " .. self.y .. " 5 5 255 155 155")
                    radiussound("weapons/g_flash.wav", self.x, self.y)
                    self.def = 3.3
                    self.rage = true
                    imagecolor(self.image, 255, 155, 155)
                    timer(5000, "CONFIG.MONSTERSKILLS.endRage", self.id)
               elseif dist <= 96 then
                    radiusmsg("Mankey uses karate chop!", self.x, self.y)
                    self:hit(id, 20)
               end
          end},
     }, 
     {
          name = 'Abra', health = 100, image = 'gfx/weiwen/pokemon/250.bmp', scalex = 2, scaley = 2, 
          atk = 0.6, def = 1.0, spd = 5, atkspd = 10, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 10, runat = 100, spawn1 = {0, 0}, spawn2 = {150, 150}, 
          exp = 8, money = 50, loot = {{chance = 5000, id = 105}}, 
          spc = {2500, function(self) 
               radiusmsg("Abra uses teleport!", self.x, self.y)
               parse("effect \"colorsmoke\" " .. self.x .. " " .. self.y .. " 5 5 255 255 255")
               local dir = math.random(math.pi*2)
               if self:move(dir, 40) or self:move(dir, -40) then
                    parse("effect \"colorsmoke\" " .. self.x .. " " .. self.y .. " 5 5 255 255 255")
               end
          end},
     }, 
     {
          name = 'Gastly', health = 100, image = 'gfx/weiwen/pokemon/8.bmp', scalex = 2, scaley = 2, r = 64, g = 0, b = 64, 
          atk = 1.2, def = 1.5, spd = 8, atkspd = 10, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 10, runat = 50, spawn1 = {0, 100}, spawn2 = {150, 150}, 
          exp = 8, money = 100, loot = {}, 
          spc = {1000, function(self, id, dist)
               if dist <= 64 and not PLAYERS[id].tmp.paralyse then
                    radiusmsg("Gastly uses lick!", self.x, self.y)
                    PLAYERS[id].tmp.paralyse = true
                    msg2(id, "You are paralysed.")
                    parse("effect \"colorsmoke\" " .. player(id, 'x') .. " " .. player(id, 'y') .. " 5 5 64 0 64")
                    timer(3000, "rem.paralyse", id)
               elseif dist <= 32 then
                    self:hit(id, 10)
               end
          end},
     }, 
     {
          name = 'Onix', health = 125, image = 'gfx/weiwen/pokemon/1.bmp', scalex = 3, scaley = 3, r = 144, g = 144, b = 144, 
          atk = 1.8, def = 5.0, spd = 3, atkspd = 10, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 5, runat = 0, range = 64, spawn1 = {165, 30}, spawn2 = {184, 48}, 
          exp = 100, money = 300, loot = {{chance = 1000, id = 310},{chance = 1000, id = 311},{chance = 1000, id = 312},{chance = 1000, id = 313},{chance = 1000, id = 314},{chance = 1000, id = 315},{chance = 1000, id = 316}}, 
          spc = {1000, function(self) 
               if not self.harden then
                    radiusmsg("Onix uses harden!", self.x, self.y)
                    parse("effect \"colorsmoke\" " .. self.x .. " " .. self.y .. " 5 5 192 192 192")
                    radiussound("weapons/g_flash.wav", self.x, self.y)
                    self.def = 7.5
                    self.harden = true
                    imagecolor(self.image, 155, 155, 255)
                    timer(5000, "CONFIG.MONSTERSKILLS.endHarden", self.id)
               end
          end},
     }, 
     {
          name = 'Voltorb', health = 100, image = 'gfx/weiwen/pokemon/5.bmp', scalex = 2, scaley = 2, r = 144, g = 144, b = 144, 
          atk = 2.3, def = 2.3, spd = 5, atkspd = 8, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 10, runat = 20, range = 48, spawn1 = {0, 100}, spawn2 = {150, 150}, 
          exp = 30, money = 130, loot = {{chance = 5000, id = 103}}, 
          spc = {1000, function(self) 
               if self.health < 20 then
                    radiusmsg("Voltorb uses selfdestruct!", self.x, self.y)
                    parse('explosion ' .. self.x .. ' ' .. self.y .. ' 128 80')
                    parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' 100 128 255 128 0')
                    parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' 100 128 255 255 0')
                    self:destroy()
               else
                    radiusmsg("Voltorb uses thundershock!", self.x, self.y)
                    parse('explosion ' .. self.x .. ' ' .. self.y .. ' 96 40')
                    parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' 100 96 255 255 0')
                    parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' 75 64 255 255 255')
               end
          end},
     }, 
     {
          name = 'Koffing', health = 100, image = 'gfx/weiwen/pokemon/251.bmp', scalex = 2, scaley = 2, r = 128, g = 128, b = 0, 
          atk = 2.0, def = 1.7, spd = 4, atkspd = 10, x = 0, y = 0, ang = 0, imgang = 0, spawnchance = 10, runat = 20, range = 48, spawn1 = {0, 100}, spawn2 = {150, 150}, 
          exp = 30, money = 150, loot = {{chance = 5000, id = 106}}, 
          spc = {1000, function(self) 
               if self.health < 20 then
                    radiusmsg("Koffing uses explosion!", self.x, self.y)
                    parse('explosion ' .. self.x .. ' ' .. self.y .. ' 128 40')
                    parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' 100 128 255 128 0')
                    parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' 100 128 255 255 0')
                    self:destroy()
               else
                    radiusmsg("Koffing uses poison fog!", self.x, self.y)
                    parse('explosion ' .. self.x .. ' ' .. self.y .. ' 96 40')
                    parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' 100 96 128 128 0')
               end
          end},
     }, 
}

CONFIG.MONSTERSKILLS = {
     endAgility = function(id)
          self = MONSTERS[tonumber(id)]
          self.spd = self._spd
          self._spd = nil
          imagecolor(self.image, 255, 255, 255)
          self.agility = nil
     end,
     endRage = function(id)
          self = MONSTERS[tonumber(id)]
          self.atk = self._atk
          self._atk = nil
          imagecolor(self.image, 255, 255, 255)
          self.rage = nil
     end,
     endHarden = function(id)
          self = MONSTERS[tonumber(id)]
          self.def = self._def
          self._def = nil
          imagecolor(self.image, 255, 255, 255)
          self.harden = nil
     end,
}

addhook("attack", "MONSTERattack")
function MONSTERattack(id)
     if gettile(PLAYERS[id].x, PLAYERS[id].y).SAFE or gettile(PLAYERS[id].x, PLAYERS[id].y).NOMONSTERS then
          return
     end
     if inarray({400, 401, 402, 403, 404}, PLAYERS[id].Equipment[7]) then
          message(id, "You may not attack on a horse.")
          return
     end
     local weapon, closest = player(id, 'weapontype')
     for _, m in ipairs(MONSTERS) do
          local x, y = player(id, 'x'), player(id, 'y')
          local dist = math.sqrt((m.x-x)^2+(m.y-y)^2)
          if dist <= (closest and closest[2] or (CONFIG.WEAPONRANGE[weapon] or CONFIG.WEAPONRANGE[50])) then
               local rot = player(id, 'rot')
               if math.abs(math.rad(rot) - math.atan2(y-m.y, x-m.x) + math.pi/2)%(2*math.pi) <= (CONFIG.WEAPONWIDTH[weapon] or CONFIG.WEAPONRANGE[50]) then
                    closest = {m, dist}
               end
          end
     end
     if closest then
          closest[1]:damage(id, math.ceil(20*((PLAYERS[id].Level+50)*PLAYERS[id].tmp.atk/closest[1].def)/math.random(60, 140)), weapon)
     end
end

addhook("ms100", "MONSTERms100")
function MONSTERms100()
     t = t + 1
     if t % 100 == 0 then
          while #MONSTERS < CONFIG.MAXMONSTERS do
               local rand, spawnNo, mapName
               while true do 
                    rand = math.random(#CONFIG.MONSTERS)
                    mapName = CONFIG.MONSTERS[rand].spawn[map'name'] and map'name' or CONFIG.DEFAULTMAP
                    spawnNo = math.random(#CONFIG.MONSTERS[rand].spawn[mapName])
                    if math.random(0, 100) < CONFIG.MONSTERS[rand].spawnchance[mapName][spawnNo] then
                         break
                    end
               end 
               local m = deepcopy(CONFIG.MONSTERS[rand])
               local x, y, tilex, tiley
               local spawn = m.spawn[mapName][spawnNo]
               repeat
                    tilex, tiley = math.random(spawn[1][1], spawn[2][1]), math.random(spawn[1][2], spawn[2][2])
               until not gettile(tilex, tiley).SAFE and 
                      not gettile(tilex, tiley).NOMONSTERS and 
                      tile(tilex, tiley, "walkable") and 
                      tile(tilex, tiley, "frame") ~= 34
               m.x, m.y = math.floor(tilex*32+16), math.floor(tiley*32+16)
               Monster:new(m)
          end
     end
     for _, m in ipairs(MONSTERS) do
          if t % m.atkspd == 0 then
               m.target = nil
               local closest
               for _, p in ipairs(table.shuffle(player(0, 'table'))) do
                    if player(p, 'health') > 0 and 
                         not gettile(PLAYERS[p].x, PLAYERS[p].y).SAFE and 
                         not gettile(PLAYERS[p].x, PLAYERS[p].y).NOMONSTERS then
                         local dist = math.sqrt((player(p, 'x')-m.x)^2 + (player(p, 'y')-m.y)^2)
                         if dist < 400 then
                              if not closest or dist < closest[2] then
                                   closest = {p, dist}
                              end
                         end
                    end
               end
               if closest then
                    local dist = closest[2]
                    if dist < 400 then
                         m.target = closest[1]
                         if m.spc and math.random(10000) <= m.spc[1] then
                              m.spc[2](m, m.target, dist)
                         elseif dist <= (m.range or 32) then
                              m:hit(m.target, 10)
                         end
                    end
               end
          end
          m.imgang = math.sin(t/2.5*math.pi) * 15
          if m.target and player(m.target, 'exists') and player(m.target, 'health') > 0 and 
               not gettile(PLAYERS[m.target].x, PLAYERS[m.target].y).SAFE and 
               not gettile(PLAYERS[m.target].x, PLAYERS[m.target].y).NOMONSTERS then
               xdist, ydist = player(m.target, 'x') - m.x, player(m.target, 'y') - m.y
               local dist = math.sqrt(xdist^2 + ydist^2)
               if dist < 400 then
                    m.ang = math.atan2(ydist, xdist)-math.pi/2+math.random(-1, 1)/2
               else
                    m.target = nil
               end
          end
          if not m.target then
               m:rot(math.random(-1, 1)/2)
          end
          if not m:move(m:rot(), m.health > m.runat and 1 or -1) then
               repeat until m:move(math.rad(math.random(360)), 1)
          end
     end
end

function Monster:new(m)
     if not (m.x or m.y) then return false end
     m.image = image(m.image, m.x, m.y, 0)
     imagescale(m.image, m.scalex, m.scaley)
     setmetatable(m, self)
     self.__index = self
     local n = #MONSTERS+1
     MONSTERS[#MONSTERS+1] = m
     m.id = n
     return m
end

function Monster:pos(x, y)
     if not x and not y then
          return self.x, self.y
     else
          self.x, self.y = x or self.x, y or self.y
          imagepos(self.image, self.x, self.y, self.imgang)
     end
     return true
end

function Monster:move(dir, amt)
     local x, y = -math.sin(dir)*amt*self.spd, math.cos(dir)*amt*self.spd
     local x, y = self.x+x, self.y+y
     local tilex, tiley = math.floor(x/32), math.floor(y/32)
     if tile(tilex, tiley, 'walkable') and tile(tilex, tiley, 'frame') ~= 34 and 
          not gettile(tilex, tiley).SAFE and 
          not gettile(tilex, tiley).NOMONSTERS then
          self:pos(x, y)
          return true
     else
          self:rot(math.random(-1, 1)*math.pi/2)
          return false
     end
end

function Monster:damage(id, dmg, wpntype)
     if not PLAYERS[id].Tutorial.damagem then
          message(id, "You have attacked a monster! Good job! Keep on attacking it until it dies.", "255128000")
          PLAYERS[id].Tutorial.damagem = true
     end
     local wpnName
     if weapon == 251 then
          wpnName = 'rune'
     elseif weapon == 46 then
          wpnName = 'firewave'
          dmg = dmg/5
     else
          wpnName = PLAYERS[id].Equipment[3] and ITEMS[PLAYERS[id].Equipment[3]].name or 'dagger'
     end
     self.health = self.health - dmg
     --print(player(id, 'name') .. ' deals ' .. dmg .. ' damage to ' .. self.name .. ' usng a ' .. wpnName .. '.')
     if self.health <= 0 then
          if not PLAYERS[id].Tutorial.killm then
               message(id, "Congratulation! You have killed your first monster. You can proceed to pick up the loot by using the drop weapon button (default G)", "255128000")
               PLAYERS[id].Tutorial.killm = true
          end
          addexp(id, math.floor(self.exp*CONFIG.EXPRATE))
          self:die()
     else
          parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' 0 ' .. self.scaley .. ' ' .. (self.r and (self.r .. ' ' .. self.g .. ' ' .. self.b) or '192 0 0'))
     end
     radiussound("weapons/machete_hit.wav", self.x, self.y)
     return true
end

function Monster:hit(id, dmg)
     if not PLAYERS[id].Tutorial.hitm then
          message(id, "A monster is attacking you! You can fight back by swinging your weapon at it.", "255128000")
          PLAYERS[id].Tutorial.hitm = true
     end
     if player(id, 'weapontype') == 41 and (math.abs(math.rad(player(id, 'rot')) - math.atan2(player(id, 'y')-self.y, player(id, 'x')-self.x) + math.pi/2)%(2*math.pi) <= math.pi*2/3) then
          EXPhit(id, self, -1, dmg/4)
          radiussound("weapons/ricmetal" .. math.random(1,2) .. ".wav", self.x, self.y)
     else
          EXPhit(id, self, -1, dmg)
          radiussound("weapons/knife_hit.wav", self.x, self.y)
     end
     return true
end

function Monster:die(id)
     local size = self.scalex+self.scaley
     parse('effect "colorsmoke" ' .. self.x .. ' ' .. self.y .. ' ' .. size .. ' 64 ' .. (self.r and (self.r .. ' ' .. self.g .. ' ' .. self.b) or '192 0 0'))
     local tilex, tiley = math.floor(self.x/32), math.floor(self.y/32)
     spawnitem(1337, tilex, tiley, math.floor(self.money*math.random(50, 150)/100)*CONFIG.MONEYRATE)
     for _, loot in ipairs(self.loot) do
          local chance = math.random(10000)
          if chance <= loot.chance then
               spawnitem(loot.id, tilex, tiley)
          end
     end
     radiussound("weapons/c4_explode.wav", self.x, self.y)
     self:destroy()
end

function Monster:destroy()
     freeimage(self.image)
     local found
     table.remove(MONSTERS, self.id)
     for i, m in ipairs(MONSTERS) do
          m.id = i
     end
     return true
end

function Monster:rot(rot)
     if not rot then
          return self.ang
     else
          self.ang = (self.ang+rot)%(math.pi*2)
     end
     return true
end
edited 2×, last 07.09.12 03:40:02 am
07.09.12 06:57:49 am
Up
miere
User
Offline Off
07.09.12 12:02:24 pm
Up
Eternal
User
Offline Off
Why don't you use this tag? the Code tag

Code:
1
Your code there


or you want us to count it where is error line or you want us to copy them to our Text editor?
To the start Previous 1 Next To the start