Преглед на файлове

Fixed unnecessary row autoincrement

Minor optimizations, too.  We'll check if the achievement exists first
before attempting to register it.
nosoop преди 10 години
родител
ревизия
374554badf
променени са 1 файла, в които са добавени 10 реда и са изтрити 6 реда
  1. 10 6
      scripting/custom_achievements.sp

+ 10 - 6
scripting/custom_achievements.sp

@@ -13,7 +13,7 @@
 #include <stocksoup/log_server>
 #include <stocksoup/tf/tempents_stocks>
 
-#define PLUGIN_VERSION "0.1.0"
+#define PLUGIN_VERSION "0.1.1"
 public Plugin myinfo = {
 	name = "[CSRD] Custom Achievements",
 	author = "nosoop",
@@ -105,18 +105,22 @@ public int Native_RegisterAchievement(Handle hPlugin, int argc) {
 	
 	int achievementStyle = GetNativeCell(2);
 	
-	g_QueryRegisterAchievement.BindString(0, internalName, false);
-	g_QueryRegisterAchievement.BindInt(1, achievementStyle, false);
-	
-	SQL_Execute(g_QueryRegisterAchievement);
-	
+	// Attempt to fetch achievement first, creating it if it doesn't exist.
 	g_QueryGetAchievementIdentifier.BindString(0, internalName, false);
 	SQL_Execute(g_QueryGetAchievementIdentifier);
 	
 	int iAchievement;
 	if (SQL_FetchRow(g_QueryGetAchievementIdentifier)) {
 		iAchievement = SQL_FetchInt(g_QueryGetAchievementIdentifier, 0);
+	} else {
+		g_QueryRegisterAchievement.BindString(0, internalName, false);
+		g_QueryRegisterAchievement.BindInt(1, achievementStyle, false);
+		
+		SQL_Execute(g_QueryRegisterAchievement);
+		
+		iAchievement = SQL_GetInsertId(g_QueryRegisterAchievement);
 	}
+	
 	LogDebug("Achievement '%s' registered under identifier %d", internalName, iAchievement);
 	return iAchievement;
 }