SANDBOX — this is a test environment. No servers are actually deployed and no real payments are charged.
Back to NxLabs

NxLabs / Vintage Story

Achievements

NBy Nateonus

Adds achievements to Vintage Story! Create achievements in your own mods using JSON files or code!

Achievements

Description

<p>You guessed it - This mod adds achievements. Currently comes with 16 achievements, and contains a super easy API for other modders to add achievements!</p> <p>Achievements work on singleplayer and multiplayer! If used on a server, unlocking an achievement will be broadcast to all players, if the server's modconfig allows it.</p> <p>Other mod developers should check out the Api Details section below. You can add achievements for this mod without requiring a dependency!</p> <p>Press 'L' (configurable) to open your Achievements Journal.</p> <p>If you wish to support my work, please consider donating a small amount at <a href="https://ko-fi.com/nateonus" target="_blank" rel="noopener">https://ko-fi.com/nateonus</a>!</p> <p>The achievements mod can be added to existing worlds without issue.</p> <p>The following mods support achievements:</p> <div class="spoiler"> <div class="spoiler-toggle">Mods with Achievements:</div> <div class="spoiler-text"> <p>Want your mod listed here? Use the achievements mod API and leave a comment!</p> <ul> <li><a href="https://mods.vintagestory.at/primitivesurvival" target="_blank" rel="noopener">Primitive Survival by SpearAndFang</a></li> <li><a href="https://mods.vintagestory.at/firearms" target="_blank" rel="noopener">Firearms by Maltiez</a></li> </ul> </div> </div> <div class="spoiler"> <div class="spoiler-toggle">Mod Authors - Code Api Details!</div> <div class="spoiler-text"> <p>The achievements API consists of a single .cs class that can be used to register, unlock, and check achievements.</p> <p>The great thing about this is that it requires no dependencies on your part. If the user has the achievements mod installed and enabled, your newly added achievements will work. If the user does not have the achievements mod installed and enabled, your newly achievements will just silently not do anything. Error free, and easy to manage.</p> <p>Step by step instructions:</p> <ol> <li>Create a new .cs class file, named "AchievementsManager".</li> <li>Replace your new file with the entire contents of the script below.</li> <li>Achievements should be registered on both sides - So call RegisterAchievement as many times as needed in your mod system's Start function.</li> <li>The achievementId should be unique across all mods - It is recommended to use something that is tied to your mod name to ensure it is unique, otherwise it will not be correctly registered.</li> <li>The achievementGraphicCode is a full item or block code. e.g. "gear-rusty" or "clay-fire".</li> <li>To finish setting up your achievement, add the following entries to your .lang file: <ol> <li>"achievement-{achievementId}": "{Achievement name}"</li> <li>"achievement-{achievementId}-desc": "{Achievement description}"</li> <li>(Optional!) "achievement-{achievementId}-desc-undiscovered" : "{Achievement description when not unlocked}"</li> </ol> </li> <li>Achievements can be unlocked or checked on either client side or server side. <ol> <li>Achievements should not be checked before they are unlocked - The unlock function already does this. If the achievement has already been unlocked, nothing happens.</li> </ol> </li> <li>The given script contains <em>no error checking </em>for an invalid achievement id. It is up to you to keep these ids in a static place.</li> <li>If your achievement appears in the Achievements Journal (L) (Requires Achievements mod installed), you have successfully created an achievement.</li> </ol> <div class="spoiler"> <div class="spoiler-toggle">AchievementsManager.cs</div> <div class="spoiler-text"> <pre class="language-csharp"><code>using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using Vintagestory.API.Common;

namespace Achievements { internal class AchievementsManager { static Assembly cachedAchievementsAssembly = null; static MethodInfo registerAchievementMethod = null; static MethodInfo unlockAchievementMethod = null; static MethodInfo isAchievementUnlockedMethod = null;

public static void RegisterAchievement(string modId, string achievementId, string achievementGraphicCode) { if (registerAchievementMethod == null) { Assembly a = GetAchievementsAssembly(); if (a == null) return; Type t = a.GetType("Achievements.AchievementsApi"); registerAchievementMethod = t.GetMethod("RegisterAchievement"); } registerAchievementMethod.Invoke(null, new object[] { modId, achievementId, achievementGraphicCode }); }

public static void UnlockAchievementForPlayer(string achievementId, EntityPlayer player) { if (unlockAchievementMethod == null) { Assembly a = GetAchievementsAssembly(); if (a == null) return; Type t = a.GetType("Achievements.AchievementsApi"); unlockAchievementMethod = t.GetMethod("UnlockAchievementForPlayer"); } unlockAchievementMethod.Invoke(null, new object[] { achievementId, player }); }

public static bool IsAchievementUnlockedForPlayer(string achievementId, EntityPlayer player, bool defaultIfNotInstalled = false) { if (isAchievementUnlockedMethod == null) { Assembly a = GetAchievementsAssembly(); if (a == null) return defaultIfNotInstalled; Type t = a.GetType("Achievements.AchievementsApi"); isAchievementUnlockedMethod = t.GetMethod("IsAchievementUnlockedForPlayer"); } return (bool)isAchievementUnlockedMethod.Invoke(null, new object[] { achievementId, player }); }

static Assembly GetAchievementsAssembly() { if (cachedAchievementsAssembly != null) return cachedAchievementsAssembly; AppDomain cDomain = AppDo

Download

No download link is available for this entry right now.

Ratings & reviews

No ratings yet

Sign in to leave a rating or comment.