function SendGMItemPacket(srcChar, socket, item)
{
if (!socket || !item)
{
return;
}
// Define the packet ID for the GM Item Packet
const PACKET_ID = 0x1A;
// Create a new packet
var packet = new Packet();
packet.ReserveSize(20); // Reserve the necessary size for the packet (minimum 20 bytes)
// Extract item properties
let serial = item.serial;
const itemID = item.id;
const amount = item.amount || 0;
const x = item.x & 0x7FFF;
const y = item.y & 0x3FFF;
const z = item.z;
const direction = item.direction || 0;
const hue = item.hue || 0;
const flags = item.flags || 0;
// Adjust serial if the item has an amount
if (amount > 0)
{
serial |= 0x80000000; // Set the high bit for stacked items
} else
{
serial &= 0x7FFFFFFF; // Ensure the high bit is not set for single items
}
// Write data to the packet
packet.WriteByte(0, PACKET_ID); // Write packet ID at position 0
packet.WriteLong(1, serial); // Write item serial at position 1
packet.WriteShort(5, itemID & 0x3FFF); // Write item ID at position 5
// Write amount if it's greater than 0
if (amount > 0)
{
packet.WriteShort(7, amount); // Write amount at position 7
}
// Adjust x-coordinate for direction flag
let adjustedX = x;
if (direction !== 0)
{
adjustedX |= 0x8000; // Set the direction flag
}
packet.WriteShort(9, adjustedX); // Write x-coordinate at position 9
// Adjust y-coordinate for hue and flags
let adjustedY = y;
if (hue !== 0)
{
adjustedY |= 0x8000; // Set the hue flag
}
if (flags !== 0)
{
adjustedY |= 0x4000; // Set the flags flag
}
packet.WriteShort(11, adjustedY); // Write y-coordinate at position 11
packet.WriteByte(13, z); // Write z-coordinate at position 13
// Write direction if it's present
if (direction !== 0)
{
packet.WriteByte(14, direction); // Write direction at position 14
}
// Write hue if it's present
if (hue !== 0)
{
packet.WriteShort(15, hue); // Write hue at position 15
}
// Write flags if they're present
if (flags !== 0)
{
packet.WriteByte(17, flags); // Write flags at position 17
}
// Send the packet to the client
socket.Send(packet);
// Free the packet to avoid memory leaks
packet.Free();
}
{
if (!socket || !item)
{
return;
}
// Define the packet ID for the GM Item Packet
const PACKET_ID = 0x1A;
// Create a new packet
var packet = new Packet();
packet.ReserveSize(20); // Reserve the necessary size for the packet (minimum 20 bytes)
// Extract item properties
let serial = item.serial;
const itemID = item.id;
const amount = item.amount || 0;
const x = item.x & 0x7FFF;
const y = item.y & 0x3FFF;
const z = item.z;
const direction = item.direction || 0;
const hue = item.hue || 0;
const flags = item.flags || 0;
// Adjust serial if the item has an amount
if (amount > 0)
{
serial |= 0x80000000; // Set the high bit for stacked items
} else
{
serial &= 0x7FFFFFFF; // Ensure the high bit is not set for single items
}
// Write data to the packet
packet.WriteByte(0, PACKET_ID); // Write packet ID at position 0
packet.WriteLong(1, serial); // Write item serial at position 1
packet.WriteShort(5, itemID & 0x3FFF); // Write item ID at position 5
// Write amount if it's greater than 0
if (amount > 0)
{
packet.WriteShort(7, amount); // Write amount at position 7
}
// Adjust x-coordinate for direction flag
let adjustedX = x;
if (direction !== 0)
{
adjustedX |= 0x8000; // Set the direction flag
}
packet.WriteShort(9, adjustedX); // Write x-coordinate at position 9
// Adjust y-coordinate for hue and flags
let adjustedY = y;
if (hue !== 0)
{
adjustedY |= 0x8000; // Set the hue flag
}
if (flags !== 0)
{
adjustedY |= 0x4000; // Set the flags flag
}
packet.WriteShort(11, adjustedY); // Write y-coordinate at position 11
packet.WriteByte(13, z); // Write z-coordinate at position 13
// Write direction if it's present
if (direction !== 0)
{
packet.WriteByte(14, direction); // Write direction at position 14
}
// Write hue if it's present
if (hue !== 0)
{
packet.WriteShort(15, hue); // Write hue at position 15
}
// Write flags if they're present
if (flags !== 0)
{
packet.WriteByte(17, flags); // Write flags at position 17
}
// Send the packet to the client
socket.Send(packet);
// Free the packet to avoid memory leaks
packet.Free();
}