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

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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