Server:Packet.writeChar Server function
Jump to navigation
Jump to search
This function was added in version: 0.0.3.0 |
Insert char value to packet. (1 byte)
Syntax
void Packet.writeChar(char value)
Required Arguments
- value: number in range -128...127
Example
Client
function random(min, max)
{
return min + rand() % (max + 1 - min)
}
const LOTTERY_PACKET_ID = 1002;
addEventHandler("onCommand", function(cmd, params)
{
if (cmd == "lottery")
{
packet <- Packet();
packet.writeUInt16(LOTTERY_PACKET_ID);
packet.writeChar(random(-127,127)); // writing random number from range -127 to 127
packet.send(RELIABLE_ORDERED);
}
});
Server
const LOTTERY_PACKET_ID = 1002;
addEventHandler("onPacket",function(pid, packet)
{
if (packet.readUInt16() == LOTTERY_PACKET_ID)
{
local id = packet.readChar(); // reading random number generated on client-side
if (id == 64)
{
local gold = Items.id("ITMI_GOLD"); // getting gold item id from items.xml file
if (gold != -1) // if item is registered, then..
{
giveItem(pid, gold, 100);
sendMessageToPlayer(pid, 0, 255, 0, "You have won 100 gold in lottery!");
}
else
{
sendMessageToPlayer(pid, 255, 0, 0, "Sorry, you have won 100 gold, but this item isn't registered :/");
}
}
}
});
Related functions
- Packet.send
- Packet.sendToAll
- Packet.reset
- Packet.writeBool
- Packet.writeChar
- Packet.writeInt8
- Packet.writeUInt8
- Packet.writeInt16
- Packet.writeUInt16
- Packet.writeInt32
- Packet.writeUInt32
- Packet.writeFloat
- Packet.writeString
- Packet.readBool
- Packet.readChar
- Packet.readInt8
- Packet.readUInt8
- Packet.readInt16
- Packet.readUInt16
- Packet.readInt32
- Packet.readUInt32
- Packet.readFloat
- Packet.readString