Guide for Adding Trophies in the LUA File
This document will guide you step by step on how to add new trophies or achievements to the LUA file.
Understand the Structure
Before adding a new trophy or achievement, it's essential to understand how the file is structured. Each trophy is represented as a table within the Config.Trophies
table.
Add a New Trophy Table
- Locate the
Config.Trophies
section in the LUA file. - Within this section, you can see several examples of trophies, such as "job", "house", "car", etc. Each of these is a table representing a trophy.
- To add a new trophy, simply create a new table following the same format.
Example
If you want to add a trophy for "First Travel", follow the format below:
["travel"] = {
["title"] = "First Travel",
["description"] = "Complete your first travel in the server",
["reward"] = {
["enable"] = true, -- active [true] or disable [false]
["type"] = "money", -- money, item
["amount"] = 1000, -- amount of money or item
["item"] = "bread", -- item name [if type is item only]
},
["other"] = {
["type"] = 0, -- Trophy type: 0 = easy, 1 = medium, etc.
["confetti"] = true, -- If you want confetti when achieved.
["sound"] = true -- If you want a notification sound.
},
},
Details to Consider
["title"]
: The name of the trophy.["description"]
: A brief description of how the trophy is obtained.["reward"]["enable"]
: If you want to enable the trophy, set totrue
. Otherwise,false
.["reward"]["type"]
: The type of reward. It can bemoney
oritem
.["reward"]["amount"]
: The amount of money or item to be rewarded.["reward"]["item"]
: The name of the item to be rewarded. Only used if the reward type isitem
.["other"]["enable"]
: The trophy type based on difficulty. It can be 0 for easy, 1 for medium, 2 for hard, and 3 for master.["other"]["confetti"]
: If you want confetti when the trophy is achieved, set totrue
. Otherwise,false
.["other"]["sound"]
: If you want a notification sound when the trophy is achieved, set totrue
. Otherwise,false
.
Troubleshoot if Needed
If the trophy isn't appearing or working correctly, double-check your code for any missing or misplaced brackets, misspelled words, or incorrect data types.
How to Implement the Trophy
Once you've set up and added your trophies, you might be wondering how to actually "award" them to players when they achieve certain milestones in the game. Here's a step-by-step guide on how to integrate the trophy system into your FiveM Server:
Use the Function
exports["ictrophies"]:NewTrophy(trophyName)
, is what you'll use to award the trophy. Replace trophyName with the name of the trophy you want to award.
For instance, to award the "First Travel" trophy, you'd use:
exports["ictrophies"]:NewTrophy("travel")
Implement in Your Script:
Place the export function at the relevant point in your script. For example, in the provided sample:
Play.Shared = function(shared, p)
-- ... other code ...
-- This is where a trophy is awarded for sharing an animation.
exports["ictrophies"]:NewTrophy("animation")
-- ... other code ...
end
Remember, the most crucial part is understanding the structure. Once you grasp that, adding new trophies will become second nature. If you ever find yourself in doubt, refer back to the example provided. Happy coding!