[Eluna] How to create custom GM commands in LUA

Sylian

Trusted
Trusted
Sylian Rep
2
0
0
Rep
10
Sylian Vouches
0
0
0
Vouches
0
Posts
86
Likes
199
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 28 56 XP
Welcome!
In this guide, I will show you how to make your own GM commands using the Eluna engine.

[NOTE]: I started on WoW emulation about 1 week ago now, so sorry if there are any errors!
[NOTE]: I strongly recommend you read the
Eluna Engine Docs to learn more!

Step 1: Create a new lua file inside your folder called "lua_scripts" located inside your server folder.
image_2023-04-02_212921314.png

Step 2: Open the new file you just created, when opened you should see an empty lua file like this.
image_2023-04-02_213156351.png

Step 3: Here we will program the whole command and then test it when we have it done, down below you can see the whole script, don't worry, I will explain it all so you can learn from it also :)
image_2023-04-02_220627688.png

Let us start from the top!

On line 1 we create a new local variable that is called "PLAYER_EVENT_ON_CHAT" which is then set to "18", the reason we set it to "18" is because that is from my understanding the way wow emulation servers are setup with the events.

On line 3 we create a new local function with a name we can choose ourselves, as you might see there are some arguments (event, player, msg, Type, lang), these are the arguments that the "PLAYER_EVENT_ON_CHAT" returns when a player sends a chat message.

On line 4 we create an if statement where we first check if the player's message was equal to our command (in this case test), and then we check if the player that sent the message has a GM rank of 3 (That is the GameMaster rank), both of these are correct we will then enter the if statement contents.

If the command and GM rank was correct we will land on line 6 now, here we tell the script to give the player who sent the command an item (in this case we use an item with the ID 1524).

On the last line (12) we tell our script to "RegisterPlayerEvent", this means that our script will listen for the "PLAYER_EVENT_ON_CHAT" event, the other argument is what function it should call when the "PLAYER_EVENT_ON_CHAT" has been triggered.

That was all!
Let us go ahead and test it, shall we?
image_2023-04-02_221941783.png

Congrats!
If everything is working right you should get the item called "Skullsplitter Tusk" when entering your new custom command!

If nothing happened, check this troubleshooting guide below!
1: Make sure you go to your World Server window and type ".reload eluna" and hit enter.
2: Make sure that your character is a GameMaster rank in your database.
4: Check the ElunaEngine Documentations if you want to see if you can fix it yourself!
3: Check your code again, if you need help you can hit me up in the PMs and I will see if I can help you!
 
Liked By 3 members :

PrivateDonut

Account Closed
banned
Rep
3
0
0
Rep
3
Vouches
0
0
0
Vouches
0
Posts
533
Likes
445
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 31 71 XP
Nice tutorial for beginners, it is great to share knowledge with others! I do have some tips you could use to make this script even better!

JavaScript:
local itemID = 100000 -- Item ID

-- We will use hook 42(known as PLAYER_EVENT_ON_COMMAND) to scan the chat for the command .test
-- OnChatMessage is just a name I decided, but you can name this anything you want.
function OnChatMessage(event, player, command)
    -- if the command .test is found, then we will add the item to the player's inventory
    if command == "test" then
        -- Add the item to the player's inventory by itemID and 1 quantity
        player:AddItem(itemID, 1)
        -- Send a broadcast message to the player to let them know they have been given an item
        player:SendBroadcastMessage("You have been given an item!")
    end
end
-- We will use hook 42(known as PLAYER_EVENT_ON_COMMAND) to sca the chat for the command .test. If the command is found, we will delete the message from the chat
local function DeleteChat(event, player, command)
    -- If the command .test is found, then we will delete the message from the chat
    if (command:find("test")) then
        -- We will return the if statement false in order to prevent the command being shown in the chat
        return false
    end
end

-- We will register the hook 42(known as PLAYER_EVENT_ON_COMMAND) to the function OnChatMessage
-- The order of this is important, as we want to register the hook before we register the function
-- If we register the function before the hook, the function will not be called
-- So we will need to enter hook number 42 first, then the function name OnChatMessage
RegisterPlayerEvent(42, OnChatMessage)
-- We will register the hook 42(known as PLAYER_EVENT_ON_COMMAND) to the function DeleteChat
-- The order of this is important, as we want to register the hook before we register the function
-- If we register the function before the hook, the function will not be called
-- So we will need to enter hook number 42 first, then the function name DeleteChat
RegisterPlayerEvent(42, DeleteChat)
- This is a Lua script but I had to use the javascript code paste since we don't actually have one for Lua on the forums.

I made the script similar to yours, but just slightly different where it will show improvement in my opinion. Instead of just scanning the chat for the command word, we will use player hook 42(PLAYER_EVENT_ON_COMMAND) for both onChatMessage and DeleteChat.

This will allow us to make it into an actual command similar to how trinity core handles its commands. So instead of just typing test, we can now type .test in order to run the command. If the player using the command meets the requirements, it will return the item ID and message informing the player they were given a item. Once the command is run, the script will then use the function DeleteChat to remove the message before anyone ever sees it.

download.png

I figured I would share this with you, so you could improve if you see it as an imporvement. Just personally, I prefer nobody to see the command message. Hopefully you find this helpful, and if you have any questions feel free to ask. :)
 
Liked By 3 members :

Sylian

Trusted
Trusted
Sylian Rep
2
0
0
Rep
10
Sylian Vouches
0
0
0
Vouches
0
Posts
86
Likes
199
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 28 56 XP
Nice tutorial for beginners, it is great to share knowledge with others! I do have some tips you could use to make this script even better!

JavaScript:
local itemID = 100000 -- Item ID

-- We will use hook 42(known as PLAYER_EVENT_ON_COMMAND) to scan the chat for the command .test
-- OnChatMessage is just a name I decided, but you can name this anything you want.
function OnChatMessage(event, player, command)
    -- if the command .test is found, then we will add the item to the player's inventory
    if command == "test" then
        -- Add the item to the player's inventory by itemID and 1 quantity
        player:AddItem(itemID, 1)
        -- Send a broadcast message to the player to let them know they have been given an item
        player:SendBroadcastMessage("You have been given an item!")
    end
end
-- We will use hook 42(known as PLAYER_EVENT_ON_COMMAND) to sca the chat for the command .test. If the command is found, we will delete the message from the chat
local function DeleteChat(event, player, command)
    -- If the command .test is found, then we will delete the message from the chat
    if (command:find("test")) then
        -- We will return the if statement false in order to prevent the command being shown in the chat
        return false
    end
end

-- We will register the hook 42(known as PLAYER_EVENT_ON_COMMAND) to the function OnChatMessage
-- The order of this is important, as we want to register the hook before we register the function
-- If we register the function before the hook, the function will not be called
-- So we will need to enter hook number 42 first, then the function name OnChatMessage
RegisterPlayerEvent(42, OnChatMessage)
-- We will register the hook 42(known as PLAYER_EVENT_ON_COMMAND) to the function DeleteChat
-- The order of this is important, as we want to register the hook before we register the function
-- If we register the function before the hook, the function will not be called
-- So we will need to enter hook number 42 first, then the function name DeleteChat
RegisterPlayerEvent(42, DeleteChat)
- This is a Lua script but I had to use the javascript code paste since we don't actually have one for Lua on the forums.

I made the script similar to yours, but just slightly different where it will show improvement in my opinion. Instead of just scanning the chat for the command word, we will use player hook 42(PLAYER_EVENT_ON_COMMAND) for both onChatMessage and DeleteChat.

This will allow us to make it into an actual command similar to how trinity core handles its commands. So instead of just typing test, we can now type .test in order to run the command. If the player using the command meets the requirements, it will return the item ID and message informing the player they were given a item. Once the command is run, the script will then use the function DeleteChat to remove the message before anyone ever sees it.

View attachment 923

I figured I would share this with you, so you could improve if you see it as an imporvement. Just personally, I prefer nobody to see the command message. Hopefully you find this helpful, and if you have any questions feel free to ask. :)
Damn dude!
Thanks for the tip, i also tried to make it a command but couldn't get it to work so will give this a try when I get home!

Again thanks a lot!
 
Liked By 1 member :

RedLine

Divine
Divine
RedLine Rep
0
0
0
Rep
0
RedLine Vouches
0
0
0
Vouches
0
Posts
74
Likes
28
Bits
2 YEARS
2 YEARS OF SERVICE
LEVEL 4 205 XP
Great tutorial from both
 
Liked By 2 members :

3,415

1,272

9,558

428

Top