Jump to content

Recommended Posts

Posted

Hello. With this share (as the subject says) your players can teleport to other players for an item. Use the .goto <playername> command. You can set the item ID in teleportItem, the cost in teleportCost and the teleport time in the teleportTimer variables. You can allow/disallow players to teleport to you with the .blockgoto command. When you teleport to the player he/she got a system message about it.

 

Tested on L2JFree 1.2.10. Credits to me. (but Intrepid helped a bit too:P)

com.l2jfree.gameserver.handler.voicedcommandhandlers.GoToPlayer.java


/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* 
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jfree.gameserver.handler.voicedcommandhandlers;

import com.l2jfree.Config;
import java.util.StringTokenizer;
import com.l2jfree.gameserver.network.serverpackets.InventoryUpdate;
import com.l2jfree.gameserver.GameTimeController;
import com.l2jfree.gameserver.SevenSigns;
import com.l2jfree.gameserver.ThreadPoolManager;
import com.l2jfree.gameserver.ai.CtrlIntention;
import com.l2jfree.gameserver.datatables.SkillTable;
import com.l2jfree.gameserver.handler.IVoicedCommandHandler;
import com.l2jfree.gameserver.instancemanager.CoupleManager;
import com.l2jfree.gameserver.instancemanager.DimensionalRiftManager;
import com.l2jfree.gameserver.instancemanager.SiegeManager;
import com.l2jfree.gameserver.model.L2Character;
import com.l2jfree.gameserver.model.L2FriendList;
import com.l2jfree.gameserver.model.L2Skill;
import com.l2jfree.gameserver.model.L2World;
import com.l2jfree.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfree.gameserver.model.entity.Siege;
import com.l2jfree.gameserver.model.zone.L2Zone;
import com.l2jfree.gameserver.model.restriction.AvailableRestriction;
import com.l2jfree.gameserver.model.restriction.ObjectRestrictions;
import com.l2jfree.gameserver.network.SystemMessageId;
import com.l2jfree.gameserver.network.serverpackets.ConfirmDlg;
import com.l2jfree.gameserver.network.serverpackets.MagicSkillUse;
import com.l2jfree.gameserver.network.serverpackets.SetupGauge;
import com.l2jfree.gameserver.network.serverpackets.SystemMessage;
import com.l2jfree.gameserver.util.Broadcast;

/** 
* @author Rizel
* 
*/
public class GoToPlayer implements IVoicedCommandHandler
{
private static final String[]	VOICED_COMMANDS	=
												{ "goto", "blockgoto" };

/* (non-Javadoc)
 * @see com.l2jfree.gameserver.handler.IVoicedCommandHandler#useVoicedCommand(String, com.l2jfree.gameserver.model.L2PcInstance), String)
 */
public boolean useVoicedCommand(String command, L2PcInstance activeChar, String name)
{
	if (command.startsWith("goto"))
	{
		return playerTeleport(activeChar, name);
	}
	if (command.startsWith("blockgoto"))
	{
		if ( activeChar._blockgoto == true )
		{
			activeChar._blockgoto = false;
			activeChar.sendMessage("Players are now allowed to teleport to you!");

		}
		if ( activeChar._blockgoto == false )
		{
			activeChar._blockgoto = true;
			activeChar.sendMessage("Players are now not allowed to teleport to you!");

		}
		return true;
	}
	return false;
}



public boolean playerTeleport(L2PcInstance activeChar, String name)
{
int teleportItem = 57;
int teleportCost = 1000;





	if (activeChar.isCastingNow() || activeChar.isMovementDisabled() || activeChar.isMuted() || activeChar.isAlikeDead())
		return false;

	Siege siege = SiegeManager.getInstance().getSiege(activeChar);

	// Check to see if the player is in olympiad.
	if (activeChar.isInOlympiadMode())
	{
		activeChar.sendMessage("You are in Olympiad!");
		return false;
	}
	// Check to see if the player is in observer mode
	else if (activeChar.inObserverMode())
	{
		activeChar.sendMessage("You are in observer mode.");
		return false;
	}
	// Check to see if the player is in an event
	else if (activeChar.isInFunEvent())
	{
		activeChar.sendMessage("You are in event now.");
		return false;
	}
	// Check to see if the player is in a festival.
	else if (activeChar.isFestivalParticipant())
	{
		activeChar.sendMessage("You can't escape from a festival.");
		return false;
	}
	// Check to see if the player is in dimensional rift.
	else if (activeChar.isInParty() && activeChar.getParty().isInDimensionalRift())
	{
		activeChar.sendMessage("You are in the dimensional rift.");
		return false;
	}
	// Check to see if player is in jail
	else if (activeChar.isInJail() || activeChar.isInsideZone(L2Zone.FLAG_JAIL))
	{
		activeChar.sendMessage("You can't escape from jail.");
		return false;
	}
	// Check if player is in Siege
	else if (siege != null && siege.getIsInProgress())
	{
		activeChar.sendMessage("You are in siege, you can't go to your partner.");
		return false;
	}
	// Check if player is in Duel
	else if (activeChar.isInDuel())
	{
		activeChar.sendMessage("You are in a duel!");
		return false;
	}
	// Check if player is a Cursed Weapon owner
	else if (activeChar.isCursedWeaponEquipped())
	{
		activeChar.sendMessage("You are currently holding a cursed weapon.");
		return false;
	}
	// Check if player is in a Monster Derby Track
	else if (activeChar.isInsideZone(L2Zone.FLAG_NOESCAPE))
	{
		activeChar.sendMessage("You cannot escape from here.");
		return false;
	}


	L2PcInstance targetplayer = L2World.getInstance().getPlayer(name);
	if (targetplayer._blockgoto == true)
	{
		activeChar.sendMessage("Your target blocked the teleport to him/her.");
		return false;
	}
                if (targetplayer.isGM())
	{
		activeChar.sendMessage("You can't teleport to GM.");
		return false;
	}
	if (targetplayer != null)
	{
		siege = SiegeManager.getInstance().getSiege(targetplayer);
	}
	else
	{
		activeChar.sendMessage("Your target is not online.");
		return false;
	}

	// Check to see if the player is in a instance.
	if (activeChar.getInstanceId() != targetplayer.getInstanceId())
	{
		activeChar.sendMessage("Your target is in another World!");
		return false;
	}
	else if (targetplayer.isInJail() || targetplayer.isInsideZone(L2Zone.FLAG_JAIL))
	{
		activeChar.sendMessage("Your target is in jail.");
		return false;
	}
	else if (targetplayer.isInOlympiadMode())
	{
		activeChar.sendMessage("Your target is in Olympiad now.");
		return false;
	}
	else if (targetplayer.inObserverMode())
	{
		activeChar.sendMessage("Your target is in observer mode.");
		return false;
	}
	else if (targetplayer.isInDuel())
	{
		activeChar.sendMessage("Your target is in a duel.");
		return false;
	}
	else if (targetplayer.isInFunEvent())
	{
		activeChar.sendMessage("Your target is in an event.");
		return false;
	}
	else if (DimensionalRiftManager.getInstance().checkIfInRiftZone(targetplayer.getX(), targetplayer.getY(), targetplayer.getZ(), false))
	{
		activeChar.sendMessage("Your target is in dimensional rift.");
		return false;
	}
	else if (targetplayer.isFestivalParticipant())
	{
		activeChar.sendMessage("Your target is in a festival.");
		return false;
	}
	else if (siege != null && siege.getIsInProgress())
	{
		if (targetplayer.getAppearance().getSex())
			activeChar.sendMessage("Your target is in siege, you can't go to her.");
		else
			activeChar.sendMessage("Your target is in siege, you can't go to him.");
		return false;
	}
	else if (targetplayer.isCursedWeaponEquipped())
	{
		activeChar.sendMessage("Your target is currently holding a cursed weapon.");
		return false;
	}
	else if (targetplayer.isInsideZone(L2Zone.FLAG_NOESCAPE))
	{
		activeChar.sendMessage("Your target is in a unsuitable area for teleporting.");
		return false;
	}
	else if (targetplayer.isIn7sDungeon() && !activeChar.isIn7sDungeon())
	{
		int playerCabal = SevenSigns.getInstance().getPlayerCabal(activeChar);
		boolean isSealValidationPeriod = SevenSigns.getInstance().isSealValidationPeriod();
		int compWinner = SevenSigns.getInstance().getCabalHighestScore();

		if (isSealValidationPeriod)
		{
			if (playerCabal != compWinner)
			{
				activeChar.sendMessage("Your target is in a Seven Signs Dungeon and you are not in the winner Cabal!");
				return false;
			}
		}
		else
		{
			if (playerCabal == SevenSigns.CABAL_NULL)
			{
				activeChar.sendMessage("Your target is in a Seven Signs Dungeon and you are not registered!");
				return false;
			}
		}
	}

	int teleportTimer = 10 * 1000;
	if (!activeChar.destroyItemByItemId("", teleportItem, teleportCost, activeChar, true))
	{
		activeChar.sendMessage("You don't have enough item to teleport.");
		return false;
	}
	activeChar.sendMessage("After " + teleportTimer / 1000 + " sec. you will be teleported to " + name +".");
	targetplayer.sendMessage("Player " + activeChar + "teleporting to you.");
	activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
	// SoE Animation section
	activeChar.setTarget(activeChar);
	activeChar.disableAllSkills();



	MagicSkillUse msk = new MagicSkillUse(activeChar, 1050, 1, teleportTimer, 0);
	Broadcast.toSelfAndKnownPlayersInRadius(activeChar, msk, 810000/*900*/);
	SetupGauge sg = new SetupGauge(0, teleportTimer);
	activeChar.sendPacket(sg);
	// End SoE Animation section

	EscapeFinalizer ef = new EscapeFinalizer(activeChar, targetplayer.getX(), targetplayer.getY(), targetplayer.getZ(), targetplayer.isIn7sDungeon());
	// Continue execution later
	activeChar.setSkillCast(ThreadPoolManager.getInstance().scheduleGeneral(ef, teleportTimer));
	activeChar.forceIsCasting(GameTimeController.getGameTicks() + teleportTimer / GameTimeController.MILLIS_IN_TICK);

	return true;
}


private static class EscapeFinalizer implements Runnable
{
private L2PcInstance	_activeChar;
private int				_partnerx;
private int				_partnery;
private int				_partnerz;
private boolean			_to7sDungeon;

EscapeFinalizer(L2PcInstance activeChar, int x, int y, int z, boolean to7sDungeon)
{
	_activeChar = activeChar;
	_partnerx = x;
	_partnery = y;
	_partnerz = z;
	_to7sDungeon = to7sDungeon;
}

public void run()
{
	if (_activeChar.isDead())
		return;
	_activeChar.setIsIn7sDungeon(_to7sDungeon);
	_activeChar.enableAllSkills();
	_activeChar.setIsCastingNow(false);

	try
	{
		_activeChar.teleToLocation(_partnerx, _partnery, _partnerz);
	}
	catch (Exception e)
	{
		_log.error(e.getMessage(), e);
	}
}
}


/* (non-Javadoc)
 * @see com.l2jfree.gameserver.handler.IVoicedCommandHandler#getVoicedCommandList()
 */
public String[] getVoicedCommandList()
{
	return VOICED_COMMANDS;
}
}

 

com.l2jfree.gameserver.model.actor.instance.L2PcInstance.java


public boolean							_inEventTvT				= false;
public boolean							_voteEvent				= false;
+	public boolean							_blockgoto				= false;

 

com.l2jfree.gameserver.handler.VoicedCommandHandler.java


	registerVoicedCommandHandler(new Banking());
+		registerVoicedCommandHandler(new GoToPlayer());

Posted

omfg. i was doing this but i stoped coding for it due to other projects:D anw cool! gj man:) keep it up! as i can see you edited the Wedding.java file and the gotolove part right?

 

also _inEventTvt is already defined in L2PcInstance no need to add it again

Posted

omfg. i was doing this but i stoped coding for it due to other projects:D anw cool! gj man:) keep it up! as i can see you edited the Wedding.java file and the gotolove part right?

 

No he dont tuch them those are just show how you can do it

Posted

well, that was an easiest way to do it coz it was already ready in Wedding.java:) good job and good luck with your java contribs:)

 

 

EDIT:

 

what about adding the teleport item and the cost into altsettings.properties?

 

in Config.java under line 1316 put:

 

	public static int		ALT_TELEPORT_ITEM;
public static int		ALT_TELEPORT_ITEM_COST;	

 

then under line 1512 put:

 

ALT_TELEPORT_ITEM = Integer.parseInt(altSettings.getProperty("AltGotoplayeritem", "57"));
ALT_TELEPORT_ITEM_COST = Integer.parseInt(altSettings.getProperty("AltGotoplayeritemcost", "10000"));	

 

and in altsettings.properties put

 

### Item ID needed to use .gotoplayer command ###
AltGotoplayeritem=57
### Item Amount ###
AltGotoplayeritemcost=10000

 

then do some changes in the GoToPlayer.java like changing

 

if (!activeChar.destroyItemByItemId("", teleportItem, teleportCost, activeChar, true))

 

to

 

if (!activeChar.destroyItemByItemId("", config.ALT_TELEPORT_ITEM, config.ALT_TELEPORT_ITEM_COST, activeChar, true))

 

Posted

well, that was an easiest way to do it coz it was already ready in Wedding.java:) good job and good luck with your java contribs:)

 

yes but you know best things come in small packages:D

and now i start to w8 for his next share he started an automated speed quiz event:D

Posted

int z = player1.getZ

int y = player1.getY

int x = player1.getX

 

If (player1.allowGoTo() && player2.getInventory.getItemByItemId(57) != null)

{

if (player2.getItemByItemId(57).getCount() >= 20000000)

{

player2.teleToCoords(x,y,z);

}

}

 

 

Much less code...Thats for teleport....you must make one more command and a new method in l2pcinstance. The allowgoto command will enable allowgoto in l2pcinstance so .goto can be used...

 

Your code is WAY too big and I still cant get why you created a new private in the voice handler and you didnt use the teleport private in l2pcinstance...Oo

Posted

my code is long becouse the event,jail,siege etc. checks ,the SoE effect and the blockgoto function. this script is a modified .gotolove but here you not teleport to your partner but teleport to any player

Posted

aye...Well I didnt read it I just saw its huge :) Good job :)

 

Edit: xMaylox it eats less resources the way he did it than writing it in L2PcInstance...That code is being read every time a character uses the command, L2PcInstance is read almost every sec, event more, on a big server

Posted

 

if (player2.getItemByItemId(57).getCount() >= 20000000)

 

 

Why >= ... if some1 have 2kk the teleport make him the 2kk .. again if character have 2kkk this will make the 2kkk ...

 

>= mean for example 20000000 and up , why not == 20000000 ...??

 

 

@Rizel: Good job  you do great Modify :) Keep Up m8!

  • 2 weeks later...
Posted

ok so i just change the command from .goto to .getto

np in compiling.

 

but when i try it IG[i tried both .goto and .getto,same error],it gives this error  [L2jfree 1.2.10]

SEVERE Client: [Character: test - Account: admin - IP: 127.0.0.1] - Failed runni
ng: [C] 38 Say2 - L2J Server Version: 1.2.10
java.lang.NullPointerException
        at com.l2jfree.gameserver.handler.voicedcommandhandlers.GetToPlayer.play
erTeleport(GetToPlayer.java:161)
        at com.l2jfree.gameserver.handler.voicedcommandhandlers.GetToPlayer.useV
oicedCommand(GetToPlayer.java:61)
        at com.l2jfree.gameserver.network.clientpackets.Say2.runImpl(Say2.java:1
56)
        at com.l2jfree.gameserver.network.clientpackets.L2GameClientPacket.run(L
2GameClientPacket.java:78)
        at com.l2jfree.gameserver.threadmanager.ExecuteWrapper.run(ExecuteWrappe
r.java:40)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
access$301(Unknown Source)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.
run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source
)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

 

any reason for this?

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
Reply to this topic...

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