--------------------- 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-------------------------


function Load_Scripts()
	Register_Script("YaLB_Killed", "", YaLB_Killed)
	Register_Script("YaLB_Gameover", "time", YaLB_Gameover)
	Register_Script("YaLB_Boot", "reason", YaLB_Boot)
	Register_Script("YaLB_Building_Sounds", "", YaLB_Building_Sounds)
	Register_Script("YaLB_Building_Damage", "", YaLB_Building_Damage)
	
end


BuildingDISounds = {
	{"m00bnpp_hlth0001i1evan_snd.wav", "m00bgpp_hlth0001i1evag_snd.wav"},
	{"m00bnhn_hlth0001i1evan_snd.wav", "m00bgib_hlth0001i1evag_snd.wav"},
	{"m00bnaf_hlth0001i1evan_snd.wav", "m00bgwf_hlth0001i1evag_snd.wav"},
	{"m00bntr_hlth0001i1evan_snd.wav", "m00bgtr_hlth0001i1evag_snd.wav"},
	{"m00bncc_hlth0001i1evan_snd.wav", "m00bgcc_hlth0001i1evag_snd.wav"},
	{"m00bnrf_hlth0001i1evan_snd.wav", "m00bgrf_hlth0001i1evag_snd.wav"},
	{"                              ", "                              "},
	{"m00bnhp_hlth0001i1evan_snd.wav", "m00bghp_hlth0001i1evag_snd.wav"},
	{"m00bncy_hlth0001i1evan_snd.wav", "m00bgcy_hlth0001i1evag_snd.wav"},
	{"m00bnol_hlth0001i1evan_snd.wav", "m00bgat_hlth0001i1evag_snd.wav"}}

YaLB_Killed = {}
function YaLB_Killed:Killed(ID, obj, killer)
	if Is_A_Star(killer) then
		Vet_Killed(killer, obj)
	end
	
	if Is_A_Star(obj) then
		if obj == killer then
			IRC_Sendc('p', "%s%.2d%s commited suicide.%s", string.char(3), Get_TeamIRCColour(Get_Team(Get_Player_ID(obj))), Pretty_Player(obj), string.char(3))
			return
		end
		if killer == 0 then
			IRC_Sendc('p', "%s%.2d%s has died.%s", string.char(3), Get_TeamIRCColour(Get_Team(Get_Player_ID(obj))), Pretty_Player(obj), string.char(3))
			return
		end
		if Is_A_Star(killer) then
			IRC_Sendc('p', "%s%.2d%s was killed by %s%s", string.char(3), Get_TeamIRCColour(Get_Team(Get_Player_ID(killer))), Pretty_Player(obj), Pretty_Player(killer), string.char(3))
		else
			IRC_Sendc('p', "%s%.2d%s was killed by the %s%s", string.char(3), Get_TeamIRCColour(Get_Object_Type(killer)), Pretty_Player(obj), Get_Translated_Preset_Name(killer), string.char(3))
		end		
	elseif Is_Vehicle(obj) then
		local driver = Get_Vehicle_Driver(obj)
		if Is_A_Star(killer) then
			if driver ~= 0 then
				IRC_Sendc('p', "%s%.2d%s's %s was destroyed by %s%s", string.char(3), Get_TeamIRCColour(Get_Team(Get_Player_ID(killer))), Get_Player_Name(driver), Get_Translated_Preset_Name(obj), Pretty_Player(killer), string.char(3))
			else
				IRC_Sendc('p', "%s%.2dA %s was destroyed by %s%s", string.char(3), Get_TeamIRCColour(Get_Team(Get_Player_ID(killer))), Get_Translated_Preset_Name(obj), Pretty_Player(killer), string.char(3))
			end
		elseif Is_Vehicle(killer) then
			if driver ~= 0 then
				IRC_Sendc('p', "%s%.2d%s's %s was destroyed by the %s%s", string.char(3), Get_TeamIRCColour(Get_Object_Type(killer)), Get_Player_Name(driver), Get_Translated_Preset_Name(obj), Get_Translated_Preset_Name(killer), string.char(3))
			else
				IRC_Sendc('p', "%s%.2dA %s was destroyed by the %s%s", string.char(3), Get_TeamIRCColour(Get_Object_Type(killer)), Get_Translated_Preset_Name(obj), Get_Translated_Preset_Name(killer), string.char(3))
			end
		elseif Is_Building(killer) then
			if driver ~= 0 then
				IRC_Sendc('p', "%s%.2d%s's %s was destroyed by the %s%s", string.char(3), Get_TeamIRCColour(Get_Object_Type(killer)), Get_Player_Name(driver), Get_Translated_Preset_Name(obj), Get_Building_Name(killer), string.char(3))
			else
				IRC_Sendc('p', "%s%.2dA %s was destroyed by the %s%s", string.char(3), Get_TeamIRCColour(Get_Object_Type(killer)), Get_Translated_Preset_Name(obj), Get_Building_Name(killer), string.char(3))
			end
		end
	elseif Is_Building(obj) and killer ~= 0 then
		IRC_Sendc('p', "%s%.2dThe %s was destroyed by %s%s", string.char(3), Get_TeamIRCColour(Get_Team(Get_Player_ID(killer))), Get_Building_Name(obj), Pretty_Player(killer), string.char(3))
	end
end


YaLB_Gameover = {}
function YaLB_Gameover:Created(ID, obj)
	Start_Timer(ID, obj, tonumber(Get_String_Parameter(ID, obj, "time")), 0)
end

function YaLB_Gameover:Timer_Expired(ID, obj, num)
	Console_Input("gameover")
end




YaLB_Boot = {}
function YaLB_Boot:Created(ID, obj)

	Console_Inputf("pamsg %d %s", Get_Player_ID(obj), Get_String_Parameter(ID, obj, "reason"))
	Start_Timer(ID, obj, 0, 0)
end

function YaLB_Boot:Timer_Expired(ID, obj, num)
	local nick = Get_Player_Name(obj)
	Console_Inputf("kick %d", Get_Player_ID(obj))
	Console_Inputf("allow %s", nick)
end




YaLB_Building_Sounds = {}
function YaLB_Building_Sounds:Created(ID, o)
	Start_Timer(ID, o, 1, 0)
end

function YaLB_Building_Sounds:Timer_Expired(ID, o, n)
	if n == 1 then
		Start_Timer(ID, o, 1, 0)
		return
	end
	
	if (Get_Health(o) + Get_Shield_Strength(o)) / (Get_Max_Health(o) + Get_Max_Shield_Strength(o)) <= 0.2 then
		local bld_type = Building_Type(o)
		if bld_type == nil or bld_type == -1 then
			Destroy_Script(ID, o)
			return
		end
		
		local bld_team = Get_Object_Type(o)
		if bld_team ~= 0 and bld_team ~= 1 then
			Destroy_Script(ID, o)
			return
		end
		
		Console_Inputf("sndt %d %s", bld_team, BuildingDISounds[bld_type+1][bld_team+1])
	
		Start_Timer(ID, o, 30, 1)
	else
		Start_Timer(ID, o, 1, 0)
	end
end

YaLB_Building_Damage = {}
function YaLB_Building_Damage:Damaged(ID, o, Damager, Damage)
	Vet_Damaged(Damager, o, Damage)
end