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!

Mob Spawn Problems

Junior Spellweaver
Joined
Sep 9, 2015
Messages
132
Reaction score
10
Code:
function spawnMob(id) {        var x = cm.getPlayer().getPosition().getX();        var y = cm.getPlayer().getPosition().getY();        var map = cm.getClient().getChannelServer().getMapFactory().getMap(cm.getPlayer().getMapId());        var mob = Packages.server.life.MapleLifeFactory.getMonster(id);        var overrideStats = Packages.server.life.MapleLifeFactory.getMonster(id).getStats();        overrideStats.setHp(stats.getHp * 2);        overrideStats.setExp(stats.getExp() * 3);        overrideStats.setMp(mob.getMaxMp());        mob.setOverrideStats(overrideStats);        map.spawnMonsterOnGroudBelow(mob, new java.awt.Point(x, y));    }
I'm trying to spawn a strong monster, for example a snail (100100), but I am having problems.
  • When I summon the monster, it changes all around the mapleworld the monster's HP and EXP value, I just need to the monster I spawned.
  • I want for example to make the monster HP x2 from its default HP, but everytime I summon a new mob it uses what the last monster I had with x2, same thing with the exp.
  • The server rate is 125x, so if I do setExp(4) it gives me 375 exp? 0.o

Can someone explain me the right way to spawn a custom monster without all of that problems? I didn't manage to do it by myself.
 
Junior Spellweaver
Joined
Apr 30, 2012
Messages
100
Reaction score
41
Code:
function spawnMob(id) {        var x = cm.getPlayer().getPosition().getX();        var y = cm.getPlayer().getPosition().getY();        var map = cm.getClient().getChannelServer().getMapFactory().getMap(cm.getPlayer().getMapId());        var mob = Packages.server.life.MapleLifeFactory.getMonster(id);        var overrideStats = Packages.server.life.MapleLifeFactory.getMonster(id).getStats();        overrideStats.setHp(stats.getHp * 2);        overrideStats.setExp(stats.getExp() * 3);        overrideStats.setMp(mob.getMaxMp());        mob.setOverrideStats(overrideStats);        map.spawnMonsterOnGroudBelow(mob, new java.awt.Point(x, y));    }
I'm trying to spawn a strong monster, for example a snail (100100), but I am having problems.
  • When I summon the monster, it changes all around the mapleworld the monster's HP and EXP value, I just need to the monster I spawned.
  • I want for example to make the monster HP x2 from its default HP, but everytime I summon a new mob it uses what the last monster I had with x2, same thing with the exp.
  • The server rate is 125x, so if I do setExp(4) it gives me 375 exp? 0.o

Can someone explain me the right way to spawn a custom monster without all of that problems? I didn't manage to do it by myself.
That's because you're modifying the data that is used in spawning many other monsters, whereas you only (probably) want to modify that one monster object. I recommend removing any additions you've made to the code and instead setting the 'overrideStats' of that specific Monster object before the "map.spawnMonsterOnGroudBelow(mob, new java.awt.Point(x, y));" line.
Code:
 var stat = em.newMonsterStats();
	    stat.setOExp(4);
	    mob.setOverrideStats(stat);
And yes, 4 * 125 is 375.
 
Upvote 0
Junior Spellweaver
Joined
Sep 9, 2015
Messages
132
Reaction score
10
That's because you're modifying the data that is used in spawning many other monsters, whereas you only (probably) want to modify that one monster object. I recommend removing any additions you've made to the code and instead setting the 'overrideStats' of that specific Monster object before the "map.spawnMonsterOnGroudBelow(mob, new java.awt.Point(x, y));" line.
Code:
 var stat = em.newMonsterStats();
        stat.setOExp(4);
        mob.setOverrideStats(stat);
And yes, 4 * 125 is 375.
Mind giving me the used newMonsterStats()? I don't have it and can't find the original on google.
 
Upvote 0
Junior Spellweaver
Joined
Sep 9, 2015
Messages
132
Reaction score
10
Or OverrideMonsterStats? isn't there?
In the source its called MapleMonsterStats.

I've added to NPCConversationManger this
Code:
public MapleMonsterStats newMonsterStats() {        return new MapleMonsterStats();    }

Now when I try to spawn the mob with this
Code:
function spawnMob(id) {        var x = cm.getPlayer().getPosition().getX();        var y = cm.getPlayer().getPosition().getY();        var map = cm.getClient().getChannelServer().getMapFactory().getMap(cm.getPlayer().getMapId());        var mob = Packages.server.life.MapleLifeFactory.getMonster(id);        var stat = cm.newMonsterStats();        stat.setHp(4);        mob.setOverrideStats(stat);        map.spawnMonsterOnGroudBelow(mob, new java.awt.Point(x, y));    }

Its spawns the mob that can't be killed.
No error given.
 
Last edited:
Upvote 0
Skilled Illusionist
Joined
Jul 17, 2010
Messages
333
Reaction score
165
Code:
public void setOverrideStats(MapleMonsterStats overrideStats) {        this.stats = overrideStats;    }
It won't change hp. Monster's hp is set when you 'init', so if you want to override hp/mp, you should do something like
Code:
this.stats = overrideStats;
this.hp = stats.getHp();
this.mp = stats.getMp();

To be honest, I want to suggest to check another source which has OverrideMonsterStats (or ChangableStats) in order to understand 'override'.
 
Upvote 0
Junior Spellweaver
Joined
Sep 9, 2015
Messages
132
Reaction score
10
It won't change hp. Monster's hp is set when you 'init', so if you want to override hp/mp, you should do something like
Code:
this.stats = overrideStats;
this.hp = stats.getHp();
this.mp = stats.getMp();

To be honest, I want to suggest to check another source which has OverrideMonsterStats (or ChangableStats) in order to understand 'override'.
Now it changed the HP, MP. Why only the HP and MP is in the MapleMonster.java also and not EXP as well for example?
But still can't kill it. At list I get an error now.

Quack - Mob Spawn Problems - RaGEZONE Forums



For now I gtg, I will download a different source that has it to try to understand it more maybe I will find something that will help me as well.
Thank you for your help!



It won't change hp. Monster's hp is set when you 'init', so if you want to override hp/mp, you should do something like
Code:
this.stats = overrideStats;
this.hp = stats.getHp();
this.mp = stats.getMp();

To be honest, I want to suggest to check another source which has OverrideMonsterStats (or ChangableStats) in order to understand 'override'.
The picture didn't work lol.

hn43PpN - Mob Spawn Problems - RaGEZONE Forums
 

Attachments

You must be registered for see attachments list
Upvote 0
Skilled Illusionist
Joined
Jul 17, 2010
Messages
333
Reaction score
165
See
MapleItemInformationProvider#getItemData (at MapleItemInformationProvider:300)
MapleItemInformationProvider#getItemEffect (at MapleItemInformationProvider:875)
especially
MapleMap#killMonster (at MapleMonster.java:747)


String idStr = "0" + String.valueOf(itemId);
iFile.getName().equals(idStr.substring(0, 4) + ".img");//somehow failed to get a wz/xml file. (due to invalid itemId or missing file)
 
Upvote 0
Junior Spellweaver
Joined
Sep 9, 2015
Messages
132
Reaction score
10
See
MapleItemInformationProvider#getItemData (at MapleItemInformationProvider:300)
MapleItemInformationProvider#getItemEffect (at MapleItemInformationProvider:875)
especially
MapleMap#killMonster (at MapleMonster.java:747)


String idStr = "0" + String.valueOf(itemId);
iFile.getName().equals(idStr.substring(0, 4) + ".img");//somehow failed to get a wz/xml file. (due to invalid itemId or missing file)
Code:
private MapleData getItemData(int itemId) {        MapleData ret = null;        String idStr = "0" + String.valueOf(itemId);        MapleDataDirectoryEntry root = itemData.getRoot();        for (MapleDataDirectoryEntry topDir : root.getSubdirectories()) {            for (MapleDataFileEntry iFile : topDir.getFiles()) {                if (iFile.getName().equals(idStr.substring(0, 4) + ".img")) { //Line 300                    ret = itemData.getData(topDir.getName() + "/" + iFile.getName());                    if (ret == null) {                        return null;                    }                    ret = ret.getChildByPath(idStr);                    return ret;                } else if (iFile.getName().equals(idStr.substring(1) + ".img")) {                    return itemData.getData(topDir.getName() + "/" + iFile.getName());                }            }        }        root = equipData.getRoot();        for (MapleDataDirectoryEntry topDir : root.getSubdirectories()) {            for (MapleDataFileEntry iFile : topDir.getFiles()) {                if (iFile.getName().equals(idStr + ".img")) {                    return equipData.getData(topDir.getName() + "/" + iFile.getName());                }            }        }        return ret;    }

Code:
public MapleStatEffect getItemEffect(int itemId) {        MapleStatEffect ret = itemEffects.get(Integer.valueOf(itemId));        if (ret == null) {            MapleData item = getItemData(itemId); //Line 875            if (item == null) {                return null;            }            MapleData spec = item.getChildByPath("spec");            ret = MapleStatEffect.loadItemEffectFromData(spec, itemId);            itemEffects.put(Integer.valueOf(itemId), ret);        }        return ret;    }

Code:
public void killMonster(final MapleMonster monster, final MapleCharacter chr, final boolean withDrops, final boolean secondTime, int animation) {        int mobid = 0;        int randomNumber = (int)(Math.random() * 190);        int mobteam = 0;        try {            mobid = monster.getId();            mobteam = monster.getTeam();        } catch (Exception e) {        }        if (mobid == 9400202) {            Server.getInstance().broadcastMessage(MaplePacketCreator.serverNotice(6, chr.getClient().getChannel(), "[Event] " + chr.getName() + " has killed a Golden Slime in " + chr.getMap().getMapName() + "!"));            chr.gainEventPoints(1, "[Event] You have gained 1 Event Point.");        }        if (chr.getMapId() > 910000000 && chr.getMapId() < 910000030) {            if (randomNumber == 40) {            chr.announce(MaplePacketCreator.earnTitleMessage("You have gained 1 Free Market Point."));            chr.setMobPoints(chr.getMobPoints() + 1);            }                        if (randomNumber == 20) {            chr.announce(MaplePacketCreator.earnTitleMessage("You have gained " + chr.getFmNx() + " NX."));            chr.giftNx(chr.getFmNx());            }         }                if (monster.getId() == 8810018 && !secondTime) {            TimerManager.getInstance().schedule(new Runnable() {                @Override                public void run() {                    killMonster(monster, chr, withDrops, true, 1);                    killAllMonsters();                }            }, 3000);            return;        }        if (chr == null) {            if (!monster.getStats().isFriendly() && !monster.getStats().isCustom()) {                spawnedMonstersOnMap.decrementAndGet();            }            monster.setHp(0);            broadcastMessage(MaplePacketCreator.killMonster(monster.getObjectId(), animation), monster.getPosition());            removeMapObject(monster);            return;        }        if (monster.getStats().getLevel() >= chr.getLevel() + 30 && !chr.isGM()) {           // AutobanFactory.GENERAL.alert(chr, " for killing a " + monster.getName() + " which is over 30 levels higher.");        }        /*         * if         * (chr.getQuest(MapleQuest.getInstance(29400)).getStatus().equals(MapleQuestStatus.Status.STARTED))         * { if (chr.getLevel() >= 120 && monster.getStats().getLevel() >= 120)         * { //FIX MEDAL SHET } else if (monster.getStats().getLevel() >=         * chr.getLevel()) { } }         */        int buff = monster.getBuffToGive();        if (buff > -1) {            MapleItemInformationProvider mii = MapleItemInformationProvider.getInstance();            for (MapleMapObject mmo : this.getAllPlayer()) {                MapleCharacter character = (MapleCharacter) mmo;                if (character.isAlive()) {                    MapleStatEffect statEffect = mii.getItemEffect(buff); //Line 747                    character.getClient().announce(MaplePacketCreator.showOwnBuffEffect(buff, 1));                    broadcastMessage(character, MaplePacketCreator.showBuffeffect(character.getId(), buff, 1), false);                    statEffect.applyTo(character);                }            }        }        if (monster.getId() == 8810018 && chr.getMapId() == 240060200) {            for (Channel cserv : Server.getInstance().getWorld(world).getChannels()) {                for (MapleCharacter player : cserv.getPlayerStorage().getAllCharacters()) {                    player.dropMessage("To the crew that have finally conquered Horned Tail after numerous attempts, I salute thee! You are the true heroes of Leafre!!");                }            }        }        if (!monster.getStats().isFriendly() && !monster.getStats().isCustom()) {            spawnedMonstersOnMap.decrementAndGet();        }        monster.setHp(0);        broadcastMessage(MaplePacketCreator.killMonster(monster.getObjectId(), animation), monster.getPosition());        //if (monster.getStats().selfDestruction() == null) {//FUU BOMBS D:        removeMapObject(monster);        //}        if (monster.getCP() > 0 && chr.getCarnival() != null) {            chr.getCarnivalParty().addCP(chr, monster.getCP());            chr.announce(MaplePacketCreator.updateCP(chr.getCP(), chr.getObtainedCP()));            broadcastMessage(MaplePacketCreator.updatePartyCP(chr.getCarnivalParty()));            //they drop items too ):        }        if (monster.getId() >= 8800003 && monster.getId() <= 8800010) {            boolean makeZakReal = true;            Collection<MapleMapObject> objects = getMapObjects();            for (MapleMapObject object : objects) {                MapleMonster mons = getMonsterByOid(object.getObjectId());                if (mons != null) {                    if (mons.getId() >= 8800003 && mons.getId() <= 8800010) {                        makeZakReal = false;                        break;                    }                }            }            if (makeZakReal) {                for (MapleMapObject object : objects) {                    MapleMonster mons = chr.getMap().getMonsterByOid(object.getObjectId());                    if (mons != null) {                        if (mons.getId() == 8800000) {                            makeMonsterReal(mons);                            updateMonsterController(mons);                            break;                        }                    }                }            }        }        MapleCharacter dropOwner = monster.killBy(chr);        if (withDrops && !monster.dropsDisabled()) {            if (dropOwner == null) {                dropOwner = chr;            }            dropFromMonster(dropOwner, monster);        }    }

I've wrote where everything is with comments, I've looked at it, didn't find why this error is given aka why it failed to get the wz.

EDIT: Why it shows the code of
Code:
in one line -.-
 
Upvote 0
Skilled Illusionist
Joined
Jul 17, 2010
Messages
333
Reaction score
165
int buff = monster.getBuffToGive();
if (buff > -1)

What will happen when the value of 'buff' is set 0 by default?


Uh, I mean, you created a new MapleMonsterStats (normally, it must be loaded from wz/database), but you've just set HP(or MP or EXP), thus, all other variables will remain at the default value, usually 0.

then
monster.getBuffToGive();//0
String idStr = "0" + String.valueOf(itemId);//"00"
iFile.getName().equals(idStr.substring(0, 4) + ".img");//throws IndexOutOfBoundsException


To avoid this problem, you can just make a clone(or copy) of it
Code:
public MapleMonsterStats newMonsterStats() {
    return (MapleMonsterStats) stats.clone();
}

or implement OverrideMonsterStats.
 
Last edited:
Upvote 0
Junior Spellweaver
Joined
Sep 9, 2015
Messages
132
Reaction score
10
int buff = monster.getBuffToGive();
if (buff > -1)

What will happen when the value of 'buff' is set 0 by default?


Uh, I mean, you created a new MapleMonsterStats (normally, it must be loaded from wz/database), but you've just set HP(or MP or EXP), thus, all other variables will remain at the default value, usually 0.

then
monster.getBuffToGive();//0
String idStr = "0" + String.valueOf(itemId);//"00"
iFile.getName().equals(idStr.substring(0, 4) + ".img");//throws IndexOutOfBoundsException


To avoid this problem, you can just make a clone(or copy) of it
Code:
public MapleMonsterStats newMonsterStats() {
    return (MapleMonsterStats) stats.clone();
}

or implement OverrideMonsterStats.
You're right, giving the default value made it work without errors. Thank you very much for your assistance!!
 
Upvote 0
Back
Top