English Tibia script thread (Post tibia requests here)

347 replies
Goto Page
To the start Previous 1 2 ... 16 17 18 Next To the start
21.09.16 02:30:12 pm
Up
Yates
Reviewer
Offline Off
My bad.

Code:
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
21.09.16 03:24:59 pm
Up
Mami Tomoe
User
Offline Off
Code:
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
02.04.17 10:05:19 am
Up
Masea
Super User
Offline Off
It's been almost a year and you're still editing tibia. ucrazy?
Create your UI easy and fast: UI Framework | Go deeper into the darkness and test your bravery: file cs2d Outlast II Modification (28)
02.04.17 10:14:48 am
Up
Mami Tomoe
User
Offline Off
Yes and my server is still up and waiting to be fixed
02.04.17 03:07:26 pm
Up
TrialAndError
User
Offline Off
@user Mami Tomoe: And what does it say on line 36...?
02.04.17 03:27:34 pm
Up
Mami Tomoe
User
Offline Off
First error:
Code:
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>

Code:
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:
Code:
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>

Code:
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
02.04.17 04:19:53 pm
Up
TrialAndError
User
Offline Off
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):

Code:
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.
02.04.17 04:53:04 pm
Up
Mami Tomoe
User
Offline Off
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:

Code:
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>

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
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:
Code:
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>

Code:
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
02.04.17 04:55:36 pm
Up
TrialAndError
User
Offline Off
You need to put size on every single monster, if you forget one, the whole thing collapses
02.04.17 05:21:16 pm
Up
Mami Tomoe
User
Offline Off
I have slowly checked and all of them have it

EDIT: Only the first error occurs now, and monsters spawn but only some move.
edited 1×, last 02.04.17 05:32:58 pm
02.04.17 05:37:57 pm
Up
TrialAndError
User
Offline Off
Weird, I have no idea. I don't think the new problem is because of the occupied thing, i did a few tests and it worked fine.
02.04.17 05:40:31 pm
Up
Mami Tomoe
User
Offline Off
Do you or can you help me via a program like TeamViewer so it will be easier?
02.04.17 05:47:22 pm
Up
TrialAndError
User
Offline Off
I can help, but probably not through teamviewer. Don't trust others to control your computer.
05.04.17 02:16:41 pm
Up
Mami Tomoe
User
Offline Off
@user TrialAndError: Fixed it
-----
Hi all I have another question, can I add minions (images) that follow me and attack what I attack if I have a certain armor?
I need it for my Bee armor that will spawn tiny bees but also for other armors
Please help!
05.04.17 02:33:05 pm
Up
Yates
Reviewer
Offline Off
You could basically copy/paste monsters and edit a little. Would take a day of work or so. Go try.
05.04.17 03:01:12 pm
Up
Mami Tomoe
User
Offline Off
So it's like adding another monster? But wont it attack me?
And how to make it spawn when I have a full set of a certain armor? And how to make it follow me and attack what I attack ?
05.04.17 05:36:54 pm
Up
Masea
Super User
Offline Off
user Mami Tomoe has written:
And how to make it spawn when I have a full set of a certain armor? And how to make it follow me and attack what I attack ?
Learning Lua answers your all questions honestly.
Create your UI easy and fast: UI Framework | Go deeper into the darkness and test your bravery: file cs2d Outlast II Modification (28)
05.04.17 06:15:04 pm
Up
Mami Tomoe
User
Offline Off
What exactly do I need to learn? I can't learn the whole Lua in a few days and if I will learn all lua my server will die because no updates
I just need the locations for those questions!
06.04.17 09:52:32 am
Up
Yates
Reviewer
Offline Off
What you're asking will take time, time people would rather not spend on projects not their own. Learn Lua.
06.04.17 12:58:33 pm
Up
Masea
Super User
Offline Off
You should have known that you need to learn Lua firstly before opening server such as current one. Sorry, but everything special takes time.
edited 1×, last 09.04.17 06:21:57 pm
Create your UI easy and fast: UI Framework | Go deeper into the darkness and test your bravery: file cs2d Outlast II Modification (28)
To the start Previous 1 2 ... 16 17 18 Next To the start