Jump to content
  • 0

ItemContainer aCis


l2jkain

Question

Hi, I'm trying to create a npc for augment but it's not showing the items the player has in inventory what do I do?

 

error should be here


 Set<ItemInstance> invitems = player.getInventory().getItems();

 

is not listing inventory items


        

Edited by l2jkain
Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0
8 minutes ago, Devlin said:

para (ItemInstance i: invites)

       i.blabla ();

 

É assim que você chama os itens?

yes 

 

Good, I'll try this way.


final Set <ItemInstance> invitems;

invitems = player.getInventory (). getItems ();

Link to comment
Share on other sites

  • 0

No reasons it wouldn't work. That would mean all calls would fail also, notably your own player inventory (using tab button, should show nothing), GM packet to show inventories of other players, etc.

 

If it's empty, it means you didn't load the data. Log the content or the size of the _items, it's probably not empty. I guess your use of the content is wrong.

Edited by Tryskell
Link to comment
Share on other sites

  • 0
11 hours ago, Tryskell said:

No reasons it wouldn't work. That would mean all calls would fail also, notably your own player inventory (using tab button, should show nothing), GM packet to show inventories of other players, etc.

 

If it's empty, it means you didn't load the data. Log the content or the size of the _items, it's probably not empty. I guess your use of the content is wrong.

 

Is not verification right?

 


/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package net.sf.l2j.gameserver.model.actor.instance;

import java.util.StringTokenizer;

import net.sf.l2j.commons.random.Rnd;
import net.sf.l2j.gameserver.ai.CtrlIntention;
import net.sf.l2j.gameserver.datatables.AugmentationData;
import net.sf.l2j.gameserver.model.L2Augmentation;
import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
import net.sf.l2j.gameserver.model.item.kind.Weapon;
import net.sf.l2j.gameserver.model.item.type.CrystalType;
import net.sf.l2j.gameserver.network.SystemMessageId;
import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage;
import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage.SMPOS;
import net.sf.l2j.gameserver.network.serverpackets.ExVariationCancelResult;
import net.sf.l2j.gameserver.network.serverpackets.ExVariationResult;
import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
import net.sf.l2j.gameserver.network.serverpackets.MyTargetSelected;
import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
import net.sf.l2j.gameserver.network.serverpackets.SkillList;
import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
import net.sf.l2j.gameserver.network.serverpackets.ValidateLocation;

public final class FastAug extends Folk
{

    public FastAug(int objectId, NpcTemplate template)
    {
        super(objectId, template);
    }
    
    @Override
    public void onBypassFeedback(Player player, String command)
    {
        if(player==null)
            return;
        
        final StringTokenizer st = new StringTokenizer(command, " ");
        final String currentcommand = st.nextToken();
            
        final String letsSliptIt = currentcommand;
        final String[] nowTheId = letsSliptIt.split("-");
        
        final String OurSplititCommand = nowTheId[0];
        final String FinallyWeHaveObjectId = nowTheId[1];
        
        switch (OurSplititCommand)
        {
            case "showremlist":
                showListWindowForRemove(player);
                player.sendPacket(new ActionFailed());
                break;
            case "showauglist":
                showListWindow(player);
                player.sendPacket(new ActionFailed());
                break;
            case "tryremove":
                
                final ItemInstance itemToRem = player.getInventory().getItemByObjectId(Integer.parseInt(FinallyWeHaveObjectId));
                  
                 if(itemToRem == null )
                 {
                     player.sendPacket(new ActionFailed());
                     return;
                 }
                 
                if (itemToRem.isEquipped())
                {
                    player.disarmWeapons();
                    player.broadcastUserInfo();
                }

                itemToRem.removeAugmentation();
                
                player.sendPacket(new ExVariationCancelResult(1));

                InventoryUpdate iu = new InventoryUpdate();
                iu.addModifiedItem(itemToRem);
                player.sendPacket(iu);
                
                player.sendPacket(new SkillList());
                
                SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.AUGMENTATION_HAS_BEEN_SUCCESSFULLY_REMOVED_FROM_YOUR_S1);
                sm.addItemName(itemToRem);
                player.sendPacket(sm);
                showListWindowForRemove(player);
                player.sendPacket(new ActionFailed());
                break;
                
            case "tryaug":
                if (player.getInventory().getInventoryItemCount(57, 0) < 200000)
                 {
                    player.sendMessage("You do not have enough adena!");
                    player.sendPacket(new ActionFailed());
                    return;
                 }
            
                 final ItemInstance itemToAug = player.getInventory().getItemByObjectId(Integer.parseInt(FinallyWeHaveObjectId));
                 
             
                 if(itemToAug == null )
                 {
                     player.sendPacket(new ActionFailed());
                     return;
                 }
                 
                if (itemToAug.isEquipped())
                {
                    player.disarmWeapons();
                    player.broadcastUserInfo();
                }
                
                 final L2Augmentation aug = AugmentationData.getInstance().generateRandomAugmentation(2,2);
                 itemToAug.setAugmentation(aug);
                                           
                final int stat12 = 0x0000FFFF & aug.getAugmentationId();
                final int stat34 = aug.getAugmentationId() >> 16;
                player.sendPacket(new ExVariationResult(stat12, stat34, 1));
                
                InventoryUpdate iua = new InventoryUpdate();
                iua.addModifiedItem(itemToAug);
                player.sendPacket(iua);
                
                StatusUpdate su = new StatusUpdate(player);
                su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
                player.sendPacket(su);
                
                showListWindow(player);
                
                player.getInventory().reduceAdena("FastAugh", 200000, player, null);

                player.sendPacket(SystemMessageId.THE_ITEM_WAS_SUCCESSFULLY_AUGMENTED);
                
                if(itemToAug.getAugmentation().getSkill()!=null)
                {
                   player.sendPacket(new ExShowScreenMessage("You have " + itemToAug.getAugmentation().getSkill().getName(), 5000, SMPOS.TOP_CENTER, true));
                   player.sendPacket(new SkillList());
                }

                player.sendPacket(new ActionFailed());
                break;    
            default: // Send a Server->Client packet ActionFailed to the Player
                player.sendPacket(new ActionFailed());
                return;
        }
        
        super.onBypassFeedback(player, command);
        
        player.sendPacket(new ActionFailed());
    }
    
    public void showListWindow(Player player)
    {
        NpcHtmlMessage nhm = new NpcHtmlMessage(5);
        StringBuilder tb = new StringBuilder("");
        String Rem = "RemoveAug";
        
        tb.append("<html><head><title>L2-Kamui</title></head><body>");
        tb.append("<center>");
        tb.append("<table width=\"250\" cellpadding=\"5\" bgcolor=\"000000\">");
        tb.append("<tr>");
        tb.append("<td width=\"45\" valign=\"top\" align=\"center\"><img src=\"L2ui_ch3.menubutton4\" width=\"38\" height=\"38\"></td>");
        tb.append("<td valign=\"top\"><font color=\"FF6600\">AugmentHelper</font>");
        tb.append("<br1><font color=\"00FF00ju\">" + player.getName() + "</font>, use this menu for fast augment :)<br1></td>");
        tb.append("</tr>");
        tb.append("</table>");
        tb.append("</center>");
        tb.append("<center>");
        tb.append("<br>");
                
        for (ItemInstance item : player.getInventory().getItems())
        {       
            if(item==null)
                continue;

            boolean canBeShow = isValid(player, item);
            
            if(canBeShow)
             {
                tb.append("<button value=\""+item.getItemName()+"\" action=\"bypass -h npc_" + getObjectId() + "_tryaug-"+item.getObjectId()+"\" width=204 height=20 back=\"sek.cbui75\" fore=\"sek.cbui75\"><br>");
             }                  
        }
        
        tb.append("<br>");
        tb.append("<button value=\""+Rem+"\" action=\"bypass -h npc_" + getObjectId() + "_showremlist-1"+"\" width=204 height=20 back=\"sek.cbui75\" fore=\"sek.cbui75\"><br>");
        tb.append("</center>");
        tb.append("</body></html>

Link to comment
Share on other sites

  • 0
  • First, unhardcode HTM - that's as much String cached you don't need to create on every call.
  • Second, use StringUtil.append, notably on the for loop.
  • Third, isValid() content is probably wrong. And item can't be null, by the way.

Replace

        for (ItemInstance item : player.getInventory().getItems())
        {       
            if(item==null)
                continue;

For

for (ItemInstance item : player.getInventory().getItems())
{       
      System.out.println(item.getItem().getName());

If you got inventory content on console, then the problem comes from your isValid() method which probably returns false everytime.

Edited by Tryskell
Link to comment
Share on other sites

  • 0

Sometimes i feel like people dont know how to use prints properly.

The first thing i do is to create a print function (e.g C ) and get addresses and values...

Also,ur xmass gift should be this https://images-na.ssl-images-amazon.com/images/I/518VZN07C1L._SX400_BO1,204,203,200_.jpg 

Link to comment
Share on other sites

  • 0
5 hours ago, bravetobe said:

Sometimes i feel like people dont know how to use prints properly.

The first thing i do is to create a print function (e.g C ) and get addresses and values...

Also,ur xmass gift should be this https://images-na.ssl-images-amazon.com/images/I/518VZN07C1L._SX400_BO1,204,203,200_.jpg 

 

It's a temporary log to see if it works or not. It hasn't any point to be kept as it is. It's totally pointless to speak about if it works fine, if there are better ways to write it, or whatever. You could at least "attack" me on the fact I don't say the dude to use debug tool, but crafting your own debug print is ridiculous too.

 

Please, avoid to "teach me" things when you do things bad yourself.

 

I invite you to read the book you linked, if there is a Eclipse debug tool chapter.

Link to comment
Share on other sites

  • 0
2 hours ago, Tryskell said:

 

It's a temporary log to see if it works or not. It hasn't any point to be kept as it is. It's totally pointless to speak about if it works fine, if there are better ways to write it, or whatever. You could at least "attack" me on the fact I don't say the dude to use debug tool, but crafting your own debug print is ridiculous too.

 

Please, avoid to "teach me" things when you do things bad yourself.

 

I invite you to read the book you linked, if there is a Eclipse debug tool chapter.

u misunderstood my post.it has nothing to do with ur code/post.

People (like op) come up with questions when they dont use a single print in a 120+ lines of code.(btw rofl)

 

Its not my job to teach anyone online what to do.Besides,questioning its way safer than telling "u are wrong" and u know that better than i do.Also i said that i do it myself and i said "the first thing i do is to create a print function .." when thats what u do is printing....Why did u get that as "u are wrong" LOL

Btw,i showed my book Kappa.

 

Btw about "crafting ur own debug print is ridiculous"  what does it even mean?

Can u explain why this is ridiculous?

If u have any better ways to check if values are correct,then go on.

Wow...

void showTable(Pair_t *P) {
	int i;
	printf("============================= \n");
	for (i = 0; i < size; i++) {
		printf("X: %d    %p , Y: %d    %p \n", P[i].x, &(P[i].x), P[i].y, &(P[i].y));
	}
	printf("============================= \n");
}

 

Edited by bravetobe
Link to comment
Share on other sites

  • 0
55 minutes ago, bravetobe said:

u misunderstood my post.it has nothing to do with ur code/post.

People (like op) come up with questions when they dont use a single print in a 120+ lines of code.(btw rofl)

 

Its not my job to teach anyone online what to do.Besides,questioning its way safer than telling "u are wrong" and u know that better than i do.Also i said that i do it myself and i said "the first thing i do is to create a print function .." when thats what u do is printing....Why did u get that as "u are wrong" LOL

Btw,i showed my book Kappa.

 

Btw about "crafting ur own debug print is ridiculous"  what does it even mean?

Can u explain why this is ridiculous?

If u have any better ways to check if values are correct,then go on.

Wow...


void showTable(Pair_t *P) {
	int i;
	printf("============================= \n");
	for (i = 0; i < size; i++) {
		printf("X: %d    %p , Y: %d    %p \n", P[i].x, &(P[i].x), P[i].y, &(P[i].y));
	}
	printf("============================= \n");
}

 

 

You don't need to log anything when you know what you code. The debug stuff hasn't any uses once the functionality is done (and works). I almost never log things when I rework / fully code stuff. If you comment and build your code correctly, it's not needed.

 

Your printf is unreadable (at least for my java knowledge), you wouldn't get worst if you were obfuscating it. If you're on a team, and someone codes things like that, you need to get a documentation to understand it.

 

Debug tool is used to see if values are correct, you can even edit them on the fly to see results. Logging as debug is for lazy asses (or if you didn't activate debug tool).

 

So coding formatting print functions is a waste of time, at least for debug purposes (which was the whole point).

Link to comment
Share on other sites

  • 0
1 hour ago, Tryskell said:

 

You don't need to log anything when you know what you code. The debug stuff hasn't any uses once the functionality is done (and works). I almost never log things when I rework / fully code stuff. If you comment and build your code correctly, it's not needed.

 

Your printf is unreadable (at least for my java knowledge), you wouldn't get worst if you were obfuscating it. If you're on a team, and someone codes things like that, you need to get a documentation to understand it.

 

Debug tool is used to see if values are correct, you can even edit them on the fly to see results. Logging as debug is for lazy asses (or if you didn't activate debug tool).

 

So coding formatting print functions is a waste of time, at least for debug purposes (which was the whole point).

personally i dont think that like 7 lines of code + call is waste of time.

I would take all the way those 10 seconds and visually find in the first run whats wrong instead of searching in the code "whats wrong with that rigatoni"

 

Why exactly someone would need documentation to understand what this printTable does?First of all,the purpose wont exist once i m done with the code and secondly,if someone doesnt understand how that print works,he should throw his certificate into the trashbin.

"Ur printf is unreadable".... u wot m8.This is no different with what u did by urself and no different than showing the values/addr of an array.

If u ask me,i consider waste of time to use the debug tool when i can type 1 print and check the console.

Why would u use any debug tool for something like this when u can see even in the first run whats going on ... 

 

If i m on a team,there is no reason to keep any code that isnt included in the main project.That code is for "personal" usage until the code works as intented.

 

People tend to code with their own personal preferences.It would be way better for someone who isnt developer,to do this way and not like OP's.

Thats my point.I prefer people using prints and search before asking instead of writing 120+ lines of code in 1 method / function (omg just kill me if its C).

 

Besides,the prints are in the console and they have nothing to do with the project itself.Whats the point to keep them when u are done.

 

P.S Maybe i print stuff coz i hate asm who knows Kappa

And btw,i m looking forward to see how u will explain OP's 120ish code spree.I did that stuff in my first year... Btw he is (future) admin.Well played

Also,i forgot to mention that i was doing some OpenGL stuff and the coordinates of the mouseclicks were saved in the array and each time the mouseclick was close to one of the cords,then the closest one was changing (so the draw is changing so the lines were changing ,so the startpoints and the end points where changing).So if u ask me,yea i prefer to check visually that sht.

 

tl;dr ANYWAY ,that wall of text was unintended.Its not about whats wrong and whats correct.The point is OP needs that book and he should debug his code

Edited by bravetobe
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

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

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock