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

  • Like 1
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...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




  • Posts

    • Well my friend, I'm not going to stay here arguing anymore, because you won't give up and much less have the humility to accept something you did wrong, as you saw, I value the work of others, I know who really creates or even takes a block of code and does something better and different, but the subject here was about a guy, nicknamed Vraekar, who steals and SELLS interfaces as if they were his, and is that within your beliefs?, belief that if the guy creates something it has to be stolen and whoever stole it can profit from it?, that's what I'm talking about, you've fought a lot against this, and today you help a guy like that to do wrong, but anyway, you know what you're doing, I hope you reflect, the community knows who does and who helps the wrong. Stay with God, because six of the problems that go around.
    • You claim you thought I was a "serious" person before. Well, maybe you just never took the time to actually know me. People evolve, but I stay true to what I do and believe in. If you’re that hung up on what I’ve been doing, maybe it's time to stop speculating and start focusing on yourself. 🙂
    • Well, at least it's clear that you don't respect the work of others. Secondly, everyone knows that you code nothing. Your group has devs. known that you've asked for a lot of help and code exchange with some well-known BRs. there are chats and I can prove it, then don't come playing the good guy because you're not. So, Celestine, I'm not judging you. I'm saying that I know that your group helped vraekar steal the codes, and I have proof. In the past, I thought you were a serious, good-natured guy, but lately, you're a different person. Your text above speaks for you.
    • What I do or who I work with is none of your concern, and honestly, I couldn't care less. Lately, I've seen a lot of people trying to make a quick buck off scams, so let's not even mention names you wouldn't want them getting upset, right? 🙂  As for the projects I've been involved with, there's a server about to launch that I’m personally waiting for, and when it does, I’ll release the work publicly for free because people deserve better than what these so called "developers" are pushing. I’m not here to defend anyone, but if you had any real knowledge, you’d see how poorly written some of these scripts are. I’ve worked with Vraekar in the past, and I know for a fact he’s never sold anything I’ve created. So before you start running your mouth, ask yourself: why are you even juding me?
    • I didn't even want to touch on your name Celestine, but it took a while to want to protect it, right? But then I say, everyone knows that you and your group helped Vraekar in deobfuscating the interfaces, do you want me to post here the dates and videos of the releases of the OMG and Silence interfaces?, and then see Vraekar's?, do you want?, a blatant copy, even their variable names, the theft is blatant, and you who are an admin here at Max and say you are the right one, helped him decrypt and remove the code obfuscation, everyone knows that, and now you come and tell me that his code is not copied?, if you want I can put all the evidence here and this will be very ugly even for you, since those you helped Vraekar and the interface dev community know this, they know about the thefts, very ugly indeed my friend that you still come and tell such a lie.   ps. And just one more thing, did you say that all the code he wrote? you became a joker? Vraekar doesn't program a single line of code, the guy works as a data analyst, what he learned was to copy and paste ready-made codes, but he doesn't write a single line of code.
  • Topics

×
×
  • Create New...