Jump to content

Question

Posted

I want to make a special command on my server :)
Example: an elven player writes ".e Hello Everyone!". For all other elves the message appears, for other races there is another message like "-is talking in elven language-".
Obviously members of other races can speak only languages that are of their race.

I just need the script for only one race, but not the humans
Can you help me?

Recommended Posts

  • 0
Posted

I want to make a special command on my server :)

Example: an elven player writes ".e Hello Everyone!". For all other elves the message appears, for other races there is another message like "-is talking in elven language-".

Obviously members of other races can speak only languages that are of their race.

I just need the script for only one race, but not the humans

Can you help me?

say2.java if(activeChar.getRace blabla == Race.Elf) it is just a check just not sure if you have to L2World.getInstance.getKnownlist.getOnlinePlayers to be => Elves , bored to open eclipse and code that but pretty much with this 2 hints i gave you the code

  • 0
Posted
public class RaceVoice implements IVoicedCommandHandler
{
    private static final String[] _voicedCommands = {"d, de, e, h, o"};
    
    @Override
    public boolean useVoicedCommand(String command, Player activeChar, String target)
    {
        if (command.startWith("d") && activeChar.getRace() == Race.Dwarf)    
        {
		// Code
       	}
        else if (command.startWith("de") && activeChar.getRace() == Race.DarkElf)    
        {
		// Code
       	}

	// ...

        return true;
    }
    
    @Override
    public String[] getVoicedCommandList()
    {
        return _voicedCommands;
    }
}

Something like this.

  • 0
Posted (edited)

In case you dont have voiced command handlers...

Say2.java

IChatHandler handler = ChatHandler.getInstance().getChatHandler(_type);
if (handler != null)
-	handler.handleChat(_type, activeChar, _target, _text);
+{
+	if (_text.startsWith(".e") && _type != 2 ) //pm case
+	{
+		switch(activeChar.getRace())
+		{
+			case ELF:
+				for (Player player : World.getInstance().getPlayers())
+				{
+					if (player.getRace() == ClassRace.ELF)
+						player.sendPacket(new CreatureSay(0, _type, player.getName(),_text.substring(2)));
+					else
+						player.sendPacket(new CreatureSay(0, _type, player.getName(),activeChar.getName() + " is writing in Elf language"));
+						
+				}
+				break;
+			case DARK_ELF:
+				//code
+				break;
+		}
+	}
+	else
+		handler.handleChat(_type, activeChar, _target, _text);
+}
Edited by melron
  • 0
Posted

 

In case you dont have voiced command handlers...

Say2.java

IChatHandler handler = ChatHandler.getInstance().getChatHandler(_type);
if (handler != null)
-	handler.handleChat(_type, activeChar, _target, _text);
+{
+	if (_text.startsWith(".e") && _type != 2 ) //pm case
+	{
+		switch(activeChar.getRace())
+		{
+			case ELF:
+				for (Player player : World.getInstance().getPlayers())
+				{
+					if (player.getRace() == ClassRace.ELF)
+						player.sendPacket(new CreatureSay(0, _type, player.getName(),_text.substring(2)));
+					else
+						player.sendPacket(new CreatureSay(0, _type, player.getName(),activeChar.getName() + " is writing in Elf language"));
+						
+				}
+				break;
+			case DARK_ELF:
+				//code
+				break;
+		}
+	}
+	else
+		handler.handleChat(_type, activeChar, _target, _text);
+}

 

a static method on broadcast.java would be better. 

  • 0
Posted

 

In case you dont have voiced command handlers...

Say2.java

IChatHandler handler = ChatHandler.getInstance().getChatHandler(_type);
if (handler != null)
-	handler.handleChat(_type, activeChar, _target, _text);
+{
+	if (_text.startsWith(".e") && _type != 2 ) //pm case
+	{
+		switch(activeChar.getRace())
+		{
+			case ELF:
+				for (Player player : World.getInstance().getPlayers())
+				{
+					if (player.getRace() == ClassRace.ELF)
+						player.sendPacket(new CreatureSay(0, _type, player.getName(),_text.substring(2)));
+					else
+						player.sendPacket(new CreatureSay(0, _type, player.getName(),activeChar.getName() + " is writing in Elf language"));
+						
+				}
+				break;
+			case DARK_ELF:
+				//code
+				break;
+		}
+	}
+	else
+		handler.handleChat(_type, activeChar, _target, _text);
+}

after reading this code i got what +++ you need :D that is awesome

  • 0
Posted (edited)

Using .e or .d or whatever is stupid , not only for you but for players also. Make something like .race Message (so all the races type the same command) .

public static void toRacePlayers(L2PcInstance p, String msg)
	{
		for (L2PcInstance player : L2World.getInstance().getPlayers())
		{
			if (player==p)
				continue;
			if(player.getRace().equals(p.getRace()))
				player.sendMessage(msg);//or sendpacket creaturesay whatever
		}
	}

Same method in all cases , non repeatable code ,  better performance , better for players.

Edited by Lioy
  • 0
Posted

Using .e or .d or whatever is stupid , not only for you but for players also. Make something like .race Message (so all the races type the same command) .

public static void toRacePlayers(L2PcInstance p, String msg)
	{
		for (L2PcInstance player : L2World.getInstance().getPlayers())
		{
			if (player==p)
				continue;
			if(player.getRace().equals(p.getRace()))
				player.sendMessage(msg);//or sendpacket creaturesay whatever
		}
	}

Same method in all cases , non repeatable code ,  better performance , better for players.

True but, why you are skipping your self since you need too the message :P

  • 0
Posted

True but, why you are skipping your self since you need too the message :P

 

I am in my smartphone :D 

  • 0
Posted (edited)
public class RaceVoice implements IVoicedCommandHandler
{
    private static final String[] _voicedCommands = {"d, de, e, h, o"};
    
    @Override
    public boolean useVoicedCommand(String command, Player activeChar, String target)
    {
        if (command.startWith("d") && activeChar.getRace() == Race.Dwarf)    
        {
		// Code
       	}
        else if (command.startWith("de") && activeChar.getRace() == Race.DarkElf)    
        {
		// Code
       	}

	// ...

        return true;
    }
    
    @Override
    public String[] getVoicedCommandList()
    {
        return _voicedCommands;
    }
}

Something like this.

 

 

My code after edit:

 if (command.startWith("d") && activeChar.getRace() == Race.Dwarf)    
     {
        player.sendPacket(new CreatureSay(0, player.getName(),activeChar.getName()));
   }

Is correct ?

 

Im noob with java :(

 

And i have a problem i have import com.l2jserver.gameserver.model.base.Race; but the console server print this message:

1. ERROR in C:\Users\Administrator\Desktop\l2j\game\data\scripts\handlers\chatha

ndlers\RaceVoice.java (at line 34)

        import com.l2jserver.gameserver.model.base;

               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Only a type can be imported. com.l2jserver.gameserver.model.base resolves to a package

Race cannot be resolved to a variable

Edited by mattiamartucci
  • 0
Posted (edited)

Can you post the whole file?

package handlers.chathandlers;

import java.util.Collection;
import java.util.StringTokenizer;
import java.util.logging.Logger;

import com.l2jserver.Config;
import com.l2jserver.gameserver.handler.IChatHandler;
import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
import com.l2jserver.gameserver.handler.VoicedCommandHandler;
import com.l2jserver.gameserver.model.BlockList;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.SystemMessageId;
import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
import com.l2jserver.gameserver.model.base.Race;
import com.l2jserver.gameserver.util.Util;

/**
 * A chat handler
 * @author durgus
 */
 public class RaceVoice implements IVoicedCommandHandler
 {
   private static final String[] _voicedCommands = {"d, de, e, h, o"};
    
    @Override
    public boolean useVoicedCommand(String command, Player activeChar, String target)
    {
        if (command.startsWith("d") && activeChar.getRace() == Race.Dwarf)    
        {
        // Code
           }
        else if (command.startsWith("de") && activeChar.getRace() == Race.DarkElf)    
        {
        // Code
           }
 
    // ...
 
        return true;
    }
    
    @Override
    public String[] getVoicedCommandList()
    {
        return _voicedCommands;
    }
}
Edited by mattiamartucci
  • 0
Posted

Btw, don't use startsWith if you have d and de, it may bug. Use equals(IgnoreCase) instead.

  • 0
Posted

Btw, don't use startsWith if you have d and de, it may bug. Use equals(IgnoreCase) instead.

Equals de? That means the player must send command ".de" and if the command is ".de hi" equals will return false. In his case want the actual command as the message - ".de" . Correct me if I'm wrong

  • 0
Posted

told you a better method but you didn't accept it :D anyway let me do this and post it in some hour i am busy atm.

Equals de? That means the player must send command ".de" and if the command is ".de hi" equals will return false. In his case want the actual command as the message - ".de" . Correct me if I'm wrong

true

  • 0
Posted

told you a better method but you didn't accept it :D anyway let me do this and post it in some hour i am busy atm.

true

I accept all guys, of course if it was php I would have already solved the problem! Anyway, thank you all for the help and of course put the credits on the script site.

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

    • Dear friends! We are constantly growing and developing, and we are finally ready to offer you the opportunity to integrate advertising across all SOCNET projects! Our service provides the opportunity to place ads on the website socnet.store, in our SMM panel socnet.pro, in Telegram bots socnet.shop and socnet.cc (celebrity bot), as well as in another new (currently secret) project. Each platform provides detailed analytics and information about available ad banners. The document below contains all detailed information in two languages — Russian and English. Here you will find answers to frequently asked questions about exact ad placement locations, integration costs, purchasing process, restrictions, and many other details. The document also contains a table with the current advertising placement queue in our projects. Document with detailed information: https://docs.google.com/document/d/1u4ro3fLkjfyvcp1Eu64rkgQy2Xl5lj87_1W25cVsqPM/edit?usp=sharing Thank you for your attention and support! Sincerely, the SOCNET team. Active project links: Digital Goods Store (Website): Go Store Telegram Bot: Go – convenient access to the store through Telegram messenger. Telegram Bot for purchasing Telegram Stars: Go – fast and profitable purchase of stars in Telegram. SMM Panel: Go – promotion of your social media accounts. We would like to present to you the current list of promotions and special offers for purchasing goods and services from our platform: 1. Promo code OCTOBER2025 (8% discount) for purchases in our store (Website, Bot) during October! You can also use the promo code for your first purchase: SOCNET (15% discount) 2. Get $1 credited to your store balance or a 10–20% discount — simply post your username after registration on our website using the following format: "SEND ME BONUS, MY USERNAME IS..." — post it in our forum thread! 3. Get $1 for your first SMM Panel trial — just open a ticket titled "Get Trial Bonus" on our website (Support). 4. Weekly Telegram Stars giveaways in our Telegram channel and in our Stars purchasing bot! News: ➡ Telegram Channel: https://t.me/accsforyou_shop ➡ WhatsApp Channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord Server: https://discord.gg/y9AStFFsrh Contacts and Support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • Dear friends! We are constantly growing and developing, and we are finally ready to offer you the opportunity to integrate advertising across all SOCNET projects! Our service provides the opportunity to place ads on the website socnet.store, in our SMM panel socnet.pro, in Telegram bots socnet.shop and socnet.cc (celebrity bot), as well as in another new (currently secret) project. Each platform provides detailed analytics and information about available ad banners. The document below contains all detailed information in two languages — Russian and English. Here you will find answers to frequently asked questions about exact ad placement locations, integration costs, purchasing process, restrictions, and many other details. The document also contains a table with the current advertising placement queue in our projects. Document with detailed information: https://docs.google.com/document/d/1u4ro3fLkjfyvcp1Eu64rkgQy2Xl5lj87_1W25cVsqPM/edit?usp=sharing Thank you for your attention and support! Sincerely, the SOCNET team. Active project links: Digital Goods Store (Website): Go Store Telegram Bot: Go – convenient access to the store through Telegram messenger. Telegram Bot for purchasing Telegram Stars: Go – fast and profitable purchase of stars in Telegram. SMM Panel: Go – promotion of your social media accounts. We would like to present to you the current list of promotions and special offers for purchasing goods and services from our platform: 1. Promo code OCTOBER2025 (8% discount) for purchases in our store (Website, Bot) during October! You can also use the promo code for your first purchase: SOCNET (15% discount) 2. Get $1 credited to your store balance or a 10–20% discount — simply post your username after registration on our website using the following format: "SEND ME BONUS, MY USERNAME IS..." — post it in our forum thread! 3. Get $1 for your first SMM Panel trial — just open a ticket titled "Get Trial Bonus" on our website (Support). 4. Weekly Telegram Stars giveaways in our Telegram channel and in our Stars purchasing bot! News: ➡ Telegram Channel: https://t.me/accsforyou_shop ➡ WhatsApp Channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord Server: https://discord.gg/y9AStFFsrh Contacts and Support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • Dear friends! We are constantly growing and developing, and we are finally ready to offer you the opportunity to integrate advertising across all SOCNET projects! Our service provides the opportunity to place ads on the website socnet.store, in our SMM panel socnet.pro, in Telegram bots socnet.shop and socnet.cc (celebrity bot), as well as in another new (currently secret) project. Each platform provides detailed analytics and information about available ad banners. The document below contains all detailed information in two languages — Russian and English. Here you will find answers to frequently asked questions about exact ad placement locations, integration costs, purchasing process, restrictions, and many other details. The document also contains a table with the current advertising placement queue in our projects. Document with detailed information: https://docs.google.com/document/d/1u4ro3fLkjfyvcp1Eu64rkgQy2Xl5lj87_1W25cVsqPM/edit?usp=sharing Thank you for your attention and support! Sincerely, the SOCNET team. Active project links: Digital Goods Store (Website): Go Store Telegram Bot: Go – convenient access to the store through Telegram messenger. Telegram Bot for purchasing Telegram Stars: Go – fast and profitable purchase of stars in Telegram. SMM Panel: Go – promotion of your social media accounts. We would like to present to you the current list of promotions and special offers for purchasing goods and services from our platform: 1. Promo code OCTOBER2025 (8% discount) for purchases in our store (Website, Bot) during October! You can also use the promo code for your first purchase: SOCNET (15% discount) 2. Get $1 credited to your store balance or a 10–20% discount — simply post your username after registration on our website using the following format: "SEND ME BONUS, MY USERNAME IS..." — post it in our forum thread! 3. Get $1 for your first SMM Panel trial — just open a ticket titled "Get Trial Bonus" on our website (Support). 4. Weekly Telegram Stars giveaways in our Telegram channel and in our Stars purchasing bot! News: ➡ Telegram Channel: https://t.me/accsforyou_shop ➡ WhatsApp Channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord Server: https://discord.gg/y9AStFFsrh Contacts and Support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • Dear friends! We are constantly growing and developing, and we are finally ready to offer you the opportunity to integrate advertising across all SOCNET projects! Our service provides the opportunity to place ads on the website socnet.store, in our SMM panel socnet.pro, in Telegram bots socnet.shop and socnet.cc (celebrity bot), as well as in another new (currently secret) project. Each platform provides detailed analytics and information about available ad banners. The document below contains all detailed information in two languages — Russian and English. Here you will find answers to frequently asked questions about exact ad placement locations, integration costs, purchasing process, restrictions, and many other details. The document also contains a table with the current advertising placement queue in our projects. Document with detailed information: https://docs.google.com/document/d/1u4ro3fLkjfyvcp1Eu64rkgQy2Xl5lj87_1W25cVsqPM/edit?usp=sharing Thank you for your attention and support! Sincerely, the SOCNET team. Active project links: Digital Goods Store (Website): Go Store Telegram Bot: Go – convenient access to the store through Telegram messenger. Telegram Bot for purchasing Telegram Stars: Go – fast and profitable purchase of stars in Telegram. SMM Panel: Go – promotion of your social media accounts. We would like to present to you the current list of promotions and special offers for purchasing goods and services from our platform: 1. Promo code OCTOBER2025 (8% discount) for purchases in our store (Website, Bot) during October! You can also use the promo code for your first purchase: SOCNET (15% discount) 2. Get $1 credited to your store balance or a 10–20% discount — simply post your username after registration on our website using the following format: "SEND ME BONUS, MY USERNAME IS..." — post it in our forum thread! 3. Get $1 for your first SMM Panel trial — just open a ticket titled "Get Trial Bonus" on our website (Support). 4. Weekly Telegram Stars giveaways in our Telegram channel and in our Stars purchasing bot! News: ➡ Telegram Channel: https://t.me/accsforyou_shop ➡ WhatsApp Channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord Server: https://discord.gg/y9AStFFsrh Contacts and Support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • Dear friends! We are constantly growing and developing, and we are finally ready to offer you the opportunity to integrate advertising across all SOCNET projects! Our service provides the opportunity to place ads on the website socnet.store, in our SMM panel socnet.pro, in Telegram bots socnet.shop and socnet.cc (celebrity bot), as well as in another new (currently secret) project. Each platform provides detailed analytics and information about available ad banners. The document below contains all detailed information in two languages — Russian and English. Here you will find answers to frequently asked questions about exact ad placement locations, integration costs, purchasing process, restrictions, and many other details. The document also contains a table with the current advertising placement queue in our projects. Document with detailed information: https://docs.google.com/document/d/1u4ro3fLkjfyvcp1Eu64rkgQy2Xl5lj87_1W25cVsqPM/edit?usp=sharing Thank you for your attention and support! Sincerely, the SOCNET team. Active project links: Digital Goods Store (Website): Go Store Telegram Bot: Go – convenient access to the store through Telegram messenger. Telegram Bot for purchasing Telegram Stars: Go – fast and profitable purchase of stars in Telegram. SMM Panel: Go – promotion of your social media accounts. We would like to present to you the current list of promotions and special offers for purchasing goods and services from our platform: 1. Promo code OCTOBER2025 (8% discount) for purchases in our store (Website, Bot) during October! You can also use the promo code for your first purchase: SOCNET (15% discount) 2. Get $1 credited to your store balance or a 10–20% discount — simply post your username after registration on our website using the following format: "SEND ME BONUS, MY USERNAME IS..." — post it in our forum thread! 3. Get $1 for your first SMM Panel trial — just open a ticket titled "Get Trial Bonus" on our website (Support). 4. Weekly Telegram Stars giveaways in our Telegram channel and in our Stars purchasing bot! News: ➡ Telegram Channel: https://t.me/accsforyou_shop ➡ WhatsApp Channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord Server: https://discord.gg/y9AStFFsrh Contacts and Support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
  • 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