Jump to content
  • 0

Restrict


InFocus

Question

Recommended Posts

  • 0
17 minutes ago, InFocus said:

Hi all, i have just a question. It is possible to restrict all items (armor,weapons,etc etc) and leave just 1 type or armor to access in zone? I mean for VoiceCommand teleport?

 

Can you explain it? you need restrictions for the .command or the zone? or both?

Link to comment
Share on other sites

  • 0
2 minutes ago, InFocus said:

I want restrictions for command

all items and for exemple for s grade don't ( S grade means armors and weapons)

So , a player with atleast 1 S-Grade item equiped is not be able to use the command right?

Link to comment
Share on other sites

  • 0
package handlers.voicedcommandhandlers;

import java.util.HashMap;
import java.util.Map;

import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.clientpackets.Say2;
import com.l2jserver.gameserver.network.serverpackets.CreatureSay;

/**
 * @author L2Amyra
 */
public class FarmZone implements IVoicedCommandHandler
{
	private static final String[] VOICED_COMMANDS =
	{
		"easy",
		"mid",
		"hard",
		"dungeon"
	};
	private static final long delay = 5000; // Millisecounds
	private static Map<Integer, Long> _reuse = new HashMap<>();
	
	@Override
	public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
	{
		if (_reuse.containsKey(activeChar.getObjectId()))
		{
			if (_reuse.get(activeChar.getObjectId()) > System.currentTimeMillis())
			{
				activeChar.sendMessage("Sorry, you can not use this command. You can use it within " + ((_reuse.get(activeChar.getObjectId()) - System.currentTimeMillis()) / 1000) + " sec's");
				return false;
			}
		}
		
		{
			
			if (activeChar.isDead())
			{
				activeChar.sendMessage("You can't teleport while you are dead!");
				return false;
			}
			else if (activeChar.isInOlympiadMode())
			{
				
				activeChar.sendMessage("You can't use this command durring olympiad!");
				return false;
			}
			else if (activeChar.isInDuel())
			{
				activeChar.sendMessage("You can't use this command when you are in duel!");
				return false;
			}
			else if (activeChar.isInCombat())
			{
				activeChar.sendMessage("You can't use this command when you are in combat!");
				return false;
			}
			else if (activeChar.getPvpFlag() > 0)
			{
				CreatureSay i = new CreatureSay(activeChar.getObjectId(), Say2.PARTY, "admin", "You can't use this command when you are flagged. Try again...!");
				activeChar.sendPacket(i);
				return false;
			}
			else if (activeChar.isJailed())
			{
				activeChar.sendMessage("You can't use this command when you are in jail");
				return false;
			}
			
			else if (activeChar.getInventory().getInventoryItemCount(57, 0) < 50000)
			{
				activeChar.sendMessage("No enough Adena!");
				return false;
			}
			else if (activeChar.getKarma() > 0)
			{
				activeChar.sendMessage("Go away. You are not welcome here !");
				return false;
			}
			else if (!activeChar.isNoble())
			{
				activeChar.sendMessage("Only Noblesse players can teleport.");
				return false;
			}
			else if (activeChar.getLevel() < 80)
			{
				activeChar.sendMessage("You can only use the command after level 80");
				return false;
			}
			{
				
				if (command.startsWith("easy"))
				{
					if (!activeChar.isNoble())
					{
						activeChar.destroyItemByItemId("consume", 57, 50000, activeChar, true);
					}
					if (!(activeChar.getLevel() < 80))
					{
						activeChar.sendMessage("You have been teleported to easy zone ");
						activeChar.teleToLocation(89006, 27373, -15691);
					}
					
					_reuse.put(activeChar.getObjectId(), System.currentTimeMillis() + delay);
				}
				else if (command.startsWith("mid"))
				{
					
					if (!activeChar.isNoble())
					{
						activeChar.destroyItemByItemId("consume", 57, 50000, activeChar, true);
					}
					if (!(activeChar.getLevel() < 80))
					{
						activeChar.sendMessage("You have been teleported to mid zone ");
						activeChar.teleToLocation(89006, 27373, -15691);
					}
					
					_reuse.put(activeChar.getObjectId(), System.currentTimeMillis() + delay);
				}
				else if (command.startsWith("hard"))
				{
					
					if (!activeChar.isNoble())
					{
						activeChar.destroyItemByItemId("consume", 57, 50000, activeChar, true);
					}
					if (!(activeChar.getLevel() < 80))
					{
						activeChar.sendMessage("You have been teleported to hard zone ");
						activeChar.teleToLocation(89006, 27373, -15691);
					}
					
					_reuse.put(activeChar.getObjectId(), System.currentTimeMillis() + delay);
				}
				else if (command.startsWith("dungeon"))
				{
					
					if (!activeChar.isNoble())
					{
						activeChar.destroyItemByItemId("consume", 57, 50000, activeChar, true);
					}
					if (!(activeChar.getLevel() < 80))
					{
						activeChar.sendMessage("You have been teleported to dungeon zone ");
						activeChar.teleToLocation(89006, 27373, -15691);
					}
					
					_reuse.put(activeChar.getObjectId(), System.currentTimeMillis() + delay);
				}
			}
			
			return true;
		}
	}
	
	@Override
	public String[] getVoicedCommandList()
	{
		return VOICED_COMMANDS;
	}
	
}

 

Link to comment
Share on other sites

  • 0
public boolean hasGradeEquipped(CrystalType type)
{
	return getInventory().getItems().stream().filter(i -> i.isEquipped() && i.getItem().getCrystalType() == type).findAny().isPresent();
}

//Usage
if (activeChar.hasGradeEquipped(CrystalType.S))
{
   activeChar.sendMessage("You cannot use this command.");
   return false;
}

Go ahead say "Thank you everyone except Kara`". Go ahead i dare you :)

Edited by Kara`
Link to comment
Share on other sites

  • 0
17 minutes ago, InFocus said:

Hh, what's this? :)) and yea, thank you Kara` for reply

http://OEciKXv.png

 

I gave you the code, is time for you to understand how things work by simple observation. If you can't understand that hasGradeEquiped must be in Player.java then you can ask Mr. Professional Moderator Melroni. I gave you the code. Do what you have to do.

 

And next time u call me trash consider that trash like me provide u help and codes since 2012. 

Edited by Kara`
Link to comment
Share on other sites

  • 0

put that method

public boolean hasGradeEquipped(CrystalType type)
{
	return getInventory().getItems().stream().filter(i -> i.isEquipped() && i.getItem().getCrystalType() == type).findAny().isPresent();
}

 

in Player.class (or what you have.. L2PcInstance?)

then you wont have problems..

 

regarding to Super Duper Kara. the code is working BUT. If we are talking about java and your object may had 5000 'equiped items' you could have big troubles with your way... findFirst() will do the right way (by checking null) and not findAny since we need to know if there is atleast 1 item that is the type we need and not get all those items.. its like you are using for( bla bla) without returning true when you find it

Edited by melron
Link to comment
Share on other sites

  • 0
25 minutes ago, melron said:

put that method


public boolean hasGradeEquipped(CrystalType type)
{
	return getInventory().getItems().stream().filter(i -> i.isEquipped() && i.getItem().getCrystalType() == type).findAny().isPresent();
}

 

in Player.class (or what you have.. L2PcInstance?)

then you wont have problems..

 

regarding to Super Duper Kara. the code is working BUT. If we are talking about java and your object may had 5000 'equiped items' you could have big troubles with your way... findFirst() will do the right way (by checking null) and not findAny since we need to know if there is atleast 1 item that is the type we need and not get all those items.. its like you are using for( bla bla) without returning true when you find it

 

Im proud that after all you learned basics of java but Mr. PRO Melroni i would like to advice you that the findAny() and findFirst() has 0 difference in terms of performance since it won't go though 5000 object you said. Simply because the filter will return max 10 or i dont remember how many equippable object you can have. So the performance here is so little that even a cpu of 1995 wouldn't consider it difference.

 

in 100 000 objects the difference of Any and First is 6 millisecond in i7

https://imgur.com/a/ioTWGcq

 

So even if we do in 100 object the difference is 0. We need move into nanoseconds which again difference is tiny.

 

Edited by Kara`
Link to comment
Share on other sites

  • 0

Well , melron i always will respect you! You are greate developer in java and everywhere in Lineage 2. 

and i want to understand this 

public boolean hasGradeEquipped(CrystalType type)
{
	return getInventory().getItems().stream().filter(i -> i.isEquipped() && i.getItem().getCrystalType() == type).findAny().isPresent();
}

i give you the code, i put this in l2pcinstance and this part of code

//Usage
if (activeChar.hasGradeEquipped(CrystalType.S))
{
   activeChar.sendMessage("You cannot use this command.");
   return false;
}

in .command?

P.S.-And yes. this package no have player.class, so i must move in L2PcInstance

Edited by InFocus
Link to comment
Share on other sites

  • 0
27 minutes ago, Kara` said:

 

Im proud that after all you learned basics of java but Mr. PRO Melroni i would like to advice you that the findAny() and findFirst() has 0 difference in terms of performance since it won't go though 5000 object you said. Simply because the filter will return max 10 or i dont remember how many equippable object you can have. So the performance here is so little that even a cpu of 1995 wouldn't consider it difference.

 

in 100 000 objects the difference of Any and First is 6 millisecond in i7

https://imgur.com/a/ioTWGcq

 

So even if we do in 100 object the difference is 0. We need move into nanoseconds which again difference is tiny.

 

What about a small refactored code?

 

https://imgur.com/a/WlU1ThX

 

@InFocus

use this

Quote

return Arrays.asList(getInventory().getItems()).stream().filter(i -> i.isEquipped() && i.getItem().getCrystalType() == type).findAny().isPresent();

 

Edited by melron
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.



  • Posts

    • L2 Insignia High Five 20x MID SERVER FOCUSED ON OLYMPIAD | PVP | AUTOFARM       OPEN BETA TEST SERVER 3 MAY 2024   GRAND OPENING 10 MAY 2024    Rates: 📜 XP/SP 20x | Spoil 15x | Drop 10x | Adena 10x 📜     Server Features: 🔥 No Olf-T Shirt, No big over-enchant, No over-power Donate 🔥 🔥 VIP Gold Color Chat, Unique Olympiad Extra Points Engine, GvG Event 🔥 🔥 Auto-Farm, LoA and DV scheduled PvP Zone, Calendar Daily Reward 🔥 🔥 Castle Instance, Solo Instance, PvP Solo Rift, Dress me system, Adena Boxes 🔥        Website: https://www.l2insignia.com  Discord: https://discord.com/invite/yEgsrHn2hQ      
    • I am selling the essence project which includes versions 388 and 439 that have been running for over 2 years or (447 as custom PVP like Pride). I have a test server for you to test them out. If you are really interested in it then contact my seller at discord: kiwi7106. Price: 4000 Euro P/s: This is a project that I have spent a lot of money and time developing, so if you are not interested in it, please get out of this topic, thank you. P/s 2: If you find the price too expensive, it's best to skip this article and find another project and don't comment negatively on my topic, thank you.
    • Someone ask me for this, it should work on any client that has Kamael race, preview:     Installation - there are two ways to install depending on how you want to use it:   Method 1: If you want to completely replace the original, do:   Copy all lines from your armorgrp to Notepad++, press Ctrl+H, check the "match whole word" option and replace:   kamael.Mkamael_m000_w_ad00   by:   AvengersKamaelWings.Avengers_MKamael_m001_w_ad00   Then replace:   MKamael.Mkamael_m000_t00_w   by:   AvengersKamaelWings.MKamael_m001_t00_w   Now repeat the same process with the female, replace:   kamael.Fkamael_m000_w_ad00   by:   AvengersKamaelWings.Avengers_FKamael_m001_w_ad00   Then replace:   FKamael.Fkamael_m000_t00_w   by:   AvengersKamaelWings.FKamael_m001_t00_w   You're done, paste everything back into File Edit and save!   Method 2: If you only want to replace in specific sets, execute the above process only on the armorgrp of those sets.   Repack by: AvengersTeamBr Password: LadrãoDeFrango      
  • Topics

×
×
  • Create New...