Forum

> > CS2D > Scripts > About my RPG tibia
Forums overviewCS2D overview Scripts overviewLog in to reply

English About my RPG tibia

6 replies
To the start Previous 1 Next To the start

old About my RPG tibia

haha1955
User Off Offline

Quote
Hi guys,

Have a Problem with my Monster.lua

My Problem is if im adding 100 Monsters in the server then its start lagging, but if im add just 50 Monster then its half lagging.

So what need i do to fix this Problem? I want 100 Monsters in my server.

And why its start lagging if im add 100 Monsters?

Im happy if any help.

old Re: About my RPG tibia

MikuAuahDark
User Off Offline

Quote
That means the server is too slow, which can be caused by
1. Slow script, and/or
2. Slow network bandwidth

To fix point 2, try increasing your server cs2d cmd transfer_speed. However fixing point 1 is not easy. You don't have any choice but to make the script faster, as others mentioned.

old Re: About my RPG tibia

TrialAndError
User Off Offline

Quote
It all boils down to the loops used in tibia and similiar projects. The more monsters = the more stuff to loop through = the slower it becomes.

I fixed most of my "slow-script" by using Quadtree and as @user Gaios: said about animating and showing only the monsters that are close to a player.

I decided to go with the Quadtree solution because I added in Guard Towers which along with the players also looped through all the monsters and did some calculations which slowed down the script even more. I had to sacrifice a bit of memory for a decent amount of improvement and it was worth it.

You can imagine with 100 monsters for every player.
100 Loops per Player per 1/10 of a second. With, if you use some kind of collision system between the monsters themselves can become 100 squared added.

Quadtree pretty much recursively divides the map into quadrants where you can store information in each quadrant or sub-quadrant with different kinds of information and query through the quadrant you are in or the neighboring quadrants to loop for targets and/or whatever you need.

It's also good to constrain the monsters in some kind of way so they don't go all over the map and instead stay in some kind of "mob area" where they and/or similiar mobs can hang out.

Along with "mob area", it would also be useful to add passiveness and agressiveness for the monsters into the mix. What I mean by that is, as long as you don't hit a monster, they will not aggro onto you and when they don't aggro they are not checking for any players to attack. You could of course have aggro on for some mobs.

TL;TR Make your loops do more work for less computation and keep down the amount of times stuff has to loop
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview