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

    • We've added 5% discounts for bulk purchases of Google accounts for orders of 300 or more, and 10% for orders of 500 or more. The discount is applied automatically when you place your order! The discount is indicated in the product title and description for each category.  
    • 🎄 CHRISTMAS EVENT 🎄   ‼️ Information and details: https://forum.l2harbor.com/threads/rozhdestvenskie-xlopoty-christmas-chores.9430/post-171464
    • METATG.ORG Direct Telegram Service Provider A bonus of +7% on every order! *We add 7% more followers than your ordered amount to proactively cover potential drops and guarantee you an honest result." Telegram Followers - Price per 1000 SUBSCRIBERS Subscribers 3 days - $0.10 ~ 8 RUB Subscribers. Daily Completion: 200,000,000 Subscribers 7 days - $0.17 ~ 13.6 RUB Subscribers. Daily Completion: 200,000,000 Subscribers 14 days - $0.20 ~ 16 RUB Subscribers. Daily Completion: 200,000,000 Subscribers 30 days - $0.30 ~ 24 RUB Subscribers. Daily Completion: 200,000,000 Subscribers 60 days - $0.40 ~ 32 RUB Subscribers, 14-day guarantee. Daily Completion: 200,000,000 Subscribers 90 days (Super Fast) - $0.50 ~ 40 RUB Subscribers, 14-day guarantee. Daily Completion: 200,000,000 Subscribers 120 days (Super Fast) - $0.60 ~ 48 RUB Subscribers, 14-day guarantee. Daily Completion: 200,000,000 Subscribers Lifetime (Super Fast) - $0.70 ~ 56 RUB Lifetime Subscribers. 14-day guarantee. Daily Completion: 200,000,000 Telegram Services - Price per 1000 Post Views - $0.06 ~ 5 RUB Reactions - $0.08 ~ 6.5 RUB Bot Starts - $0.10 ~ 8 RUB Bot Starts with referrals - $0.15 ~ 12 RUB DISCOUNTS and CASHBACK for large volumes Direct Supplier. We work from our own accounts with our own software! High execution speed. Multiple payment methods. We work 24/7! Additional discounts are discussed for volumes starting from $1000 per day. SUPPORT 24/7 - TELEGRAM WEBSITE 24/7 - METATG.ORG
    • Added: a brand-new default dashboard template. You can now add multiple game/login server builds. Full support for running both PTS & L2J servers simultaneously, with switching between them. Payment systems: added OmegaPay and Pally (new PayPal-style API). Account history now stores everything: donations, items delivered to characters, referrals, transfers between game accounts, and coin transfers to another master account. Personal Promo Code System: you can create a promo code and assign it to a user or promoter. When donating, a player can enter this promo code to receive bonus coins, and the promo code owner also receives a bonus — all fully configurable in the admin panel.     Look demo site: demo
  • 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