One of the restrictions of stored procs is that they cannot contain use database;
statements. To accomplish what you're looking for, you could run sp_executesql from master and pass in a tsql string that executes sp_executesql in the context of a specific database. Something like this:
--This is the tsql statement that gets executed on a specific user db.
--You would use this to build your "create proc", "alter proc", "create user", etc statements.
DECLARE @InnerSql NVARCHAR(MAX) = 'SELECT DB_NAME()'
DECLARE @DB SYSNAME = 'DatabaseName'
DECLARE @Tsql NVARCHAR(MAX) = '[' + @DB + ']..sp_executesql N''' + @InnerSql + ''''
EXEC sp_executesql @Tsql;