Jump to content

Java - How to create Your own /commands


Recommended Posts

Ok . Everyone know how to create these commands like .command , but now i want to say how to create thats /command . I think it look much better  ;)

 


 

This guide is for L2J files , if somone want make it for other pack , should change imports .

 

Ok . As We know...in newest L2J rev , we have handlers in DataPack ( .java files ) so we dont must compile them in core to make them working .

 


 

Ok . For example we want to create command and when we use it , it will show us window with our text .

 

1 . First step :

 

You should open :

data\scripts\handlers\usercommandhandlers

 

2. Second Step :

 

Create new .java file . For example ServerInfo.java

 

3. Third Step :

 

- Ok , We have our .java file . So now We must open this file and start writing :

 

/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* 
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

 

We know , this is GNU license , dont forget to paste it in our file .

 


 

- Then We must import some classes needed for shown html window in game , so :

 

package handlers.usercommandhandlers;

import net.sf.l2j.gameserver.handler.IUserCommandHandler;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;

 


 

Ok , we have imported needed classes from core , now we must create our class :

 

public class ServerInfo implements IUserCommandHandler
{
private static final int[] COMMAND_IDS =
{
	121
};

 

Now all should ask...omg but what is that ? What its this ID ( 121 in this example ) . The answer is simple :

 

This is ID form our client . We can define this in : commandname-e.dat file . Ok , download FileEdit and open this fille , we should have somethink like that :

 

whdw91.jpg

 

- Ok , first column if for command number ( 1,2,3,4,5,5 ... )

- Secound column is for command ID - yes we need it in our class ( I'ill show it again , where we will put ID ) :

 

 

private static final int[] COMMAND_IDS =

{

121

};

 


 

Ok , we want to add that command : /serverinfo , so we must put :

 

- 122 in first column , becouse last one was 121 .. ( we are smarts - yeah  ;) )

- 121 in secound column , becouse last one was 120 ... ok this is our comman ID , we must this into our class ( look upper , to show where put this ... )

- And in third column we must add :

 

a,serverinfo\0

 

Now when we use /serverinfo in game , server will try to use command with 121 ID

 

So it look like this :

 

1248un6.jpg

 

- Close and save file , this is it  ;)

 


 

Now add to our script this :

 

/**

*

* @see net.sf.l2j.gameserver.handler.IUserCommandHandler#useUserCommand(int, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance)

*/

public boolean useUserCommand(int id, L2PcInstance activeChar)

{

if (id != COMMAND_IDS[0])

return false;

                NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);

                npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Your Text Here</body></html>");

                activeChar.sendPacket(npcHtmlMessage);

                return true;

        }

 

/**

*

* @see net.sf.l2j.gameserver.handler.IUserCommandHandler#getUserCommandList()

*/

public int[] getUserCommandList()

{

return COMMAND_IDS;

}

}

 


 

Done , our ServerInfo.java should look that :

 

/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* 
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package handlers.usercommandhandlers;

import net.sf.l2j.gameserver.handler.IUserCommandHandler;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;

/**
* Support for /serverinfo command
* Added by Matim
*/
public class ServerInfo implements IUserCommandHandler
{
private static final int[] COMMAND_IDS =
{
	121
};

/**
 * 
 * @see net.sf.l2j.gameserver.handler.IUserCommandHandler#useUserCommand(int, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance)
 */
public boolean useUserCommand(int id, L2PcInstance activeChar)
{
	if (id != COMMAND_IDS[0])
		return false;
                NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0); 
                npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Your team won the event. Look in your inventory, there should be your reward.</body></html>"); 
                activeChar.sendPacket(npcHtmlMessage); 
                return true;
        }

/**
 * 
 * @see net.sf.l2j.gameserver.handler.IUserCommandHandler#getUserCommandList()
 */
public int[] getUserCommandList()
{
	return COMMAND_IDS;
}
}

 


 

Now we must add our script to MasterHandler.java in \data\scripts\handlers folder

 

- Open this file : And find these lines , in first column :

 

import handlers.usercommandhandlers.ChannelDelete;
import handlers.usercommandhandlers.ChannelLeave;
import handlers.usercommandhandlers.ChannelListUpdate;
import handlers.usercommandhandlers.ClanPenalty;
import handlers.usercommandhandlers.ClanWarsList;
import handlers.usercommandhandlers.DisMount;
import handlers.usercommandhandlers.Escape;
import handlers.usercommandhandlers.InstanceZone;
import handlers.usercommandhandlers.Loc;
import handlers.usercommandhandlers.Mount;
import handlers.usercommandhandlers.OlympiadStat;
import handlers.usercommandhandlers.PartyInfo;
import handlers.usercommandhandlers.Time;

 

and add our :

 

import handlers.usercommandhandlers.ServerInfo;

 


 

Now find this column :

 

	private static void loadUserHandlers()
{
	UserCommandHandler.getInstance().registerUserCommandHandler(new ClanPenalty());
	UserCommandHandler.getInstance().registerUserCommandHandler(new ClanWarsList());
	UserCommandHandler.getInstance().registerUserCommandHandler(new DisMount());
	UserCommandHandler.getInstance().registerUserCommandHandler(new Escape());
	UserCommandHandler.getInstance().registerUserCommandHandler(new InstanceZone());
	UserCommandHandler.getInstance().registerUserCommandHandler(new Loc());
	UserCommandHandler.getInstance().registerUserCommandHandler(new Mount());
	UserCommandHandler.getInstance().registerUserCommandHandler(new PartyInfo());
	UserCommandHandler.getInstance().registerUserCommandHandler(new Time());
	UserCommandHandler.getInstance().registerUserCommandHandler(new OlympiadStat());
	UserCommandHandler.getInstance().registerUserCommandHandler(new ChannelLeave());
	UserCommandHandler.getInstance().registerUserCommandHandler(new ChannelDelete());
	UserCommandHandler.getInstance().registerUserCommandHandler(new ChannelListUpdate());
	UserCommandHandler.getInstance().registerUserCommandHandler(new ServerInfo());
	_log.config("Loaded " + UserCommandHandler.getInstance().size() + " UserHandlers");
}

 

And add this :

 

UserCommandHandler.getInstance().registerUserCommandHandler(new ServerInfo());

 

(under : UserCommandHandler.getInstance().registerUserCommandHandler(new ChannelListUpdate()); )

 


 

Save , and restart Your server , done now type /serverinfo in game  ;)

 

Credits goes to me

Link to comment
Share on other sites

OMG Great share I was looking for a guide like this , cause I only know how to edit commands from Banking.java but couldn't find a way to crate a seperate *.java file.

Thanks again.

Link to comment
Share on other sites

you made us laugh so much

it's hard to find good server's without cilent modding

 

Us? how many ppl are you? are like all in one?

 

1 Waring stay on topic!

 

As i said is very good guide for starter .... but is client moding so... illegal... If you don't agree go expres your opinion at www.NcSoft.com.

Link to comment
Share on other sites

Man ...i fully agree with that what are you talking about , but as i said ..this is for thats people who need and want use it..same like custom items.

Link to comment
Share on other sites

  • 2 weeks later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now



×
×
  • Create New...