
local UNL = { }
-- ---------------------------------------------------------
--   Name: UnoLimited
--   Author: Garry 98.50% - Megiddo .75% - JamminR .75% - Jay209015(#%) A "Team Ulysses idea
--   Desc: Allows defined groups to spawn past the sbox_max limits.
--   v1 release to Ulysses - v1.1 - Fixed sents (evil garry)
--	 v2 Added group control - ULib 2.4+ required
-- ---------------------------------------------------------





-- ------- Please ask for Team Ulysses assistance editing below this line ----------------




local function LimitReachedProcess( ply, str )
	local c = server_settings.Int( "sbox_max"..str, 0 )
	-- Always allow in single player
	if (SinglePlayer()) then return true end
	
	if ur.limit[str][ply:GetUserGroup()] then
		c = tonumber(ur.limit[str][ply:GetUserGroup()])
	elseif str != "sents" then
		c = server_settings.Int( "sbox_max"..str, 0 )
	else
		return true
	end

	-- Always allow if multiplier is -1
	if c == -1 then return true end

	if ( ply:GetCount( str ) < c || c < 0 ) then return true end

	ply:LimitHit( str )
	return false

end

local function init()
/*---------------------------------------------------------
   Name: gamemode:PlayerSpawnRagdoll( ply, model )
   Desc: Return true if it's allowed 
---------------------------------------------------------*/
function GAMEMODE:PlayerSpawnRagdoll( ply, model )
	if ur.spawn.ragdoll[ply:GetUserGroup()] then
		for k,v in pairs(ur.spawn.ragdoll[ply:GetUserGroup()]) do
			if string.find(v, string.lower(model)) then
				ULib.tsay(ply, "Adminstration Has Blocked Use Of This Ragdoll")
				return false
			end
		end
	end

	return LimitReachedProcess( ply, "ragdolls" )
	
end


/*---------------------------------------------------------
   Name: gamemode:PlayerSpawnProp( ply, model )
   Desc: Return true if it's allowed 
---------------------------------------------------------*/

/*---------------------------------------------------------
   Name: gamemode:PlayerSpawnEffect( ply, model )
   Desc: Return true if it's allowed 
---------------------------------------------------------*/
function GAMEMODE:PlayerSpawnEffect( ply, model )

	return LimitReachedProcess( ply, "effects" )

end

/*---------------------------------------------------------
   Name: gamemode:PlayerSpawnVehicle( ply, model, vname, vtable )
   Desc: Return true if it's allowed 
---------------------------------------------------------*/
function GAMEMODE:PlayerSpawnVehicle( ply, model, vname, vtable )
	if ur.spawn.vehicle[ply:GetUserGroup()] then
		for k,v in pairs(ur.spawn.vehicle[ply:GetUserGroup()]) do
			if string.find(v, string.lower(vname)) then
				ULib.tsay(ply, "Adminstration Has Blocked Use Of This Vehicle")
				return false
			end
		end
	end

	return LimitReachedProcess( ply, "vehicles" )
	
end

function GAMEMODE:PlayerSpawnSENT( ply, name )

	if ur.spawn.sent[ply:GetUserGroup()] then
		for k,v in pairs(ur.spawn.sent[ply:GetUserGroup()]) do
			if string.find(v, string.lower(name)) then
				ULib.tsay(ply, "Adminstration Has Blocked Use Of This SENT")
				return false
			end
		end
	end
	
	return LimitReachedProcess( ply, "sents" )
	
end

/*---------------------------------------------------------
   Name: gamemode:PlayerSpawnNPC( ply, npc_type )
   Desc: Return true if player is allowed to spawn the NPC
---------------------------------------------------------*/
function GAMEMODE:PlayerSpawnNPC( ply, npc_type, equipment )
	if ur.spawn.npc[ply:GetUserGroup()] then
		for k,v in pairs(ur.spawn.npc[ply:GetUserGroup()]) do
			if string.find(v, string.lower(npc_type)) then
				ULib.tsay(ply, "Adminstration Has Blocked Use Of This NPC")
				return false
			end
		end
	end

	return LimitReachedProcess( ply, "npcs" )	
	
end

local meta = FindMetaTable( "Player" )
// Return if there's nothing to add on to
if (!meta) then return end

function meta:CheckLimit( str )

	// No limits in single player
	if (SinglePlayer()) then return true end
	
	local c = tonumber(ur.limit.props[ self:GetUserGroup() ])
	
	if !c then
		c = server_settings.Int( "sbox_max"..str, 0 )
	end

	if ( c < 0 ) then return true end
	if ( self:GetCount( str ) > c-1 ) then self:LimitHit( str ) return false end

	return true

end

end

hook.Add( "Initialize", "LimitInitilize", init )

