Jump to content

Recommended Posts

Posted (edited)

Make a zone required party with minimum members for lucera.

 


package zones;

import java.util.Collection;
import java.util.Iterator;
import l2.gameserver.instancemanager.ReflectionManager;
import l2.gameserver.listener.zone.OnZoneEnterLeaveListener;
import l2.gameserver.model.Creature;
import l2.gameserver.model.Party;
import l2.gameserver.model.Player;
import l2.gameserver.model.Zone;
import l2.gameserver.network.l2.components.CustomMessage;
import l2.gameserver.network.l2.s2c.ExShowScreenMessage;
import l2.gameserver.scripts.ScriptFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PartyZone implements OnZoneEnterLeaveListener, ScriptFile {
	private static final Logger bEb = LoggerFactory.getLogger(PartyZone.class);
	private static final PartyZone bHe = new PartyZone();
	private static final String bHf = "PartyZone";
	private Object PartyInfo;

	public PartyZone() {
	}

	public void onLoad() {
		byte var1 = 0;
		Collection var2 = ReflectionManager.DEFAULT.getZones();
		Iterator var3 = var2.iterator();

		while(var3.hasNext()) {
			Zone var4 = (Zone)var3.next();
			if (var4.getParams().getBool("PartyZone", false)) {
				var4.addListener(bHe);
			}
		}

		if (var1 > 0) {
			bEb.info("PartyZone: added {} party zone(s).", Integer.valueOf(var1));
		}

	}

	public void onReload() {
		this.onShutdown();
		this.onLoad();
	}

	public void onShutdown() {
		Collection var1 = ReflectionManager.DEFAULT.getZones();
		Iterator var2 = var1.iterator();

		while(var2.hasNext()) {
			Zone var3 = (Zone)var2.next();
			if (var3.getParams().getBool("PartyZone", false)) {
				var3.removeListener(bHe);
			}
		}

	}

	public void onZoneEnter(Zone var1, Creature var2) {
		if (var2.isPlayer()) {
			Player var3 = var2.getPlayer();
			Party var4 = var3.getParty();
			if (var4 == null) {
				String var10 = (new CustomMessage("zone.services.PartyZone", var3, new Object[0])).toString();
				var3.sendPacket(new ExShowScreenMessage(var10, 10000, ExShowScreenMessage.ScreenMessageAlign.TOP_CENTER, false));
				var3.teleToClosestTown();
			}

			if (var3.getParty().getMemberCount() <= 4) {
				String var10 = (new CustomMessage("zone.services.PartyZone", var3, new Object[0])).toString();
				var3.sendPacket(new ExShowScreenMessage(var10, 10000, ExShowScreenMessage.ScreenMessageAlign.TOP_CENTER, false));
				var3.teleToClosestTown();
			}
		}

	}

	public void onZoneLeave(Zone var1, Creature var2) {
	}
}

 

Next you have to add this parameter in zone:         <set name="PartyZone" val="true" />

 

For example:

 

    <zone name="[primeval_peace1]" type="fun" >
            <coords loc="10408 -27395 -4290 -1290" />
            <coords loc="12065 -25334 -4290 -1290" />
            <coords loc="12223 -23159 -4290 -1290" />
            <coords loc="10424 -22340 -4290 -1290" />
            <coords loc="9566 -23131 -4290 -1290" />
            <coords loc="9290 -24261 -4290 -1290" />
        </polygon>
    </zone>

 

Make it like this:

 

    <zone name="[primeval_peace1]" type="fun" >

    <set name="PartyZone" val="true" />
            <coords loc="10408 -27395 -4290 -1290" />
            <coords loc="12065 -25334 -4290 -1290" />
            <coords loc="12223 -23159 -4290 -1290" />
            <coords loc="10424 -22340 -4290 -1290" />
            <coords loc="9566 -23131 -4290 -1290" />
            <coords loc="9290 -24261 -4290 -1290" />
        </polygon>
    </zone>

 

Then go to en string gameserver\data\string and add this line:

zone.services.PartyZone=You Are Not Currently In A Party With Minimum 5 Party Members So You Cannot Enter.

And this line to ru string gameserver\data\string:

zone.services.PartyZone=Вы не находитесь в партии с минимум 5 членами партии Так что вы не можете войти.

If you want to change the value of minimum players then you have to change the number 4 in this line in ext:

if (var3.getParty().getMemberCount() <= 4) {

 

DOWNLOAD EXT

 

This is a simple code i make it for my needs you can remake it as you want don't spam this topic.

Edited by • Punisher •
  • Thanks 2
Posted (edited)

I don't think deleting my reply is by any means the right thing to do here. I am not spamming, I am expressing my opinion and helping/warning admins that might want to use a party zone in their own server.

Your code works, I am just saying how to improve it, I did not force you to do it but someone might want my opinion.

 

Reposted:

 

 

Variable naming is terrible.

byte var1 = 0;

This will always be 0,

 

since you don't check if the players leave the party while within the zone, a simple check in the teleporter would be enough. This whole code can be replaced by 1 line of code.

 

In addition to that, the method onZoneEnter, can be made like so:

 

    public void onZoneEnter(Zone zone, Creature creature)
    {
        if (creature.isPlayer() && (creature.getPlayer().getParty() == null || creature.getParty().getMembers().size() < 5))
        {
            creature.getPlayer().sendMessage("You are not in a party that consists of 5 or more members, you cannot enter the party zone.");
            creature.getPlayer().teleToClosestTown();
        }
    }

 

 

Generally, the idea to teleport players back, the moment they teleport in the zone is very very bad and will result in a laggy, long teleport or even some critical errors.

Edited by An4rchy
Posted (edited)

First of all your code is not working and as i say in description i make it for my needs if you can make it better you can reshare it this maybe helps more than to judge my code when you dont give any solution here, a simple teleport is not better since you can walk into the zone!

Edited by • Punisher •
Posted (edited)

Why would someone walk all the way to the Party zone? :D

 

But even if he did, a party zone that needs 3 people to enter should have difficult to kill mobs, therefore someone going there solo (by walking) would achieve nothing for him other than wasting his time.

 

Anyway, I just pointed out how to improve your code, perhaps you should implement my improvements in your other codes too. The logic ‘if it works, it’s ok’ is not quite right and you should consider all possibilities when you code something.

Edited by An4rchy
Posted
16 hours ago, An4rchy said:

I don't think deleting my reply by any means the right thing to do here. I am not spamming, I am expressing my opinion and helping/warning admins that might want to use a party zone in their own server.

Your code works, I am just saying how to improve it, I did not force you to do it but someone might want my opinion.

 

Reposted:

Variable naming is terrible,.


byte var1 = 0;

This will always be 0,

 

You really point out var name to an amateur person who have no idea what java is? We are in 2020 and sharing 10 lines of code which is against rules while deleting other's comment or chat ban them if the post does not contain "Thanks ! Very useful code". 

 

So again don't bother.

Posted (edited)
10 minutes ago, Elfocrash said:

Tbh the code looks like it's been decompiled, there is no way he wrote this. Not because he is bad but because there is no way a human being actually writes code like this.

 

  • The static final field names look obfuscated
  • The Object PartyInfo makes it seem like there was a class named PartyInfo that he didn't have access to
  • This collection var and iterator is what the IL code will be converted to in a stream().foreach if I'm not wrong
  • var1, var2, var3, var4 are decompiling names
  • The empty public constructor 

Lucera doesnt give you source the only you can do is to create extensions with intelij or the IDEA program you are using in my subject (im not professional java coder) i just take some examples and i make it thats all nothing special ! 

Edited by Dragic
Posted
4 minutes ago, Elfocrash said:

I know it doesn't give you source but it doesn't force you to name the fields or write the implementations in some special way. I've written code for Lucera's plugin engine before and they look like normal code with some listeners

I would say the same thing if I were you but we are not all on the same level :laughing:

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