Skip to content

How to Add Custom Commands

Muhammad Kevin edited this page Mar 7, 2023 · 1 revision

In this page will tell you how to add custom commands

  1. to make custom commands, you must goto events/eventClient.c file
  2. after you goto events/eventClient.c file, add else if at the end of else if blocks
if (isStr(command[0], "/proxyhelp")) {
    sendPacket(3, "action|log\nmsg|>> Commands: /helloworld", clientPeer);
}
else if (isStr(command[0], "/helloworld")) {
    sendPacket(3, "action|log\nmsg|`2Hello World", clientPeer);
}
else if (isStr(command[0], "/testarg")) {
    if (!command[1]) {
        sendPacket(3, "action|log\nmsg|Please input argument", clientPeer);
        free(command); // prevent memleak
        break;
    }
    sendPacket(3, CatchMessage("action|log\nmsg|%s", command[1]), clientPeer);
}
// add else if here
else enet_peerSend(event.packet, serverPeer);
  1. to make your own custom commands, make code like this
  • If you want to make custom commands without arguments
else if (isStr(command[0], "/yourcommand")) {
    // your code here
}
  • If you want to make custom commands with arguments
else if (isStr(command[0], "/yourcommandwithargs")) {
    if (!command[1]) {
        sendPacket(3, "action|log\nmsg|your warning message here", clientPeer);
        free(command); // prevent memleak
        break;
    }
    // your code here
}

and then, the result code is like this

if (isStr(command[0], "/proxyhelp")) {
    sendPacket(3, "action|log\nmsg|>> Commands: /helloworld", clientPeer);
}
else if (isStr(command[0], "/helloworld")) {
    sendPacket(3, "action|log\nmsg|`2Hello World", clientPeer);
}
else if (isStr(command[0], "/testarg")) {
    if (!command[1]) {
        sendPacket(3, "action|log\nmsg|Please input argument", clientPeer);
        free(command); // prevent memleak
        break;
    }
    sendPacket(3, CatchMessage("action|log\nmsg|%s", command[1]), clientPeer);
}
else if (isStr(command[0], "/yourcommand")) {
    // your code here
}
else if (isStr(command[0], "/yourcommandwithargs")) {
    if (!command[1]) {
        sendPacket(3, "action|log\nmsg|your warning message here", clientPeer);
        free(command); // prevent memleak
        break;
    }
    // your code here
}
else enet_peerSend(event.packet, serverPeer);