L2JMobius

Interlude NoblessMaster removes items before level check

Robotukas5 · 11 · 323

Offline Robotukas5

  • Heir
  • **
    • Posts: 24
Description

In the NoblessMaster script the required items are removed before checking the player level requirement

If a player has the required items but is below the required level for example level 78 or 79 when the requirement is 80 the script removes the items and then denies Noblesse

Expected behavior

The script should first check the level requirement and only remove items after the level condition is satisfied


Online Mobius

  • Distinguished King
  • *****
    • Posts: 19715
Description

In the NoblessMaster script the required items are removed before checking the player level requirement

If a player has the required items but is below the required level for example level 78 or 79 when the requirement is 80 the script removes the items and then denies Noblesse

Expected behavior

The script should first check the level requirement and only remove items after the level condition is satisfied

Put the script in an AI.
Tell it what it should be done.
Share the result with us.
:D


Online Naker

  • Count
  • *****
    • Posts: 450
  • Coding Dreams
Description

In the NoblessMaster script the required items are removed before checking the player level requirement

If a player has the required items but is below the required level for example level 78 or 79 when the requirement is 80 the script removes the items and then denies Noblesse

Expected behavior

The script should first check the level requirement and only remove items after the level condition is satisfied
If you give me the quest ID I will do it


Offline Robotukas5

  • Heir
  • **
    • Posts: 24
If you give me the quest ID I will do it
This is not a quest ID. It is your custom script (costum) NoblessMaster.
Path: data/scripts/custom/NoblessMaster/NoblessMaster.java
Bug: items are taken before the level requirement check. Please swap the order so level is checked first, then items are removed.


Online Naker

  • Count
  • *****
    • Posts: 450
  • Coding Dreams
This is not a quest ID. It is your custom script (costum) NoblessMaster.
Path: data/scripts/custom/NoblessMaster/NoblessMaster.java
Bug: items are taken before the level requirement check. Please swap the order so level is checked first, then items are removed.
Already are checked first level and then items...
1.- If player already is nobles
2.- If player have the level
3.- The items

Try with else if
Code: [Select]
### Eclipse Workspace Patch 1.0
#P L2J_Mobius_CT_0_Interlude
Index: dist/game/data/scripts/custom/NoblessMaster/NoblessMaster.java
===================================================================
--- dist/game/data/scripts/custom/NoblessMaster/NoblessMaster.java
+++ dist/game/data/scripts/custom/NoblessMaster/NoblessMaster.java
@@ -59,12 +59,12 @@
  return "1003000-3.htm";
  }
 
- if (player.getLevel() < NoblessMasterConfig.NOBLESS_MASTER_LEVEL_REQUIREMENT)
+ else if (player.getLevel() < NoblessMasterConfig.NOBLESS_MASTER_LEVEL_REQUIREMENT)
  {
  return "1003000-2.htm";
  }
 
- if (NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT > 0)
+ else if (NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT > 0)
  {
  if (getQuestItemsCount(player, NoblessMasterConfig.NOBLESS_MASTER_ITEM_ID) < NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT)
  {



Offline Robotukas5

  • Heir
  • **
    • Posts: 24
Already are checked first level and then items...
1.- If player already is nobles
2.- If player have the level
3.- The items

Try with else if
Code: [Select]
  Your patch does not solve the issue.

The problem is not the if/else structure.
The real issue is that takeItems() is executed before validating the level requirement.

Because of that, the required item is removed even if the player does not meet the level requirement, and noblesse is not granted.

The correct logic is to check the level first, and only then validate and remove the required items.
### Eclipse Workspace Patch 1.0
#P L2J_Mobius_CT_0_Interlude
Index: dist/game/data/scripts/custom/NoblessMaster/NoblessMaster.java
===================================================================
--- dist/game/data/scripts/custom/NoblessMaster/NoblessMaster.java
+++ dist/game/data/scripts/custom/NoblessMaster/NoblessMaster.java
@@ -59,12 +59,12 @@
  return "1003000-3.htm";
  }
 
- if (player.getLevel() < NoblessMasterConfig.NOBLESS_MASTER_LEVEL_REQUIREMENT)
+ else if (player.getLevel() < NoblessMasterConfig.NOBLESS_MASTER_LEVEL_REQUIREMENT)
  {
  return "1003000-2.htm";
  }
 
- if (NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT > 0)
+ else if (NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT > 0)
  {
  if (getQuestItemsCount(player, NoblessMasterConfig.NOBLESS_MASTER_ITEM_ID) < NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT)
  {

   Your patch does not solve the issue.

The problem is not the if/else structure.
The real issue is that takeItems() is executed before validating the level requirement.

Because of that, the required item is removed even if the player does not meet the level requirement, and noblesse is not granted.

The correct logic is to check the level first, and only then validate and remove the required items.


Offline Robotukas5

  • Heir
  • **
    • Posts: 24
Here is the correct and tested version.
It fixes the issue properly.
Feel free to use it if needed.
Code: [Select]

/**
 * @author Mobius
 */
public class NoblessMaster extends Script
{
    // Item
    private static final int NOBLESS_TIARA = 7694;

    private NoblessMaster()
    {
        addStartNpc(NoblessMasterConfig.NOBLESS_MASTER_NPCID);
        addTalkId(NoblessMasterConfig.NOBLESS_MASTER_NPCID);
        addFirstTalkId(NoblessMasterConfig.NOBLESS_MASTER_NPCID);
    }

    @Override
    public String onEvent(String event, Npc npc, Player player)
    {
        if (!NoblessMasterConfig.NOBLESS_MASTER_ENABLED)
        {
            return null;
        }

        switch (event)
        {
            case "noblesse":
            {
                if (player.isNoble())
                {
                    return "1003000-3.htm";
                }

                // Level check FIRST (prevents item loss)
                if (player.getLevel() < NoblessMasterConfig.NOBLESS_MASTER_LEVEL_REQUIREMENT)
                {
                    return "1003000-2.htm";
                }

                // Item check + take items AFTER level check
                if (NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT > 0)
                {
                    if (getQuestItemsCount(player, NoblessMasterConfig.NOBLESS_MASTER_ITEM_ID) < NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT)
                    {
                        player.sendMessage(NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT + " unit(s) of the item " + ItemData.getInstance().getTemplate(NoblessMasterConfig.NOBLESS_MASTER_ITEM_ID).getName() + " is/are required.");
                        return "1003000-4.htm";
                    }

                    takeItems(player, NoblessMasterConfig.NOBLESS_MASTER_ITEM_ID, NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT);
                }

                if (NoblessMasterConfig.NOBLESS_MASTER_REWARD_TIARA)
                {
                    giveItems(player, NOBLESS_TIARA, 1);
                }

                player.setNoble(true);
                player.sendPacket(QuestSound.ITEMSOUND_QUEST_FINISH.getPacket());
                return "1003000-1.htm";
            }
        }

        return null;
    }

    @Override
    public String onFirstTalk(Npc npc, Player player)
    {
        return "1003000.htm";
    }

    public static void main(String[] args)
    {
        new NoblessMaster();
    }
}



Online Naker

  • Count
  • *****
    • Posts: 450
  • Coding Dreams
Here is the correct and tested version.
It fixes the issue properly.
Feel free to use it if needed.
Code: [Select]

/**
 * @author Mobius
 */
public class NoblessMaster extends Script
{
    // Item
    private static final int NOBLESS_TIARA = 7694;

    private NoblessMaster()
    {
        addStartNpc(NoblessMasterConfig.NOBLESS_MASTER_NPCID);
        addTalkId(NoblessMasterConfig.NOBLESS_MASTER_NPCID);
        addFirstTalkId(NoblessMasterConfig.NOBLESS_MASTER_NPCID);
    }

    @Override
    public String onEvent(String event, Npc npc, Player player)
    {
        if (!NoblessMasterConfig.NOBLESS_MASTER_ENABLED)
        {
            return null;
        }

        switch (event)
        {
            case "noblesse":
            {
                if (player.isNoble())
                {
                    return "1003000-3.htm";
                }

                // Level check FIRST (prevents item loss)
                if (player.getLevel() < NoblessMasterConfig.NOBLESS_MASTER_LEVEL_REQUIREMENT)
                {
                    return "1003000-2.htm";
                }

                // Item check + take items AFTER level check
                if (NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT > 0)
                {
                    if (getQuestItemsCount(player, NoblessMasterConfig.NOBLESS_MASTER_ITEM_ID) < NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT)
                    {
                        player.sendMessage(NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT + " unit(s) of the item " + ItemData.getInstance().getTemplate(NoblessMasterConfig.NOBLESS_MASTER_ITEM_ID).getName() + " is/are required.");
                        return "1003000-4.htm";
                    }

                    takeItems(player, NoblessMasterConfig.NOBLESS_MASTER_ITEM_ID, NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT);
                }

                if (NoblessMasterConfig.NOBLESS_MASTER_REWARD_TIARA)
                {
                    giveItems(player, NOBLESS_TIARA, 1);
                }

                player.setNoble(true);
                player.sendPacket(QuestSound.ITEMSOUND_QUEST_FINISH.getPacket());
                return "1003000-1.htm";
            }
        }

        return null;
    }

    @Override
    public String onFirstTalk(Npc npc, Player player)
    {
        return "1003000.htm";
    }

    public static void main(String[] args)
    {
        new NoblessMaster();
    }
}

You post the same fuck script with some IA comment....on the current verison already are checed first the level......
Code: [Select]
public String onEvent(String event, Npc npc, Player player)
{
if (!NoblessMasterConfig.NOBLESS_MASTER_ENABLED)
{
return null;
}

switch (event)
{
case "noblesse":
{
if (player.isNoble())
{
return "1003000-3.htm";
}

if (player.getLevel() < NoblessMasterConfig.NOBLESS_MASTER_LEVEL_REQUIREMENT)
{
return "1003000-2.htm";
}

if (NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT > 0)
{
if (getQuestItemsCount(player, NoblessMasterConfig.NOBLESS_MASTER_ITEM_ID) < NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT)
{
player.sendMessage(NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT + " unit(s) of the item " + ItemData.getInstance().getTemplate(NoblessMasterConfig.NOBLESS_MASTER_ITEM_ID).getName() + " is/are required.");
return "1003000-4.htm";
}

takeItems(player, NoblessMasterConfig.NOBLESS_MASTER_ITEM_ID, NoblessMasterConfig.NOBLESS_MASTER_ITEM_COUNT);
}

if (NoblessMasterConfig.NOBLESS_MASTER_REWARD_TIARA)
{
giveItems(player, NOBLESS_TIARA, 1);
}

player.setNoble(true);
player.sendPacket(QuestSound.ITEMSOUND_QUEST_FINISH.getPacket());
return "1003000-1.htm";
}
}

return null;
}
So 2 things you use a old version as fuck or are on drugs....


Online Mobius

  • Distinguished King
  • *****
    • Posts: 19715
So 2 things you use a old version as fuck or are on drugs....
Apparently the released version does not have our change yet.


Online Naker

  • Count
  • *****
    • Posts: 450
  • Coding Dreams

Online Mobius

  • Distinguished King
  • *****
    • Posts: 19715