Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Release] Fix mob spawns in rev 0.0.7

Newbie Spellweaver
Joined
Apr 2, 2008
Messages
33
Reaction score
0
Alright it's actually very simple

1. Replace this code in Mobs.cpp

Code:
void Mobs::checkSpawn(int mapid){
    for(unsigned int i=0; i<info[mapid].size(); i++){
        int check=0;
        for(unsigned int j=0; j<mobs[mapid].size(); j++){
            if(i == mobs[mapid][j]->getMapID()){
                check=1;
                break;
            }
        }
        if(!check){
            Mob* mob = new Mob();
            mobs[mapid].push_back(mob);
            Pos mobpos;
            mobpos.x = info[mapid][i].x;
            mobpos.y = info[mapid][i].cy;
            mob->setPos(mobpos);
            mob->setID(i+100);
            mob->setMobID(info[mapid][i].id);
            mob->setMapID(i);
            mob->setHP(mobinfo[info[mapid][i].id].hp);
            mob->setMP(mobinfo[info[mapid][i].id].mp);
            mob->setFH(info[mapid][i].fh);
            mob->setType(2);
        }
        int num;
        for(unsigned int j=0; j<mobs[mapid].size(); j++)
            if(i == mobs[mapid][j]->getMapID()){
                num = j;
                break;
            }
        if(Maps::info[mapid].Players.size() > 0 && mobs[mapid][num]->getControl()==0){
            int maxpos = distPos(mobs[mapid][num]->getPos(), Maps::info[mapid].Players[0]->getPos());
            int posi = 0;
            for(unsigned int k=0; k<Maps::info[mapid].Players.size(); k++){
                int curpos = distPos(mobs[mapid][num]->getPos(), Maps::info[mapid].Players[k]->getPos());
                if(curpos < maxpos){
                    maxpos = curpos;
                    posi = k;
                }
            }
            if(!check)
                MobsPacket::spawnMob(Maps::info[mapid].Players[posi], mobs[mapid][num], Maps::info[mapid].Players, 1);
            mobs[mapid][num]->setControl(Maps::info[mapid].Players[posi]);
        }
    }
}    

void Mobs::showMobs(Player* player){
    for(unsigned int i=0; i<mobs[player->getMap()].size(); i++){
        MobsPacket::showMob(player, mobs[player->getMap()][i]);
    }
}

void Mobs::updateSpawn(int mapid){
    for(unsigned int i=0; i<mobs[mapid].size(); i++){
        if(Maps::info[mapid].Players.size() > 0 && mobs[mapid][i]->getControl()==NULL){
            int maxpos = distPos(mobs[mapid][i]->getPos(), Maps::info[mapid].Players[0]->getPos());
            int posi = 0;
            for(unsigned int k=0; k<Maps::info[mapid].Players.size(); k++){
                int curpos = distPos(mobs[mapid][i]->getPos(), Maps::info[mapid].Players[k]->getPos());
                if(curpos < maxpos){
                    maxpos = curpos;
                    posi = k;
                }
            }
            mobs[mapid][i]->setControl(Maps::info[mapid].Players[posi]);
        }
        else if(Maps::info[mapid].Players.size() == 0)
            mobs[mapid][i]->setControl(NULL);
    }
}

with this one:

Code:
void Mobs::checkSpawn(int mapid){
    if((int)GetTickCount() > last[mapid] + 10000){
        for(unsigned int i=0; i<info[mapid].size(); i++){
            int check=0;
            for(unsigned int j=0; j<mobs[mapid].size(); j++){
                if(i == mobs[mapid][j]->getMapID()){
                    check=1;
                    break;
                }
            }
            if(!check){
                Mob* mob = new Mob();
                mobs[mapid].push_back(mob);
                Pos mobpos;
                mobpos.x = info[mapid][i].x;
                mobpos.y = info[mapid][i].cy;
                mob->setPos(mobpos);
                mob->setID(i+100);
                mob->setMobID(info[mapid][i].id);
                mob->setMapID(i);
                mob->setHP(mobinfo[info[mapid][i].id].hp);
                mob->setMP(mobinfo[info[mapid][i].id].mp);
                mob->setFH(info[mapid][i].fh);
                mob->setType(2);
            }
            int num;
            for(unsigned int j=0; j<mobs[mapid].size(); j++)
                if(i == mobs[mapid][j]->getMapID()){
                    num = j;
                    break;
                }

            if(Maps::info[mapid].Players.size() > 0 && mobs[mapid][num]->getControl()==0){
                int maxpos = distPos(mobs[mapid][num]->getPos(), Maps::info[mapid].Players[0]->getPos());
                int posi = 0;
                for(unsigned int k=0; k<Maps::info[mapid].Players.size(); k++){
                    int curpos = distPos(mobs[mapid][num]->getPos(), Maps::info[mapid].Players[k]->getPos());
                    if(curpos < maxpos){
                        maxpos = curpos;
                        posi = k;
                    }
                }
                if(!check)
                    MobsPacket::spawnMob(Maps::info[mapid].Players[posi], mobs[mapid][num], Maps::info[mapid].Players, 1);
                mobs[mapid][num]->setControl(Maps::info[mapid].Players[posi]);
            }
        }
        last[mapid] = (int)GetTickCount();
    }
}    

void Mobs::showMobs(Player* player){
    checkSpawn(player->getMap());
    for(unsigned int i=0; i<mobs[player->getMap()].size(); i++){
        MobsPacket::showMob(player, mobs[player->getMap()][i]);
    }
}

void Mobs::updateSpawn(int mapid){
    for(unsigned int i=0; i<mobs[mapid].size(); i++){
        if(Maps::info[mapid].Players.size() > 0 && mobs[mapid][i]->getControl()==NULL){
            int maxpos = distPos(mobs[mapid][i]->getPos(), Maps::info[mapid].Players[0]->getPos());
            int posi = 0;
            for(unsigned int k=0; k<Maps::info[mapid].Players.size(); k++){
                int curpos = distPos(mobs[mapid][i]->getPos(), Maps::info[mapid].Players[k]->getPos());
                if(curpos < maxpos){
                    maxpos = curpos;
                    posi = k;
                }
            }
            mobs[mapid][i]->setControl(Maps::info[mapid].Players[posi]);
        }
        else if(Maps::info[mapid].Players.size() == 0)
            mobs[mapid][i]->setControl(NULL);
    }
}


2. Open up Mobs.h and add this:

Code:
static hash_map <int, int> last;

under this:

Code:
class Mobs {
public:
    static hash_map <int, MobInfo> mobinfo;
    static hash_map <int, SpawnsInfo> info;
    static hash_map <int, vector<Mob*>> mobs;

3. Go back to Mobs.cpp and add this:

Code:
hash_map <int, int> Mobs::last;

under this:

Code:
hash_map <int, MobInfo> Mobs::mobinfo;
hash_map <int, SpawnsInfo> Mobs::info;
hash_map <int, vector<Mob*>> Mobs::mobs;

4. Then in Mobs.cpp add this:

Code:
checkSpawn(player->getMap());

under this:

Code:
void Mobs::monsterControl(Player* player, unsigned char* packet, int size){

Compile and play. Worked for me and that's exactly what I did.


Now my only problem is server crashing with the same old lame debug assertion error "line 242 in list"
 
Elite Diviner
Joined
Oct 1, 2007
Messages
433
Reaction score
0
Thanks for it, now rev007 is completed. Testing it.
 
Newbie Spellweaver
Joined
Mar 10, 2007
Messages
7
Reaction score
0
Razzen if it works can you post a repack ill be very glad if you do. Please can you?
 
Newbie Spellweaver
Joined
Apr 2, 2008
Messages
33
Reaction score
0
Thanks for it, now rev007 is completed. Testing it.

Not quite completed, only thing left for me is:

vioLy - [Release] Fix mob spawns in rev 0.0.7 - RaGEZONE Forums
 
Elite Diviner
Joined
Oct 1, 2007
Messages
433
Reaction score
0
I'll see if I can do it. I've added every code I did with my 006 and still I have nothing of the problems you guys have =/, Now that I'm almost finish testing it.. If it work, I'd be more than happy.

EDIT: How do you reproduce that debug? I've never gotten it with 10-20 people online.
 
Newbie Spellweaver
Joined
Mar 10, 2007
Messages
7
Reaction score
0
I'll see if I can do it. I've added every code I did with my 006 and still I have nothing of the problems you guys have =/, Now that I'm almost finish testing it.. If it work, I'd be more than happy.

EDIT: How do you reproduce that debug? I've never gotten it with 10-20 people online.

sorry for the double but can you repack if it works? Just quick question.
 
Junior Spellweaver
Joined
Apr 6, 2007
Messages
146
Reaction score
0
since when was there a mob spawn error? and what exactly is it
 
Newbie Spellweaver
Joined
Apr 2, 2008
Messages
33
Reaction score
0
since when was there a mob spawn error? and what exactly is it

In revision 0.0.7 monsters will freeze up and die out(don't respawn) so pretty much maps are empty and can cause d/c's and server crashes.
 
Newbie Spellweaver
Joined
Feb 28, 2008
Messages
45
Reaction score
0
the hell?! void Mobs::monsterControl(Player* player, unsigned char* packet, int size){ isnt even in mobs.cpp
 
Newbie Spellweaver
Joined
Aug 16, 2007
Messages
91
Reaction score
0
You can actually debug the server, even if it crashes like that... so long as you force the position to the end of each function and don't allow them to actually do anything.

Last time that happened, I traced the problem back to:

Code:
void Selector::selectThread () {
...
unsigned int count = handlers.size();
for (hash_map<int,SelectHandler*>::iterator iter = handlers.begin(); iter != handlers.end(); iter++){
...
in Selector.cpp.

FYI this only happens if the client has already been deleted AFTER it's entered the for loop.

This is a problem with multiple threads having access to the same data without any sort of locking method (critical sections help here).

This should be pretty easy to fix...

A quote from kikiness about that problem. The debug problem thing.
 
Newbie Spellweaver
Joined
Apr 5, 2008
Messages
10
Reaction score
0
Violy I get the line 242 list iterator error as well.. still haven't figured it out, it might be due to the fact that there are too many people connecting. Or it may be a dual core/quad core problem, but when I change the affinity of the maplestoryserver.exe file it lags the game a lot.

I added this in, the monsters spawn fine, but now the drops don't disappear like they were before.
 
Last edited:
Initiate Mage
Joined
Apr 3, 2008
Messages
4
Reaction score
0
Compiling...
Mobs.cpp
c:\documents and settings\arthur\desktop\titanmsver007\maplestoryserver\maplestoryserver\mobs.cpp(13) : error C2039: 'last' : is not a member of 'Mobs'
c:\documents and settings\arthur\desktop\titanmsver007\maplestoryserver\maplestoryserver\mobs.h(34) : see declaration of 'Mobs'


what does this mean?
 
Back
Top