Project Zomboid

Project Zomboid

Bravens trofæer
 Denne tråd er blevet fastgjort, så den er sikkert vigtig
Braven  [udvikler] 15. okt. 2023 kl. 0:30
For Modders
Here's a simple guide to adding custom achievements and tracking variables for your mod using the Braven's Achievement mod support in LUA:

Adding an Achievement
To add an achievement, declare a LUA table with the required fields: name, description, icon, and achieved. For example:
myAchievement = {name = "My Achievement", description = "The Description", icon = "Image File Name", achieved = false}

Add the achievement to BB_Achievements like this:
BB_Achievements.myAchievement = {name = "My Achievement", description = "The Description", icon = "Image File Name", achieved = false}

It's best to add your achievement during a game event like "onInitGlobalModData." Here's an example:
local function onInitGlobalModData() if not BB_Achievements.myAchievement then BB_Achievements.myAchievement = {name = "My Achievement", description = "The Description", icon = "Image File Name", achieved = false} end end Events.OnInitGlobalModData.Add(onInitGlobalModData)

Handling the Achievement
You can call and handle the achievement using BB_Achievements.myAchievement.
To check if the achievement has been completed, use BB_Achievements.myAchievement.achieved, which is a boolean.

If you want to set an achievement as completed by the Player, simply call the function AchievementHandler.popIn(BB_Achievements.myAchievement) and the mod will do the rest for you. Here's an example:
local EveryTenMinutes = function() if BB_Achievements.myAchievement.achieved == false then AchievementHandler.popIn(BB_Achievements.myAchievement) end end Events.EveryTenMinutes.Add(EveryTenMinutes)

Tracking Variables
If you want to add your own tracking variable, declare it with the desired type. For instance, if you want to track the number of zombies killed:
myTracker = 0

You can handle the tracker's value using BB_Achievements_Tracker.
Add your tracker to BB_Achievements_Tracker[/b] like this:
BB_Achievements_Tracker.myTracker = 0

Important Notes
  • You can override existing achievements by declaring the same variable after it has been added.
  • Make sure the icon variable for each achievement is just the name of the image file located in the "media/UI/" directory and is of file type .PNG.
  • Make sure the name and description variables for each achievement have translation files, at least in English.

Full Working Example
Here is a fully functional example of how to add your own achievement, track it, and handle it.
The goal is to add an achievement called "Axeman!" that triggers when the Player has an axe in their inventory.
local function onInitGlobalModData() if not BB_Achievements.gotAnAxe then BB_Achievements.gotAnAxe = {name = "Axeman", description = "IGUI_Axeman_Description", icon = "AxemanIcon", achieved = false} end end Events.OnInitGlobalModData.Add(onInitGlobalModData) local function everyTenMinutes() local playerObj = getPlayer() local playerInv = playerObj:getInventory() if not BB_Achievements.gotAnAxe.achieved then local hasAxe = playerInv:containsType("Axe") if hasAxe then AchievementHandler.popIn(BB_Achievements.gotAnAxe) end end end Events.EveryTenMinutes.Add(everyTenMinutes)

That's the basic process for adding custom achievements and tracking variables to your mod using the Braven's Achievement mod support in LUA.
Sidst redigeret af Braven; 15. okt. 2023 kl. 20:50