Jump to content

[Guides]Multiple L2j Guides: Part 1.


Recommended Posts

Hello everybody. Here I am again with another topic.

Here you will learn about a few things in l2j.

It would be a bit annoying if I made a new topic for each guide, so I decided to compile them in this one. Let's begin?

 


 

Chapter 1: Voiced Commands

 

All of us know the Voiced Commands.

Simple commands for players that start with the dot (.)

 

So, let's see how to make a simple one!

Let's begin with the well known license (That part can be skipped, but let's do it for fun xD)

/*
* 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 2, 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* http://www.gnu.org/copyleft/gpl.html
*/

 

You can also replace it with your own "license".

Let's continue setting the package.

Since the Voicedcommands are made in the voicedcommandhandlers, the package will always be the same. Which means that the package will be:

package net.sf.l2j.gameserver.handler.voicedcommandhandlers;

 

Okay we are done with this.

Now let's continue with the imports.

You have two options: You will either set the imports now, if you know what you'll use or leave it for later (you'll write what you want and import the proper stuff manually).

 

We'll work with the online voiced command in order to show you a few things (you all know what it does, it shows the ammount of Online players). Even if I know what we'll write, I won't add the imports now, to show you about the imports.

 

Okay, let's add your name as authors now, in order to show who wrote the code!

/**
* @author YourNameHere
*/

You just have to insert your name instead of the "YourNameHere".

 

Let's start the main stuff!

You have to set the class as public and show that it implements the "IVoicedCommandHandler".

So, the form will be like this:

public class OnlinePlayers implements IVoicedCommandHandler

For other codes, the form will be the same, although the "OnlinePlayers" must be replaced with your new voicedcommand.

 

Let's start writing. You all know how! {

Now, let's set the voicedcommands that will be made in this file.

how to do this? Simple. First decide what the command will be. Then show it in this form:

private static final String[] VOICED_COMMANDS ={"on"};

 

Instead of "on" you will need to write your command. Don't delete the "" though!

 

Now let's write what will happen when a player presses the command.

In this case, once the player presses the command he will see the ammount of players online.

So:

public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
        {
	        if (command.startsWith("on"))
	        {
	            showPlayers(activeChar, target);		
	        }
	        return true;
               }

Don't forget! Instead of "on" you have to add your own command, and instead of the action I set (showPlayers) you have to set your own.

 

We would have to end our code with this:

public String[] getVoicedCommandList()
{
	return VOICED_COMMANDS;
}

 

Although, in this code we have to explain what the action above is.

Since the "showPlayers" doesn't exist, we have to "Explain" what it is and what it does.

So, in this case we set the void and make it to send some systemmessages to the player, in order to inform him about the ammount of online players.

So it will be:

public void showPlayers (L2PcInstance player, String target)
{

	{
          	        sm = new SystemMessage(SystemMessageId.S1_S2);	
          	        sm.addString("players are online.");
          	        sm.addNumber(L2World.getInstance().getAllPlayers().size());
          	        player.sendPacket(sm);

	}
}

 

In the end we just close it with a "}".

Now it's time to set the imports!

Let's see what we used.

In our imports we always use the IVoicedCommandHandler, so

import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;

Next, we used the L2World in order to see how many players are online.

So,

import net.sf.l2j.gameserver.model.L2World;

Don't forget the L2PcInstance, for the activeChar (the online active player).

import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;

And in the end we used systemmessages to tell him how many players were online.

So we import these two:

import net.sf.l2j.gameserver.network.SystemMessageId;
import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;

Use the function "Organise Imports" and the code is ready!

Now save and close your file!

 

We are not done yet, though!

There is something left!

We have to register our code!

 

In Gracia it will be done on the MasterHandler file, so it will be registered on the VoicedCommands part like that:

VoicedCommandHandler.getInstance().registerVoicedCommandHandler(new OnlinePlayers());

There's no need to import the location of the file, since it imports automaticaly every file at that folder.

 

In Interlude it will be different. You will have to go at Gameserver.java file, open it and add the import.

This file will be imported like:

import net.sf.l2j.gameserver.handler.voicedcommandhandlers.OnlinePlayers;

And now comes the registeration.

Find the VoicedCommands part, and register the new command like:

_voicedCommandHandler.registerVoicedCommandHandler(new OnlinePlayers());

 

And we're done!

That's how you created a brand new Voiced Command! =]

 

 

Chapter 2: Configurations

 

All of us know the "Config" file. Custom/non modifications are being added there. The reason though is not to add custom features, but to make our lifes easier! Configs are made in order to handle specified settings from simple modifcations. For example, you can simply add a custom TvT Event. You add the teleporting coordinates, you enable it, you set the reward, etc. But if you want to change these settings, in the future many times, you will get pissed off if you don't find the values easily. The solution? You make them configurable. In the configs, you can just change a few numbers or a "True" to "False" (and vice versa) and change the whole server in no time! So we will now see easily, how to make our own configuration. We will make a simple one. My goal is not to teach you what each thing in Config.java does, or how to make every single value configurable. What I want to do, is to show you what Configurations are, and how to start Configuring stuff. Let's begin!

 

First of all, we find what we want to set configurable.

I picked the OnlinePlayers VoicedCommands that we created in a previous guide!

So, let's see.

We will set the use of the class configurable.

What do I mean?

We will create a config that if we set to "True", will enable the use of the VoicedCommand, otherwise (if set to "False) will disable it.

We first create the configuration at the Config.java file, located in net.sf.l2j

Open the file and search for

/**define L2JMODS */

Under this, we have to set the new boolean.. (If you don't know what booleans are, then read the last part of my l2j guide in the L2j Section).

So, let's add this:

public static boolean ENABLE_OUR_CODE;

Instead of ENABLE_OUR_CODE, you can set another name, like ENABLE_ONLINE_VC.

Now, let's search for

Properties L2JModSettings

.

You'll see some configurations about Champion Mobs, etc.

You will have to place the new configuration under those (for example).

So let's add this:

ENABLE_OUR_CODE = Boolean.parseBoolean(L2JModSettings.getProperty("EnableTheCode", "True"));

 

You can replace again the ENABLE_OUR_CODE with something you like, although it must be the same with the one you set above. The "EnableTheCode" is what will be shown at the properties file. About the "True" value we set, you don't have to worry. The feature will be enabled/disabled depending ONLY to the value you will set at the properties file (In this case, l2jmods).

 

So we are done with the java part of the configuration.

Now, let's find the properties file (l2jmods) and add the new configuration.

Open the file and add in the end this:

EnableTheCode = True

You can set it either to true or false. Absolutely your decision.

 

The last part! We have to set this at a place where the code we added before (the custom voiced command, in this case) will be affected. What does this mean? We must find the proper place to add the configuration! In our case, we will go at the place where we registered the command! (MasterHandler for Gracia and Gameserver for Interlude).

Above the code with which we registered the command (this code:

_voicedCommandHandler.registerVoicedCommandHandler(new OnlinePlayers());

Above it, we add the configuration.

if(Config.ENABLE_OUR_CODE)

 

And that's it!

What did we finally do? We created a configuration for the OnlinePlayers voiced command.

If we set the value to "True" the command will be ok. If we set it to "False" the command will be disabled!

 

 

 

What did we learn today? How to create a new VoicedCommand, and how to make Configurations!

I did my best to explain everything in an informal way, so it can be understood by newbies.

If there is something you'd like to learn, or something you didn't understand, feel free to ask here!

Don't spam please.

 

Best Regards,

Coyote™.

 

PS: More guides like these will come soon, if I find free time.

 

To be Continued...

http://www.maxcheaters.com/forum/index.php?topic=123823.0

Link to comment
Share on other sites

FUUUUUUUUUUUU ~~~

 

 

stolen ideas ajajajajajaj gg noob :D

 

Naah, there is just no space left in here.

http://www.maxcheaters.com/forum/index.php?topic=92146.0

 

So I continue them like that xD

Link to comment
Share on other sites

Naah, there is just no space left in here.

http://www.maxcheaters.com/forum/index.php?topic=92146.0

 

So I continue them like that xD

from mine topic in greek section i meant :D

 

 

anyway make sure you will continue them , because noobs keep creating - using preconfs

Link to comment
Share on other sites

anyway make sure you will continue them , because noobs keep creating - using preconfs

 

I will keep creating guides..

I just need free time, and the next days I doubt if I have some..

I'll continue them soon though, don't worry..

Link to comment
Share on other sites

hahah the license and author part is funny.. well u have some good guides Coyote.. will help alot of nabs here that have no clue what they doing :P

i plan on making a full detailed guide "coding an event from scratch" and i will be coding a ctf or dm there.. but probably i wont soon since im a lazy ass.. xD

 

edit: btw u maybe wanna add somewhere in the guide that in epilogue instead of "net.sf.l2j" u need to put "com.l2jserver" (or something like that.. i dont have it in front of me right now)

Link to comment
Share on other sites

hahah the license and author part is funny.. well u have some good guides Coyote.. will help alot of nabs here that have no clue what they doing :P

i plan on making a full detailed guide "coding an event from scratch" and i will be coding a ctf or dm there.. but probably i wont soon since im a lazy ass.. xD

 

Well, thanks and good luck with your future guide!

Link to comment
Share on other sites

As a newbie in java, i have a question. What exactly is this part doing?

public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)

 

It is the boolean that, let's say, shows the command and its use.

It shows that if the player presses ".on" then the action below happens.

Link to comment
Share on other sites

  • 2 months later...

i can't add new command becaus my VoicedCommandHandler.java it look like this:

 

package net.sf.l2j.gameserver.handler;

import java.util.Map;
import java.util.logging.Logger;

import javolution.util.FastMap;
import net.sf.l2j.Config;

public class VoicedCommandHandler
{
private static Logger _log = Logger.getLogger(ItemHandler.class.getName());

private static VoicedCommandHandler _instance;

private Map<String, IVoicedCommandHandler> _datatable;

public static VoicedCommandHandler getInstance()
{
	if (_instance == null)
	{
		_instance = new VoicedCommandHandler();
	}
	return _instance;
}

private VoicedCommandHandler()
{
	_datatable = new FastMap<String, IVoicedCommandHandler>();
}

public void registerVoicedCommandHandler(IVoicedCommandHandler handler)
{
	String[] ids = handler.getVoicedCommandList();
	for (int i = 0; i < ids.length; i++)
	{
		if (Config.DEBUG) _log.fine("Adding handler for command "+ids[i]);
		_datatable.put(ids[i], handler);
	}
}

public IVoicedCommandHandler getVoicedCommandHandler(String voicedCommand)
{
	String command = voicedCommand;
	if (voicedCommand.indexOf(" ") != -1) {
		command = voicedCommand.substring(0, voicedCommand.indexOf(" "));
	}
	if (Config.DEBUG)
		_log.fine("getting handler for command: "+command+
				" -> "+(_datatable.get(command) != null));
	return _datatable.get(command);
}

    public int size()
    {
        return _datatable.size();
    }
}

what can i do?

Link to comment
Share on other sites

i can't add new command becaus my VoicedCommandHandler.java it look like this:

 

package net.sf.l2j.gameserver.handler;

import java.util.Map;
import java.util.logging.Logger;

import javolution.util.FastMap;
import net.sf.l2j.Config;

public class VoicedCommandHandler
{
private static Logger _log = Logger.getLogger(ItemHandler.class.getName());

private static VoicedCommandHandler _instance;

private Map<String, IVoicedCommandHandler> _datatable;

public static VoicedCommandHandler getInstance()
{
	if (_instance == null)
	{
		_instance = new VoicedCommandHandler();
	}
	return _instance;
}

private VoicedCommandHandler()
{
	_datatable = new FastMap<String, IVoicedCommandHandler>();
}

public void registerVoicedCommandHandler(IVoicedCommandHandler handler)
{
	String[] ids = handler.getVoicedCommandList();
	for (int i = 0; i < ids.length; i++)
	{
		if (Config.DEBUG) _log.fine("Adding handler for command "+ids[i]);
		_datatable.put(ids[i], handler);
	}
}

public IVoicedCommandHandler getVoicedCommandHandler(String voicedCommand)
{
	String command = voicedCommand;
	if (voicedCommand.indexOf(" ") != -1) {
		command = voicedCommand.substring(0, voicedCommand.indexOf(" "));
	}
	if (Config.DEBUG)
		_log.fine("getting handler for command: "+command+
				" -> "+(_datatable.get(command) != null));
	return _datatable.get(command);
}

    public int size()
    {
        return _datatable.size();
    }
}

what can i do?

 

Add them in gameserver

serch for:

_log.config("VoicedCommandHandler: Loaded " + _voicedCommandHandler.size() + " handlers.");

and add before:

_voicedCommandHandler.registerVoicedCommandHandler(new Wedding());

Replace Wedding with your VoicedCommand Name Save & Exit and you are done :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.



×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock