Jump to content

Recommended Posts

Posted

DISCLAIMER: I know this code is not complete ,  but it's something to begin with for those who want to create this specific event (if they find it useful) saving them some time. It ain't much but it's free.


LuckyBoxNPC.java

LuckyChests.java

NPC XML

 

 

Video

Posted
2 hours ago, LordPanic said:

DISCLAIMER: I know this code is not complete ,  but it's something to begin with for those who want to create this specific event (if they find it useful) saving them some time. It ain't much but it's free.


LuckyBoxNPC.java

LuckyChests.java

NPC XML

 

 

Video

 

Ok let's start.

 

1. You're doing an iteration over 

private final List<Npc> _boxList = new ArrayList<>();	

which mean ArrayList<> is not the proper type. Use CopyOnWriteArrayList for thread safety reasons.

 

2. This is completely useless, also you're doing double "setTarget"

if(this.isDead()) 
{
		player.setTarget(player);
		player.setTarget(null);
		return;
}

 (Also this is needless)

 

3. Why initialize a variable using 0 and then add the value again? Why no do it directly?

int chanceToDie = 0;			
chanceToDie = Rnd.get(100);

 

4. Why this check exists in both then and else case?

LuckyChests.getInstance().removeluckyBox(this.getObjectId());

 

Posted
1 hour ago, Kara said:

 

Ok let's start.

 

1. You're doing an iteration over 

private final List<Npc> _boxList = new ArrayList<>();	

which mean ArrayList<> is not the proper type. Use CopyOnWriteArrayList for thread safety reasons.

 

lmao why use this CopyOnWriteTrash when his code doesn't seem to have concurrency issues?

ArrayList is the way to go for casual codes like this his list rarely ever gets populated

Posted
6 hours ago, xdem said:

lmao why use this CopyOnWriteTrash when his code doesn't seem to have concurrency issues?

ArrayList is the way to go for casual codes like this his list rarely ever gets populated

Didnt you read? Its not completed. Image write this code and remove element while is reading

Posted

Thanks for sharing. If you wrote this code, could you explain your thought about this line?

doCast(SkillTable.getInstance().getInfo(4143, Math.min(10, Math.round(4143 / 10))));

 

i mean the 2nd parameter of getInfo method. There isn't any dynamic data there and it will always return 10 as level. Whats its purpose?

Posted (edited)
9 hours ago, Kara said:

 

Ok let's start.

 

1. You're doing an iteration over 

private final List<Npc> _boxList = new ArrayList<>();	

which mean ArrayList<> is not the proper type. Use CopyOnWriteArrayList for thread safety reasons.

 

Nope it's fine this is the reason why i use Iterator to begin with. For example this one will lead to CME

public void removeluckyBox(int boxid) {
		for(Npc mob : _boxList) {
			if(mob.getObjectId() == boxid) {							
				_boxList.remove(mob);
				Broadcast.announceToOnlinePlayers("[Lucky Chest]: ["+_boxList.size()+"] left.", true);				
			}			
			//TODO if(_boxList.isEmpty()){ teleport players back and end the event }
		}		
	}

 

Compared to:

public void removeluckyBox(int boxid) {
		for(Iterator<Npc> iterator = _boxList.iterator(); iterator.hasNext();) {
			Npc mob = iterator.next();
			if(mob.getObjectId() == boxid) {							
				iterator.remove();
				Broadcast.announceToOnlinePlayers("[Lucky Chest]: ["+_boxList.size()+"] left.", true);				
			}			
			//TODO if(_boxList.isEmpty()){ teleport players back and end the event }
		}		
	}

 

9 hours ago, Kara said:

 

2. This is completely useless, also you're doing double "setTarget"

if(this.isDead()) 
{
		player.setTarget(player);
		player.setTarget(null);
		return;
}

 

True i guess there is a more effective way to just ignore completely players who target the dead box's. This is the best i could figure out at that time. Im sure there is a packet requestcancelmytarget or whatever to do it the "right" way.

 

9 hours ago, Kara said:

 

 

3. Why initialize a variable using 0 and then add the value again? Why no do it directly?

int chanceToDie = 0;			
chanceToDie = Rnd.get(100);

 

Obviously i could Rnd.get(100) < 50 w.o variables to begin with. I dont even know why i didnt change it.
 

 

9 hours ago, Kara said:

4. Why this check exists in both then and else case?

LuckyChests.getInstance().removeluckyBox(this.getObjectId());

 

True i dont know why i ignored this one.

  

22 minutes ago, melron said:

Thanks for sharing. If you wrote this code, could you explain your thought about this line?

doCast(SkillTable.getInstance().getInfo(4143, Math.min(10, Math.round(4143 / 10))));

 

i mean the 2nd parameter of getInfo method. There isn't any dynamic data there and it will always return 10 as level. Whats its purpose?

I did change it on source forgot to change it to pastebin aswell and yes u are right , just put the 10 which is the lvl of the skill

 

Thanks for  pointing out the mistakes , i will fix them.

Edited by LordPanic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • TG Support: https://t.me/buyingproxysup | Channel: https://t.me/buyingproxycom Discord support: #buyingproxy | Server: Join the BuyingProxy Discord Server!  Create your free account here
    • PERFECT PERSPECTIVE IS ALMOST ALWAYS A DEATH SENTENCE ▪ Think if the document lies perfectly flat and everything is “level” it’ll be fine? Most of the time, that’s exactly what gives away the fake. Real smartphones, especially wide-angle cameras, always add natural distortions: - Slight warping at the edges of the document - Perspective distortions in the corners - Light curvature of the plane due to distance and shooting angle When everything is perfectly flat and geometrically flawless — algorithms and verifiers immediately recognize a “staged scene.” ▪ A genuine shot is never mathematically perfect. It’s these small lens distortions that make the frame look alive and believable.  Want perspective that won’t raise questions even from the most demanding verifiers? Write to us — we’ll create geometry that looks like it was shot with a real phone in real conditions. › TG: @mustang_service_ms ( https:// t.me/ mustang_service_ms ) › Channel: Mustang Service ( https:// t.me/ +JPpJCETg-xM1NjNl ) #documents #drawing #perspective #editing #geometry
    • Gemini Pro 18 Month Personal Gmail Upgrade Available We are now accepting new orders for Gemini Pro + Google One AI Pro 18 Month Plan.   Plan Details: ✅ 18 Months Validity ✅ Upgrade on Your Personal Gmail ✅ 5TB Google One Storage ✅ Gemini Pro / Google AI Pro Access ✅ Veo 3, NotebookLM, Google AI Features ✅ Family Sharing Support where available ✅ Fast Delivery: 10 minutes to 24 hours ✅ 24/7 KloudItem Support   Price: $15 One Time Payment   Important: Stock is limited, so please check availability before ordering.   Order & Support: Order from KloudItem or contact us through our official support channel. ------------------------------------------- CONTACT Order Here: BUY GEMINI PRO Email: support@klouditem.com Telegram Channel: @klouditemcom Telegram Support: klouditem All Contact: https://linktr.ee/klouditem Website: https://klouditem.com Hours: 24/7 -- Always online
    • Hello everyone,   A quick update from the Emerge team. The official launch of Emerge Eclipse x10 is just around the corner and we are currently finishing the final preparations to ensure a smooth and stable opening for all players. Our team has been working on performance improvements, network optimizations, and additional infrastructure to provide the best possible experience from day one.   🚀 Launch Date: 7 June 2026 🕕 Launch Time: 18:00 CET We would like to invite everyone to join our Discord community where all announcements, updates, events, and support information are posted first. 🌐 Website: https://l2emerge.com 💬 Discord: https://discord.gg/l2emerge Thank you for all the support and feedback during the preparation phase. We look forward to seeing both new and veteran Lineage II players on launch day. See you soon on Emerge!
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..