Forum

> > CS2D > Scripts > Tibia script thread (Post tibia requests here)
Forums overviewCS2D overview Scripts overviewLog in to reply

English Tibia script thread (Post tibia requests here)

347 replies
Page
To the start Previous 1 216 17 18 Next To the start

old Re: Tibia script thread (Post tibia requests here)

Yates
Reviewer Off Offline

Quote
My bad.

1
2
3
4
5
6
7
8
function occupied(x,y,monsterid)
    for n, m in pairs (MONSTERS) do
        if monsterid ~= n and math.sqrt(math.pow(math.abs(m.x-x),2) + math.pow(math.abs(m.y-y),2)) <= m.size then
            return true
        end
    end
    return false
end

old Re: Tibia script thread (Post tibia requests here)

Mami Tomoe
User Off Offline

Quote
1
2
3
4
5
LUA ERROR: sys/lua/cs2dtibia/functions.lua:36: attempt to compare number with nil
 -> sys/lua/cs2dtibia/functions.lua:36: in function 'occupied'
 -> sys/lua/cs2dtibia/monsters.lua:1450: in function 'pos'
 -> sys/lua/cs2dtibia/monsters.lua:1476: in function 'move'
 -> sys/lua/cs2dtibia/monsters.lua:1428: in function <sys/lua/cs2dtibia/monsters.lua:1354>
I don't know what that means maybe it's getting nil values I think OK


EDIT: Hi guys it's been almost a year and I'm still waiting
No pressure
edited 2×, last 02.04.17 09:30:53 am

old Re: Tibia script thread (Post tibia requests here)

Mami Tomoe
User Off Offline

Quote
First error:
1
2
3
LUA ERROR: sys/lua/cs2dtibia/functions.lua:445: attempt to index field '?' (a nil value)
 -> sys/lua/cs2dtibia/functions.lua:445: in function 'gettile'
 -> sys/lua/cs2dtibia/monsters.lua:1372: in function <sys/lua/cs2dtibia/monsters.lua:1354>
1
2
3
function gettile(x,y)
	return TILEZONE[y][x] --LINE 445
end

Second error comes after first one and keeps spamming every few milliseconds:
1
2
3
4
5
LUA ERROR: sys/lua/cs2dtibia/functions.lua:36: attempt to compare number with nil
 -> sys/lua/cs2dtibia/functions.lua:36: in function 'occupied'
 -> sys/lua/cs2dtibia/monsters.lua:1450: in function 'pos'
 -> sys/lua/cs2dtibia/monsters.lua:1476: in function 'move'
 -> sys/lua/cs2dtibia/monsters.lua:1428: in function <sys/lua/cs2dtibia/monsters.lua:1354>
1
2
3
4
5
6
7
8
function occupied(x,y,monsterid)
    for n, m in pairs (MONSTERS) do
        if monsterid ~= n and math.sqrt(math.pow(math.abs(m.x-x),2) + math.pow(math.abs(m.y-y),2)) <= m.size then --LINE 36
            return true
        end
    end
    return false
end

old Re: Tibia script thread (Post tibia requests here)

TrialAndError
User Off Offline

Quote
First problem, I once solved it, no idea how. tbh.

But the second problem, I guess we forgot to tell you that you need to put a new attribute called "size" to every monster.

Example (Check end of Line 3):

1
2
3
4
5
6
7
8
9
10
11
12
13
{
		name = 'Bulbasaur', health = 100, image = 'gfx/weiwen/pokemon/1.png', 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, runat = 0, size = 32, -- HERE
		spawnchance = {['rpg_mapb'] = {5}}, 
		spawn = {
			['rpg_mapb'] = {SPAWNS.BOTTOMHALF}
		}, 
		exp = 15, money = 100, loot = {{chance = 5000, id = 102}, {chance = 250, id = 221}}, 
		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}, 
	}



P.S. [WARNING]: The code is known to crash/freeze the server if two monsters collide or spawn on top of each other.

old Re: Tibia script thread (Post tibia requests here)

Mami Tomoe
User Off Offline

Quote
user TrialAndError has written
P.S. [WARNING]: The code is known to crash/freeze the server if two monsters collide or spawn on top of each other.

How to fix that?

I did what you did and there is no spam in console except 2 errors and no monsters at all:

1
2
LUA ERROR: sys/lua/cs2dtibia/monsters.lua:1413: attempt to index a nil value
 -> sys/lua/cs2dtibia/monsters.lua:1413: in function <sys/lua/cs2dtibia/monsters.lua:1395>
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
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 																	--LINE 1413
				  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
					for k,v in pairs (rotate_to_player) do
						if m.name == v then
							m.imgang = math.deg(math.atan2(ydist, xdist))+90
						end
					end
               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

And this error:
1
2
3
4
5
LUA ERROR: sys/lua/cs2dtibia/functions.lua:36: attempt to compare number with nil
 -> sys/lua/cs2dtibia/functions.lua:36: in function 'occupied'
 -> sys/lua/cs2dtibia/monsters.lua:1450: in function 'pos'
 -> sys/lua/cs2dtibia/monsters.lua:1476: in function 'move'
 -> sys/lua/cs2dtibia/monsters.lua:1428: in function <sys/lua/cs2dtibia/monsters.lua:1354>
1
2
3
4
5
6
7
8
function occupied(x,y,monsterid)
    for n, m in pairs (MONSTERS) do
        if monsterid ~= n and math.sqrt(math.pow(math.abs(m.x-x),2) + math.pow(math.abs(m.y-y),2)) <= m.size then --LINE 36
            return true
        end
    end
    return false
end
To the start Previous 1 216 17 18 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview