Achievements TRULY FIXXED!

I just read Rabidtoaster did stop coding it so I began to fix it.
I don’t know if it’s right to make a third new thread about “Achievements”, but this is truly fixxed and the fans of this should see this.

###############################
###############################
FIXED VERSION OF RABIDTOASTER’S (and other’s) UNOFFICAL ACHIEVEMENTS BY NEKRES ( 4NDY )!

  • Fixed some achievements try to calling global Localplayer()
    Solution: Local[P]layer() not Local[p]layer() with lower case p . WHAT THE FUCK! That is LUA FOR BEGINNERS!

-Fixed some icons showing the pink/purple texture in the achievements panel.

  • Fixed main bug: Try to call
    GAMEMODE:‘OnSpawnMenuOpen’ Failed: sandbox\gamemode\spawnmenu/spawnmenu.lua:66: attempt to call field ‘SpawnMenuOpen’ (a nil value)
    , because ‘achievements’ was re-defined in this addon.
    Solution: Simple. I have just ‘achievements’ changed to ‘CCachievements’ in every *.lua file that existed in this addon folder. That was a annoying job.
    That means, if you want to make your own costum achievements, you will have to write ‘CCachievements’ instead of ‘achievements’.

– Checked all fucking *.lua- files, if they got bugs/errors. HOLY CRAP WAS THAT ANNOYING.
(I also added a little credit achievement :P)
###############################
###############################

DOWNLOAD:
http://www.garrysmod.org/img/?t=dll&id=123091


I have taken my credit in adding a little achievement, so I will at this point just thanks rabidtoaster to make it open source, so I could fix it. :stuck_out_tongue:

Yeah, I wouldn’t use something that was coded by a guy that can’t even spell fixed. But good work, I guess?

You’re right, my english is so poor. I’m very sorry.

Not your fault but,

You’r is actually spelt You’re
Fixed has only one x in it.

I believe, this one was my keyboard’s fault.
I already fixed … uhm… “fixed”
(If you find a mistake in this post, please, don’t post xD)

Was wondering which addon was causing those strange errors when I open or close the spawn menu.

Mystery solved!

hey, I put this folder in Addons, I already got 3 achievements! But when I go see them, I cant find them. Only the normal achievements appear!!! Please help me.

Open the unoffical achievements menu manually with the console command ‘achievements’, go there to options and then choose a different BIND KEY.
(or just bind ‘achievements’ manually.)

[lua]

print( “Converting unofficial achievements to SQLite…” )

local convert = {
[ “ls_suffocation.txt” ] = “suffocation.txt”,
[ “thatsnotatoilet.txt” ] = “thatnotatoilet.txt”
}

local values = {
[ “Meeting The Locals” ] = “list”,
[ “Server Browser” ] = “list”,
[ “Tourist” ] = “list”
}

local oldreg = CCachievements.Register
for _, filename in pairs( file.FindInLua( “achievements/*.lua” ) ) do
local datafile = string.Replace( filename, “.lua”, “.txt” )
datafile = convert[ datafile ] or datafile
if ( file.Exists( “achievements/” … datafile ) ) then
local value = file.Read( “achievements/” … datafile )
function CCachievements.Register( name )
CCachievements.SetValue( name, values[ name ] or “total”, value )
end
include( “achievements/” … filename )
end
end
CCachievements.Register = oldreg

CCachievements.SaveValues()

print( “Convert Completed!” )
[/lua]

Should i type this script to \orangebox\garrysmod\lua\autorun\server\mysqlpdata.lua ?

[lua]

–[[
MySQL PData Replacement by _Undefined

  • Used for sharing player data between servers.
    ]]–

include(“mysqlpdata_config.lua”)

require(“mysqloo”)

– Error handler.
local function DBError(self, err)
if err then
MsgN("PData [DB Error]: " … err)
end
end

– Connect.
local PDataDB = mysqloo.connect(pdatadb_host, pdatadb_user, pdatadb_pass, pdatadb_name, pdatadb_port)
PDataDB.onConnectionFailed = DBError
PDataDB:connect()

– If no connection, stop here.
if not PDataDB:status() == mysqloo.DATABASE_CONNECTED then MsgN(“PData [DB]: Connection failed! (” … err … “)”) return end

local Player = _R.Player
local oldsetpdata = _R.Player.SetPData – Only need to override Set, as Get will always pull from the local database, and be synched.

– Override SetPData to send to MySQL.
function Player:SetPData(key, value)
oldsetpdata(self, key, value) – Keep it local.

MsgN("PData [SQL -> MySQL]: Updating '" .. key .. "' for '" .. self:UniqueID() .. "' with '" .. value .. "'!")

deleteQ = PDataDB:query("DELETE FROM `playerdata` WHERE `uniqueid` = '" .. self:UniqueID() .. "' AND `key` = '" .. key .. "'")
deleteQ.onError = DBError
deleteQ:start()

insertQ = PDataDB:query("INSERT INTO `playerdata` (`uniqueid`, `key`, `value`) VALUES ('" .. self:UniqueID() .. "', '" .. key .. "', '" .. value .. "')")
insertQ.onError = DBError
insertQ:start()

end

– Sync from MySQL to local SQL. Done on a timer, or manually with pdata_mysql2sql.
local function MySQL2SQL()
selectQ = PDataDB:query(“SELECT * FROM playerdata“)
selectQ.onData = function(self, data)
MsgN(“PData [MySQL -> SQL]: Updated '” … data.key … “’ for '” … data.uniqueid … “’ with '” … data.value … “’!”)
key = Format(”%s[%s]”, data.uniqueid, data.key)
sql.Query(“DELETE FROM playerpdata WHERE infoid = " … SQLStr(data.key))
sql.Query(“INSERT INTO playerpdata (infoid, value) VALUES (”…SQLStr(data.key)…”, “…SQLStr(data.value)…”)")
end
selectQ.onError = DBError
selectQ:start()
end

– Sync from local SQL to MySQL. Only done by command, and should be done once on the ititial server.
local function SQL2MySQL()
local data = sql.Query(“select * from playerpdata”)

for _, row in pairs(data) do
	local value = row['value']
	local infoid = row['infoid']
	
	local split = string.Explode("[", infoid)
	
	local uniqueid = split[1]
	local key = string.sub(split[2], 1, -2)
	
	deleteQ = PDataDB:query("DELETE FROM `playerdata` WHERE `uniqueid` = '" .. uniqueid .. "' and `key` = '" .. key .. "'")
	deleteQ.onError = DBError
	deleteQ:start()
	
	insertQ = PDataDB:query("INSERT INTO `playerdata` (`uniqueid`, `key`, `value`) VALUES ('" .. uniqueid .. "', '" .. key .. "', '" .. value .. "')")
	insertQ.onError = DBError
	insertQ:start()
	MsgN("PData [SQL -> MySQL]: Updated '" .. key .. "' for '" .. uniqueid .. "' with '" .. value .. "'!")
end

end

– Create timer to update SQL from MySQL.
timer.Create(“Update_Local_PData”, pdatasync_schedule, 0, function()
MySQL2SQL()
end)

– Command to sync from SQL to MySQL.
concommand.Add(“pdata_sql2mysql”, function(ply, cmd, args)
if not ply:IsSuperAdmin() then return end

if not ply.HasBeenWarned then
	ply.HasBeenWarned = true
	ply:PrintMessage(HUD_PRINTCONSOLE, "WARNING! This command will overwrite anything in the MySQL database with the data in the local SQL database. Are you sure you want to do this? Run this command again to confirm.

")
return
else
ply:PrintMessage(HUD_PRINTCONSOLE, "Updated MySQL with SQL data!
")
SQL2MySQL()
end
end)

– Command to sync from MySQL to SQL. Should be run once on initial server.
concommand.Add(“pdata_mysql2sql”, function(ply, cmd, args)
if not ply:IsSuperAdmin() then return end

if not ply.HasBeenWarned then
	ply.HasBeenWarned = true
	ply:PrintMessage(HUD_PRINTCONSOLE, "WARNING! This command will overwrite anything in the local SQL database with data from the MySQL database. Are you sure you want to do this? Run this command again to confirm.

")
return
else
ply:PrintMessage(HUD_PRINTCONSOLE, "Updated SQL with MySQL data!
")
MySQL2SQL()
end
end)

function getUserData(i)

local meta = FindMetaTable(“Player”);

function meta:getUserData(i)
D = i:getData()[1]
if(D == nil)then
//RunQuery(“INSERT INTO players ( Steam, Name, Points, Status) VALUES ( 1, ‘2’, 0, 0)”)
RunQuery(“INSERT INTO players ( Steam, Name, Points, Status) VALUES ( “…self:UniqueID()…”, '”…self:Nick()…"’, 0, 0)")
else

end

end
end

function RunQuery(q)

local query1 = database:query(q)
query1:start()
end

function FirstSpawn( ply )

local query1 = database:query("SELECT * FROM players WHERE Steam = "…ply:UniqueID())
query1.onSuccess = getUserData
query1:start()
end

hook.Add( “PlayerInitialSpawn”, “mhsPointsInit”, FirstSpawn )

print( “Converting unofficial achievements to SQLite…” )

local convert = {
[ “ls_suffocation.txt” ] = “suffocation.txt”,
[ “thatsnotatoilet.txt” ] = “thatnotatoilet.txt”
}

local values = {
[ “Meeting The Locals” ] = “list”,
[ “Server Browser” ] = “list”,
[ “Tourist” ] = “list”
}

local oldreg = CCachievements.Register
for _, filename in pairs( file.FindInLua( “achievements/*.lua” ) ) do
local datafile = string.Replace( filename, “.lua”, “.txt” )
datafile = convert[ datafile ] or datafile
if ( file.Exists( “achievements/” … datafile ) ) then
local value = file.Read( “achievements/” … datafile )
function CCachievements.Register( name )
CCachievements.SetValue( name, values[ name ] or “total”, value )
end
include( “achievements/” … filename )
end
end
CCachievements.Register = oldreg

CCachievements.SaveValues()

print( “Convert Completed!” )

[/lua]

And i typed achievements to console But nothing happened…

anyone?

This is fully clientside, until you make AddCSLuaFile(“For/all/lua/files/needed/without/*.lua/filename/behind”) in a autorun file so players who connect to your server gets the files.

How do i use it for TTT servers?

Sanks you wery much!