A Code that gives NPE and dont know why ( Incorrect code to)

Find the proper support area, Saga-Version.
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
Akken
Posts: 4
Joined: Sun Jul 10, 2011 9:48 pm

A Code that gives NPE and dont know why ( Incorrect code to)

Post by Akken »

If you want to receive support we need this info to help you properly.
» Find Revision
L2J Revision Last IL:
L2JDP Revision Last IL:

Code: Select all

  ### Eclipse Workspace Patch 1.0    #P TEST_GAMESERVER    Index: java/net/sf/l2j/Config.java    ===================================================================    --- java/net/sf/l2j/Config.java (revision 4699)    +++ java/net/sf/l2j/Config.java (working copy)    @@ -881,6 +881,11 @@         public static boolean L2JMOD_WEDDING_SAMESEX;         public static boolean L2JMOD_WEDDING_FORMALWEAR;         public static int L2JMOD_WEDDING_DIVORCE_COSTS;    +        +    //Specific weapon critical raise    +    public static boolean ALLOW_SPECIFIC_WEAP_CRIT_RAISE;    +    public static int MAGIC_CRITICAL_WEAPON_ID;    +    public static int PHYSIC_CRITICAL_WEAPON_ID;              // Packet information         /** Count the amount of packets per minute ? */    @@ -1859,6 +1864,11 @@                     L2JMOD_WEDDING_FORMALWEAR               = Boolean.parseBoolean(L2JModSettings.getProperty("WeddingFormalWear", "True"));                     L2JMOD_WEDDING_DIVORCE_COSTS            = Integer.parseInt(L2JModSettings.getProperty("WeddingDivorceCosts", "20"));         +                    +                //Specific critical raise    +               ALLOW_SPECIFIC_WEAP_CRIT_RAISE           = Boolean.parseBoolean(L2JModSettings.getProperty("AllowSpecificWeapCrit","False"));    +               MAGIC_CRITICAL_WEAPON_ID                 = Integer.parseInt(L2JModSettings.getProperty("MagicCriticalId","65535"));    +               PHYSIC_CRITICAL_WEAPON_ID                = Integer.parseInt(L2JModSettings.getProperty("PhysicCriticalId","65535"));                     if (TVT_EVENT_PARTICIPATION_NPC_ID == 0)                     {                         TVT_EVENT_ENABLED = false;    Index: java/config/l2jmods.properties    ===================================================================    --- java/config/l2jmods.properties      (revision 4699)    +++ java/config/l2jmods.properties      (working copy)    @@ -37,6 +37,14 @@     # Specified reward item rnd qty     ChampionRewardItemQty = 1         +#Allow Specific weapon Increase    +#Critical/Magic critical damages    +#Allow Or Dissallow This function    +AllowSpecificWeapCrit = False    +#Choose item Id For Magic Critical    +MagicCriticalId = 65535    +#Choose item Id For Physical Critical    +PhysicCriticalId = 65535     #---------------------------------------------------------------     # Wedding System (by evill33t)                         #---------------------------------------------------------------    Index: java/net/sf/l2j/gameserver/skills/Formulas.java    ===================================================================    --- java/net/sf/l2j/gameserver/skills/Formulas.java     (revision 4699)    +++ java/net/sf/l2j/gameserver/skills/Formulas.java     (working copy)    @@ -27,6 +27,7 @@     import net.sf.l2j.gameserver.instancemanager.SiegeManager;     import net.sf.l2j.gameserver.model.Inventory;     import net.sf.l2j.gameserver.model.L2Character;    +import net.sf.l2j.gameserver.model.L2ItemInstance;     import net.sf.l2j.gameserver.model.L2SiegeClan;     import net.sf.l2j.gameserver.model.L2Skill;     import net.sf.l2j.gameserver.model.L2Summon;    @@ -1156,8 +1157,19 @@                            }                    }         -    -               if (crit) damage += attacker.getCriticalDmg(target, damage);    +           L2ItemInstance pramatia = ((L2PcInstance) attacker).getInventory().getPaperdollItem(9);    +               if (crit)    +               {    +                       if (Config.ALLOW_SPECIFIC_WEAP_CRIT_RAISE)    +                                       {    +                                        if(pramatia.getItemId() == Config.PHYSIC_CRITICAL_WEAPON_ID )    +                   if(attacker.isBehindTarget())    +                                                damage = damage + 2 + attacker.getCriticalDmg(target, damage);    +                                        else    +                                                damage += attacker.getCriticalDmg(target, damage);    +                                       }    +                       else    +                               damage += attacker.getCriticalDmg(target, damage);    +               }                    if (shld && !Config.ALT_GAME_SHIELD_BLOCKS)                    {                            defence += target.getShldDef();    @@ -1326,7 +1338,21 @@                                    }                            }                    }    -               else if (mcrit) damage *= 4;    +                  +               L2ItemInstance pramatia = ((L2PcInstance) attacker).getInventory().getPaperdollItem(9);    +               if (mcrit)    +               {    +                       if (Config.ALLOW_SPECIFIC_WEAP_CRIT_RAISE)    +                       {    +                               if(pramatia.getItemId() == Config.MAGIC_CRITICAL_WEAPON_ID)    +                      if (attacker.isBehindTarget())    +                                       damage *= 4;    +                               else    +                                       damage *= 2;    +                                          +                       }    +                       else    +                               damage *= 2;    +               }                         // Pvp bonusses for dmg                    if((attacker instanceof L2PcInstance || attacker instanceof L2Summon)
Hello a friend of mine just created this code:

i added this but it gives x44444 dmgs and also it gives hit on every side

what i want from the code?

if attacker hits target and target is behind (like backstab) to give +1000 more dmg than the current
User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 7008
Joined: Tue Aug 11, 2009 3:36 am

Re: A Code that gives NPE and dont know why ( Incorrect code

Post by Zoey76 »

Possible problems:
  • ClassCastException: not all attackers are L2PcInstance.
  • NullPointerException 1: not all attackers has inventory, if you fix ClassCastException all will be L2PcInstance and they should have inventory.
  • NullPointerException 2: not all attackers has a weapon equipped.
Pseudocode:

Code: Select all

 ...L2ItemInstance pramatia = null;if (attacker instanceof L2PcInstance){    pramatia = ((L2PcInstance) attacker).getInventory().getPaperdollItem(9);}if (crit){   if ((pramatia != null) && Config.ALLOW_SPECIFIC_WEAP_CRIT_RAISE)   {       ...   }   else   {       damage += attacker.getCriticalDmg(target, damage);   }}... 
Anyway the right way should be, if the custom mod is enabled then try to get the weapon.
You should post patch in a diff file since forum breaks tab indentation.

PS: it's my post number 666 :twisted:
Powered by Eclipse 4.34 🌌 | Eclipse Temurin 21 ☕ | MariaDB 11.3.2 🗃️ | L2J Server 2.6.3.0 - High Five 🚀

🔗 Join our Discord! 🎮💬
Akken
Posts: 4
Joined: Sun Jul 10, 2011 9:48 pm

Re: A Code that gives NPE and dont know why ( Incorrect code

Post by Akken »

Zoey76 wrote:Possible problems:
  • ClassCastException: not all attackers are L2PcInstance.
  • NullPointerException 1: not all attackers has inventory, if you fix ClassCastException all will be L2PcInstance and they should have inventory.
  • NullPointerException 2: not all attackers has a weapon equipped.
Pseudocode:

Code: Select all

 ...L2ItemInstance pramatia = null;if (attacker instanceof L2PcInstance){    pramatia = ((L2PcInstance) attacker).getInventory().getPaperdollItem(9);}if (crit){   if ((pramatia != null) && Config.ALLOW_SPECIFIC_WEAP_CRIT_RAISE)   {       ...   }   else   {       damage += attacker.getCriticalDmg(target, damage);   }}... 
Anyway the right way should be, if the custom mod is enabled then try to get the weapon.
You should post patch in a diff file since forum breaks tab indentation.

PS: it's my post number 666 :twisted:
actually theres a problem on attack it gives lol dmg example i hit without the mod 1900critical and when i enable the target hets 100++ k so if you can to give me a corrected code of formula.java,

that what i need it is , if attacker hits the target from behind then targets get +1000 more dmg from the default..
example:
Attacker hits for 1200 critical, if mod enabled then target will get 2200
User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 7008
Joined: Tue Aug 11, 2009 3:36 am

Re: A Code that gives NPE and dont know why ( Incorrect code

Post by Zoey76 »

Code: Select all

if (Config.ALLOW_SPECIFIC_WEAP_CRIT_RAISE && (pramatia.getItemId() == Config.PHYSIC_CRITICAL_WEAPON_ID) && attacker.isBehindTarget()){    damage += (attacker.getCriticalDmg(target, damage) + Config.PHYSIC_CRITICAL_BONUS);}else{    damage += attacker.getCriticalDmg(target, damage);}
You'll need to create following configuration variable Config.PHYSIC_CRITICAL_BONUS.
Powered by Eclipse 4.34 🌌 | Eclipse Temurin 21 ☕ | MariaDB 11.3.2 🗃️ | L2J Server 2.6.3.0 - High Five 🚀

🔗 Join our Discord! 🎮💬
Akken
Posts: 4
Joined: Sun Jul 10, 2011 9:48 pm

Re: A Code that gives NPE and dont know why ( Incorrect code

Post by Akken »

Zoey76 wrote:

Code: Select all

if (Config.ALLOW_SPECIFIC_WEAP_CRIT_RAISE && (pramatia.getItemId() == Config.PHYSIC_CRITICAL_WEAPON_ID) && attacker.isBehindTarget()){    damage += (attacker.getCriticalDmg(target, damage) + Config.PHYSIC_CRITICAL_BONUS);}else{    damage += attacker.getCriticalDmg(target, damage);}
You'll need to create following configuration variable Config.PHYSIC_CRITICAL_BONUS.

ye all you say is correct the shit is i only know to import codes, i dont know shit from java so a completed code will be appreciated, if not ok :/
User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 7008
Joined: Tue Aug 11, 2009 3:36 am

Re: A Code that gives NPE and dont know why ( Incorrect code

Post by Zoey76 »

Here is th patch for Formulas.java I hope you know how to use it:
You do not have the required permissions to view the files attached to this post.
Powered by Eclipse 4.34 🌌 | Eclipse Temurin 21 ☕ | MariaDB 11.3.2 🗃️ | L2J Server 2.6.3.0 - High Five 🚀

🔗 Join our Discord! 🎮💬
Akken
Posts: 4
Joined: Sun Jul 10, 2011 9:48 pm

Re: A Code that gives NPE and dont know why ( Incorrect code

Post by Akken »

Zoey76 wrote:Here is th patch for Formulas.java I hope you know how to use it:
yes thnx but i didnt tested yet if you got time just inform if it got the +1000 bonuses or else how i can make it?
Post Reply