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!

Make any NPC scriptable

Legendary Battlemage
Loyal Member
Joined
Sep 28, 2008
Messages
600
Reaction score
291
Can you show me how having 2-3 different NPCs would look like? All I do is NPC script so when it comes to packets I'm clueless.
Ahh, I guess you could use it this way straight

// I don't know what npc id, but oh well..
PHP:
public static final int[] npcId = {123, 456, 789};
public static final String[] desc = {"Hi, I'm 123", "456 npc here", "789"};

public static MaplePacket setNPCScriptable() {
	MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
	mplew.writeShort(SendOpcode.SET_NPC_SCRIPTABLE.getValue());
	mplew.write(Constants.npcId.length); // following structure is repeated n times
	for (int i = 0; i < Constants.npcId.length; i++) {
		mplew.writeInt(Constants.npcId[i]);
		mplew.writeMapleAsciiString(Constants.desc[i]);
		mplew.writeInt(0); // start time
		mplew.writeInt(Integer.MAX_VALUE); // end time
	}
	return mplew.getPacket();
}


Oh and, you can't script it with status I guess. you only can edit the text of the npcs with default text. Basically a sendOk/sendNext
 
Custom Title Activated
Loyal Member
Joined
Nov 14, 2008
Messages
1,025
Reaction score
641
// I don't know what npc id, but oh well..
PHP:
private static int[] npcId = {123, 456, 789};
private static String[] desc = {"Hi, I'm 123", "456 npc here", "789"};

public static List<Pair<Integer, String>> getCustomNpc() {
	List<Pair<Integer, String>> listtt = new ArrayList<Pair<Integer, String>>();
	for (int i = 0; i < npcId.length; i++) {
		listtt.add(new Pair<Integer, String>(npcId[i], desc =[i]));
	}
	return listtt;
}

// In logged in handler, or something
c.getSession().write(MaplePacketCreator.setNPCScriptable(Constants.getCustomNpc());

Oh and, you can't script it with status I guess. you only can edit the text of the npcs with default text. Basically a sendOk/sendNext

EDIT* Ahh, if you don't wanna put in a pair, you could do it straight from the constants

why did you create a method just for that lol all you have to do is send the packet like this in loggedinhandler

Code:
        c.announce(MaplePacketCreator.setNPCScriptable(9010000, "Maple Admin"));

under player.setRates();

replace 9010000 for your npc id and Maple admin to w/e you want. its just a description. I put the npc name so i don't get lost. Then you just code your npc like alway.
 
Legendary Battlemage
Loyal Member
Joined
Sep 28, 2008
Messages
600
Reaction score
291
why did you create a method just for that lol all you have to do is send the packet like this in loggedinhandler

Code:
        c.announce(MaplePacketCreator.setNPCScriptable(9010000, "Maple Admin"));

under player.setRates();

replace 9010000 for your npc id and Maple admin to w/e you want. its just a description. I put the npc name so i don't get lost. Then you just code your npc like alway.

So that you don't have to send the packet multiple times for different npcs.
Code:
c.announce(MaplePacketCreator.setNPCScriptable(9010000, "Maple Admin"));
c.announce(MaplePacketCreator.setNPCScriptable(xxx, "Spinel"));

You could only send it once for it.
And, I don't think you could script it, the description is the text of the npc. Basically, "Editing" the npc's default text in the client/wz

Edit* Ahh, Not sure about using the .js right now. But oh well. confused myself :\
 
Last edited:
Custom Title Activated
Loyal Member
Joined
Nov 14, 2008
Messages
1,025
Reaction score
641
Well it will still work either way so :p
 
Junior Spellweaver
Joined
Feb 8, 2011
Messages
121
Reaction score
17
So this edits the description of the NPC, and then you can script it using java scripts?

This only edits what they say in the very beginning, then it leads on to the other script?

RZ is so painfully slow at the moment.
 
Custom Title Activated
Loyal Member
Joined
Nov 14, 2008
Messages
1,025
Reaction score
641
description is just a note for you. (or something like that) it has nothing to do with the npc script
 
Junior Spellweaver
Joined
Feb 8, 2011
Messages
121
Reaction score
17
OH. So inputing the npc ID will make it scriptable, and that's all. That "description", shows up ... where? Imma input this in when I get home.
 
Newbie Spellweaver
Joined
Nov 14, 2011
Messages
80
Reaction score
24
You can also just copy paste 3 calls to send this packet with a different npc id each time. It's less efficient but It's easier to keep track of imo, but I only make one npc scriptable on my server anyway.

The description has something to do with when the NPC has a quest, but I'm not sure how or what.
 
Junior Spellweaver
Joined
Feb 8, 2011
Messages
121
Reaction score
17
Code:
/**
     * Makes any NPC in the game scriptable.
     * @param npcId - The NPC's ID, found in WZ files/MCDB
     * @param description - If the NPC has quests, this will be the text of the menu item
     * @return 
     */
    public static MaplePacket setNPCScriptable(int npcId, String description) {
        MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
        mplew.writeShort(SendOpcode.SET_NPC_SCRIPTABLE.getValue());
        mplew.write(1); // following structure is repeated n times
        mplew.writeInt(npcId);
        mplew.writeMapleAsciiString(description);
        mplew.writeInt(0); // start time
        mplew.writeInt(Integer.MAX_VALUE); // end time
        return mplew.getPacket();
    }

Mkay so don't write the NPC ID in this one.
Then in logged in handler.

Code:
c.announce(MaplePacketCreator.setNPCScriptable(9010000, "Maple Admin"));
c.announce(MaplePacketCreator.setNPCScriptable(xxx, "Spinel"));
 
Initiate Mage
Joined
Dec 9, 2011
Messages
1
Reaction score
0
I cant find PlayerLoggedInHandler.java in ZenthosV83 Repack, can someone help me find out which file it is.
 
Junior Spellweaver
Joined
Feb 8, 2011
Messages
121
Reaction score
17
Note: Certain NPCs remain unscriptable. I just tried them out myself. I'm not sure if it was a script error, but npc "Duey" remains unchattable.
 
Legendary Battlemage
Loyal Member
Joined
Dec 13, 2010
Messages
649
Reaction score
140
Note: Certain NPCs remain unscriptable. I just tried them out myself. I'm not sure if it was a script error, but npc "Duey" remains unchattable.
Duey has his own packets. He isn't your generic npc.
 
Custom Title Activated
Loyal Member
Joined
Mar 17, 2009
Messages
1,911
Reaction score
538
Sorry for the bump. Anyone got the v97 value? I'll post it if I find it.
 
Nae-un <33
Joined
Jun 23, 2012
Messages
554
Reaction score
70
Sorry for the bump as well, but did anyone happen to have the v62 opcode?
 
Junior Spellweaver
Joined
Mar 19, 2016
Messages
100
Reaction score
0
v62 opcode is 0xC8 (200 decimal).
PHP:
int __stdcall CNpcPool::OnNpcTemplatePacket(int a1, int a2)
{
  int result; // eax@2

  if ( a1 == 0xC8 )
    result = CNpcTemplate::OnSetNpcScript(a2);
  return result;
}


And for v75?
 
Back
Top