Skip to content

Chat Command For Races

Featured Replies

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?

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

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.

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

 

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. 

 

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

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

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

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

 

I am in my smartphone :D 

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

  • Author

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

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

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

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

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.