Monster size affects nothing in RPG Tibia

Hi, I'm working on an RPG script because I'm not good enough at Lua to create my own
I have different monsters with different image sizes but when I try to change their

self.size

it doesn't affect anything.
I've searched throughout the whole script and it's only used here:

Code:

12345678910

--[[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 falseend]]

That function isn't even used.

I suppose

self.size

is supposed to be checked in this hook:

Code:

1234567891011121314151617181920212223242526

addhook("attack", "RPG.attackHookMonster")function RPG.attackHookMonster(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 hudMsg(id,"You may not attack on a horse.","note") 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 if free_line(player(id,"x"),player(id,"y"),m.x,m.y) then closest = {m, dist} end end end end if closest then closest[1]:damage(id,math.floor(((PLAYERS[id].tmp.atk*10)/closest[1].def)), weapon) endend

But I don't know where.
I've tried adding it to the function in random places but either it's not the right way or I've done it wrong.

Another place where it could be placed in is this function where I used to use the occupied function until it caused some issues and I was told I better off not use it:

Code:

12345678910111213141516171819202122232425

function Monster:pos(x, y) if not x and not y then return self.x, self.y else --if not occupied(x,y,self.id) then self.x, self.y = x or self.x, y or self.y --end for all = 1, 32 do if player(all,"exists") and getHealth(all) > 0 then if player(all,"x") >= self.x-800 and player(all,"x") <= self.x+800 and player(all,"y") >= self.y-800 and player(all,"y") <= self.y+800 then imagepos(self.image, self.x, self.y, self.imgang) if not self.alpha then self.alpha=1 end imagealpha(self.image, self.alpha) break end end if all == 32 then imagealpha(self.image, 0) end end end return trueend

The existing code will not work if you simply decide to add it to the monster position function. You'll end up with monsters spawning on top of eachother that are unable to move because their path is obstructed. You also will have to change the hit detection, which wouldn't be all too hard, but I would recommend changing it completely by using the image hitzones instead.

I could probably find my old monsters file if you'd like, but I won't be cutting out bits to suit your needs, I'll just post it all and you can decide what you want to use.

Let me know if you're interested and I'll go searching tonight on one of my drives.

to work so I can have higher hitboxes on monsters but if you know how to have a hitbox based on the monster's image size it would probably be better and easier because I won't have to go through each monster setting up it's own

My apologies, I cannot find the version where I remade the monster functions, I can only find one from 2015 where I only checked the occupied space:

Code:

12345678910111213141516171819202122232425262728293031

function Monster:pos(x, y) if not x and not y then return self.x, self.y else if not occupied(x,y,self.id) then self.x, self.y = x or self.x, y or self.y end for all = 1, 17 do if player(all,"exists") and player(all,"health") > 0 then if player(all,"x") >= self.x-800 and player(all,"x") <= self.x+800 and player(all,"y") >= self.y-800 and player(all,"y") <= self.y+800 then imagepos(self.image, self.x, self.y, self.imgang) imagealpha(self.image, 1) break end end if all == 17 then imagealpha(self.image, 0) end end end return trueend

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 falseend

Within the position function it checks whether the space is occupied or not. It also contains a neat for loop that's so super-duper-awesome and why did I even.. In any case, it checks whether a player is nearby, if no one is, the image position will not change. This helped a lot of lag players were experiencing and also stops spectators taking a look around your map to see what monsters lurk around.

So this won't really help your issue with the monster sizes, but at least you won't have monsters walking over one another any more (yay!)

The only differences between my function and yours is that yours doesn't include this:

Code:

123

if not self.alpha then self.alpha=1end

below line 10.

And the fact you're using the occupied function while I'm not.
I'll give the occupied function another go and see what happens.

I now remember why I removed it, I have bosses in the script that are supposed to summon "minions".
The minions are spawned on top of the bosses which prevent the bosses from being able to move, the only way I can probably solve this is if I make bosses ignore the occupied function, not sure if that's a good idea though...

Well I've made bosses and minions ignore that function so now only monsters care about it, makes boss fights a little easier.

I've changed my occupied function to this:

Code:

12345678

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)) <= m.width and math.sqrt(math.pow(math.abs(m.y-y),2)) <= m.height) then return true end end return falseend