NPC Help

Newbie Spellweaver
Joined
Jun 13, 2008
Messages
94
Reaction score
13
Im trying to make a npc that will send someone to a random map from a set of maps(as long as no one else is in the map) for 1 item, and put a timer on that map. How would I start this npc?

Im guessing make an array of all the maps, and have it check for people in the maps, and then send them, and take the item. But how do I make it check for people, and choose the map?
 
I think there is some sort of method that actually checks how many people are in the map, check if it is less than 0, then send it there if so...

This method should be located in MapleMap, I am assuming.
 
Upvote 0
You have to use Javascript to do it. Your welcome.

Omg, you're so much help!

Anyways, I tried to make one.

var em = cm.getEventManager("bossspawn");
cm.gainMeso(-10000000);
em.startInstance(cm.getMap());


All it did was take the mesos. No instance, no warp.
 
Last edited:
Upvote 0
Omg, you're so much help!

Anyways, I tried to make one.

var em = cm.getEventManager("bossspawn");
cm.gainMeso(-10000000);
em.startInstance(cm.getMap());


All it did was take the mesos. No instance, no warp.

Is it that hard to do something like
if cm.getPlayer().getMap().getMapSize(mapid) == maps (i think you are using arrays)
warp
 
Upvote 0
Well, yes, a instanced map would be the best, in my opinion, since you could use one map and just have each player on a different instance. This would allow you to have an infinite amount of players able to do the "event" or whatever at one time.

No, don't use Event scripts; they suck. You'd just need a new class which handles all of the instancing. I'm too lazy to help you with that though. :*:

Npc:
PHP:
maps = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // Put all maps here
itemid = 0; // item to take away upon teleporting
var possibleMaps = new Array();
returnMap = 0; // Map to warp to after timer is up

function start() {
	cm.sendYesNo("#e Would you like to attempt to join a map. It will cost 1 #t"+itemid+"# #v"+itemid+". ");
}

function action(m, t, s) {
	if (m > 0) {
		for (int i = 0; i < maps.length; i++)
			if (cm.getPlayer().getMap(maps[i]).getAllPlayer().size() == 0)
				possibleMaps.push(maps[i]);
		if (possibleMaps.length > 0) {
			cm.gainItem(itemid, -1);
			cm.warpWithTimer(Math.floor(Math.random() * possibleMaps.length), returnMap, 5); // Last number is number of seconds the timer/clock lasts
		} else
			cm.sendOk("#e Sorry, but all of the maps are full. Please try later! ");
	}
	cm.dispose();
}

Method ( place in NpcConversationManager.java ):
PHP:
    public void warpWithTimer(int toMapId, final int destinationMapId, int timer) { // seconds
        changeMap(toMapId);
        client.announce(MaplePacketCreator.getClock(timer));
        TimerManager.getInstance().schedule(new Runnable() {
            @Override
            public void run() {
                changeMap(client.getChannelServer().getMapFactory().getMap(mapid));
            }
        }, timer * 1000);
    }
 
Upvote 0
Well, yes, a instanced map would be the best, in my opinion, since you could use one map and just have each player on a different instance. This would allow you to have an infinite amount of players able to do the "event" or whatever at one time.

No, don't use Event scripts; they suck. You'd just need a new class which handles all of the instancing. I'm too lazy to help you with that though. :*:

Npc:
PHP:
maps = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; // Put all maps here
itemid = 0; // item to take away upon teleporting
var possibleMaps = new Array();
returnMap = 0; // Map to warp to after timer is up

function start() {
	cm.sendYesNo("#e Would you like to attempt to join a map. It will cost 1 #t"+itemid+"# #v"+itemid+". ");
}

function action(m, t, s) {
	if (m > 0) {
		for (int i = 0; i < maps.length; i++)
			if (cm.getPlayer().getMap(maps[i]).getAllPlayer().size() == 0)
				possibleMaps.push(maps[i]);
		if (possibleMaps.length > 0) {
			cm.gainItem(itemid, -1);
			cm.warpWithTimer(Math.floor(Math.random() * possibleMaps.length), returnMap, 5); // Last number is number of seconds the timer/clock lasts
		} else
			cm.sendOk("#e Sorry, but all of the maps are full. Please try later! ");
	}
	cm.dispose();
}

Method ( place in NpcConversationManager.java ):
PHP:
    public void warpWithTimer(int toMapId, final int destinationMapId, int timer) { // seconds
        changeMap(toMapId);
        client.announce(MaplePacketCreator.getClock(timer));
        TimerManager.getInstance().schedule(new Runnable() {
            @Override
            public void run() {
                changeMap(client.getChannelServer().getMapFactory().getMap(mapid));
            }
        }, timer * 1000);
    }
That Method has all kinds of errors. Mainly not recognizing client,timermanager,nor changeMap. Trying to fix em though. I really appreciate this.

I got it to about here.

PHP:
public void warpWithTimer(MapleClient c,int toMapId, final int destinationMapId, int timer) { // seconds 
        changeMap(toMapId); 
        c.announce(CField.getClock(timer)); 
        MapTimer.getInstance().schedule(new Runnable() { 
            @Override 
            public void run() { 
                changeMap(client.getChannelServer().getMapFactory().getMap(MapId)); 
            } 
        }, timer * 1000); 
    }
Im having cannot find symbol on changeMap , announce ,client, and MapId.
 
Last edited:
Upvote 0
Oh.. sorry. I thought you were using OdinMs, and not Lithium or whatever that shitty source is called.

You already changed "client" to "c" so that's good, jus change changemap to c.getPlayer().changeMap( for both of them and replace the MapId in the parenthesis to "destinationMapId" and you should be good.
 
Upvote 0
uMOmx - NPC Help - RaGEZONE Forums
Well that helped a little.

~update, fixed the 2 errors in run, I declared MapleClient as final. not sure how to fix the announce and the first line though. It's saying there is no suitable method for changemap,and it cant find the symbol announce.

tried to make a announce in MapleClient. Didn't work out. Caused more problems.

PHP:
    public void announce(MaplePacketEncoder packet) {        
        session.write(packet);
    }
 

Attachments

  • uMOmx - NPC Help - RaGEZONE Forums
    uMOmx.webp
    17.6 KB · Views: 42
Last edited:
Upvote 0
uMOmx - NPC Help - RaGEZONE Forums
Well that helped a little.

~update, fixed the 2 errors in run, I declared MapleClient as final. not sure how to fix the announce and the first line though. It's saying there is no suitable method for changemap,and it cant find the symbol announce.

c.getSession().announce
 
Upvote 0
Nope, still doesn't work. It can't find the symbol announce. Should the one I made work or should the MaplePacketEncoder be something else. It's the only thing I could think of that would be relevant.
 
Upvote 0
You are changing map, but not telling it which portal to go to. That's why it can't find a suitable method to use.
If in doubt, add portal 0 as 'most' maps have that.


 
Upvote 0
Back