-- This LUA only show you how does Achievements script is linked to this LUA

-- When you dofile the Achievements lua, it return the init function which can be called when you're already set up all of your code. Should be called on last line
-- You can also call Achievements.Functions.Init, it would berhave same
local Init=dofile("sys/lua/achievements.txt")

-- We use the table called "Achievements.List" to insert our list of achievements
-- Those below is just example achievements.

table.insert(Achievements.List,{
	Name="Attack 1 times!",		-- Achievement name
	Desc="Just press left mouse button!",	-- Description shown
	Success="Yay, Achievements 'Attack 1 times!' complete! +500$",	-- Achievements message. Put nil to use default message
	Variable="Attack_Test1",
	CounterVariable="Complete",
	DefaultValue=false,
	Used_Hooks=HOOK_JOIN+HOOK_LEAVE+HOOK_ATTACK,	-- Used Hooks.
	Hooks={
		-- Function to executed on hook occurs
		[HOOK_ATTACK]=function(aid,id)
			if not Achievements[id].Attack_Test1.Complete then
				Achievements[id].Attack_Test1.Complete=true
				parse("setmoney "..id.." "..player(id,"money")+500)
				Achievements.Functions.Done(aid,id)
			end
		end,
		[HOOK_LEAVE]=function(aid,id)
			Achievements[id].Attack_Test1.Complete=false
		end,
		[HOOK_JOIN]=function(aid,id)
			Achievements[id].Attack_Test1.Complete=false
		end
	}
})

table.insert(Achievements.List,{
	Name="You're dead!",
	Desc="Make yourself killed!",
	Success=nil,	-- Use default message
	Variable="DEAD",-- Variable used
	CounterVariable="NULL",
	DefaultValue=0,
	Used_Hooks=HOOK_KILL,
	Hooks={
		[HOOK_KILL]=function(aid,id,pl)
			if Achievements[pl].DEAD.NULL==0 then
				Achievements[pl].DEAD.NULL=1
				Achievements.Functions.Done(aid,pl)
			end
		end
	}
})

addhook("join","load_all_achievements")
function load_all_achievements(id)
	-- Anything is handled(such as usgn check) by the function itself. So just call it
	Achievements.Functions.Load(id)
end

addhook("leave","save_all_achievements")
function save_all_achievements(id)
	-- Anything is handled(such as usgn check) by the function itself. So just call it
	Achievements.Functions.Save(id)
end

addhook("say","list_all_achievements",-32768)
function list_all_achievements(id,txt)
	if txt:find("!my_achievements")==1 then
		local List=Achievements.Functions.List(id)
		for n,v in pairs(List) do
			msg2(id,"\169000255000Name: "..v[1])
			msg2(id,"\169000255000Desc: "..v[2])
		end
		return 1
	end
end
-- Let's call the init function
Init()
-- EOF