Jump to content

Recommended Posts

Posted

Hi there, i made this code today, because Sundays are kinda boring. It is one NPC again, which i like it a lot. It is not the NPC that i like, but its function.

So, with this NPC player is able to teleport with his party in an area where only parties allowed to teleport. Code is easy-configurable for new people in L2J developing. This code cointains, Allow-Checker that checks if player & his party allowed to enter in party area and have fun. NPC shows automatically in its dialog if player is allowed or not. However, it contains parties & players (inside party area) calculator, and sends it to HTML dialog automatically too. To enable this mod you have to do some modifications by your own because i am not able to guess which area you would like to make party area. If party allowed to enter, it removes from all party members the item consume & count, after that it teleports players.

 

How to enable parties & players calculator:

• Check "config"  variables in code, which are mentioned below.

• Choose which area you would like to make your party area & find its name (//zone_check with your GM character inside the zone).

• Find its folder-location. (Server/data/zones/(your zone location).xml

• Add in this zone an id (whatever you want) like that

• Add this id number on "config" variable in code (variable mentioned below)

 

Example:

I want make party area Abandoned Camp. I go with my GM character in Abandon Camp and i use //zone_check. It shows me nothing because this zone is nothing (Not effect zone, not water zone, etc...) because result from //zone_check was empty. So, i create a new folder on Server/data/zones/Test.xml and i install inside this code:

 

<zone name="Party Area" id="155" type="ArenaZone" (You can set here whatever you want) shape="NPoly" minZ="-15756" maxZ="11556">

<node X="-49881" Y="147747" />

<node X="-52646" Y="148679" />

<node X="-56224" Y="147232" />

<node X="-58319" Y="145146" />

<spawn X="83503" Y="149113" Z="-3405" />

</zone>

 

So, i have to add in my "config" variable this ID (155).

 

Ok, so lets continue to NPC, preview & code installation/modification.

 

Preview (HTM Dialog):

 

dialogv.png

 

conditionsl.png

 

Preview Dialog Messages:

 

•Leader

leadermsg.png

 

•Party Member

ptmesage.png

 

How to install:

 

1. Create a new java file on data/scripts/custom/PartyTeleporter/PartyTeleporter.java

 

Paste this code:

package custom.PartyTeleporter;
import com.l2jserver.gameserver.cache.HtmCache;
import com.l2jserver.gameserver.datatables.ItemTable;
import com.l2jserver.gameserver.instancemanager.ZoneManager;
import com.l2jserver.gameserver.model.L2Party;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.quest.Quest;
import com.l2jserver.gameserver.model.zone.L2ZoneType;
import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
import com.l2jserver.gameserver.network.serverpackets.ItemList;
import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;

/**
* @author `Heroin
* Made For Maxcheaters.com
* PartyTeleporter
*/
public class PartyTeleporter extends Quest
{
private static final int npcid = 36650; // npc id
//-------------------------------------
//Teleport Location Coordinates X,Y,Z.
//Use /loc command in game to find them.
private static final int locationX = -56742; // npc id
private static final int locationY = 140569; // npc id
private static final int locationZ = -2625; // npc id
//-------------------------------------
//-------------------------------------
// Select the id of your zone.
// If you dont know how to find your zone id is simple.
// Go to data/zones/(your zone file).xml and find your zone
// E.g: <zone name="dion_monster_pvp" id="6" type="ArenaZone" shape="NPoly" minZ="-3596" maxZ="0">
/**The id of your zone is id="6" */
/**---------------------------------------------------------------------------*/
/**WARNING: If your zone does not have any id or your location is not on any zone in data/zones/ folder, you have to add one by your self*/ // required to calculate parties & players
/**---------------------------------------------------------------------------*/
private static final int ZoneId = 155; //Here you have to set your zone Id
//-------------------------------------
private static final int MinPtMembers = 2; // Minimum Party Members Count For Enter on Zone.
private static final int ItemConsumeId = 57; // Item Consume id.
private static final int ItemConsumeNum = 100; // Item Consume Am.ount.
private static final boolean ShowPlayersInside = true; //If you set it true, NPC will show how many players are inside area.
private static final boolean ShowPartiesInside = true; //If you set it true, NPC will show how many parties are inside area.
//-------------------------------------
private static String htm = "data/scripts/custom/PartyTeleporter/1.htm"; //html location.
private static String ItemName = ItemTable.getInstance().createDummyItem(ItemConsumeId).getItemName(); //Item name, Dont Change this


public PartyTeleporter(int questId, String name, String descr)
{
	super(questId, name, descr);
	addFirstTalkId(npcid);
	addTalkId(npcid);
	addStartNpc(npcid);
}

@Override
public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
{
	if (event.startsWith("partytp"))
	{
		TP(event, npc, player, event);
	}

	return "";
}
@SuppressWarnings("deprecation")
public int getPartiesInside(int zoneId)//Calculating parties inside party area.
    {
        int i = 0;
        for (L2ZoneType zone : ZoneManager.getInstance().getAllZones())
            if (zone.getId() == zoneId)
            {
                for (L2Character character : zone.getCharactersInside().values())
                    if (character instanceof L2PcInstance && (!((L2PcInstance) character).getClient().isDetached()) && 
                    		((L2PcInstance) character).getParty() != null && 
                    		((L2PcInstance) character).getParty().isLeader((L2PcInstance) character))
                        i++;
            }
        return i;
    } 
@SuppressWarnings("deprecation")
public int getPlayerInside(int zoneId)//Calculating players inside party area.
    {
        int i = 0;
        for (L2ZoneType zone : ZoneManager.getInstance().getAllZones())
            if (zone.getId() == zoneId)
            {
                for (L2Character character : zone.getCharactersInside().values())
                    if (character instanceof L2PcInstance && (!((L2PcInstance) character).getClient().isDetached()))
                        i++;
            }
return i;
} 
private boolean PartyItemsOk(L2PcInstance player)
//Checks if all party members have the item in their inventory.
//If pt member has not enough items, party not allowed to enter.
{

	try
	{
		for (L2PcInstance member : player.getParty().getPartyMembers())
		{
			if (member.getInventory().getItemByItemId(ItemConsumeId) == null)

			{
				player.sendMessage("Your party member "+member.getName()+" does not have enough items.");
				return false;
			}
			if (member.getInventory().getItemByItemId(ItemConsumeId).getCount() < ItemConsumeNum)
			{
				player.sendMessage("Your party member "+member.getName()+" does not have enough items.");
				return false;
			}
		}
		return true;

	}
	catch (Exception e)
	{
		player.sendMessage("Something went wrong try again.");
		return true;
	}
}

private void proccessTP(L2PcInstance player) // Teleporting party members to zone
{
	for (L2PcInstance member : player.getParty().getPartyMembers())
	{
		member.teleToLocation(locationX, locationY, locationZ);//Location X, Y ,Z
	}
}
private void TP(String event, L2Npc npc, L2PcInstance player, String command) // Teleport player & his party
{

	try
	{
		L2Party pt = player.getParty();
		if (pt == null)
		{
			player.sendMessage("You are not currently on party.");
			return;
		}
		if (!pt.isLeader(player))
		{
			player.sendMessage("You are not party leader.");
			return;
		}
		if (pt.getMemberCount() < MinPtMembers)
		{
			player.sendMessage("You are going to need a bigger party " +
					"in order to enter party area.");
			return;
		}
		if (!PartyItemsOk(player))
		{
			return;
		}
		else
		{
			proccessTP(player);
			for (L2PcInstance ppl : pt.getPartyMembers())
			{
				if (ppl.getObjectId() != player.getObjectId())//Dont send this message to pt leader.
				{
					ppl.sendMessage("Your party leader asked to teleport on party area!");//Message only to party members
				}
				ppl.sendMessage(ItemConsumeNum+" "+ItemName+" have been dissapeared.");//Item delete from inventory message
				ppl.getInventory().destroyItemByItemId("Party_Teleporter", ItemConsumeId, ItemConsumeNum, ppl, true);//remove item from inventory
				ppl.sendPacket(new InventoryUpdate());//Update
				ppl.sendPacket(new ItemList(ppl, false));//Update
				ppl.sendPacket(new StatusUpdate(ppl));//Update

			}
			//Sends message to party leader.
			player.sendMessage(ItemConsumeNum*player.getParty().getMemberCount()+" "+ItemName+" dissapeard from your party.");
		}

	}
	catch (Exception e)
	{
		player.sendMessage("Something went wrong try again.");
	}
}

@Override
public String onFirstTalk(L2Npc npc, L2PcInstance player)
{
	final int npcId = npc.getNpcId();
	if (player.getQuestState(getName()) == null)
	{
		newQuestState(player);
	}
	if (npcId == npcid)
	{
		String html = HtmCache.getInstance().getHtm(player.getHtmlPrefix(), htm);
		html = html.replaceAll("%player%", player.getName());//Replaces %player% with player name on html
		html = html.replaceAll("%itemname%", ItemName);//Item name replace on html
		html = html.replaceAll("%price%", player.getParty()!=null ? ""+ItemConsumeNum*player.getParty().getMemberCount()+"": "0");//Price calculate replace
		html = html.replaceAll("%minmembers%", ""+MinPtMembers);//Mimum entry party members replace
		html = html.replaceAll("%allowed%", isAllowedEnter(player) ? "<font color=00FF00>allowed</font>" :
			"<font color=FF0000>not allowed</font>");//Condition checker replace on html
		html = html.replaceAll("%parties%", ShowPartiesInside ? "<font color=FFA500>Parties Inside: "+getPartiesInside(ZoneId)+"</font><br>": "");//Parties inside
		html = html.replaceAll("%players%", ShowPlayersInside ? "<font color=FFA500>Players Inside: "+getPlayerInside(ZoneId)+"</font><br>": "");//Players Inside
		NpcHtmlMessage npcHtml = new NpcHtmlMessage(0);
		npcHtml.setHtml(html);
		player.sendPacket(npcHtml);
	}
	return "";
}
private boolean isAllowedEnter(L2PcInstance player) //Checks if player & his party is allowed to teleport.
{
	if (player.getParty() != null)
	{
		if( player.getParty().getMemberCount() >= MinPtMembers && PartyItemsOk(player))//Party Length & Item Checker
		{
			return true;
		}
		else 
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}
public static void main(final String[] args)
{
	new PartyTeleporter(-1, PartyTeleporter.class.getSimpleName(), "custom");
	System.out.println("Party Teleporter by `Heroin has been loaded successfully!");
}
}

 

2.Create a new htm file on data/scripts/custom/PartyTeleporter/1.htm

 

Paste this code ont it:

<html>
<title>%player%</title>
<body><center>
<img src="L2UI_CH3.herotower_deco" width=256 height=32></center><br>
You have to be a party leader in order to ask from me to teleport you and your party inside party area.<br>
Minimum Number Of Party Members: <font color="LEVEL">%minmembers%</font>.<br>
You are currently %allowed% to enter party area with your party.<br>
Party Teleport will cost you total: <font color="LEVEL">%price% %itemname%</font><br>
<center>
%parties%
%players%

<table><tr>
<td><button value="Teleport Me & My Party!" action="bypass -h Quest PartyTeleporter partytp" width=180 height=21 back="L2UI_CT1.Button_DF_Down" fore="L2UI_CT1.Button_DF"></td>
</tr></table>


<br><br>
<center>
<img src="L2UI_CH3.herotower_deco" width=256 height=32></center>
</body></html>

 

3. Add script on scripts.cfg file:

custom/PartyTeleporter/PartyTeleporter.java

 

4. Run this query on your database or install the NPC by yourself.

INSERT INTO `npc` VALUES ('36650', '13173', 'PartyTeleporter', '1', 'MaxCheaters.com', '1', 'LineageNPC.clear_npc', '8.00', '19.00', '85', 'male', 'L2Npc', null, null, null, null, null, '40', '43', '30', '21', '20', '20', '0', '0', null, null, null, null, '230', '1', '0', '333', '0', '0', '0', '60.00000', '120.00000', '1', '1', '0', '0');

 

How to Modify:

 

Check Variables on code:

private static final int npcid = 36650; // npc id
//-------------------------------------
//Teleport Location Coordinates X,Y,Z.
//Use /loc command in game to find them.
private static final int locationX = -56742; // npc id
private static final int locationY = 140569; // npc id
private static final int locationZ = -2625; // npc id
//-------------------------------------
//-------------------------------------
// Select the id of your zone.
// If you dont know how to find your zone id is simple.
// Go to data/zones/(your zone file).xml and find your zone
// E.g: <zone name="dion_monster_pvp" id="6" type="ArenaZone" shape="NPoly" minZ="-3596" maxZ="0">
/**The id of your zone is id="6" */
/**---------------------------------------------------------------------------*/
/**WARNING: If your zone does not have any id or your location is not on any zone in data/zones/ folder, you have to add one by your self*/ // required to calculate parties & players
/**---------------------------------------------------------------------------*/
private static final int ZoneId = 155; //Here you have to set your zone Id
//-------------------------------------
private static final int MinPtMembers = 2; // Minimum Party Members Count For Enter on Zone.
private static final int ItemConsumeId = 57; // Item Consume id.
private static final int ItemConsumeNum = 100; // Item Consume Am.ount.
private static final boolean ShowPlayersInside = true; //If you set it true, NPC will show how many players are inside area.
private static final boolean ShowPartiesInside = true; //If you set it true, NPC will show how many parties are inside area.
//-------------------------------------
private static String htm = "data/scripts/custom/PartyTeleporter/1.htm"; //html location.

 

Credits & Idea: `Heroin

  • Upvote 1
Posted

First of all mine its totally different with totally different java and html code.

Secondly my code is consisted of only one script and one html.

 

p.s i am not even registered in l2jserver.com

 

Posted

First of all mine its totally different with totally different java and html code.

Secondly my code is consisted of only one script and one html.

 

p.s i am not even registered in l2jserver.com

 

main idea of yours? -party teleporter

main idea of FBIagent? -party teleporter

  • 3 weeks later...
Posted

help...

 

1. ERROR in \custom\PTTele\PTTele.java (at line 72)
        for (L2Character character : zone.getCharactersInside().values())
                                                                ^^^^^^
The method values() is undefined for the type Collection<L2Character>
----------
2. ERROR in \custom\PTTele\PTTele.java (at line 87)
        for (L2Character character : zone.getCharactersInside().values())
                                                                ^^^^^^
The method values() is undefined for the type Collection<L2Character>
----------
2 problems (2 errors)The method getAllZones() from the type com.l2jserver.gamese
rver.instancemanager.ZoneManager is deprecated
The method values() is undefined for the type java.util.Collection<com.l2jserver
.gameserver.model.actor.L2Character>
The method getAllZones() from the type com.l2jserver.gameserver.instancemanager.
ZoneManager is deprecated
The method values() is undefined for the type java.util.Collection<com.l2jserver
.gameserver.model.actor.L2Character>
Failed executing script: C:\L2J-Server\game\data\scripts\custom\PTTele
\PTTele.java. See PTTele.java.error.log for details.

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