Jump to content
  • 0

PK Cleaner NPC Problem


~~Darius~~

Question

Recommended Posts

  • 0

change line:

if(player.getInventory().getItemByItemId(Config.PK_CLEAN_ID).getCount() < Config.PK_CLEAN_PRICE)

to:

L2ItemInstance item = player.getInventory().getItemByItemId(Config.PK_CLEAN_ID);
if(item != null && item.getCount() < Config.PK_CLEAN_PRICE)

Link to comment
Share on other sites

  • 0

[PL] teraz  dziala ale choc kiedy mam pk i nie mam itema zeruje mi pk a gdy nie mam pk i klikne zeby wyczyscilo caly czas  mi pisze "Your karma cleaned, continue to play"

i mam tez :

http://s6.ifotos.pl/img/Przechwyt_rqrweep.PNG

 

[en]

when i no have item and have pk  npc clean mine pk

and  when no have pk  and click "clean" i have messesage

"Your karma cleaned, continue to play"

and i have :

http://s6.ifotos.pl/img/Przechwyt_rqrweep.PNG

how to fix it?

 

 

Link to comment
Share on other sites

  • 0

First of all , i really love that

 

/**

* Author: Leki

*/

 

Good job Leki with your share .

Anyway , keeping onpost , all gonna work for sure , i read the whole code and didn't found something wrong . Maybe there should be the problem :

 

 else if(player.getKarma() == 0)
                                player.sendMessage("You don't have any karma, i cannot change it any lower!");
                else // here should be added another if ? Not sure 

As Leki said , " I don't know H5 core as good as interlude ". The best developers for hi5 that i know are from "L2jHidden" project .You should contact them.

 

Good luck in fixing your problem .

Link to comment
Share on other sites

  • 0

add the {} to the else block

before

                               player.setKarma(0);

{

after

                                player.sendMessage("Your karma cleaned, continue to play!"); 

}

add an else before the super(...) call, we dont need it if it was CleanPK

 

add "final" to

L2ItemInstance item = player.getInventory().getItemByItemId(Config.PK_CLEAN_ID);

this is not an error but will have better performance

Link to comment
Share on other sites

  • 0

[pl] Vampir i tak choc nie mam itemka a mam pk czysci mi to pk :/ choc zmienilem znak

 

masz caly kod:

http://pastebin.com/8C2A3PgM - teraz bedzie dzialac :)

Link to comment
Share on other sites

  • 0
http://pastebin.com/fAe11P4Z masz, nie mam pojecia czemu zrobilem tak duzo bledow w tak malym kodzie, chyba mialem mozg wylaczony, teraz bedzie spoko :)
Link to comment
Share on other sites

  • 0

As wrote vampir, if you haven't the item, it tries to find setCount from a null item, so you will have a NPE in case you haven't the item and try to speak with the PK remover dude. And that will happen on every chronicle, even IL, until you edited method.

 

"final" keyword doesn't impact performance at all, but it's a security for coder. He knows this stuff won't be edited by future edition. You could drop entire final keys from the code with no change. You're right to use "final" when you can, cause it's a good use.

 

A contrario, "static" keyword improves performance, as that method/variable will be shared amongst instances of that class (case of loggers, for example : you use static, only one logger is created for all instances). It means too if you edited (in case of a variable) it, it will affect all instances. So it must be used only when you need it.

 

Just saying.

 

About

super.onBypassFeedback(player, command);

, generally it's with a "else" before. Like that even if that npc hasn't the command, he inherits of others commands "in case of".

 

Finaly, L2PcInstance got a useful check you're using, but you use it bad.

 

					if (!player.destroyItemByItemId("SevenSigns", stoneType, stonesNeeded, this, true))
					return;

 

destroyItemByItemId returns a boolean which mean you can drop the previous check about count. You get ride of one check, and of the NPE in same time and reduces code.

 


 

@Override
public void onBypassFeedback(L2PcInstance player, String command)
{
if (command.startsWith("CleanPK"))
{
	if(player.destroyItemByItemId("CleanKarma", Config.PK_CLEAN_ID, Config.PK_CLEAN_PRICE, this, true))
	{
		player.setKarma(0);
		player.sendMessage("Your karma is cleaned.");       
	}
	else
		player.sendMessage("You don't have enough required items.");
}
else 
	super.onBypassFeedback(player, command);
}

Link to comment
Share on other sites

  • 0

[pl]dobra wszystko  dziala thx Vampir i sorry ze ci zawracalem przyslowiowa dupe :P tylko mi wyskakuje gdy nacisne clean "L2PKCleanerInstance:

Unkown NPC bypass: "cleanPK" npcid: 9999" ale to chyba nic waznego. aa ps moge z 1 sprawa do ciebie na PM ?

Link to comment
Share on other sites

  • 0

"final" keyword doesn't impact performance at all

they do, since you have a var that can only de intialized once, the VM can use it read-only, and that will increase the performance.

 

[...] declaring a final field helps the optimizer make better optimization decisions, because if the compiler knows the field's value will not change, it can safely cache the value in a register.

http://www.ibm.com/developerworks/java/library/j-jtp1029/index.html

 

The revised memory model proposed by JSR 133 includes special provisions for final fields, provisions that are absent from the existing specification. Newer VMs already implement this specification, and treat final fields accordingly. Because final fields are assigned exactly once, aggressive optimizations in a multithreaded context become possible. Specifically, a field doesn't need to be ever reloaded, since its value is guaranteed never to change.

http://renaud.waldura.com/doc/java/final-keyword.shtml

 

Example of Strings differences (final/ not final). nothing to do with our case, but still a relation between "final" and "performance"

http://www.coderanch.com/t/518466/Performance/java/Compiler-optimization-final-variables

 

 

This is a minimal impove. And there are things that can give a lot more than this (for example direct access and not getters/setters, inside the class) or use C++. But still impact on performance

Link to comment
Share on other sites

  • 0

In your own IBM link, you can read

While performance is not a good reason to declare a class or method as final, there are still good reasons to sometimes write final classes.

 

Seems only variables worth to put final. I don't believe you gain something like even 1%, the main point is immutation (or whatever it's named).

Link to comment
Share on other sites

  • 0

I agree, so best thing is to make variables final if they are outside methods, otherwise it's not that important and code isnt readable that well as before.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Posts

    • L2 Insignia High Five 20x MID SERVER FOCUSED ON OLYMPIAD | PVP | AUTOFARM       OPEN BETA TEST SERVER 3 MAY 2024   GRAND OPENING 10 MAY 2024    Rates: 📜 XP/SP 20x | Spoil 15x | Drop 10x | Adena 10x 📜     Server Features: 🔥 No Olf-T Shirt, No big over-enchant, No over-power Donate 🔥 🔥 VIP Gold Color Chat, Unique Olympiad Extra Points Engine, GvG Event 🔥 🔥 Auto-Farm, LoA and DV scheduled PvP Zone, Calendar Daily Reward 🔥 🔥 Castle Instance, Solo Instance, PvP Solo Rift, Dress me system, Adena Boxes 🔥        Website: https://www.l2insignia.com  Discord: https://discord.com/invite/yEgsrHn2hQ      
    • I am selling the essence project which includes versions 388 and 439 that have been running for over 2 years or (447 as custom PVP like Pride). I have a test server for you to test them out. If you are really interested in it then contact my seller at discord: kiwi7106. Price: 4000 Euro P/s: This is a project that I have spent a lot of money and time developing, so if you are not interested in it, please get out of this topic, thank you. P/s 2: If you find the price too expensive, it's best to skip this article and find another project and don't comment negatively on my topic, thank you.
    • Someone ask me for this, it should work on any client that has Kamael race, preview:     Installation - there are two ways to install depending on how you want to use it:   Method 1: If you want to completely replace the original, do:   Copy all lines from your armorgrp to Notepad++, press Ctrl+H, check the "match whole word" option and replace:   kamael.Mkamael_m000_w_ad00   by:   AvengersKamaelWings.Avengers_MKamael_m001_w_ad00   Then replace:   MKamael.Mkamael_m000_t00_w   by:   AvengersKamaelWings.MKamael_m001_t00_w   Now repeat the same process with the female, replace:   kamael.Fkamael_m000_w_ad00   by:   AvengersKamaelWings.Avengers_FKamael_m001_w_ad00   Then replace:   FKamael.Fkamael_m000_t00_w   by:   AvengersKamaelWings.FKamael_m001_t00_w   You're done, paste everything back into File Edit and save!   Method 2: If you only want to replace in specific sets, execute the above process only on the armorgrp of those sets.   Repack by: AvengersTeamBr Password: LadrãoDeFrango      
  • Topics

×
×
  • Create New...