- Joined
- Jun 14, 2024
- Messages
- 31
- Thread Author
- #1
Lets make a script that sends a message to the player on login.
First thing i do is go and look at Eluna's documentation and see what events are available.
You can find these here
elunaluaengine.github.io
There you will see all the player events.
We are going to use PLAYER_EVENT_ON_LOGIN = 3, // (event, player)
The number 3 is the event id. We will use this to register our event at the end.
The comment (event, player) tells us what the event returns and what our parameters should be.
So we start our script by declaring a function
Inside of this function were going to send the player a message.
To find all functions available to the player object you can find that by searching Player in the documentation.
I found the function Player:SendBroadcastMessage
elunaluaengine.github.io
I also found the function WorldObject:GetName
elunaluaengine.github.io
Now you may of noticed its not a child of player but instead is a child of WorldObject this is completely fine bc a player is a world object.
So lets combine the 2 and add it to our function.
To concatenate a string you use the operator .. as shown above.
Now we need to register our event.
With that done we can now save our script and put it in the lua_scripts folder.
And .reload eluna and login to see our message.
With that you have created your first Eluna script.
Creating scripts with Eluna is really easy you just need to use the documentation to find what you want to do and then use it.
First thing i do is go and look at Eluna's documentation and see what events are available.
You can find these here
Global:RegisterPlayerEvent - Eluna
API documentation for the Global:RegisterPlayerEvent method in the Eluna engine.
There you will see all the player events.
We are going to use PLAYER_EVENT_ON_LOGIN = 3, // (event, player)
The number 3 is the event id. We will use this to register our event at the end.
The comment (event, player) tells us what the event returns and what our parameters should be.
So we start our script by declaring a function
Code:
local function OnLogin(event, player)
end
Inside of this function were going to send the player a message.
To find all functions available to the player object you can find that by searching Player in the documentation.
I found the function Player:SendBroadcastMessage
Player:SendBroadcastMessage - Eluna
API documentation for the Player:SendBroadcastMessage method in the Eluna engine.
I also found the function WorldObject:GetName
WorldObject:GetName - Eluna
API documentation for the WorldObject:GetName method in the Eluna engine.
Now you may of noticed its not a child of player but instead is a child of WorldObject this is completely fine bc a player is a world object.
So lets combine the 2 and add it to our function.
Code:
local function OnLogin(event, player)
player:SendBroadcastMessage("Welcome, "..player:GetName().."!")
end
To concatenate a string you use the operator .. as shown above.
Now we need to register our event.
Code:
local function OnLogin(event, player)
player:SendBroadcastMessage("Welcome, "..player:GetName().."!")
end
RegisterPlayerEvent(3, OnLogin)
With that done we can now save our script and put it in the lua_scripts folder.
And .reload eluna and login to see our message.
With that you have created your first Eluna script.
Creating scripts with Eluna is really easy you just need to use the documentation to find what you want to do and then use it.