--------------------- Polite Notice ---------------------
-- YaLB was created by Daniel Astbury (jnz)            --
-- The source is avaliable to anyone, however          --
-- please do not take it can claim it yours.           --
-- Please follow my example and release your own.      --
-----------------------Thank you-------------------------


Defence_Chance = 0.5
Rules = ""
Website = ""
AutoRotate = {}
AutoRotateTimeout = 120000

function Game_First_Load()
	local block = Find_Block("YaLB")
	if block ~= nil  then
		if block.Keys['Defence_Chance'] ~= nil then
			Defence_Chance = tonumber(block.Keys['Defence_Chance']) / 100
		end
		
		Rules = block.Keys['Rules'] or "None";
		Website = block.Keys['Website'] or "None";
	end
	
	block = Find_Block("AutoAnnounce")
	AutoRotate = {}
	
	if block ~= nil then
		local key = 1
		local x = block.Keys[string.format("%.2d", key)]
		while x ~= nil do
			table.insert(AutoRotate, x)
			key = key + 1
			x = block.Keys[string.format("%.2d", key)]
		end
	end
end

function Load_Game()
	if math.random() < Defence_Chance then
		Console_Input(string.format("msg Base defences have been enabled."))
		Load_Defences()
	else
		Console_Input(string.format("msg Base defences have been disabled."))
	end
end

function db_Load_Defences_Callback(userdata, argc, data, columns)
	local pos = Vector3(tonumber(data[4]), tonumber(data[5]), tonumber(data[6]))
	local obj = Create_Object(data[2], pos)
end

function Load_Defences()
	local map = Get_Current_Map()
	
	db:Query("", "db_Load_Defences_Callback", string.format("SELECT * FROM Defences WHERE Map = '%s';", map))
end