local hobo = {}
local police = {}
local sek = {}
local gang = {}
local thief = {}
local dog = {}

timer.Simple(0, function()
	hobo[TEAM_HOBO] = true
	hobo[TEAM_HOBOKING] = true

	police[TEAM_POLICE] = true
	police[TEAM_CHIEF] = true

	sek[TEAM_SEK] = true
	sek[TEAM_SEKSNIPER] = true
	sek[TEAM_SEKLEADER] = true

	gang[TEAM_GANGSTER] = true
	gang[TEAM_GANGSTERBOSS] = true
	gang[TEAM_MAFIOSO] = true
	gang[TEAM_MAFIABOSS] = true
	gang[TEAM_REBEL] = true
	gang[TEAM_REBELBOSS] = true

	thief[TEAM_THIEF] = true
	thief[TEAM_MASTERTHIEF] = true

	dog[TEAM_STRAY] = true
	dog[TEAM_POLICEDOG] = true
end)

-- Kategorie: Allgemein

if SERVER then
	local fists = {
		["weapon_fists"] = true,
	}

	-- Diese 2 Hooks sind geteilt für alle Kategorien, um Leistung zu sparen.
	hook.Add("EntityTakeDamage", "MG_LevelSys:Skill", function(ply, dmg)
		local att = dmg:GetAttacker()
		local infl = dmg:GetInflictor()
		local att_is_ply = att:IsPlayer()
		local is_ply = ply:IsPlayer()
		local hitgroup = dmg:IsExplosionDamage() and HITGROUP_CHEST or dmg:IsFallDamage() and HITGROUP_LEFTLEG or dmg:IsBulletDamage() and is_ply and ply:LastHitGroup() or HITGROUP_CHEST
		local att_team, ply_team

		local mult = 1

		if att_is_ply then
			att_team = att_team or att:Team()

			if infl:IsValid() and infl:IsWeapon() then
				local class = infl:GetClass()
				local typ = infl.WeaponType

				if fists[class] then
					if att.ComboAttack then

						-- general_fists_combo

						local skill = att:getSkillPercentage("general_fists_combo")
						if skill > 0 then
							mult = mult + skill
						end
					else

						-- general_fists_dmg

						local skill = att:getSkillPercentage("general_fists_dmg")
						if skill > 0 then
							mult = mult + skill
						end
					end

					-- refinery_dealmaker

					if att_team == TEAM_REFFINERY and ply:GetClass() == "zrush_fuelbuyer_npc" then
						local skill = att:getSkillPercentage("refinery_dealmaker") 
						if skill > 0 then
							if math.Rand(0, 100) <= (skill * 100) then
								for i=1, #zrush.Fuel do
									zrush.f.FuelBuyer_SellFuel(ply, att, i)
								end

								zrush.f.FuelBuyer_DirectSell(ply, att)
							end
						end
					end
				end

				-- general_dmg_pistol

				if typ == "pistol" then
					local skill = att:getSkillPercentage("general_dmg_pistol")
					if skill > 0 then
						mult = mult + skill
					end
				end

				-- general_dmg_revolver

				if typ == "revolver" then
					local skill = att:getSkillPercentage("general_dmg_revolver")
					if skill > 0 then
						mult = mult + skill
					end
				end

				-- general_dmg_assault

				if typ == "assault" then
					local skill = att:getSkillPercentage("general_dmg_assault")
					if skill > 0 then
						mult = mult + skill
					end
				end

				-- general_melee_dull

				if typ == "melee_dull" then
					local skill = att:getSkillPercentage("general_melee_dull")
					if skill > 0 then
						mult = mult + skill
					end
				end

				-- general_melee_sharp

				if typ == "melee_sharp" then
					local skill = att:getSkillPercentage("general_melee_sharp")
					if skill > 0 then
						mult = mult + skill
					end
				end

				-- general_dmg_body_sniper

				if typ == "sniper" then
					if hitgroup != HITGROUP_HEAD then
						local skill = att:getSkillPercentage("general_dmg_body_sniper")
						if skill > 0 then
							mult = mult + skill
						end
					end
				end

				-- terror_melee_sharp

				if att_team == TEAM_TERROR and typ == "melee_sharp" then
					local skill = att:getSkillPercentage("terror_melee_sharp")
					if skill > 0 then
						mult = mult + skill
					end
				end

				-- miner_pickaxe_dmg

				if att_team == TEAM_MINER and class == "mining_pickaxe" then
					local skill = att:getSkillPercentage("miner_pickaxe_dmg")
					if skill > 0 then
						mult = mult + skill
					end
				end

				-- hitman_dmg_melee_sharp

				if att_team == TEAM_HITMAN and typ == "melee_sharp" then
					local skill = att:getSkillPercentage("hitman_dmg_melee_sharp")
					if skill > 0 then
						mult = mult + skill
					end
				end

				if is_ply then
					ply_team = ply_team or att:Team()

					-- sek_res

					if sek[ply_team] then
						if typ == "melee_sharp" then
							local skill =  ply:getSkillPercentage("sek_res") 
							if skill > 0 then
								if (ply.SkillNegate or 0) <= CurTime() then
									ply.SkillNegate = CurTime() + 40
									mult = mult - skill
								end
							end
						end
					end

					-- sek_dmg

					if sek[att_team] then
						local skill = att:getSkillPercentage("sek_dmg")
						if skill > 0 then
							if MG_IsLight(infl.Category) or MG_IsHeavy(infl.Category) then
								mult = mult + skill
							else
								mult = mult - skill
							end
						end
					end
				end
			end

			-- general_dmg_rage

			if att:Health() < 20 then
				local skill = att:getSkillPercentage("general_dmg_rage")
				if skill > 0 then
					mult = mult + skill
				end
			end

			-- general_dmg_crit

			local skill = att:getSkillPercentage("general_dmg_crit") 
			if skill > 0 then
				if math.Rand(0, 100) <= (skill * 100) then
					mult = mult + 1.5
				end
			end

			att_team = att_team or att:Team()

			-- dog_dmg

			if dog[att_team] then
				local skill = att:getSkillPercentage("dog_dmg")
				if skill > 0 then
					mult = mult + skill
				end
			end

			-- gang_dmg

			if gang[att_team] then
				if att:isWanted() then
					local skill = att:getSkillPercentage("gang_dmg") 
					if skill > 0 then
						mult = mult + skill
					end
				end
			end
		end

		if is_ply then
			ply_team = ply_team or ply:Team()

			-- general_def_head

			if hitgroup and hitgroup == HITGROUP_HEAD then
				local skill = ply:getSkillPercentage("general_def_head") 
				if skill > 0 then
					mult = mult - skill
				end
			end

			-- terror_dmg_exp

			if tm == TEAM_TERROR then
				local skill = ply:getSkillPercentage("terror_def_exp") 
				if skill > 0 then
					mult = mult - skill
				end
			end

			if att_is_ply then
				att_team = att_team or att:Team()

				-- hitman_dmg_dist

				if att_team == TEAM_HITMAN and att:getHitTarget() == ply then
					local skill = att:getSkillPercentage("hitman_dmg_dist") 
					if skill > 0 then
						if (att:EyePos():Distance(ply:GetPos()) * 0.0254) >= 20 then
							mult = mult + skill
						end
					end
				end

				-- police_dmg_wanted

				if police[att_team] then
					if ply:isWanted() then
						local skill = att:getSkillPercentage("police_dmg_wanted") 
						if skill > 0 then
							mult = mult + skill
						end
					end
				end

				-- police_res_cuffs

				if police[ply_team] then
					if (ply.SkillProtection or 0) >= CurTime() then
						local skill = ply:getSkillPercentage("police_res_cuffs") 
						if skill > 0 then
							mult = mult - skill
						end
					end
				end
				
				-- sek_equipspeed

				if sek[ply_team] then
					ply.SkillDamage = CurTime() + 6
				end

				-- dog_dmg_hunger

				if dog[ply_team] then
					if ply.HM_TakingDamage then
						local skill = ply:getSkillPercentage("dog_dmg_hunger") 
						if skill > 0 then
							mult = mult - skill
						end
					end
				end
			end
		end

		dmg:ScaleDamage(mult)
	end, HOOK_MONITOR_HIGH or -2)

	hook.Add("MG_Lib_BonusStats", "MG_LevelSys:Skill", function(ply, job_tbl)

		-- general_jumppower

		local skill = 1 + ply:getSkillPercentage("general_jumppower")
		if skill > 1 then
			ply:SetJumpPower(ply:GetJumpPower() * skill)
		end

		-- general_walkspeed

		local skill = 1 + ply:getSkillPercentage("general_walkspeed")
		if skill > 1 then
			local run_spd = ply:GetRunSpeed()
			local walk_spd = ply:GetWalkSpeed()
			local new_speed = walk_spd * skill
			if walk_spd == run_spd then
				ply:SetRunSpeed(run_spd * skill)
			end
			ply:SetWalkSpeed(walk_spd * skill)
		end

		-- general_runspeed

		local skill = 1 + ply:getSkillPercentage("general_runspeed")
		if skill > 1 then
			ply:SetRunSpeed(ply:GetRunSpeed() * skill)
		end

		-- general_crouchspeed

		local skill = 1 + ply:getSkillPercentage("general_crouchspeed")
		if skill > 1 then
			ply:SetCrouchedWalkSpeed(ply:GetCrouchedWalkSpeed() * skill)
		end

		local tm = ply:Team()

		-- citizen_runspeed

		if tm == TEAM_CITIZEN then
			local skill = 1 + ply:getSkillPercentage("citizen_runspeed")
			if skill > 1 then
				ply:SetRunSpeed(ply:GetRunSpeed() * skill)
			end
		end

		-- priest_runspeed

		if tm == TEAM_CITIZEN and os.date("%a", os.time()) == "Sun" then
			local skill = 1 + ply:getSkillPercentage("priest_runspeed")
			if skill > 1 then
				ply:SetRunSpeed(ply:GetRunSpeed() * skill)
			end
		end

		-- hobo_runspeed

		if tm == TEAM_CITIZEN then
			local skill = 1 + ply:getSkillPercentage("hobo_runspeed")
			if skill > 1 then
				ply:SetRunSpeed(ply:GetRunSpeed() * skill)
			end
		end

		if ply:Armor() <= 0 then

			-- hobo_armor

			if hobo[tm] then
				local skill = 1 + ply:getSkillPercentage("hobo_armor")
				if skill > 1 then
					if math.Rand(0, 100) <= (skill * 100) then
						ply:SetArmor(math.min(ply:Armor() + 10, 100))
					end
				end
			end

			if tm == TEAM_SECRETSERVICE then

				-- ss_armor

				local skill = 100 * ply:getSkillPercentage("ss_armor")
				if skill > 0 then
					ply:SetArmor(math.min(ply:Armor() + skill, 100))
				end

				-- ss_armor2

				local skill = 100 * ply:getSkillPercentage("ss_armor2")
				if skill > 0 then
					ply:SetArmor(math.min(ply:Armor() + skill, 100))
				end
			end

			-- security_armor

			if tm == TEAM_SECURITY then
				local skill = 100 * ply:getSkillPercentage("security_armor")
				if skill > 0 then
					ply:SetArmor(math.min(ply:Armor() + skill, 100))
				end
			end
		end
	end)

	hook.Add("MG_SalaryOverride", "MG_LevelSys:Skill", function(ply, salary)
		local mult = 1

		-- general_loan

		local skill = ply:getSkillPercentage("general_loan")
		if skill > 0 then
			mult = mult + skill
		end

		-- citizen_loan

		local skill = ply:getSkillPercentage("citizen_loan")
		if skill > 0 then
			mult = mult + skill
		end

		-- priest_loan

		local skill = ply:getSkillPercentage("priest_loan")
		if skill > 0 then
			mult = mult + skill
		end

		return salary * mult
	end)

	-- general_xp

	hook.Add("MG_LevelSys:AddXP", "MG_LevelSys:Skill", function(ply, amount)
		local mult = 1

		local skill = ply:getSkillPercentage("general_xp")
		if skill > 0 then
			mult = mult + skill
		end

		local skill = ply:getSkillPercentage("general_xp2")
		if skill > 0 then
			mult = mult + skill
		end

		local skill = ply:getSkillPercentage("general_xp3")
		if skill > 0 then
			mult = mult + skill
		end

		local skill = ply:getSkillPercentage("general_xp4")
		if skill > 0 then
			mult = mult + skill
		end

		return amount * mult
	end)

	hook.Add("MG_LevelSys:TimerXP", "MG_LevelSys:Skill", function(ply, amount)
		local job_tbl = ply:getJobTable()

		local skill = 1 + ply:getSkillPercentage("general_xp_time")
		if skill > 1 then
			amount = amount * skill
		end

		return amount
	end)

	hook.Add("MG_LevelSys:SkillPercentageMult", "MG_LevelSys:Skill", function(ply, amount, id, skip, update)
		if skip or update or id == "general_%mult" or id == "general_%mult2" then return end

		local mult = 1

		local skill = ply:getSkillPercentage("general_%mult")
		if skill > 0 then
			mult = mult + skill
		end

		local skill = ply:getSkillPercentage("general_%mult2")
		if skill > 0 then
			mult = mult + skill
		end

		return amount * mult
	end)

	hook.Add("GlorifiedBanking.InterestModifier", "MG_LevelSys:Skill", function(ply, amount)
		local mult = 1

		local skill = ply:getSkillPercentage("general_steueroase")
		if skill > 0 then
			mult = mult + skill
		end

		return math.floor(amount * mult)
	end)

	hook.Add("GlorifiedBanking.MaxInterestModifier", "MG_LevelSys:Skill", function(ply, amount)
		local mult = 1

		local skill = ply:getSkillPercentage("general_investor")
		if skill > 0 then
			mult = mult + skill
		end

		local skill = ply:getSkillPercentage("general_investor2")
		if skill > 0 then
			mult = mult + skill
		end

		local skill = ply:getSkillPercentage("general_investor3")
		if skill > 0 then
			mult = mult + skill
		end

		return math.floor(amount * mult)
	end)
end

hook.Add("M9K_DeployMultiplier", "MG_LevelSys:Skill", function(self, speed)
	local ply = self:GetOwner()
	if !IsValid(ply) then return end

	local tm = ply:Team()

	if sek[tm] and (ply.SkillDamage or 0) > CurTime() then

		-- sek_equipspeed

		local skill = 1 + ply:getSkillPercentage("sek_equipspeed")
		if skill > 1 then
			speed = speed * skill
		end
	elseif tm == TEAM_CHIEF then

		-- chief_equipspeed

		local skill = 1 + ply:getSkillPercentage("chief_equipspeed")
		if skill > 1 then
			speed = speed * skill
		end
	end

	return speed
end)

hook.Add("M9K_ConeMultiplier", "MG_LevelSys:Skill", function(self, cone)
	local ply = self:GetOwner()
	if !IsValid(ply) then return end

	if self.GetPredictedAiming then
		if self:GetPredictedAiming() then

			-- general_precision_aim

			local skill = 1 - ply:getSkillPercentage("general_precision_aim")
			if skill < 1 then
				cone = cone * skill
			end
		else

			-- general_precision_hip

			local skill = 1 - ply:getSkillPercentage("general_precision_hip")
			if skill < 1 then
				cone = cone * skill
			end
		end
	end

	return cone
end)

hook.Add("M9K_RecoilMultiplier", "MG_LevelSys:Skill", function(self, recoil)
	local ply = self:GetOwner()
	if !IsValid(ply) then return end

	if self.GetPredictedAiming then
		if self:GetPredictedAiming() then

			-- general_recoil_aim

			local skill = 1 - ply:getSkillPercentage("general_recoil_aim")
			if skill < 1 then
				recoil = recoil * skill
			end
		else

			-- general_recoil_hip

			local skill = 1 - ply:getSkillPercentage("general_recoil_hip")
			if skill < 1 then
				recoil = recoil * skill
			end
		end
	end

	return recoil
end)

-- general_reload_shotgun

hook.Add("M9K_ShotgunReloadMultiplier", "MG_LevelSys:Skill", function(self, speed)
	local ply = self:GetOwner()
	if !IsValid(ply) then return end

	local skill = 1 - ply:getSkillPercentage("general_reload_shotgun")
	if skill < 1 then
		speed = speed * skill
	end

	return speed
end)

-- general_reload

hook.Add("M9K_ReloadMultiplier", "MG_LevelSys:Skill", function(self, speed)
	local ply = self:GetOwner()
	if !IsValid(ply) then return end

	local skill = 1 + ply:getSkillPercentage("general_reload")
	if skill > 1 then
		speed = speed * skill
	end

	return speed
end)

-- general_regen

if SERVER then
	hook.Add("DarkRP_HealSpeed", "MG_LevelSys:Skill", function(ply, speed)
		local skill = 1 - ply:getSkillPercentage("general_regen")
		if skill < 1 then
			speed = speed * skill
		end

		return speed
	end)
end

-- general_friendly_fire

if SERVER then
	hook.Add("Party_DamageScale", "MG_LevelSys:Skill", function(attacker, target, scale)
		local skill = attacker:getSkillPercentage("general_friendly_fire")
		if skill > 0 then
			scale = scale - skill
		end

		return scale
	end)
end

if SERVER then
	hook.Add("Cuffs_ModifyCuffs", "MG_LevelSys:Skill", function(ply, cuffs, target)

		local tm = ply:Team()

		if ply:isCP() then

			-- sb_cuffs

			if IsValid(target) and target:IsPlayer() then
				local skill = 1 - ply:getSkillPercentage("sb_cuffs")
				if skill < 1 and cuffs.GetCuffTime then
					local time = cuffs:GetCuffTime() - CurTime()
					time = time * skill
					cuffs:SetCuffTime(CurTime() + time)
				end
			end
		elseif gang[tm] then

			-- gang_cuffs_speed

			if IsValid(target) and target:IsPlayer() then
				if !target:isCP() then
					local skill = 1 - ply:getSkillPercentage("gang_cuffs_speed")
					if skill < 1 and cuffs.GetCuffTime then
						local time = cuffs:GetCuffTime() - CurTime()
						time = time * skill
						cuffs:SetCuffTime(CurTime() + time)
					end
				end
			end
		elseif tm == TEAM_ZOLL then

			-- sb_cuffs

			if IsValid(target) and target:IsPlayer() then
				local skill = 1 - ply:getSkillPercentage("sb_cuffs")
				if skill < 1 and cuffs.GetCuffTime then
					local time = cuffs:GetCuffTime() - CurTime()
					time = time * skill
					cuffs:SetCuffTime(CurTime() + time)
				end
			end
		end
	end)
end

hook.Add("Cuffs_BreakStrength", "MG_LevelSys:Skill", function(ply, strength, wep)
	if IsValid(wep:GetFriendBreaking()) then return end

	local tm = ply:Team()

	if gang[tm] then

		-- gang_cuffs_free

		local skill = 1 + ply:getSkillPercentage("gang_cuffs_free")
		if skill > 1 then
			str2 = strength * skill
			return str2
		end
	end
end)

hook.Add("Cuffs_RegenSpeed", "MG_LevelSys:Skill", function(ply, strength, wep)
	if IsValid(wep:GetFriendBreaking()) then return end

	local tm = ply:Team()

	if gang[tm] then

		-- gang_cuffs_free

		local skill = 1 + ply:getSkillPercentage("gang_cuffs_free")
		if skill > 1 then
			str2 = strength * skill
			return str2
		end
	end
end)

-- general_alcoholic

if SERVER then
	hook.Add("drug_killuser", "MG_LevelSys:Skill", function(ply, class, cur, death)
		if class == "drug_alcohol" and cur > death then
			local skill = 1 + ply:getSkillPercentage("general_alcoholic")
			if skill > 1 then
				cur = cur - CurTime()
				death = death - CurTime()
				death = death * (1 + ply:getSkillPercentage("general_alcoholic"))
				if cur <= death then
					return false
				end
			end
		end
	end)
end

-- general_prepared

hook.Add("r_player", "MG_LevelSys:Skill", function(ply)
	if ply:Alive() and ply:Armor() < 100 then
		local skill = 100 * ply:getSkillPercentage("general_prepared")
		if skill > 0 then
			ply:SetArmor(math.min(ply:Armor() + skill, 100))
		end
	end
end)

hook.Add("g_player", "MG_LevelSys:Skill", function(ply)
	if ply:Alive() and ply:Armor() < 100 then
		local skill = 100 * ply:getSkillPercentage("general_prepared")
		if skill > 0 then
			ply:SetArmor(math.min(ply:Armor() + skill, 100))
		end
	end
end)

hook.Add("checkerCheckTime", "MG_LevelSys:Skill", function(wep, owner, length)
	if owner:isCP() then

		-- sb_checker

		local skill = 1 - owner:getSkillPercentage("sb_checker")
		if skill < 1 then
			length = length * skill
			return length
		end
	elseif owner:Team() == TEAM_SECURITY then

		-- security_checker

		local skill = 1 - owner:getSkillPercentage("security_checker")
		if skill < 1 then
			length = length * skill
			return length
		end
	end
end)

-- Kategorie: Banker

-- banker_printer

if SERVER then
	hook.Add("MoneyPrinter_TakeMoney", "MG_LevelSys:Skill_Banker", function(ply, ent)
		if ply:Team() == TEAM_BANKER then
			local skill = 1 - ply:getSkillPercentage("banker_printer")
			if skill < 1 then
				ent.SpeedMod = skill
				ent.SpeedModTime = CurTime() + 600
			end
		end
	end)

	hook.Add("MoneyPrinter_ManipulateDelay", "MG_LevelSys:Skill_Banker", function(ent, delay)
		if ent.SpeedMod and (ent.SpeedModTime or 0) > CurTime() then
			delay = delay * ent.SpeedMod
			return delay
		end
	end)
end

-- banker_safe

if SERVER then
	hook.Add("MoneyPot_ReceiveMoney", "MG_LevelSys:Skill_Banker", function(ent, money)
		local owner = ent.CPPIGetOwner and ent:CPPIGetOwner()
		if owner:IsPlayer() and owner:Team() == TEAM_BANKER then
			local skill = owner:getSkillPercentage("banker_safe")
			if skill > 0 then
				ent.ProductionTime = 60
				ent.ProductionValue = skill
				ent.ProductionMaxMoney = 100000
				ent:SetNWInt("Production", CurTime() + ent.ProductionTime)
			end
		end
	end)
end

-- Kategorie: Gärtner

-- gardener_growth

if SERVER then
	hook.Add("Farming_ModifyGrowthSpeed", "MG_LevelSys:Skill_Gardener", function(ent, growth)
		local owner = ent:Getowning_ent()
		if owner:IsPlayer() and owner:Team() == TEAM_GARDENER then
			if ent:GetSize() < 100 then
				local skill = 1 - owner:getSkillPercentage("gardener_growth")
				if skill < 1 then
					growth = growth * skill
					return growth
				end
			end
		end
	end)
end

-- gardener_sprinkler

if SERVER then
	hook.Add("Farming_Water", "MG_LevelSys:Skill_Gardener", function(ent)
		local owner = ent:Getowning_ent()
		if owner:IsPlayer() and owner:Team() == TEAM_GARDENER then
			local skill = owner:getSkillPercentage("gardener_sprinkler") 
			if skill > 0 then
				if math.Rand(0, 100) <= (skill * 100) then
					for k, v in pairs(owner.GardenerPlots or {}) do
						if !IsValid(k) or k:GetID() < 1 then continue end
						k:Water()
					end
				end
			end
		end
	end)
end

-- Kategorie: Ölraffinerist

-- refinery_oilmult

if SERVER then
	hook.Add("zrush_CreateDrillHole", "MG_LevelSys:Skill_Refinery", function(ent, hole, ply)
		if IsValid(ply) and ply:Team() == TEAM_REFFINERY then
			local skill = 1 + ply:getSkillPercentage("refinery_oilmult")
			if skill > 1 then
				hole:SetOilAmount(hole:GetOilAmount() * skill)
			end
		end
	end)
end

-- Kategorie: Bergmann

-- miner_pickaxe_speed

hook.Add("Mining_PickaxeSpeed", "MG_LevelSys:Skill_Miner", function(wep, speed)
	local owner = wep:GetOwner()
	if owner:IsPlayer() and owner:Team() == TEAM_MINER then
		local skill = 1 - owner:getSkillPercentage("miner_pickaxe_speed")
		if skill < 1 then
			speed = speed * skill
			return speed
		end
	end
end)

-- Kategorie: Methkoch

-- methcook_ace

hook.Add("canPrintWeaponName", "MG_LevelSys:Skill_Methcook", function(wep, ply, name, is_illegal)
	if is_illegal and ply:Team() == TEAM_METHCOOK then
		local skill = ply:getSkillPercentage("methcook_ace")
		if skill > 0 then
			if math.Rand(0, 100) <= (skill * 100) then
				return false
			end
		end
	end
end)

-- methcook_calc

hook.Add("zmlab_InsertAluminium", "MG_LevelSys:Skill_Methcook", function(combiner, ent, amt)
	local owner = combiner:Getowning_ent()
	if owner:IsPlayer() and owner:Team() == TEAM_METHCOOK and (combiner:GetAluminium() + 1) < combiner:GetNeedAluminium() then
		local skill = owner:getSkillPercentage("methcook_calc")
		if skill > 0 then
			if math.Rand(0, 100) <= (skill * 100) then
				return amt + 1
			end
		end
	end
end)

-- Kategorie: Drogenhändler

-- dealer_connections

if SERVER then
	hook.Add("WeedPlant_ModifySellDelay", "MG_LevelSys:Skill_Dealer", function(ent, delay)
		local owner = ent:Getowning_ent()
		if owner:IsPlayer() and owner:Team() == TEAM_DEALER then
			local skill = 1 - owner:getSkillPercentage("dealer_connections")
			if skill < 1 then
				delay = delay * skill
				return delay
			end
		end
	end)
end

-- dealer_multitasker

if SERVER then
	hook.Add("WeedPlant_Water", "MG_LevelSys:Skill_Dealer", function(ent)
		local owner = ent:Getowning_ent()
		if owner:IsPlayer() and owner:Team() == TEAM_DEALER then
			local skill = owner:getSkillPercentage("dealer_multitasker") 
			if skill > 0 then
				if math.Rand(0, 100) <= (skill * 100) then
					for k, v in pairs(owner.WeedPlants or {}) do
						if !IsValid(k) or k:GetDead() then continue end
						k:Water()
					end
				end
			end
		end
	end)
end

-- dealer_empire

if SERVER then
	hook.Add("WeedPlant_ModifyMoneyAmount", "MG_LevelSys:Skill_Dealer", function(ent, money)
		local owner = ent:Getowning_ent()
		if owner:IsPlayer() and owner:Team() == TEAM_DEALER then
			local skill = 1 + owner:getSkillPercentage("dealer_empire")
			if skill > 1 then
				money = money * skill
				return money
			end
		end
	end)
end

-- Kategorie: Obdachlose

-- hobo_hoarder

if SERVER then
	hook.Add("Dumpster_Speed", "MG_LevelSys:Skill_Hobo", function(ent, ply, speed)
		local tm = ply:Team()
		if hobo[tm] then
			local skill = 1 - ply:getSkillPercentage("hobo_hoarder")
			if skill < 1 then
				speed = speed * skill
				return speed
			end
		end
	end)
end

-- hobo_pee

hook.Add("InitializePeeSWEP", "MG_LevelSys:Skill_Hobo", function(wep, ply)
	local tm = ply:Team()
	if hobo[tm] then
		local skill = 1 + ply:getSkillPercentage("hobo_pee")
		if skill > 1 then
			local extended = wep.Primary.ClipSize * skill
			wep.Primary.ClipSize = extended
			wep.Primary.DefaultClip = extended
			wep:SetClip1(extended)
		end
	end
end)

-- Kategorie: Mechaniker

-- mechanic_magic

if SERVER then
	hook.Add("VC_playerRepairedPart", "MG_LevelSys:Skill_Mechanic", function(ply, ent)
		if ply:Team() == TEAM_REPAIR then
			if table.IsEmpty(ent:VC_getDamagedParts()) then return end

			local skill = ply:getSkillPercentage("mechanic_magic") 
			if skill > 0 then
				if math.Rand(0, 100) <= (skill * 100) then
					ent:VC_repairFull_Admin()
				end
			end
		end
	end)
end

-- mechanic_fuel

hook.Add("MG_VMod_FuelSpeed", "MG_LevelSys:Skill_Mechanic", function(wep, speed)
	local owner = wep:GetOwner()
	if owner:IsPlayer() and owner:Team() == TEAM_REPAIR then
		local skill = 1 - owner:getSkillPercentage("mechanic_fuel") 
		if skill < 1 then
			speed = speed * skill
			return speed
		end
	end
end)

-- Kategorie: Bürgermeister

-- mayor_taxes

if SERVER then
	hook.Add("Economy_ApplyTaxes", "MG_LevelSys:Skill_Mayor", function(ply, taxes, amount)
		for _, v in ipairs(EconomyConfig.HasMayor) do
			local skill = v:getSkillPercentage("mayor_taxes")
			if skill > 0 then
				local taxes = math.floor(taxes * skill)
				if taxes > 0 then
					v:addMoney(taxes)
				end
			end
		end
	end)
end

-- mayor_communityfield

hook.Add("OnPlayerChangedTeam", "MG_LevelSys:Skill_Mayor", function(ply, o, n)
	if !EconomyConfig or o == n then return end
	if n == EconomyConfig.MayorTeam and EconomyConfig.EconomyBank < 50000 then
		local skill = ply:getSkillPercentage("mayor_communityfield") 
		if skill > 0 then
			local amount = math.floor(100 * skill)
			if amount > 0 then
				EconomyConfig.EconomyBank = EconomyConfig.EconomyBank + amount
				EconomyFunctions.SyncBank()
			end
		end
	end
end)

-- Kategorie: Polizist & Wachtmeister

-- police_res_cuffs

hook.Add("Cuffs_OnPlayerHandcuffing", "MG_LevelSys:Skill_CP", function(ply, target)
	local tm = ply:Team()
	if police[tm] then
		if target:isCP() then return end

		ply.SkillProtection = CurTime() + 2
	end
end)

-- police_taser

hook.Add("onPlayerTasered", "MG_LevelSys:Skill_CP", function(ply, target)
	local tm = ply:Team()
	if police[tm] then
		ply.SkillHit = true
	end
end)

hook.Add("onPlayerUsed", "MG_LevelSys:Skill_CP", function(ply, target)
	local tm = ply:Team()
	if police[tm] then
		ply.SkillHit = nil
	end
end)

hook.Add("taserRecharge", "MG_LevelSys:Skill_CP", function(wep, length)
	local owner = wep:GetOwner()
	if !owner:IsValid() or !owner.SkillHit then return end
	local tm = owner:Team()
	if police[tm] then
		local skill = 1 - owner:getSkillPercentage("police_taser")
		if skill < 1 then
			length = length * skill
			return length
		end
	end
end)

-- Kategorie: SEKs

if SERVER then
	hook.Add("ArmoryAddArmor", "MG_LevelSys:Skill_SEK", function(ply, armor)
		local tm = ply:Team()
		if sek[tm] then
			local skill = 1 + ply:getSkillPercentage("sek_armor")
			if skill > 1 then
				armor = armor * skill
				return armor
			end
		end
	end)
end

-- Kategorie: Organisierte Gangs

-- gang_keypad

hook.Add("KeypadCrackTime", "MG_LevelSys:Skill_Gang", function(ply, wep, speed)
	if gang[ply:Team()] then
		local skill = 1 - ply:getSkillPercentage("gang_keypad")
		if skill < 1 then
			speed = speed * skill
			return speed
		end
	end
end)

-- gang_robber

if SERVER then
	hook.Add("getMoneyWorthForRobbing", "MG_LevelSys:Skill_Gang", function(ply, worth, ent)
		if gang[ply:Team()] then
			local skill = 1 + ply:getSkillPercentage("gang_robber")
			if skill > 1 then
				worth = worth * skill
				return worth
			end
		end
	end)
end

-- Kategorie: Diebe

-- thief_caution

if SERVER then
	hook.Add("MG_DoorUpgrade_PreStartAlarm", "MG_LevelSys:Skill_Thief", function(ply, ent)
		if thief[ply:Team()] then
			local skill = 1 + ply:getSkillPercentage("thief_caution")
			if skill > 1 then
				if math.Rand(0, 100) <= (skill * 100) then
					return false
				end
			end
		end
	end)
end

-- thief_stealspeed

hook.Add("pickPocketTime", "MG_LevelSys:Skill_Thief", function(wep, length)
	local owner = wep:GetOwner()
	if owner:IsValid() and thief[owner:Team()] then
		local skill = 1 - owner:getSkillPercentage("thief_stealspeed")
		if skill < 1 then
			length = length * skill
			return length
		end
	end
end)

-- thief_lockpick_speed

hook.Add("lockpickTimeDoor", "MG_LevelSys:Skill_Thief", function(ply, ent, speed)
	if thief[ply:Team()] then
		local skill = 1 - ply:getSkillPercentage("thief_lockpick_speed")
		if skill < 1 then
			speed = speed * skill
			return speed
		end
	end
end)

-- thief_lockpick_sound

hook.Add("DarkRP_LockpickVolume", "MG_LevelSys:Skill_Thief", function(wep, volume)
	local owner = wep:GetOwner()
	if owner:IsPlayer() and thief[owner:Team()] then
		local ent = wep:GetLockpickEnt()
		if ent:IsValid() and ent:isDoor() then
			local skill = 1 - owner:getSkillPercentage("thief_lockpick_sound")
			if skill < 1 then
				volume = volume * skill
				return volume
			end
		end
	end
end)

-- Kategorie: Hunde

-- dog_hunger

if SERVER then
	hook.Add("Hungermod_HungerCycle", "MG_LevelSys:Skill_Dog", function(ply)
		if dog[ply:Team()] then
			local skill = ply:getSkillPercentage("dog_hunger")
			if skill > 0 then
				if math.Rand(0, 100) <= (skill * 100) then
					return false
				end
			end
		end
	end)
end
