Jump to content

Recommended Posts

Posted (edited)

Hello Cheaters, 

 

It's my First Topic in this great forums, that's why i decided to try to help the community as i got help here before , by creating some tutorials specially for Backend (Java / C# if needed / PHP), and forgive me if this breaking any rules and let me know as soon as you notice that to correct :) . So let's cut that talk and get started.

 

Table of Contents :

  • What is Voiced Commands about ?
  • For which Pack/Version is this tutorial ?
  • Create your first Command
  • Register your Command into GameServer

What is Voiced Commands About :

 

Well, Voiced Commands are that commands that Player can use into chat input and it's starting with a dot (.) , for example (.dressme, .join , .register ....... etc).  and we usually add such commands to private servers to make life easier for players like adding a command which will convert player adena to Goldbars, another one for teleporting to custom location ..... and so on.

 

For which Pack/Version is this Tutorial :

 

Screenshot, Codes and the one i work on is a my private modified pack that's based on L2JServer for Hi5, but to be honest it should be working fine with all Packs if you can find some files locations like IVoicedCommandHandler.java and GameServer.java , so if you have a search skills then you can apply it to any pack and any chronicle and we will discuss that, dun worry.

 

Com'on this is too much talk why we i don't just shut up  get started  :gusta: .

 

Create your first Voiced Command :

 

We can create our command code in two places (Server Pack or Data Pack), personally i prefer add it to Data Pack Scripts, but for the sake of simplicity and to make it easy for you to implement it in different packs and older version of L2 i'll do it this time in Server Pack.

 

Step 1 :

 

So go to your Server Pack Java Source and fine a Package called com.l2jserver.gameserver.handler or you can create your own package if you can work with Java well.

 

once you get to that location (or your own package), right click on that > New > Class

 

image.png

 

Step 2 :

 

- Choose a Name for your Voiced Command Handler File, i'll name it ServerInfoVoicedCommandHandler , since i will make this command show player the server info document , well it's not useful but this tutorial meant for educations purpose not a product, so you can use your imagination and make your amazing command :)

- Clear what's inside Superclass text

- Click on Add in front of Interfaces section and Search for IVoicedCommandHandler, and when u find it Click Ok

 

image.png

 

 

image.png

 

 

Step 3 :

 

Once our class Created we will notice that we have 2 important sections (methods), useVoicedCommand and getVoicedCommandList.

 

useVoicedCommand  : is the method of block of code that will execute when a player use our command, so this is where our code will be

getVoicedCommandList : is where our server will look to know which command(s) this file/class can handle .

 

Note : if you are not familiar with Java , here is a note .. we usually add the code of any method between the curly-braces (  { } ) and any thing between { } we call it code block, if any need a guide for Java let me know and see if i can help :)

 

So inside getVoicedCommandList code block we need to add this code :

return new String[] {"serverinfo"};

this line of code will tell Game Server that this class can handle voiced command .serverinfo

 

Step 4 :

 

Now we need to Implement the actual feature of this command, so we need to write the right code that do that job, in our case we need to show and html file to the player this file can contain server info, so we need first to create an html file into our data/html/custom folder and i'll name it serverinfo.html, and here is a simple code that we can test it with .

<html><title>L2JSamDev Info</title>
<body>
<center>
	<br><br>
	<center>
	<img src="L2UI_CH3.herotower_deco" width=256 height=32><br>
	<font name="hs9" color="00aff0">Hello This is the Server Info</font><br>
	<img src="L2UI_CH3.herotower_deco" width=256 height=32><br>
</center>
</body>
</html>

Step 5 :

 

We need to add the code to useVoicedCommand method that show this html document to user, and here is the simplest code for this task

//Get Html Content
String documentContent = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/custom/serverinfo.html");
//If not Found then Stop
if(documentContent == null) {return false;}
//If Document Found then Prepare a new Message to Send it to Player
NpcHtmlMessage message = new NpcHtmlMessage();
message.setHtml(documentContent);
//Send Document to Player
activeChar.sendPacket(message);
//Well it's Success
return true;

Note : if you get errors like HtmCache or NpcHtmlMessage cannot resolve, just hover over it and click Import HtmCache/NpcHtmlMessa 

 

image.png

 

 

So our final Code will look like : 

package com.l2jserver.gameserver.handler;

import com.l2jserver.gameserver.cache.HtmCache;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;

public class ServerInfoVoicedCommand implements IVoicedCommandHandler {

	@Override
	public boolean useVoicedCommand(String command, L2PcInstance activeChar,
			String params) {
		//Get Html Content
		String documentContent = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/custom/serverinfo.html");
		//If not Found then Stop
		if(documentContent == null) {return false;}
		//If Document Found then Prepare a new Message to Send it to Player
		NpcHtmlMessage message = new NpcHtmlMessage();
		message.setHtml(documentContent);
		//Send Document to Player
		activeChar.sendPacket(message);
		//Well it's Success
		return true;
	}

	@Override
	public String[] getVoicedCommandList() {
		return new String[] {"serverinfo"};
	}

}

Step 6 :

 

- UPDATED as suggested By @meIron ( Thanks for Suggestion :) )

 

Just one more task to be good to go and test our new command, we need to register this command to the main VoicedCommandHandler, simple go to VoicedCommandHandler.java file which usually located at com.l2jserver.gameserver.handler or com.PACKNAME.gameserver.handler and in constructor which is the method called VoicedCommandHandler() add this like of code AFTER :

_datatable = new HashMap<>();

Add this

registerHandler(new ServerInfoVoicedCommand());

in the end it will look like 

 

constructor.png

 

Tip : you can register it in another way by adding it to MasterHandle.java in Datapack but we seek simplicity in this tutorial

 

Step 7 : 

 

Let's Build that Project and Log in Game to test it

 

image.jpg

 

Voila, Our Useless command Working  :-beep- yeah:

 

If you have any question or need another java tutorial or even have an idea to implement and wonder how it could be just lemme know, maybe i can help :)

Edited by SamDev-Coder
  • Upvote 2
Posted

Good work my friend. Just one thing.

VoicedCommandHandler.getInstance()

isn't register all the commands inside?

Posted

Good work my friend. Just one thing.

VoicedCommandHandler.getInstance()

isn't register all the commands inside?

Thank you Brother for you comment :)

well VoicedCommandHandler.getInstance() will call the Constructor Method and in Constructor method, this is the code

protected VoicedCommandHandler()
{
    _datatable = new HashMap<>();
}

this will just initiate the HashMap, but it wont initiate it more than once since this class implement Singleton Pattern, which means Constructor being called one time only

Posted

Well you can edit your constructor and call one method that registering all your commands like 

registerHandler(new Online());
registerHandler(new Event());
registerHandler(new Some());
registerHandler(new Voiced());
registerHandler(new Commands());
registerHandler(new Here());

to avoid in gameserver all these new lines that contains .getInstance() etc

it's clearly about readability :P

Posted

@melron

 

You're totally right brother i agree with you, your code is pretty to be honest :)

But you can say it's just a habit as Programming Instructor, used to reduce topics and try to focus on basics to not let readers get confused about strange terms like : Constructors, OOP, Design Patterns, Encapsulation, Polymorphism .... etc .

For my self i would like to add it in a custom package to make things organized and i have a Handlers class that register all voiced, bypasses, admin ... etc.

 

I like readability as you do :)

Posted

Thanks for this share.. We need active people to help the others.

Good job and take care what merlon says.. Will be more clearly.

 

Keep sharing..

Posted

Thanks for this share.. We need active people to help the others.

Good job and take care what merlon says.. Will be more clearly.

 

Keep sharing..

Thank you brother, and i hope i can help others :)

and of course meIron is talking right, so i'll update the main post

  • 7 months later...
Posted

can you make for me one 4 commands like .buffer open the buffer shop ,,,,    .donate open the donation shop ,,,,,,, .Gk open the gk menu and .gmshop to open the normal shop ?? pls ? because im really poor in java  and i dont understand many things from this topic 

Posted

Answer is no. Even if he make you the command, THEN, you need to create bypasses to handle everything.

 

If you don't understand, read till you do. If you can't, simply skip the idea, don't add new commands. Once you learn, you add them.

Posted
On 15.04.2018 at 1:03 AM, SweeTs said:

Answer is no. Even if he make you the command, THEN, you need to create bypasses to handle everything.

 

If you don't understand, read till you do. If you can't, simply skip the idea, don't add new commands. Once you learn, you add them.

Thank you bro . but you can be more explicit , just if u want !

Posted

hi everyone , maybe any can explain me how i can make a command like .buffer ? when i type .buffer in chat i want to open html page from comunity board with buffs ? please ? i think its not hard to make a simple code to open a html page of buffer but im really poor in java and i need help please , thanks everyone

Posted
1 hour ago, Prostyle1990 said:

hi everyone , maybe any can explain me how i can make a command like .buffer ? when i type .buffer in chat i want to open html page from comunity board with buffs ? please ? i think its not hard to make a simple code to open a html page of buffer but im really poor in java and i need help please , thanks everyone

poor is your brain, use the rest of it to do some search in the forum and you will learn by viewing codes and what they do.

Posted
55 minutes ago, Nightw0lf said:

poor is your brain, use the rest of it to do some search in the forum and you will learn by viewing codes and what they do.

thanks for your comment , but i already searched on forum but still i dont know how to make a voice command that why i ask here maybe you can show me an example of a voice command to open an html like gatekeeper html or buffer ....

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



  • Posts

    • if is pvp server change type to raidboss 🙂 and check stats from xml
    • Hello community, I’d like to share an improved version of the L2smr editor for StaticMeshes, focused on solving some workflow issues I found in the original tool. CreditsThis project is based on the original acmi/L2smr repository https://github.com/acmi/L2smr , created by acmi, and I updated it to Java 17 with some additional features. Issues in the original L2smr Too many windows: each StaticMesh opened in a new one → cluttered desktop. No search: navigating through hundreds of StaticMeshActors was slow and tedious. Added improvements Flexible views Single Window Mode: reuse one window instead of opening new ones. Multiple Window Mode: still available for those who prefer having several views open simultaneously. Real-time Search Field Instant filtering as you type. Case-insensitive search. “Reset” button to quickly clear the search.     Installation and Execution: Clone the repository: git clone https://github.com/Jeep12/l2smr.git cd l2smr        2.Build the project:   ./gradlew build        3. Run the application:     ./run.bat      Or simply double-click on run.bat.     The run.bat script automatically extracts JavaFX from the included javafx-17.0.2.zip file in the javafx/ directory, sets up the required libraries, and launches the application. You don’t    need to install JavaFX separately.      Repository: https://github.com/Jeep12/l2smr     Maybe these features already existed in another version or fork, and they might not be very big changes, but since I didn’t know about them and found them necessary, I decided to          implement them myself and wanted to share them.      
    • no....Mobius L2Clientdat and L2FileEditor can do that...but still cant works with TaiWanese Grand Crusade ,especially Armorgrp.dat and Armorgrp-Classic.dat
    • L2GOLD - Halcyon x45 Project Classic Interlude   C6 - Classic Interlude: Protocol 110     Is a complete copy of L2Gold in Classic [110 Protocol] with L2OFF files.   Fully L2Gold Features - Daily Quest - Daily Mining Quest - Ancient Weapons -Refine System  -Rebirth System -Fully configurable everything you want -Gold stats/Gold skills/Gold items working 100% -Zones 100% alike  -Unique donations system (npc or voicedcommand .donate) - On Enchant success announcement ( if +16 for weapon, 8 for armor , 7 for jewel) - Announce of Castle Lord - Announce of Hero  - Olympiad Max A grade - Olympiad Buffs on matches changed to Gold Alike - Working fully Dreadbane   - AI Mods: Static Time for RB   Automated Events: Squash Watermelon RB Event High rate  (those are fully automated)   Server is running a Test Server: Online to anyone can test it.   Game Client: https://www.mediafire.com/file/1d8xe18rvgi04lx/L2_Classic_Interlude_Client_V2.rar/file   Game Patch: https://www.mediafire.com/file/3z4b8ezy93h2z1g/L2Halcyon+Gold+Patch.rar/file   GM Accounts: ID: root pass root [ accounts go from  root1 until root20 ]   Regular Accounts Registrations: http://84.247.164.27/?page=register   Some Screenshots: https://imgur.com/a/o7TxzTN   Contact me here via PM (only serious buyers).    Price of the product: Fully Server Pack + Source ( 250 Euros )
    • ✨ A Service with Vibes  Vibe SMS ✨   Vibe SMS is not just a platform for working with numbers. We’ve built it to be simple, convenient, and stress-free, so your tasks get done without hassle. We value real communication: we listen to your ideas, provide support, and make sure everyone feels calm and confident. With us, you’re not just a client  you’re part of a space built on trust, support, and a human touch. Vibe SMS is a place where people matter and where we create an atmosphere you’ll want to stay in.   Website link — https://vibe-sms.net/ Our Telegram channel — https://t.me/vibe_sms
  • Topics

×
×
  • 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