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

    • Update M54: Global HP/MP/CP consumable handling expanded beyond combat-only usage. Offensive mage idle recovery with learned skill Battle Heal. Spellhowler/Storm Screamer prioritizes Hurricane, using Vampiric Claw mostly below 90% HP. Major structural refactor initialized: Added category/class organization such as Archer, Dagger, Tank, Mage, Healer, Support and Specialized class files. Further structural cleanup. Extracted combat memory/state and more class-policy logic from the main controller. Added global stuck/inactivity watchdog for bots blocked by terrain/geodata. Added unreachable dropped ground-item timeout/temporary blacklist. Reworked Necromancer/Soultaker PvP: Dominator level 78+ maintains learned Arcane Power toggle on. Overlord/Dominator level 44+ maintains learned Soul Guard toggle automatically. Stability/scalability update: Bot controller ticks staggered instead of all starting in the same phase: Same 350 ms update rate retained Reduces simultaneous AI workload bursts. Removed the old manual aggressive-monster EVT_AGGRESSION bridge. Phantoms now use native Lucera setActive() behavior so monsters aggro them naturally. Reduced unnecessary NPC scans and native AI event pressure. Added saved-bot equipment overrides using a separate database table:         lucera_autobots_items Existing lucera_autobots remains the main saved-bot identity/state table. Equipment rows are linked to saved bots through bot_id. Added optional convenience view to show bot name together with equipment overrides:         lucera_autobots_items_view Added editable equipment slots in columns: Weapon Shield Helmet Chest Legs Gloves Boots Necklace Left/Right Earrings Left/Right Rings Equipment override values: 0 = use normal class/level profile item -1 = force slot empty >0 = equip that Item ID Custom equipment works only for saved database bots. Default class/level equipment profiles remain unchanged. Supports custom equipment from No Grade to S Grade, regardless of the bot's current level. Added validation for invalid item IDs and incompatible equipment slots. Added handling for: Two-handed weapons vs shields Full-body armor vs separate leggings Added all-grade Soulshots and Spiritshots to bot inventory/replenishment so custom lower-grade weapons still use the correct shots. Mage profiles that already use Blessed Spiritshots keep that behavior with all relevant grades available. First save the bot normally so it exists in table:         lucera_autobots Then open:         lucera_autobots_items Find the row with the same bot_id and edit only the equipment slots you want. Example: weapon_id = 6608 shield_id = -1 helmet_id = 0 chest_id = 0 legs_id = 0 gloves_id = 0 boots_id = 0 This means: weapon_id 6608 → custom weapon shield_id -1 → no shield all 0 values → keep normal default profile equipment After editing the DB, despawn and respawn the saved bot so M54 reloads its equipment overrides. Do not edit bot_id. Use it only to identify which saved bot the equipment row belongs to.   DOWNLOAD
    • It will be multi client so it will detect the client from the files and adapt the packets and asset loading. I am aiming for C4 and H5 after IL
    • this is just to simplify your life, time, and can be done for free by yourself just watch some tutorials, in case you don't wanna waste time check it out!   https://l2getwork.art   https://l2getwork.art/showcase.html  
    • Good job! Any chance for it to be downgradeable or at least compatible with older chronicles?
    • Fermata now runs in a web browser too. Try it here: https://web.fermata.gg/    
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..