[Help] Being able to see items on the ground

12/11/2010 16:29 micro1337#1
I've been here for a long time but never really posted. Anyways, I'm using Hybrid's 5017 source and I'm having trouble with being able to see items on the ground. I've handled dropping an item like so in the packet handler:

(it's something simple for now)

Code:
        public static void DropItem(GameClient Client, ItemUsagePacket Packet)
        {
            IConquerItem thisItem = Client.GetInventoryItem(Packet.UID);
            
            Item item = new Item(Client.Entity.MapID,
                                Client.Entity.X,
                                Client.Entity.Y);

            Client.RemoveInventory(thisItem.UID);

            Kernel.ItemsOnTheFloor.Add(thisItem.UID, item);
        }
But I don't know what to do from there. Is it something with the general data packet that I have to deal with?
12/11/2010 23:19 pro4never#2
You need to send the ground item packet (1101) with the subtype you require (add/remove/loot/etc) based on actions. As part of your spawn screen method you should be sending the ground items currently in range to clients.
12/11/2010 23:57 FuriousFag#3
Afaik Arco did this in his release of hybrids 5017.so you might want to check that out.
12/12/2010 05:57 micro1337#4
Wow thank you pro! I can't believe how simple the solution was. It took some thinking though. I was thinking that when I send this packet I would also have to do something in code to be able to see it in game. But I had to stop and think "what is the role of the client?". The client spawns the item when it receives the packet. Not the server spawning the item. Here is my code:

Code:
                                      case "@drop":
                                            {
                                                IConquerItem itm = new ItemDataPacket(true);
                                                itm.ID = 480339;
                                                itm.Plus = 12;
                                                itm.UID = ItemDataPacket.NextItemUID;

                                                byte[] packet = new byte[20];
                                                PacketBuilder.WriteUInt16(20, packet, 0);
                                                PacketBuilder.WriteUInt16(1101, packet, 2);
                                                PacketBuilder.WriteUInt32(itm.UID, packet, 4);
                                                PacketBuilder.WriteUInt32(itm.ID, packet, 8);
                                                PacketBuilder.WriteUInt16(Client.Entity.X, packet, 12);
                                                PacketBuilder.WriteUInt16(Client.Entity.Y, packet, 14);
                                                PacketBuilder.WriteUInt32(0x1, packet, 16);


                                                Kernel.ToLocal(packet, Client.Entity.X, Client.Entity.Y, Client.Entity.MapID, 0, 0);
                                                break;
                                            }
Edit: Ok, I've fixed the drop method like so:

Code:
        static public void DropItem(GameClient Client, ItemUsagePacket Packet)
        {
            IConquerItem thisItem = Client.GetInventoryItem(Packet.UID);

            Client.RemoveInventory(thisItem.UID);

            byte[] packet = new byte[20];
            PacketBuilder.WriteUInt16(20, packet, 0);
            PacketBuilder.WriteUInt16(1101, packet, 2);
            PacketBuilder.WriteUInt32(thisItem.UID, packet, 4);
            PacketBuilder.WriteUInt32(thisItem.ID, packet, 8);
            PacketBuilder.WriteUInt16(Client.Entity.X, packet, 12);
            PacketBuilder.WriteUInt16(Client.Entity.Y, packet, 14);
            PacketBuilder.WriteUInt32(0x1, packet, 16);

            Item item = new Item();
            item.UID = thisItem.UID;
            item.ID = thisItem.ID;
            item.MapID = Client.Entity.MapID;
            item.Plus = thisItem.Plus;
            item.Position = thisItem.Position;
            item.SocketOne = thisItem.SocketOne;
            item.SocketTwo = thisItem.SocketTwo;
            item.X = Client.Entity.X;
            item.Y = Client.Entity.Y;
            item.Enchant = thisItem.Enchant;
            item.Bless = thisItem.Bless;

            Kernel.ItemsOnTheFloor.Add(item.UID, item);
            Kernel.ToLocal(packet, Client.Entity.X, Client.Entity.Y, Client.Entity.MapID, 0, 0);
        }
And I thought it would be a good idea to update the client every time it jumps so it will be able to see items throughout the map--but one problem. The client keeps playing the item drop sound whenever I jump. Am I sending the wrong subtype or does the wiki not have all the subtypes? Is this a good idea to begin with?

In the jump method:

Code:
                foreach (KeyValuePair<uint, Item> itm in Kernel.ItemsOnTheFloor)
                {
                    if (itm.Value.MapID == Client.Entity.MapID && Kernel.CanSee(itm.Value.X, itm.Value.Y, Client.Entity.X, Client.Entity.Y))
                    {
                        byte[] packet = new byte[20];
                        PacketBuilder.WriteUInt16(20, packet, 0);
                        PacketBuilder.WriteUInt16(1101, packet, 2);
                        PacketBuilder.WriteUInt32(itm.Value.UID, packet, 4);
                        PacketBuilder.WriteUInt32(itm.Value.ID, packet, 8);
                        PacketBuilder.WriteUInt16(itm.Value.X, packet, 12);
                        PacketBuilder.WriteUInt16(itm.Value.Y, packet, 14);
                        PacketBuilder.WriteUInt32(0x1, packet, 16);

                        Client.Send(packet);
                    }
                }