Jump to content
  • 0

Chat Command For Races


mattiamartucci

Question

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?

Link to comment
Share on other sites

Recommended Posts

  • 0

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

Link to comment
Share on other sites

  • 0
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.

Link to comment
Share on other sites

  • 0

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
Link to comment
Share on other sites

  • 0

 

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. 

Link to comment
Share on other sites

  • 0

 

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

Link to comment
Share on other sites

  • 0

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
Link to comment
Share on other sites

  • 0

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

Link to comment
Share on other sites

  • 0
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
Link to comment
Share on other sites

  • 0

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
Link to comment
Share on other sites

  • 0

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

Link to comment
Share on other sites

  • 0

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

Link to comment
Share on other sites

  • 0

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.

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
Answer this question...

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