Jump to content
  • 0

Restrict


InFocus
 Share

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




  • Posts

    • I contacted Ave for a custom launcher on December 22, and purchased it on December 27. Ave promised to deliver after new year's eve. I gave him an extense deadline for an entire month, until January 27, which is today.   Ave stopped responding in Discord in January 13. I tried messaging him multiple times, and never received an answer again.   Yesterday, I used another account to try to get an answer from him in Skype. He answered instantly, which means he was actively ignoring me in the other account. When I told him who I was, he proceeded to block me in Skype.   I understand being busy or not having time, but he never mentioned any of those being the case. He agreed to the job and confirmed it, asked for a deadline himself, and confirmed that it would be "easily done by then". At this point he proceeded to ghost me for the rest of the month, never answering again. and never delivered anything. Sadly there is nothing to see here but a regular scam.
    • Hello.  I added this on aCis401 but i found some serious problems on the code. First of all i updated all sql queries and i removed the character_memo_alt (its useless) and instead i saved everything in character_memo. All custom edits on Gameclient.java caused a serious problem (WARNING on GS) when a players was logging out. I found this part useless too so i removed it. Then i removed all Tournament arenas and OutOfZoneTask (i found them useless too because all games are instanced). Another bug is :when a team is on countdown to port in, for those 10 seconds was able to register on another game. That caused serious issues if another team join the Q and could port your team on next game before you finish the active one. And last bug is with the pets. Instance is not handled upon teleport in arena so enemies cannot kill your pet. I fixed more things for sure but i don't remember something else big.    Its a very good system if you can manage to fix/update. I don't recommend it for live server as it is.   Keep up.
    • still missing infinite odyssey 
    • Hello, so I was wondering do phantom summomers have Soulless demon contract debuff (mana drain) in Hellbound chronicle like L2Reborn? Was thinking of going phantom summoner if i could farm with Soulless (Shadow's 30% xp steal is too much to me) Thx!
  • 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