Hello everyone, this tutorial will show you how to create a script which will get detected by the server and run successfully. For this tutorial we will create a script which prints a message in the chat each time the player (re-)spawns.
First off, go to the /FiveReborn/resources directory. You should see a lot of folders. Create a new one called “Welcome” and then go in it.
Now server needs to be told that this is a resource. We tell the server to load this by creating a new file in it, called __resource.lua (2x _ !). Now the server understands that this is something that can be loaded.
“That’s it?” you might ask. No, we need to tell the server what to do with this resource and fill it with stuff that should be done afterwards. Lets open the file.
You might see that there’s absolutely nothing in it. Lets begin to fill it with something.
First off, we add a
resource_manifest_version '77731fab-63ca-442c-a67b-abc70f28dfa5'
at the top. This is required since a recent update to access the new goodies that came with it. Basically it tells the server “This was made for the … update”.
Next we add a
client_script "client.lua"
The server will now load this file, which we will create and fill with some code soon. There’s also a server_script "file.lua"
if you have ever looked at another script. There’s a difference between a client_script and a server_script. We will only need a client_script for now.
Save the file and create a new file, called “client.lua”. Open it and copy & paste this in it
AddEventHandler("playerSpawned", function(spawn)
TriggerEvent("chatMessage", "", { 0, 0, 0 }, "Hello world!")
end)
Now lets take a look at what all this means.
AddEventHandler(
This tells the server “I want to do stuff when something specific happens.”
"playerSpawned",
“I want to listen for this event.”
function(spawn)
“Do the following stuff now, and also pass me where the player spawned.”
TriggerEvent("chatMessage", "", { 0, 0, 0 }, "Hello world!")
“I want to show a message to this player. No sender should show up, the sender name (which doesn’t exist here anyways) should show up in the rgb colors 0, 0, 0 (black) and the message should be “Hello world!””
end)
“That’s it.”
Now save this file and go to your citmp-server.yml file. Add a - Welcome
under AutoStartResources:. Save this too and start up your server.
Now if you join your server and you followed this tutorial correctly, you will see a “Hello world!” in white in the chat.
Congratulations! You just created a script that has been detected by the server and even did something.
What now?
The possibilities are infinite! There isn’t much documentation so you’ll have to do some research. This will be your new best friend for that.
Also have an eye in the server console and the F8 in-game console if your script doesn’t want to run.
Use this to quickly check if your syntax is correct.
Also take a look at scripts from other people to see how certain things are being achieved. I’ve got alot of public scripts here that you can take a look at to see how stuff works.
Good luck!